Skip to content

Commit

Permalink
[ios][android] Update react-native-svg to 13.9.0 (expo#22934)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanjhughes authored Jun 16, 2023
1 parent f5fa30f commit bca4fbd
Show file tree
Hide file tree
Showing 76 changed files with 1,676 additions and 996 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class ExponentPackage : ReactPackage {
nativeModules.add(RNCWebViewModule(reactContext))
nativeModules.add(NetInfoModule(reactContext))
nativeModules.add(RNSharedElementModule(reactContext))
nativeModules.addAll(SvgPackage().createNativeModules(reactContext))
nativeModules.addAll(SvgPackage().getNativeModuleIterator(reactContext).map { it.module })
nativeModules.addAll(MapsPackage().createNativeModules(reactContext))
nativeModules.addAll(RNDateTimePickerPackage().createNativeModules(reactContext))
nativeModules.addAll(stripePackage.createNativeModules(reactContext))
Expand Down
37 changes: 12 additions & 25 deletions android/vendored/unversioned/react-native-svg/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ buildscript {
mavenCentral()
google()
}

dependencies {
classpath("com.android.tools.build:gradle:3.6.1")
classpath "com.diffplug.spotless:spotless-plugin-gradle:5.15.0"
classpath("com.android.tools.build:gradle:7.4.2")
classpath "com.diffplug.spotless:spotless-plugin-gradle:6.17.0"
}
}
}
Expand Down Expand Up @@ -39,7 +39,10 @@ def safeExtGet(prop, fallback) {

android {
compileSdkVersion safeExtGet('compileSdkVersion', 28)

def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
if (agpVersion.tokenize('.')[0].toInteger() >= 7) {
namespace "com.horcrux.svg"
}
// Used to override the NDK path/version on internal CI or by allowing
// users to customize the NDK path/version from their root project (e.g. for M1 support)
if (rootProject.hasProperty("ndkPath")) {
Expand All @@ -54,20 +57,18 @@ android {
//noinspection OldTargetApi
targetSdkVersion safeExtGet('targetSdkVersion', 28)
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()

consumerProguardFiles 'proguard-rules.pro'
}
lintOptions {
abortOnError false
}

sourceSets.main {
java {
if (isNewArchitectureEnabled()) {
srcDirs += [
"src/fabric/java",
]
} else {
if (!isNewArchitectureEnabled()) {
srcDirs += [
"src/paper/java",
"src/paper/java",
"build/generated/source/codegen/java"
]
}
Expand All @@ -86,19 +87,5 @@ repositories {
}

dependencies {
if (isNewArchitectureEnabled()) {
implementation project(":packages:react-native:ReactAndroid")
} else {
implementation 'com.facebook.react:react-native:+'
}
}

if (isNewArchitectureEnabled()) {
react {
reactRoot = rootProject.file("../node_modules/react-native/")
jsRootDir = file("../src/fabric/")
codegenDir = rootProject.file("../node_modules/react-native-codegen/")
libraryName = "rnsvg"
codegenJavaPackageName = "com.horcrux.rnsvg"
}
implementation 'com.facebook.react:react-native:+'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-keep public class com.horcrux.svg.** {*;}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.graphics.Path;
import com.facebook.react.bridge.Dynamic;
import com.facebook.react.bridge.ReactContext;
import java.util.ArrayList;

@SuppressLint("ViewConstructor")
class CircleView extends RenderableView {
Expand Down Expand Up @@ -79,6 +80,28 @@ Path getPath(Canvas canvas, Paint paint) {
double r = relativeOnOther(mR);

path.addCircle((float) cx, (float) cy, (float) r, Path.Direction.CW);

elements = new ArrayList<>();
elements.add(
new PathElement(
ElementType.kCGPathElementMoveToPoint, new Point[] {new Point(cx, cy - r)}));
elements.add(
new PathElement(
ElementType.kCGPathElementAddLineToPoint,
new Point[] {new Point(cx, cy - r), new Point(cx + r, cy)}));
elements.add(
new PathElement(
ElementType.kCGPathElementAddLineToPoint,
new Point[] {new Point(cx + r, cy), new Point(cx, cy + r)}));
elements.add(
new PathElement(
ElementType.kCGPathElementAddLineToPoint,
new Point[] {new Point(cx, cy + r), new Point(cx - r, cy)}));
elements.add(
new PathElement(
ElementType.kCGPathElementAddLineToPoint,
new Point[] {new Point(cx - r, cy), new Point(cx, cy - r)}));

return path;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.graphics.RectF;
import com.facebook.react.bridge.Dynamic;
import com.facebook.react.bridge.ReactContext;
import java.util.ArrayList;

@SuppressLint("ViewConstructor")
class EllipseView extends RenderableView {
Expand Down Expand Up @@ -98,6 +99,27 @@ Path getPath(Canvas canvas, Paint paint) {
new RectF((float) (cx - rx), (float) (cy - ry), (float) (cx + rx), (float) (cy + ry));
path.addOval(oval, Path.Direction.CW);

elements = new ArrayList<>();
elements.add(
new PathElement(
ElementType.kCGPathElementMoveToPoint, new Point[] {new Point(cx, cy - ry)}));
elements.add(
new PathElement(
ElementType.kCGPathElementAddLineToPoint,
new Point[] {new Point(cx, cy - ry), new Point(cx + rx, cy)}));
elements.add(
new PathElement(
ElementType.kCGPathElementAddLineToPoint,
new Point[] {new Point(cx + rx, cy), new Point(cx, cy + ry)}));
elements.add(
new PathElement(
ElementType.kCGPathElementAddLineToPoint,
new Point[] {new Point(cx, cy + ry), new Point(cx - rx, cy)}));
elements.add(
new PathElement(
ElementType.kCGPathElementAddLineToPoint,
new Point[] {new Point(cx - rx, cy), new Point(cx, cy - ry)}));

return path;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.view.View;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReadableMap;
import java.util.ArrayList;
import javax.annotation.Nullable;

@SuppressLint("ViewConstructor")
Expand Down Expand Up @@ -72,13 +73,15 @@ void draw(final Canvas canvas, final Paint paint, final float opacity) {
setupGlyphContext(canvas);
clip(canvas, paint);
drawGroup(canvas, paint, opacity);
renderMarkers(canvas, paint, opacity);
}

void drawGroup(final Canvas canvas, final Paint paint, final float opacity) {
pushGlyphContext();
final SvgView svg = getSvgView();
final GroupView self = this;
final RectF groupRect = new RectF();
elements = new ArrayList<>();
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
if (child instanceof MaskView) {
Expand All @@ -96,6 +99,7 @@ void drawGroup(final Canvas canvas, final Paint paint, final float opacity) {
int count = node.saveAndSetupCanvas(canvas, mCTM);
node.render(canvas, paint, opacity * mOpacity);
RectF r = node.getClientRect();

if (r != null) {
groupRect.union(r);
}
Expand All @@ -109,6 +113,11 @@ void drawGroup(final Canvas canvas, final Paint paint, final float opacity) {
if (node.isResponsible()) {
svg.enableTouchEvents();
}

if (node.elements != null) {
elements.addAll(node.elements);
}

} else if (child instanceof SvgView) {
SvgView svgView = (SvgView) child;
svgView.drawChildren(canvas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.graphics.Path;
import com.facebook.react.bridge.Dynamic;
import com.facebook.react.bridge.ReactContext;
import java.util.ArrayList;

@SuppressLint("ViewConstructor")
class LineView extends RenderableView {
Expand Down Expand Up @@ -96,6 +97,13 @@ Path getPath(Canvas canvas, Paint paint) {

path.moveTo((float) x1, (float) y1);
path.lineTo((float) x2, (float) y2);

elements = new ArrayList<>();
elements.add(
new PathElement(ElementType.kCGPathElementMoveToPoint, new Point[] {new Point(x1, y1)}));
elements.add(
new PathElement(ElementType.kCGPathElementAddLineToPoint, new Point[] {new Point(x2, y2)}));

return path;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ void renderMarker(

markerTransform.reset();
Point origin = position.origin;
markerTransform.setTranslate((float) origin.x * mScale, (float) origin.y * mScale);
markerTransform.setTranslate((float) origin.x, (float) origin.y);

double markerAngle = "auto".equals(mOrient) ? -1 : Double.parseDouble(mOrient);
float degrees = 180 + (float) (markerAngle == -1 ? position.angle : markerAngle);
markerTransform.preRotate(degrees);

boolean useStrokeWidth = "strokeWidth".equals(mMarkerUnits);
if (useStrokeWidth) {
markerTransform.preScale(strokeWidth, strokeWidth);
markerTransform.preScale(strokeWidth / mScale, strokeWidth / mScale);
}

double width = relativeOnWidth(mMarkerWidth) / mScale;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@
package com.horcrux.svg;

import android.annotation.SuppressLint;
import android.graphics.Matrix;
import com.facebook.common.logging.FLog;
import com.facebook.react.bridge.Dynamic;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.common.ReactConstants;
import javax.annotation.Nullable;

@SuppressLint("ViewConstructor")
class MaskView extends GroupView {
Expand All @@ -32,14 +27,6 @@ class MaskView extends GroupView {
@SuppressWarnings({"FieldCanBeLocal", "unused"})
private Brush.BrushUnits mMaskContentUnits;

private static final float[] sRawMatrix =
new float[] {
1, 0, 0,
0, 1, 0,
0, 0, 1
};
private Matrix mMatrix = null;

public MaskView(ReactContext reactContext) {
super(reactContext);
}
Expand Down Expand Up @@ -128,24 +115,6 @@ public void setMaskContentUnits(int maskContentUnits) {
invalidate();
}

public void setMaskTransform(@Nullable ReadableArray matrixArray) {
if (matrixArray != null) {
int matrixSize = PropHelper.toMatrixData(matrixArray, sRawMatrix, mScale);
if (matrixSize == 6) {
if (mMatrix == null) {
mMatrix = new Matrix();
}
mMatrix.setValues(sRawMatrix);
} else if (matrixSize != -1) {
FLog.w(ReactConstants.TAG, "RNSVG: Transform matrices must be of size 6");
}
} else {
mMatrix = null;
}

invalidate();
}

@Override
void saveDefinition() {
if (mName != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public PathView(ReactContext reactContext) {
public void setD(String d) {
mPath = PathParser.parse(d);
elements = PathParser.elements;
for (PathElement elem : elements) {
for (Point point : elem.points) {
point.x *= mScale;
point.y *= mScale;
}
}
invalidate();
}

Expand Down
Loading

0 comments on commit bca4fbd

Please sign in to comment.