Skip to content

fix: update extended component for DefsView #2674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion android/src/main/java/com/horcrux/svg/DefsView.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
import android.annotation.SuppressLint;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.view.View;
import com.facebook.react.bridge.ReactContext;

@SuppressLint("ViewConstructor")
class DefsView extends DefinitionView {
class DefsView extends RenderableView {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DefinitionView is the exact fit for Defs; instead of changing it to Renderable, we should move the necessary functions from Renderable to Definition.


public DefsView(ReactContext reactContext) {
super(reactContext);
Expand All @@ -24,6 +25,11 @@ public DefsView(ReactContext reactContext) {
@Override
void draw(Canvas canvas, Paint paint, float opacity) {}

@Override
Path getPath(Canvas canvas, Paint paint) {
return null;
}

void saveDefinition() {
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
Expand Down
24 changes: 24 additions & 0 deletions apps/common/test/Test2615.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {Svg, Defs, Pattern, Path, Rect} from 'react-native-svg';

export default function Test2615() {
return (
<Svg color={'red'}>
<Defs>
<Pattern
id={'pattern'}
patternUnits="userSpaceOnUse"
width={9}
height={9}>
<Path d="M -1,2 l 6,0" stroke="currentColor" strokeWidth={3} />
</Pattern>
</Defs>
<Rect
x={0}
y={0}
width="100%"
height="100%"
fill={`url(#${'pattern'})`}
/>
</Svg>
);
}
28 changes: 28 additions & 0 deletions apps/common/test/Test2616.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {Defs, G, Path, Pattern, Rect, Svg} from 'react-native-svg';

export default function IconWithHexAlpha() {
return (
<Svg height={'500'} width={'500'}>
<Defs>
<Pattern
id={'pattern'}
patternUnits="userSpaceOnUse"
width={9}
height={9}>
<G stroke="#00000030" strokeWidth={3}>
<Path d="M0,9 l9,-9" />
<Path d="M-1,1 l2,-2" />
<Path d="M8,10 l2,-2" />
</G>
</Pattern>
</Defs>
<Rect
x={0}
y={0}
width="100%"
height="100%"
fill={`url(#${'pattern'})`}
/>
</Svg>
);
}
2 changes: 2 additions & 0 deletions apps/common/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import Test2417 from './Test2417';
import Test2455 from './Test2455';
import Test2471 from './Test2471';
import Test2520 from './Test2520';
import Test2615 from './Test2615';
import Test2616 from './Test2616';

export default function App() {
return <ColorTest />;
Expand Down
Loading