From bca4fbd3e8f2be22d0d7e21114f09c9ebbb0c453 Mon Sep 17 00:00:00 2001 From: Alan Hughes <30924086+alanjhughes@users.noreply.github.com> Date: Fri, 16 Jun 2023 13:40:14 +0100 Subject: [PATCH] [ios][android] Update react-native-svg to 13.9.0 (#22934) --- .../host/exp/exponent/ExponentPackage.kt | 2 +- .../react-native-svg/android/build.gradle | 37 +- .../android/proguard-rules.pro | 1 + .../main/java/com/horcrux/svg/CircleView.java | 23 ++ .../java/com/horcrux/svg/EllipseView.java | 22 ++ .../main/java/com/horcrux/svg/GroupView.java | 9 + .../main/java/com/horcrux/svg/LineView.java | 8 + .../main/java/com/horcrux/svg/MarkerView.java | 4 +- .../main/java/com/horcrux/svg/MaskView.java | 31 -- .../main/java/com/horcrux/svg/PathView.java | 6 + .../horcrux/svg/RNSVGRenderableManager.java | 52 ++- .../main/java/com/horcrux/svg/RectView.java | 17 + .../java/com/horcrux/svg/RenderableView.java | 37 +- .../horcrux/svg/RenderableViewManager.java | 152 ++------- .../main/java/com/horcrux/svg/SVGLength.java | 4 +- .../main/java/com/horcrux/svg/SvgPackage.java | 318 ++++++++++++++++-- .../main/java/com/horcrux/svg/SvgView.java | 13 +- .../java/com/horcrux/svg/SvgViewManager.java | 186 +++++++++- .../java/com/horcrux/svg/SvgViewModule.java | 15 +- .../java/com/horcrux/svg/VirtualView.java | 83 +++-- .../RNSVGMaskManagerDelegate.java | 3 - .../RNSVGMaskManagerInterface.java | 1 - .../RNSVGSvgViewAndroidManagerDelegate.java | 168 +++++++++ .../RNSVGSvgViewAndroidManagerInterface.java | 61 ++++ .../RNSVGSvgViewManagerDelegate.java | 74 ---- .../RNSVGSvgViewManagerInterface.java | 29 -- .../svg/NativeSvgRenderableModuleSpec.java | 57 ++++ .../horcrux/svg/NativeSvgViewModuleSpec.java | 28 ++ apps/bare-expo/ios/Podfile.lock | 4 +- apps/bare-expo/package.json | 2 +- apps/native-component-list/package.json | 2 +- dev-home-config.json | 2 +- ios/Podfile.lock | 4 +- .../react-native-svg/RNSVG.podspec.json | 4 +- .../apple/Elements/RNSVGClipPath.mm | 12 +- .../apple/Elements/RNSVGDefs.mm | 12 +- .../apple/Elements/RNSVGForeignObject.mm | 12 +- .../apple/Elements/RNSVGGroup.mm | 12 +- .../apple/Elements/RNSVGImage.h | 9 +- .../apple/Elements/RNSVGImage.mm | 132 +++++--- .../apple/Elements/RNSVGLinearGradient.mm | 12 +- .../apple/Elements/RNSVGMarker.mm | 12 +- .../apple/Elements/RNSVGMask.h | 1 - .../apple/Elements/RNSVGMask.mm | 28 +- .../apple/Elements/RNSVGPath.mm | 12 +- .../apple/Elements/RNSVGPattern.mm | 15 +- .../apple/Elements/RNSVGRadialGradient.mm | 12 +- .../apple/Elements/RNSVGSvgView.h | 8 +- .../apple/Elements/RNSVGSvgView.mm | 48 ++- .../apple/Elements/RNSVGSymbol.mm | 12 +- .../apple/Elements/RNSVGUse.mm | 12 +- .../react-native-svg/apple/RNSVGNode.h | 8 +- .../react-native-svg/apple/RNSVGNode.mm | 19 +- .../react-native-svg/apple/RNSVGRenderable.mm | 4 +- .../apple/RNSVGRenderableModule.h | 21 ++ .../apple/RNSVGRenderableModule.mm | 219 ++++++++++++ .../apple/RNSVGSvgViewModule.h | 21 ++ .../apple/RNSVGSvgViewModule.mm | 94 ++++++ .../apple/Shapes/RNSVGCircle.mm | 12 +- .../apple/Shapes/RNSVGEllipse.mm | 12 +- .../apple/Shapes/RNSVGLine.mm | 12 +- .../apple/Shapes/RNSVGRect.mm | 12 +- .../react-native-svg/apple/Text/RNSVGTSpan.mm | 12 +- .../react-native-svg/apple/Text/RNSVGText.mm | 12 +- .../apple/Text/RNSVGTextPath.mm | 12 +- .../apple/Text/RNSVGTopAlignedLabel.h | 1 + .../apple/Utils/RNSVGCGFCRule.h | 3 +- .../apple/Utils/RNSVGFabricConversions.h | 3 + .../apple/ViewManagers/RNSVGMaskManager.mm | 1 - .../apple/ViewManagers/RNSVGNodeManager.mm | 131 +------- .../ViewManagers/RNSVGRenderableManager.mm | 173 ---------- .../apple/ViewManagers/RNSVGSvgViewManager.mm | 57 ---- .../apple/ViewManagers/RNSVGTextManager.mm | 1 - packages/expo-stories/package.json | 2 +- packages/expo/bundledNativeModules.json | 2 +- yarn.lock | 8 +- 76 files changed, 1676 insertions(+), 996 deletions(-) create mode 100644 android/vendored/unversioned/react-native-svg/android/proguard-rules.pro create mode 100644 android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewAndroidManagerDelegate.java create mode 100644 android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewAndroidManagerInterface.java delete mode 100644 android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewManagerDelegate.java delete mode 100644 android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewManagerInterface.java create mode 100644 android/vendored/unversioned/react-native-svg/android/src/paper/java/com/horcrux/svg/NativeSvgRenderableModuleSpec.java create mode 100644 android/vendored/unversioned/react-native-svg/android/src/paper/java/com/horcrux/svg/NativeSvgViewModuleSpec.java create mode 100644 ios/vendored/unversioned/react-native-svg/apple/RNSVGRenderableModule.h create mode 100644 ios/vendored/unversioned/react-native-svg/apple/RNSVGRenderableModule.mm create mode 100644 ios/vendored/unversioned/react-native-svg/apple/RNSVGSvgViewModule.h create mode 100644 ios/vendored/unversioned/react-native-svg/apple/RNSVGSvgViewModule.mm diff --git a/android/expoview/src/main/java/versioned/host/exp/exponent/ExponentPackage.kt b/android/expoview/src/main/java/versioned/host/exp/exponent/ExponentPackage.kt index d8146b3f59b2e..c47cbbca14140 100644 --- a/android/expoview/src/main/java/versioned/host/exp/exponent/ExponentPackage.kt +++ b/android/expoview/src/main/java/versioned/host/exp/exponent/ExponentPackage.kt @@ -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)) diff --git a/android/vendored/unversioned/react-native-svg/android/build.gradle b/android/vendored/unversioned/react-native-svg/android/build.gradle index 5d38f6d8e9f1b..5dfc225ad32cb 100644 --- a/android/vendored/unversioned/react-native-svg/android/build.gradle +++ b/android/vendored/unversioned/react-native-svg/android/build.gradle @@ -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" } } } @@ -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")) { @@ -54,6 +57,8 @@ android { //noinspection OldTargetApi targetSdkVersion safeExtGet('targetSdkVersion', 28) buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() + + consumerProguardFiles 'proguard-rules.pro' } lintOptions { abortOnError false @@ -61,13 +66,9 @@ android { sourceSets.main { java { - if (isNewArchitectureEnabled()) { - srcDirs += [ - "src/fabric/java", - ] - } else { + if (!isNewArchitectureEnabled()) { srcDirs += [ - "src/paper/java", + "src/paper/java", "build/generated/source/codegen/java" ] } @@ -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:+' } diff --git a/android/vendored/unversioned/react-native-svg/android/proguard-rules.pro b/android/vendored/unversioned/react-native-svg/android/proguard-rules.pro new file mode 100644 index 0000000000000..19f9ddebfcaa0 --- /dev/null +++ b/android/vendored/unversioned/react-native-svg/android/proguard-rules.pro @@ -0,0 +1 @@ +-keep public class com.horcrux.svg.** {*;} diff --git a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/CircleView.java b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/CircleView.java index e31664e203734..3caccec683e03 100644 --- a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/CircleView.java +++ b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/CircleView.java @@ -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 { @@ -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; } } diff --git a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/EllipseView.java b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/EllipseView.java index 2f91d13de360f..73b5df8c73b34 100644 --- a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/EllipseView.java +++ b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/EllipseView.java @@ -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 { @@ -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; } } diff --git a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/GroupView.java b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/GroupView.java index 4b0a88adf7c72..a17c1bdf263bc 100644 --- a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/GroupView.java +++ b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/GroupView.java @@ -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") @@ -72,6 +73,7 @@ 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) { @@ -79,6 +81,7 @@ void drawGroup(final Canvas canvas, final Paint paint, final float opacity) { 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) { @@ -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); } @@ -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); diff --git a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/LineView.java b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/LineView.java index d927f4578aa1b..4832443f78104 100644 --- a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/LineView.java +++ b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/LineView.java @@ -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 { @@ -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; } } diff --git a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/MarkerView.java b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/MarkerView.java index 9ea9403bed327..a78949ac3ce6b 100644 --- a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/MarkerView.java +++ b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/MarkerView.java @@ -160,7 +160,7 @@ 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); @@ -168,7 +168,7 @@ void renderMarker( boolean useStrokeWidth = "strokeWidth".equals(mMarkerUnits); if (useStrokeWidth) { - markerTransform.preScale(strokeWidth, strokeWidth); + markerTransform.preScale(strokeWidth / mScale, strokeWidth / mScale); } double width = relativeOnWidth(mMarkerWidth) / mScale; diff --git a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/MaskView.java b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/MaskView.java index 8b974fce9853e..c91503aa5da92 100644 --- a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/MaskView.java +++ b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/MaskView.java @@ -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 { @@ -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); } @@ -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) { diff --git a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/PathView.java b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/PathView.java index eaa4c918b550e..06829bd00dbde 100644 --- a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/PathView.java +++ b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/PathView.java @@ -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(); } diff --git a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/RNSVGRenderableManager.java b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/RNSVGRenderableManager.java index 87d2480c0c1bb..712c4f268911a 100644 --- a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/RNSVGRenderableManager.java +++ b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/RNSVGRenderableManager.java @@ -19,30 +19,35 @@ import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.WritableMap; +import com.facebook.react.module.annotations.ReactModule; +import com.horcrux.rnsvg.NativeSvgRenderableModuleSpec; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import javax.annotation.Nonnull; -class RNSVGRenderableManager extends ReactContextBaseJavaModule { +@ReactModule(name = RNSVGRenderableManager.NAME) +class RNSVGRenderableManager extends NativeSvgRenderableModuleSpec { RNSVGRenderableManager(ReactApplicationContext reactContext) { super(reactContext); } + public static final String NAME = "RNSVGRenderableModule"; + @Nonnull @Override public String getName() { - return "RNSVGRenderableManager"; + return NAME; } @SuppressWarnings("unused") @ReactMethod(isBlockingSynchronousMethod = true) - public boolean isPointInFill(int tag, ReadableMap options) { - RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag); + @Override + public boolean isPointInFill(Double tag, ReadableMap options) { + RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag.intValue()); if (svg == null) { return false; } @@ -57,8 +62,9 @@ public boolean isPointInFill(int tag, ReadableMap options) { @SuppressWarnings("unused") @ReactMethod(isBlockingSynchronousMethod = true) - public boolean isPointInStroke(int tag, ReadableMap options) { - RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag); + @Override + public boolean isPointInStroke(Double tag, ReadableMap options) { + RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag.intValue()); if (svg == null) { return false; } @@ -82,8 +88,9 @@ public boolean isPointInStroke(int tag, ReadableMap options) { @SuppressWarnings("unused") @ReactMethod(isBlockingSynchronousMethod = true) - public float getTotalLength(int tag) { - RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag); + @Override + public double getTotalLength(Double tag) { + RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag.intValue()); if (svg == null) { return 0; } @@ -103,8 +110,9 @@ public float getTotalLength(int tag) { @SuppressWarnings("unused") @ReactMethod(isBlockingSynchronousMethod = true) - public WritableMap getPointAtLength(int tag, ReadableMap options) { - RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag); + @Override + public WritableMap getPointAtLength(Double tag, ReadableMap options) { + RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag.intValue()); if (svg == null) { return Arguments.createMap(); } @@ -137,8 +145,9 @@ public WritableMap getPointAtLength(int tag, ReadableMap options) { @SuppressWarnings("unused") @ReactMethod(isBlockingSynchronousMethod = true) - public WritableMap getBBox(int tag, ReadableMap options) { - RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag); + @Override + public WritableMap getBBox(Double tag, ReadableMap options) { + RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag.intValue()); if (svg == null) { return Arguments.createMap(); } @@ -187,15 +196,20 @@ public WritableMap getBBox(int tag, ReadableMap options) { @SuppressWarnings("unused") @ReactMethod(isBlockingSynchronousMethod = true) - public WritableMap getCTM(int tag) { - RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag); + @Override + public WritableMap getCTM(Double tag) { + RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag.intValue()); if (svg == null) { return Arguments.createMap(); } float scale = svg.mScale; Matrix ctm = new Matrix(svg.mCTM); - Matrix invViewBoxMatrix = svg.getSvgView().mInvViewBoxMatrix; + SvgView svgView = svg.getSvgView(); + if (svgView == null) { + throw new RuntimeException("Did not find parent SvgView for view with tag: " + tag); + } + Matrix invViewBoxMatrix = svgView.mInvViewBoxMatrix; ctm.preConcat(invViewBoxMatrix); float[] values = new float[9]; @@ -213,8 +227,9 @@ public WritableMap getCTM(int tag) { @SuppressWarnings("unused") @ReactMethod(isBlockingSynchronousMethod = true) - public WritableMap getScreenCTM(int tag) { - RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag); + @Override + public WritableMap getScreenCTM(Double tag) { + RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag.intValue()); if (svg == null) { return Arguments.createMap(); } @@ -234,6 +249,7 @@ public WritableMap getScreenCTM(int tag) { } @ReactMethod + @Override public void getRawResource(String name, Promise promise) { try { ReactApplicationContext context = getReactApplicationContext(); diff --git a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/RectView.java b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/RectView.java index a146b2d487056..ec6128b036df2 100644 --- a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/RectView.java +++ b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/RectView.java @@ -16,6 +16,7 @@ import android.os.Build; import com.facebook.react.bridge.Dynamic; import com.facebook.react.bridge.ReactContext; +import java.util.ArrayList; @SuppressLint("ViewConstructor") class RectView extends RenderableView { @@ -170,6 +171,22 @@ Path getPath(Canvas canvas, Paint paint) { path.close(); // Ensure isSimplePath = false such that rect doesn't become represented using // integers } + + elements = new ArrayList<>(); + elements.add( + new PathElement(ElementType.kCGPathElementMoveToPoint, new Point[] {new Point(x, y)})); + elements.add( + new PathElement( + ElementType.kCGPathElementAddLineToPoint, new Point[] {new Point(x + w, y)})); + elements.add( + new PathElement( + ElementType.kCGPathElementAddLineToPoint, new Point[] {new Point(x + w, y + h)})); + elements.add( + new PathElement( + ElementType.kCGPathElementAddLineToPoint, new Point[] {new Point(x, y + h)})); + elements.add( + new PathElement(ElementType.kCGPathElementAddLineToPoint, new Point[] {new Point(x, y)})); + return path; } } diff --git a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/RenderableView.java b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/RenderableView.java index 2aa196cdf5ce4..a0b185641d8ee 100644 --- a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/RenderableView.java +++ b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/RenderableView.java @@ -27,9 +27,8 @@ import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableType; -import com.facebook.react.uimanager.PointerEvents; import com.facebook.react.touch.ReactHitSlopView; - +import com.facebook.react.uimanager.PointerEvents; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.regex.Matcher; @@ -37,7 +36,7 @@ import javax.annotation.Nullable; @SuppressWarnings({"WeakerAccess", "RedundantSuppression"}) -abstract public class RenderableView extends VirtualView implements ReactHitSlopView { +public abstract class RenderableView extends VirtualView implements ReactHitSlopView { RenderableView(ReactContext reactContext) { super(reactContext); @@ -96,23 +95,23 @@ abstract public class RenderableView extends VirtualView implements ReactHitSlop private static final Pattern regex = Pattern.compile("[0-9.-]+"); - @Nullable - public Rect getHitSlopRect() { - /* - * In order to make the isTouchPointInView fail we need to return a very improbable Rect for the View - * This way an SVG with box_none carrying its last descendent with box_none will have the expected behavior of just having events on the actual painted area - */ - if (mPointerEvents == PointerEvents.BOX_NONE) { - return new Rect(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE); - } - return null; + @Nullable + public Rect getHitSlopRect() { + /* + * In order to make the isTouchPointInView fail we need to return a very improbable Rect for the View + * This way an SVG with box_none carrying its last descendent with box_none will have the expected behavior of just having events on the actual painted area + */ + if (mPointerEvents == PointerEvents.BOX_NONE) { + return new Rect(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE); } + return null; + } - @Override - public void setId(int id) { - super.setId(id); - RenderableViewManager.setRenderableView(id, this); - } + @Override + public void setId(int id) { + super.setId(id); + RenderableViewManager.setRenderableView(id, this); + } public void setVectorEffect(int vectorEffect) { this.vectorEffect = vectorEffect; @@ -367,7 +366,7 @@ void render(Canvas canvas, Paint paint, float opacity) { float maskY = (float) relativeOnHeight(mask.mY); float maskWidth = (float) relativeOnWidth(mask.mW); float maskHeight = (float) relativeOnHeight(mask.mH); - maskCanvas.clipRect(maskX, maskY, maskWidth, maskHeight); + maskCanvas.clipRect(maskX, maskY, maskWidth + maskX, maskHeight + maskY); Paint maskPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mask.draw(maskCanvas, maskPaint, 1); diff --git a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/RenderableViewManager.java b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/RenderableViewManager.java index 72180eebb2f89..6882d4a3fe5c6 100644 --- a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/RenderableViewManager.java +++ b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/RenderableViewManager.java @@ -149,6 +149,12 @@ protected VirtualViewManager(SVGClass svgclass) { mClassName = svgclass.toString(); } + protected ViewManagerDelegate mDelegate; + + protected ViewManagerDelegate getDelegate() { + return mDelegate; + } + static class RenderableShadowNode extends LayoutShadowNode { @SuppressWarnings({"unused", "EmptyMethod"}) @@ -464,11 +470,6 @@ public void setPointerEvents(V view, @Nullable String pointerEventsStr) { } } - @ReactProp(name = "onLayout") - public void setOnLayout(V node, boolean onLayout) { - node.setOnLayout(onLayout); - } - @ReactProp(name = "name") public void setName(V node, String name) { node.setName(name); @@ -733,11 +734,7 @@ static class GroupViewManager extends GroupViewManagerAbstract mDelegate = new RNSVGGroupManagerDelegate(this); } - private final ViewManagerDelegate mDelegate; - - protected ViewManagerDelegate getDelegate() { - return mDelegate; - } + public static final String REACT_CLASS = "RNSVGGroup"; } static class PathViewManager extends RenderableViewManager @@ -747,11 +744,7 @@ static class PathViewManager extends RenderableViewManager mDelegate = new RNSVGPathManagerDelegate(this); } - private final ViewManagerDelegate mDelegate; - - protected ViewManagerDelegate getDelegate() { - return mDelegate; - } + public static final String REACT_CLASS = "RNSVGPath"; @ReactProp(name = "d") public void setD(PathView node, String d) { @@ -828,10 +821,6 @@ public void setAlignmentBaseline(K view, @Nullable String value) { view.setMethod(value); } - public void setTextAnchor(K view, @Nullable String value) { - // TODO: is it available on Android? - } - public void setDx(K view, @Nullable ReadableArray value) { view.setDeltaX(value); } @@ -840,14 +829,6 @@ public void setDy(K view, @Nullable ReadableArray value) { view.setDeltaY(value); } - public void setPositionX(K view, @Nullable ReadableArray value) { - view.setPositionX(value); - } - - public void setPositionY(K view, @Nullable ReadableArray value) { - view.setPositionY(value); - } - public void setX(K view, @Nullable ReadableArray value) { view.setPositionX(value); } @@ -892,11 +873,7 @@ static class TextViewManager extends TextViewManagerAbstract mDelegate = new RNSVGTextManagerDelegate(this); } - private final ViewManagerDelegate mDelegate; - - protected ViewManagerDelegate getDelegate() { - return mDelegate; - } + public static final String REACT_CLASS = "RNSVGText"; TextViewManager(SVGClass svgClass) { super(svgClass); @@ -911,17 +888,13 @@ static class TSpanViewManager extends TextViewManagerAbstract mDelegate = new RNSVGTSpanManagerDelegate(this); } + public static final String REACT_CLASS = "RNSVGTSpan"; + TSpanViewManager(SVGClass svgClass) { super(svgClass); mDelegate = new RNSVGTSpanManagerDelegate(this); } - private final ViewManagerDelegate mDelegate; - - protected ViewManagerDelegate getDelegate() { - return mDelegate; - } - @ReactProp(name = "content") public void setContent(TSpanView node, @Nullable String content) { node.setContent(content); @@ -935,17 +908,13 @@ static class TextPathViewManager extends TextViewManagerAbstract mDelegate = new RNSVGTextPathManagerDelegate(this); } + public static final String REACT_CLASS = "RNSVGTextPath"; + TextPathViewManager(SVGClass svgClass) { super(svgClass); mDelegate = new RNSVGTextPathManagerDelegate(this); } - private final ViewManagerDelegate mDelegate; - - protected ViewManagerDelegate getDelegate() { - return mDelegate; - } - @ReactProp(name = "href") public void setHref(TextPathView node, String href) { node.setHref(href); @@ -998,11 +967,7 @@ static class ImageViewManager extends RenderableViewManager mDelegate = new RNSVGImageManagerDelegate(this); } - private final ViewManagerDelegate mDelegate; - - protected ViewManagerDelegate getDelegate() { - return mDelegate; - } + public static final String REACT_CLASS = "RNSVGImage"; @ReactProp(name = "x") public void setX(ImageView node, Dynamic x) { @@ -1083,11 +1048,7 @@ static class CircleViewManager extends RenderableViewManager mDelegate = new RNSVGCircleManagerDelegate(this); } - private final ViewManagerDelegate mDelegate; - - protected ViewManagerDelegate getDelegate() { - return mDelegate; - } + public static final String REACT_CLASS = "RNSVGCircle"; @ReactProp(name = "cx") public void setCx(CircleView node, Dynamic cx) { @@ -1139,11 +1100,7 @@ static class EllipseViewManager extends RenderableViewManager mDelegate = new RNSVGEllipseManagerDelegate(this); } - private final ViewManagerDelegate mDelegate; - - protected ViewManagerDelegate getDelegate() { - return mDelegate; - } + public static final String REACT_CLASS = "RNSVGEllipse"; @ReactProp(name = "cx") public void setCx(EllipseView node, Dynamic cx) { @@ -1210,11 +1167,7 @@ static class LineViewManager extends RenderableViewManager mDelegate = new RNSVGLineManagerDelegate(this); } - private final ViewManagerDelegate mDelegate; - - protected ViewManagerDelegate getDelegate() { - return mDelegate; - } + public static final String REACT_CLASS = "RNSVGLine"; @ReactProp(name = "x1") public void setX1(LineView node, Dynamic x1) { @@ -1281,11 +1234,7 @@ static class RectViewManager extends RenderableViewManager mDelegate = new RNSVGRectManagerDelegate(this); } - private final ViewManagerDelegate mDelegate; - - protected ViewManagerDelegate getDelegate() { - return mDelegate; - } + public static final String REACT_CLASS = "RNSVGRect"; @ReactProp(name = "x") public void setX(RectView node, Dynamic x) { @@ -1379,11 +1328,7 @@ static class ClipPathViewManager extends GroupViewManagerAbstract mDelegate = new RNSVGClipPathManagerDelegate(this); } - private final ViewManagerDelegate mDelegate; - - protected ViewManagerDelegate getDelegate() { - return mDelegate; - } + public static final String REACT_CLASS = "RNSVGClipPath"; } static class DefsViewManager extends VirtualViewManager @@ -1394,11 +1339,7 @@ static class DefsViewManager extends VirtualViewManager mDelegate = new RNSVGDefsManagerDelegate(this); } - private final ViewManagerDelegate mDelegate; - - protected ViewManagerDelegate getDelegate() { - return mDelegate; - } + public static final String REACT_CLASS = "RNSVGDefs"; } static class UseViewManager extends RenderableViewManager @@ -1409,11 +1350,7 @@ static class UseViewManager extends RenderableViewManager mDelegate = new RNSVGUseManagerDelegate(this); } - private final ViewManagerDelegate mDelegate; - - protected ViewManagerDelegate getDelegate() { - return mDelegate; - } + public static final String REACT_CLASS = "RNSVGUse"; @ReactProp(name = "href") public void setHref(UseView node, String href) { @@ -1484,11 +1421,7 @@ static class SymbolManager extends GroupViewManagerAbstract mDelegate = new RNSVGSymbolManagerDelegate(this); } - private final ViewManagerDelegate mDelegate; - - protected ViewManagerDelegate getDelegate() { - return mDelegate; - } + public static final String REACT_CLASS = "RNSVGSymbol"; @ReactProp(name = "minX") public void setMinX(SymbolView node, float minX) { @@ -1528,11 +1461,7 @@ static class PatternManager extends GroupViewManagerAbstract mDelegate = new RNSVGPatternManagerDelegate(this); } - private final ViewManagerDelegate mDelegate; - - protected ViewManagerDelegate getDelegate() { - return mDelegate; - } + public static final String REACT_CLASS = "RNSVGPattern"; @ReactProp(name = "x") public void setX(PatternView node, Dynamic x) { @@ -1643,11 +1572,7 @@ static class MaskManager extends GroupViewManagerAbstract mDelegate = new RNSVGMaskManagerDelegate(this); } - private final ViewManagerDelegate mDelegate; - - protected ViewManagerDelegate getDelegate() { - return mDelegate; - } + public static final String REACT_CLASS = "RNSVGMask"; @ReactProp(name = "x") public void setX(MaskView node, Dynamic x) { @@ -1714,11 +1639,6 @@ public void setMaskUnits(MaskView node, int maskUnits) { public void setMaskContentUnits(MaskView node, int maskContentUnits) { node.setMaskContentUnits(maskContentUnits); } - - @ReactProp(name = "maskTransform") - public void setMaskTransform(MaskView node, @Nullable ReadableArray matrixArray) { - node.setMaskTransform(matrixArray); - } } static class ForeignObjectManager extends GroupViewManagerAbstract @@ -1728,11 +1648,7 @@ static class ForeignObjectManager extends GroupViewManagerAbstract mDelegate; - - protected ViewManagerDelegate getDelegate() { - return mDelegate; - } + public static final String REACT_CLASS = "RNSVGForeignObject"; @ReactProp(name = "x") public void setX(ForeignObjectView node, Dynamic x) { @@ -1798,11 +1714,7 @@ static class MarkerManager extends GroupViewManagerAbstract mDelegate = new RNSVGMarkerManagerDelegate(this); } - private final ViewManagerDelegate mDelegate; - - protected ViewManagerDelegate getDelegate() { - return mDelegate; - } + public static final String REACT_CLASS = "RNSVGMarker"; @ReactProp(name = "refX") public void setRefX(MarkerView node, Dynamic refX) { @@ -1909,11 +1821,7 @@ static class LinearGradientManager extends VirtualViewManager mDelegate; - - protected ViewManagerDelegate getDelegate() { - return mDelegate; - } + public static final String REACT_CLASS = "RNSVGLinearGradient"; @ReactProp(name = "x1") public void setX1(LinearGradientView node, Dynamic x1) { @@ -1995,11 +1903,7 @@ static class RadialGradientManager extends VirtualViewManager mDelegate; - - protected ViewManagerDelegate getDelegate() { - return mDelegate; - } + public static final String REACT_CLASS = "RNSVGRadialGradient"; @ReactProp(name = "fx") public void setFx(RadialGradientView node, Dynamic fx) { diff --git a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/SVGLength.java b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/SVGLength.java index e58998367fb95..e5830833837a9 100644 --- a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/SVGLength.java +++ b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/SVGLength.java @@ -104,11 +104,11 @@ static SVGLength from(Dynamic dynamic) { } static SVGLength from(String string) { - return new SVGLength(string); + return string != null ? new SVGLength(string) : new SVGLength(); } static SVGLength from(Double value) { - return new SVGLength(value); + return value != null ? new SVGLength(value) : new SVGLength(); } static String toString(Dynamic dynamic) { diff --git a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/SvgPackage.java b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/SvgPackage.java index 741f043e6f947..ce9615233dcad 100644 --- a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/SvgPackage.java +++ b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/SvgPackage.java @@ -10,50 +10,306 @@ import static com.horcrux.svg.RenderableViewManager.*; -import com.facebook.react.ReactPackage; +import androidx.annotation.Nullable; +import com.facebook.react.TurboReactPackage; +import com.facebook.react.ViewManagerOnDemandReactPackage; import com.facebook.react.bridge.JavaScriptModule; +import com.facebook.react.bridge.ModuleSpec; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.common.MapBuilder; +import com.facebook.react.module.annotations.ReactModule; +import com.facebook.react.module.annotations.ReactModuleList; +import com.facebook.react.module.model.ReactModuleInfo; +import com.facebook.react.module.model.ReactModuleInfoProvider; +import com.facebook.react.turbomodule.core.interfaces.TurboModule; import com.facebook.react.uimanager.ViewManager; -import java.util.Arrays; +import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.annotation.Nonnull; +import javax.inject.Provider; -public class SvgPackage implements ReactPackage { +@ReactModuleList( + nativeModules = { + SvgViewModule.class, + RNSVGRenderableManager.class, + }) +public class SvgPackage extends TurboReactPackage implements ViewManagerOnDemandReactPackage { + + private @Nullable Map mViewManagers; + + private Map getViewManagersMap(final ReactApplicationContext reactContext) { + if (mViewManagers == null) { + Map specs = MapBuilder.newHashMap(); + specs.put( + GroupViewManager.REACT_CLASS, + ModuleSpec.viewManagerSpec( + new Provider() { + @Override + public NativeModule get() { + return new GroupViewManager(); + } + })); + specs.put( + PathViewManager.REACT_CLASS, + ModuleSpec.viewManagerSpec( + new Provider() { + @Override + public NativeModule get() { + return new PathViewManager(); + } + })); + specs.put( + CircleViewManager.REACT_CLASS, + ModuleSpec.viewManagerSpec( + new Provider() { + @Override + public NativeModule get() { + return new CircleViewManager(); + } + })); + specs.put( + EllipseViewManager.REACT_CLASS, + ModuleSpec.viewManagerSpec( + new Provider() { + @Override + public NativeModule get() { + return new EllipseViewManager(); + } + })); + specs.put( + LineViewManager.REACT_CLASS, + ModuleSpec.viewManagerSpec( + new Provider() { + @Override + public NativeModule get() { + return new LineViewManager(); + } + })); + specs.put( + RectViewManager.REACT_CLASS, + ModuleSpec.viewManagerSpec( + new Provider() { + @Override + public NativeModule get() { + return new RectViewManager(); + } + })); + specs.put( + TextViewManager.REACT_CLASS, + ModuleSpec.viewManagerSpec( + new Provider() { + @Override + public NativeModule get() { + return new TextViewManager(); + } + })); + specs.put( + TSpanViewManager.REACT_CLASS, + ModuleSpec.viewManagerSpec( + new Provider() { + @Override + public NativeModule get() { + return new TSpanViewManager(); + } + })); + specs.put( + TextPathViewManager.REACT_CLASS, + ModuleSpec.viewManagerSpec( + new Provider() { + @Override + public NativeModule get() { + return new TextPathViewManager(); + } + })); + specs.put( + ImageViewManager.REACT_CLASS, + ModuleSpec.viewManagerSpec( + new Provider() { + @Override + public NativeModule get() { + return new ImageViewManager(); + } + })); + specs.put( + ClipPathViewManager.REACT_CLASS, + ModuleSpec.viewManagerSpec( + new Provider() { + @Override + public NativeModule get() { + return new ClipPathViewManager(); + } + })); + specs.put( + DefsViewManager.REACT_CLASS, + ModuleSpec.viewManagerSpec( + new Provider() { + @Override + public NativeModule get() { + return new DefsViewManager(); + } + })); + specs.put( + UseViewManager.REACT_CLASS, + ModuleSpec.viewManagerSpec( + new Provider() { + @Override + public NativeModule get() { + return new UseViewManager(); + } + })); + specs.put( + SymbolManager.REACT_CLASS, + ModuleSpec.viewManagerSpec( + new Provider() { + @Override + public NativeModule get() { + return new SymbolManager(); + } + })); + specs.put( + LinearGradientManager.REACT_CLASS, + ModuleSpec.viewManagerSpec( + new Provider() { + @Override + public NativeModule get() { + return new LinearGradientManager(); + } + })); + specs.put( + RadialGradientManager.REACT_CLASS, + ModuleSpec.viewManagerSpec( + new Provider() { + @Override + public NativeModule get() { + return new RadialGradientManager(); + } + })); + specs.put( + PatternManager.REACT_CLASS, + ModuleSpec.viewManagerSpec( + new Provider() { + @Override + public NativeModule get() { + return new PatternManager(); + } + })); + specs.put( + MaskManager.REACT_CLASS, + ModuleSpec.viewManagerSpec( + new Provider() { + @Override + public NativeModule get() { + return new MaskManager(); + } + })); + specs.put( + ForeignObjectManager.REACT_CLASS, + ModuleSpec.viewManagerSpec( + new Provider() { + @Override + public NativeModule get() { + return new ForeignObjectManager(); + } + })); + specs.put( + MarkerManager.REACT_CLASS, + ModuleSpec.viewManagerSpec( + new Provider() { + @Override + public NativeModule get() { + return new MarkerManager(); + } + })); + specs.put( + SvgViewManager.REACT_CLASS, + ModuleSpec.viewManagerSpec( + new Provider() { + @Override + public NativeModule get() { + return new SvgViewManager(); + } + })); + mViewManagers = specs; + } + return mViewManagers; + } + + /** {@inheritDoc} */ + @Override + public List getViewManagerNames(ReactApplicationContext reactContext) { + return (List) getViewManagersMap(reactContext).keySet(); + } + + @Override + protected List getViewManagers(ReactApplicationContext reactContext) { + return new ArrayList<>(getViewManagersMap(reactContext).values()); + } + + /** {@inheritDoc} */ + @Override + public @Nullable ViewManager createViewManager( + ReactApplicationContext reactContext, String viewManagerName) { + ModuleSpec spec = getViewManagersMap(reactContext).get(viewManagerName); + return spec != null ? (ViewManager) spec.getProvider().get() : null; + } - @Nonnull @Override - public List createViewManagers(@Nonnull ReactApplicationContext reactContext) { - return Arrays.asList( - new GroupViewManager(), - new PathViewManager(), - new CircleViewManager(), - new EllipseViewManager(), - new LineViewManager(), - new RectViewManager(), - new TextViewManager(), - new TSpanViewManager(), - new TextPathViewManager(), - new ImageViewManager(), - new ClipPathViewManager(), - new DefsViewManager(), - new UseViewManager(), - new SymbolManager(), - new LinearGradientManager(), - new RadialGradientManager(), - new PatternManager(), - new MaskManager(), - new ForeignObjectManager(), - new MarkerManager(), - new SvgViewManager()); + public NativeModule getModule(String name, @Nonnull ReactApplicationContext reactContext) { + switch (name) { + case SvgViewModule.NAME: + return new SvgViewModule(reactContext); + case RNSVGRenderableManager.NAME: + return new RNSVGRenderableManager(reactContext); + default: + return null; + } } - @Nonnull @Override - public List createNativeModules(@Nonnull ReactApplicationContext reactContext) { - return Arrays.asList( - new SvgViewModule(reactContext), new RNSVGRenderableManager(reactContext)); + public ReactModuleInfoProvider getReactModuleInfoProvider() { + try { + Class reactModuleInfoProviderClass = + Class.forName("com.horcrux.svg.SvgPackage$$ReactModuleInfoProvider"); + return (ReactModuleInfoProvider) reactModuleInfoProviderClass.newInstance(); + } catch (ClassNotFoundException e) { + // ReactModuleSpecProcessor does not run at build-time. Create this ReactModuleInfoProvider by + // hand. + return new ReactModuleInfoProvider() { + @Override + public Map getReactModuleInfos() { + final Map reactModuleInfoMap = new HashMap<>(); + + Class[] moduleList = + new Class[] { + SvgViewModule.class, RNSVGRenderableManager.class, + }; + + for (Class moduleClass : moduleList) { + ReactModule reactModule = moduleClass.getAnnotation(ReactModule.class); + + reactModuleInfoMap.put( + reactModule.name(), + new ReactModuleInfo( + reactModule.name(), + moduleClass.getName(), + reactModule.canOverrideExistingModule(), + reactModule.needsEagerInit(), + reactModule.hasConstants(), + reactModule.isCxxModule(), + TurboModule.class.isAssignableFrom(moduleClass))); + } + + return reactModuleInfoMap; + } + }; + } catch (InstantiationException | IllegalAccessException e) { + throw new RuntimeException( + "No ReactModuleInfoProvider for MyPackage$$ReactModuleInfoProvider", e); + } } @SuppressWarnings("unused") diff --git a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/SvgView.java b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/SvgView.java index 523fcc16caec4..b49dce2db7f5a 100644 --- a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/SvgView.java +++ b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/SvgView.java @@ -19,6 +19,7 @@ import android.util.Base64; import android.view.View; import android.view.ViewParent; +import android.view.accessibility.AccessibilityNodeInfo; import com.facebook.react.bridge.Dynamic; import com.facebook.react.bridge.ReactContext; import com.facebook.react.uimanager.DisplayMetricsHolder; @@ -72,6 +73,16 @@ public void setId(int id) { SvgViewManager.setSvgView(id, this); } + @Override + public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { + super.onInitializeAccessibilityNodeInfo(info); + + Rect r = new Rect(); + boolean isVisible = this.getGlobalVisibleRect(r); + info.setVisibleToUser(isVisible); + info.setClassName(this.getClass().getCanonicalName()); + } + @Override public void invalidate() { super.invalidate(); @@ -186,7 +197,7 @@ private void clearChildCache() { } public void setTintColor(Integer tintColor) { - mTintColor = tintColor; + mTintColor = tintColor != null ? tintColor : 0; invalidate(); clearChildCache(); } diff --git a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/SvgViewManager.java b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/SvgViewManager.java index 54aa57af473df..cbe9a5308c8d5 100644 --- a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/SvgViewManager.java +++ b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/SvgViewManager.java @@ -8,15 +8,18 @@ package com.horcrux.svg; +import android.graphics.Rect; import android.util.SparseArray; import com.facebook.react.bridge.Dynamic; +import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.PointerEvents; import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.ViewManagerDelegate; import com.facebook.react.uimanager.ViewProps; import com.facebook.react.uimanager.annotations.ReactProp; -import com.facebook.react.viewmanagers.RNSVGSvgViewManagerDelegate; -import com.facebook.react.viewmanagers.RNSVGSvgViewManagerInterface; +import com.facebook.react.viewmanagers.RNSVGSvgViewAndroidManagerDelegate; +import com.facebook.react.viewmanagers.RNSVGSvgViewAndroidManagerInterface; import com.facebook.react.views.view.ReactViewGroup; import com.facebook.react.views.view.ReactViewManager; import java.lang.reflect.InvocationTargetException; @@ -29,9 +32,10 @@ * ViewManager for RNSVGSvgView React views. Renders as a {@link SvgView} and handles invalidating * the native view on view updates happening in the underlying tree. */ -class SvgViewManager extends ReactViewManager implements RNSVGSvgViewManagerInterface { +class SvgViewManager extends ReactViewManager + implements RNSVGSvgViewAndroidManagerInterface { - private static final String REACT_CLASS = "RNSVGSvgView"; + public static final String REACT_CLASS = "RNSVGSvgViewAndroid"; private static final SparseArray mTagToSvgView = new SparseArray<>(); private static final SparseArray mTagToRunnable = new SparseArray<>(); @@ -43,7 +47,7 @@ protected ViewManagerDelegate getDelegate() { } public SvgViewManager() { - mDelegate = new RNSVGSvgViewManagerDelegate(this); + mDelegate = new RNSVGSvgViewAndroidManagerDelegate(this); } static void setSvgView(int tag, SvgView svg) { @@ -182,4 +186,176 @@ public void setPointerEvents(SvgView view, @Nullable String pointerEventsStr) { e.printStackTrace(); } } + + @Override + public void setHasTVPreferredFocus(SvgView view, boolean value) { + super.setTVPreferredFocus(view, value); + } + + @Override + public void setBorderTopEndRadius(SvgView view, float value) { + super.setBorderRadius(view, 6, value); + } + + @Override + public void setBorderBottomStartRadius(SvgView view, float value) { + super.setBorderRadius(view, 7, value); + } + + @Override + public void setBorderBottomColor(SvgView view, @Nullable Integer value) { + super.setBorderColor(view, 4, value); + } + + @Override + public void setNextFocusDown(SvgView view, int value) { + super.nextFocusDown(view, value); + } + + @Override + public void setBorderRightColor(SvgView view, @Nullable Integer value) { + super.setBorderColor(view, 2, value); + } + + @Override + public void setNextFocusRight(SvgView view, int value) { + super.nextFocusRight(view, value); + } + + @Override + public void setBorderLeftColor(SvgView view, @Nullable Integer value) { + super.setBorderColor(view, 1, value); + } + + @Override + public void setBorderColor(SvgView view, @Nullable Integer value) { + super.setBorderColor(view, 0, value); + } + + @Override + public void setRemoveClippedSubviews(SvgView view, boolean value) { + super.setRemoveClippedSubviews(view, value); + } + + @Override + public void setNextFocusForward(SvgView view, int value) { + super.nextFocusForward(view, value); + } + + @Override + public void setNextFocusUp(SvgView view, int value) { + super.nextFocusUp(view, value); + } + + @Override + public void setAccessible(SvgView view, boolean value) { + super.setAccessible(view, value); + } + + @Override + public void setBorderStartColor(SvgView view, @Nullable Integer value) { + super.setBorderColor(view, 5, value); + } + + @Override + public void setBorderBottomEndRadius(SvgView view, float value) { + super.setBorderRadius(view, 8, value); + } + + @Override + public void setBorderEndColor(SvgView view, @Nullable Integer value) { + super.setBorderColor(view, 6, value); + } + + @Override + public void setFocusable(SvgView view, boolean value) { + super.setFocusable(view, value); + } + + @Override + public void setNativeBackgroundAndroid(SvgView view, @Nullable ReadableMap value) { + super.setNativeBackground(view, value); + } + + @Override + public void setBorderTopStartRadius(SvgView view, float value) { + super.setBorderRadius(view, 5, value); + } + + @Override + public void setNativeForegroundAndroid(SvgView view, @Nullable ReadableMap value) { + super.setNativeForeground(view, value); + } + + @Override + public void setBackfaceVisibility(SvgView view, @Nullable String value) { + super.setBackfaceVisibility(view, value); + } + + @Override + public void setBorderStyle(SvgView view, @Nullable String value) { + super.setBorderStyle(view, value); + } + + @Override + public void setNeedsOffscreenAlphaCompositing(SvgView view, boolean value) { + super.setNeedsOffscreenAlphaCompositing(view, value); + } + + @Override + public void setHitSlop(SvgView view, @Nullable ReadableMap hitSlopMap) { + // we don't call super here since its signature changed in RN 0.69 and we want backwards + // compatibility + if (hitSlopMap != null) { + view.setHitSlopRect( + new Rect( + hitSlopMap.hasKey("left") + ? (int) PixelUtil.toPixelFromDIP(hitSlopMap.getDouble("left")) + : 0, + hitSlopMap.hasKey("top") + ? (int) PixelUtil.toPixelFromDIP(hitSlopMap.getDouble("top")) + : 0, + hitSlopMap.hasKey("right") + ? (int) PixelUtil.toPixelFromDIP(hitSlopMap.getDouble("right")) + : 0, + hitSlopMap.hasKey("bottom") + ? (int) PixelUtil.toPixelFromDIP(hitSlopMap.getDouble("bottom")) + : 0)); + } + } + + @Override + public void setBorderTopColor(SvgView view, @Nullable Integer value) { + super.setBorderColor(view, 3, value); + } + + @Override + public void setNextFocusLeft(SvgView view, int value) { + super.nextFocusLeft(view, value); + } + + @Override + public void setBorderRadius(SvgView view, double value) { + super.setBorderRadius(view, 0, (float) value); + } + + @Override + public void setBorderTopLeftRadius(SvgView view, double value) { + super.setBorderRadius(view, 1, (float) value); + } + + @Override + public void setBorderTopRightRadius(SvgView view, double value) { + super.setBorderRadius(view, 2, (float) value); + } + + @Override + public void setBorderBottomRightRadius(SvgView view, double value) { + super.setBorderRadius(view, 3, (float) value); + } + + @Override + public void setBorderBottomLeftRadius(SvgView view, double value) { + super.setBorderRadius(view, 4, (float) value); + } } diff --git a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/SvgViewModule.java b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/SvgViewModule.java index 30397a6e2e278..6173acad2baf8 100644 --- a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/SvgViewModule.java +++ b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/SvgViewModule.java @@ -10,21 +10,25 @@ import com.facebook.react.bridge.Callback; import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.UiThreadUtil; +import com.facebook.react.module.annotations.ReactModule; +import com.horcrux.rnsvg.NativeSvgViewModuleSpec; import javax.annotation.Nonnull; -class SvgViewModule extends ReactContextBaseJavaModule { +@ReactModule(name = SvgViewModule.NAME) +class SvgViewModule extends NativeSvgViewModuleSpec { SvgViewModule(ReactApplicationContext reactContext) { super(reactContext); } + public static final String NAME = "RNSVGSvgViewModule"; + @Nonnull @Override public String getName() { - return "RNSVGSvgViewManager"; + return NAME; } private static void toDataURL( @@ -76,7 +80,8 @@ public void run() { @SuppressWarnings("unused") @ReactMethod - public void toDataURL(int tag, ReadableMap options, Callback successCallback) { - toDataURL(tag, options, successCallback, 0); + @Override + public void toDataURL(Double tag, ReadableMap options, Callback successCallback) { + toDataURL(tag.intValue(), options, successCallback, 0); } } diff --git a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/VirtualView.java b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/VirtualView.java index 1123e129ffe1b..c414af2366435 100644 --- a/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/VirtualView.java +++ b/android/vendored/unversioned/react-native-svg/android/src/main/java/com/horcrux/svg/VirtualView.java @@ -7,10 +7,12 @@ import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Path; +import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Region; import android.view.View; import android.view.ViewParent; +import android.view.accessibility.AccessibilityNodeInfo; import com.facebook.common.logging.FLog; import com.facebook.react.bridge.Dynamic; import com.facebook.react.bridge.ReactContext; @@ -20,7 +22,7 @@ import com.facebook.react.uimanager.DisplayMetricsHolder; import com.facebook.react.uimanager.OnLayoutEvent; import com.facebook.react.uimanager.PointerEvents; -import com.facebook.react.uimanager.UIManagerModule; +import com.facebook.react.uimanager.UIManagerHelper; import com.facebook.react.uimanager.events.EventDispatcher; import com.facebook.react.views.view.ReactViewGroup; import java.util.ArrayList; @@ -73,7 +75,6 @@ public abstract class VirtualView extends ReactViewGroup { final float mScale; private boolean mResponsible; - private boolean mOnLayout; String mDisplay; String mName; @@ -107,6 +108,32 @@ void setPointerEvents(PointerEvents pointerEvents) { mPointerEvents = pointerEvents; } + @Override + public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { + super.onInitializeAccessibilityNodeInfo(info); + if (mClientRect != null) { + + SvgView root = getSvgView(); + + int[] rootPositionOnScreen = new int[2]; + getSvgView().getLocationOnScreen(rootPositionOnScreen); + Rect infoBoundsInScreen = new Rect(); + infoBoundsInScreen.left = rootPositionOnScreen[0] + (int) Math.floor(mClientRect.left); + infoBoundsInScreen.top = rootPositionOnScreen[1] + (int) Math.floor(mClientRect.top); + infoBoundsInScreen.right = infoBoundsInScreen.left + (int) Math.ceil(mClientRect.width()); + infoBoundsInScreen.bottom = infoBoundsInScreen.top + (int) Math.ceil(mClientRect.height()); + + Rect rootVisibleRect = new Rect(); + boolean isRootVisible = root.getGlobalVisibleRect(rootVisibleRect); + boolean infoIsVisibleToUser = isRootVisible && infoBoundsInScreen.intersect(rootVisibleRect); + + String infoClassName = this.getClass().getCanonicalName(); + info.setBoundsInScreen(infoBoundsInScreen); + info.setClassName(infoClassName); + info.setVisibleToUser(infoIsVisibleToUser); + } + } + @Override public void invalidate() { if (this instanceof RenderableView && mPath == null) { @@ -249,11 +276,6 @@ public void setDisplay(String display) { invalidate(); } - public void setOnLayout(boolean onLayout) { - mOnLayout = onLayout; - invalidate(); - } - public void setMask(String mask) { mMask = mask; invalidate(); @@ -291,30 +313,27 @@ public void setOpacity(float opacity) { } public void setMatrix(Dynamic matrixArray) { - ReadableType type = matrixArray.getType(); - if (!matrixArray.isNull() && type.equals(ReadableType.Array)) { - ReadableArray matrix = matrixArray.asArray(); - setMatrix(matrix); + boolean isArrayType = !matrixArray.isNull() && matrixArray.getType().equals(ReadableType.Array); + setMatrix(isArrayType ? matrixArray.asArray() : null); + } + + public void setMatrix(@Nullable ReadableArray matrixArray) { + if (matrixArray != null) { + int matrixSize = PropHelper.toMatrixData(matrixArray, sRawMatrix, mScale); + if (matrixSize == 6) { + if (mMatrix == null) { + mMatrix = new Matrix(); + mInvMatrix = new Matrix(); + } + mMatrix.setValues(sRawMatrix); + mInvertible = mMatrix.invert(mInvMatrix); + } else if (matrixSize != -1) { + FLog.w(ReactConstants.TAG, "RNSVG: Transform matrices must be of size 6"); + } } else { mMatrix.reset(); mInvMatrix.reset(); mInvertible = true; - super.invalidate(); - clearParentCache(); - } - } - - public void setMatrix(ReadableArray matrixArray) { - int matrixSize = PropHelper.toMatrixData(matrixArray, sRawMatrix, mScale); - if (matrixSize == 6) { - if (mMatrix == null) { - mMatrix = new Matrix(); - mInvMatrix = new Matrix(); - } - mMatrix.setValues(sRawMatrix); - mInvertible = mMatrix.invert(mInvMatrix); - } else if (matrixSize != -1) { - FLog.w(ReactConstants.TAG, "RNSVG: Transform matrices must be of size 6"); } super.invalidate(); clearParentCache(); @@ -376,6 +395,7 @@ boolean isResponsible() { abstract Path getPath(Canvas canvas, Paint paint); + @Nullable SvgView getSvgView() { if (svgView != null) { return svgView; @@ -577,12 +597,11 @@ void setClientRect(RectF rect) { setRight(right); setBottom(bottom); } - if (!mOnLayout) { - return; - } EventDispatcher eventDispatcher = - mContext.getNativeModule(UIManagerModule.class).getEventDispatcher(); - eventDispatcher.dispatchEvent(OnLayoutEvent.obtain(this.getId(), left, top, width, height)); + UIManagerHelper.getEventDispatcherForReactTag(mContext, getId()); + if (eventDispatcher != null) { + eventDispatcher.dispatchEvent(OnLayoutEvent.obtain(this.getId(), left, top, width, height)); + } } RectF getClientRect() { diff --git a/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGMaskManagerDelegate.java b/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGMaskManagerDelegate.java index 849f8ed52803a..8730b0a1fc674 100644 --- a/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGMaskManagerDelegate.java +++ b/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGMaskManagerDelegate.java @@ -167,9 +167,6 @@ public void setProperty(T view, String propName, @Nullable Object value) { case "maskContentUnits": mViewManager.setMaskContentUnits(view, value == null ? 0 : ((Double) value).intValue()); break; - case "maskTransform": - mViewManager.setMaskTransform(view, (ReadableArray) value); - break; default: super.setProperty(view, propName, value); } diff --git a/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGMaskManagerInterface.java b/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGMaskManagerInterface.java index a5627bd4483b7..c799c16456c8d 100644 --- a/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGMaskManagerInterface.java +++ b/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGMaskManagerInterface.java @@ -56,5 +56,4 @@ public interface RNSVGMaskManagerInterface { void setWidth(T view, @Nullable Double value); void setMaskUnits(T view, int value); void setMaskContentUnits(T view, int value); - void setMaskTransform(T view, @Nullable ReadableArray value); } diff --git a/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewAndroidManagerDelegate.java b/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewAndroidManagerDelegate.java new file mode 100644 index 0000000000000..043ed13dcccad --- /dev/null +++ b/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewAndroidManagerDelegate.java @@ -0,0 +1,168 @@ +/** +* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). +* +* Do not edit this file as changes may cause incorrect behavior and will be lost +* once the code is regenerated. +* +* @generated by codegen project: GeneratePropsJavaDelegate.js +*/ + +package com.facebook.react.viewmanagers; + +import android.view.View; +import androidx.annotation.Nullable; +import com.facebook.react.bridge.ColorPropConverter; +import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.uimanager.BaseViewManagerDelegate; +import com.facebook.react.uimanager.BaseViewManagerInterface; + +public class RNSVGSvgViewAndroidManagerDelegate & RNSVGSvgViewAndroidManagerInterface> extends BaseViewManagerDelegate { + public RNSVGSvgViewAndroidManagerDelegate(U viewManager) { + super(viewManager); + } + @Override + public void setProperty(T view, String propName, @Nullable Object value) { + switch (propName) { + case "bbWidth": + if (value instanceof String) { + mViewManager.setBbWidth(view, (String) value); + } else if (value instanceof Double) { + mViewManager.setBbWidth(view, (Double) value); + } else { + mViewManager.setBbWidth(view, (Double) null); + } + break; + case "bbHeight": + if (value instanceof String) { + mViewManager.setBbHeight(view, (String) value); + } else if (value instanceof Double) { + mViewManager.setBbHeight(view, (Double) value); + } else { + mViewManager.setBbHeight(view, (Double) null); + } + break; + case "minX": + mViewManager.setMinX(view, value == null ? Float.NaN : ((Double) value).floatValue()); + break; + case "minY": + mViewManager.setMinY(view, value == null ? Float.NaN : ((Double) value).floatValue()); + break; + case "vbWidth": + mViewManager.setVbWidth(view, value == null ? Float.NaN : ((Double) value).floatValue()); + break; + case "vbHeight": + mViewManager.setVbHeight(view, value == null ? Float.NaN : ((Double) value).floatValue()); + break; + case "align": + mViewManager.setAlign(view, value == null ? null : (String) value); + break; + case "meetOrSlice": + mViewManager.setMeetOrSlice(view, value == null ? 0 : ((Double) value).intValue()); + break; + case "tintColor": + mViewManager.setTintColor(view, ColorPropConverter.getColor(value, view.getContext())); + break; + case "color": + mViewManager.setColor(view, ColorPropConverter.getColor(value, view.getContext())); + break; + case "pointerEvents": + mViewManager.setPointerEvents(view, value == null ? null : (String) value); + break; + case "hasTVPreferredFocus": + mViewManager.setHasTVPreferredFocus(view, value == null ? false : (boolean) value); + break; + case "borderTopEndRadius": + mViewManager.setBorderTopEndRadius(view, value == null ? 0f : ((Double) value).floatValue()); + break; + case "borderBottomStartRadius": + mViewManager.setBorderBottomStartRadius(view, value == null ? 0f : ((Double) value).floatValue()); + break; + case "borderBottomColor": + mViewManager.setBorderBottomColor(view, ColorPropConverter.getColor(value, view.getContext())); + break; + case "nextFocusDown": + mViewManager.setNextFocusDown(view, value == null ? 0 : ((Double) value).intValue()); + break; + case "borderRightColor": + mViewManager.setBorderRightColor(view, ColorPropConverter.getColor(value, view.getContext())); + break; + case "nextFocusRight": + mViewManager.setNextFocusRight(view, value == null ? 0 : ((Double) value).intValue()); + break; + case "borderLeftColor": + mViewManager.setBorderLeftColor(view, ColorPropConverter.getColor(value, view.getContext())); + break; + case "borderColor": + mViewManager.setBorderColor(view, ColorPropConverter.getColor(value, view.getContext())); + break; + case "removeClippedSubviews": + mViewManager.setRemoveClippedSubviews(view, value == null ? false : (boolean) value); + break; + case "nextFocusForward": + mViewManager.setNextFocusForward(view, value == null ? 0 : ((Double) value).intValue()); + break; + case "nextFocusUp": + mViewManager.setNextFocusUp(view, value == null ? 0 : ((Double) value).intValue()); + break; + case "accessible": + mViewManager.setAccessible(view, value == null ? false : (boolean) value); + break; + case "borderStartColor": + mViewManager.setBorderStartColor(view, ColorPropConverter.getColor(value, view.getContext())); + break; + case "borderBottomEndRadius": + mViewManager.setBorderBottomEndRadius(view, value == null ? 0f : ((Double) value).floatValue()); + break; + case "borderEndColor": + mViewManager.setBorderEndColor(view, ColorPropConverter.getColor(value, view.getContext())); + break; + case "focusable": + mViewManager.setFocusable(view, value == null ? false : (boolean) value); + break; + case "nativeBackgroundAndroid": + mViewManager.setNativeBackgroundAndroid(view, (ReadableMap) value); + break; + case "borderTopStartRadius": + mViewManager.setBorderTopStartRadius(view, value == null ? 0f : ((Double) value).floatValue()); + break; + case "nativeForegroundAndroid": + mViewManager.setNativeForegroundAndroid(view, (ReadableMap) value); + break; + case "backfaceVisibility": + mViewManager.setBackfaceVisibility(view, value == null ? null : (String) value); + break; + case "borderStyle": + mViewManager.setBorderStyle(view, value == null ? null : (String) value); + break; + case "needsOffscreenAlphaCompositing": + mViewManager.setNeedsOffscreenAlphaCompositing(view, value == null ? false : (boolean) value); + break; + case "hitSlop": + mViewManager.setHitSlop(view, (ReadableMap) value); + break; + case "borderTopColor": + mViewManager.setBorderTopColor(view, ColorPropConverter.getColor(value, view.getContext())); + break; + case "nextFocusLeft": + mViewManager.setNextFocusLeft(view, value == null ? 0 : ((Double) value).intValue()); + break; + case "borderTopRightRadius": + mViewManager.setBorderTopRightRadius(view, value == null ? 0f : ((Double) value).doubleValue()); + break; + case "borderBottomRightRadius": + mViewManager.setBorderBottomRightRadius(view, value == null ? 0f : ((Double) value).doubleValue()); + break; + case "borderRadius": + mViewManager.setBorderRadius(view, value == null ? 0f : ((Double) value).doubleValue()); + break; + case "borderBottomLeftRadius": + mViewManager.setBorderBottomLeftRadius(view, value == null ? 0f : ((Double) value).doubleValue()); + break; + case "borderTopLeftRadius": + mViewManager.setBorderTopLeftRadius(view, value == null ? 0f : ((Double) value).doubleValue()); + break; + default: + super.setProperty(view, propName, value); + } + } +} diff --git a/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewAndroidManagerInterface.java b/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewAndroidManagerInterface.java new file mode 100644 index 0000000000000..8a52978f91227 --- /dev/null +++ b/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewAndroidManagerInterface.java @@ -0,0 +1,61 @@ +/** +* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). +* +* Do not edit this file as changes may cause incorrect behavior and will be lost +* once the code is regenerated. +* +* @generated by codegen project: GeneratePropsJavaInterface.js +*/ + +package com.facebook.react.viewmanagers; + +import android.view.View; +import androidx.annotation.Nullable; +import com.facebook.react.bridge.ReadableMap; + +public interface RNSVGSvgViewAndroidManagerInterface { + void setBbWidth(T view, @Nullable String value); + void setBbWidth(T view, @Nullable Double value); + void setBbHeight(T view, @Nullable String value); + void setBbHeight(T view, @Nullable Double value); + void setMinX(T view, float value); + void setMinY(T view, float value); + void setVbWidth(T view, float value); + void setVbHeight(T view, float value); + void setAlign(T view, @Nullable String value); + void setMeetOrSlice(T view, int value); + void setTintColor(T view, @Nullable Integer value); + void setColor(T view, @Nullable Integer value); + void setPointerEvents(T view, @Nullable String value); + void setHasTVPreferredFocus(T view, boolean value); + void setBorderTopEndRadius(T view, float value); + void setBorderBottomStartRadius(T view, float value); + void setBorderBottomColor(T view, @Nullable Integer value); + void setNextFocusDown(T view, int value); + void setBorderRightColor(T view, @Nullable Integer value); + void setNextFocusRight(T view, int value); + void setBorderLeftColor(T view, @Nullable Integer value); + void setBorderColor(T view, @Nullable Integer value); + void setRemoveClippedSubviews(T view, boolean value); + void setNextFocusForward(T view, int value); + void setNextFocusUp(T view, int value); + void setAccessible(T view, boolean value); + void setBorderStartColor(T view, @Nullable Integer value); + void setBorderBottomEndRadius(T view, float value); + void setBorderEndColor(T view, @Nullable Integer value); + void setFocusable(T view, boolean value); + void setNativeBackgroundAndroid(T view, @Nullable ReadableMap value); + void setBorderTopStartRadius(T view, float value); + void setNativeForegroundAndroid(T view, @Nullable ReadableMap value); + void setBackfaceVisibility(T view, @Nullable String value); + void setBorderStyle(T view, @Nullable String value); + void setNeedsOffscreenAlphaCompositing(T view, boolean value); + void setHitSlop(T view, @Nullable ReadableMap value); + void setBorderTopColor(T view, @Nullable Integer value); + void setNextFocusLeft(T view, int value); + void setBorderTopRightRadius(T view, double value); + void setBorderBottomRightRadius(T view, double value); + void setBorderRadius(T view, double value); + void setBorderBottomLeftRadius(T view, double value); + void setBorderTopLeftRadius(T view, double value); +} diff --git a/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewManagerDelegate.java b/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewManagerDelegate.java deleted file mode 100644 index 47ecf6cc037b5..0000000000000 --- a/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewManagerDelegate.java +++ /dev/null @@ -1,74 +0,0 @@ -/** -* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). -* -* Do not edit this file as changes may cause incorrect behavior and will be lost -* once the code is regenerated. -* -* @generated by codegen project: GeneratePropsJavaDelegate.js -*/ - -package com.facebook.react.viewmanagers; - -import android.view.View; -import androidx.annotation.Nullable; -import com.facebook.react.bridge.ColorPropConverter; -import com.facebook.react.uimanager.BaseViewManagerDelegate; -import com.facebook.react.uimanager.BaseViewManagerInterface; - -public class RNSVGSvgViewManagerDelegate & RNSVGSvgViewManagerInterface> extends BaseViewManagerDelegate { - public RNSVGSvgViewManagerDelegate(U viewManager) { - super(viewManager); - } - @Override - public void setProperty(T view, String propName, @Nullable Object value) { - switch (propName) { - case "bbWidth": - if (value instanceof String) { - mViewManager.setBbWidth(view, (String) value); - } else if (value instanceof Double) { - mViewManager.setBbWidth(view, (Double) value); - } else { - mViewManager.setBbWidth(view, (Double) null); - } - break; - case "bbHeight": - if (value instanceof String) { - mViewManager.setBbHeight(view, (String) value); - } else if (value instanceof Double) { - mViewManager.setBbHeight(view, (Double) value); - } else { - mViewManager.setBbHeight(view, (Double) null); - } - break; - case "minX": - mViewManager.setMinX(view, value == null ? Float.NaN : ((Double) value).floatValue()); - break; - case "minY": - mViewManager.setMinY(view, value == null ? Float.NaN : ((Double) value).floatValue()); - break; - case "vbWidth": - mViewManager.setVbWidth(view, value == null ? Float.NaN : ((Double) value).floatValue()); - break; - case "vbHeight": - mViewManager.setVbHeight(view, value == null ? Float.NaN : ((Double) value).floatValue()); - break; - case "align": - mViewManager.setAlign(view, value == null ? null : (String) value); - break; - case "meetOrSlice": - mViewManager.setMeetOrSlice(view, value == null ? 0 : ((Double) value).intValue()); - break; - case "tintColor": - mViewManager.setTintColor(view, ColorPropConverter.getColor(value, view.getContext())); - break; - case "color": - mViewManager.setColor(view, ColorPropConverter.getColor(value, view.getContext())); - break; - case "pointerEvents": - mViewManager.setPointerEvents(view, value == null ? null : (String) value); - break; - default: - super.setProperty(view, propName, value); - } - } -} diff --git a/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewManagerInterface.java b/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewManagerInterface.java deleted file mode 100644 index f70093a5c3dc2..0000000000000 --- a/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewManagerInterface.java +++ /dev/null @@ -1,29 +0,0 @@ -/** -* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). -* -* Do not edit this file as changes may cause incorrect behavior and will be lost -* once the code is regenerated. -* -* @generated by codegen project: GeneratePropsJavaInterface.js -*/ - -package com.facebook.react.viewmanagers; - -import android.view.View; -import androidx.annotation.Nullable; - -public interface RNSVGSvgViewManagerInterface { - void setBbWidth(T view, @Nullable String value); - void setBbWidth(T view, @Nullable Double value); - void setBbHeight(T view, @Nullable String value); - void setBbHeight(T view, @Nullable Double value); - void setMinX(T view, float value); - void setMinY(T view, float value); - void setVbWidth(T view, float value); - void setVbHeight(T view, float value); - void setAlign(T view, @Nullable String value); - void setMeetOrSlice(T view, int value); - void setTintColor(T view, @Nullable Integer value); - void setColor(T view, @Nullable Integer value); - void setPointerEvents(T view, @Nullable String value); -} diff --git a/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/horcrux/svg/NativeSvgRenderableModuleSpec.java b/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/horcrux/svg/NativeSvgRenderableModuleSpec.java new file mode 100644 index 0000000000000..6007dd2bfba48 --- /dev/null +++ b/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/horcrux/svg/NativeSvgRenderableModuleSpec.java @@ -0,0 +1,57 @@ +/** + * This code was generated by + * [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + *

Do not edit this file as changes may cause incorrect behavior and will be lost once the code + * is regenerated. + * + * @generated by codegen project: GenerateModuleJavaSpec.js + * @nolint + */ +package com.horcrux.rnsvg; + +import com.facebook.proguard.annotations.DoNotStrip; +import com.facebook.react.bridge.Promise; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.bridge.WritableMap; + +public abstract class NativeSvgRenderableModuleSpec extends ReactContextBaseJavaModule { + public NativeSvgRenderableModuleSpec(ReactApplicationContext reactContext) { + super(reactContext); + } + + @ReactMethod(isBlockingSynchronousMethod = true) + @DoNotStrip + public abstract boolean isPointInFill(Double tag, ReadableMap options); + + @ReactMethod(isBlockingSynchronousMethod = true) + @DoNotStrip + public abstract boolean isPointInStroke(Double tag, ReadableMap options); + + @ReactMethod(isBlockingSynchronousMethod = true) + @DoNotStrip + public abstract double getTotalLength(Double tag); + + @ReactMethod(isBlockingSynchronousMethod = true) + @DoNotStrip + public abstract WritableMap getPointAtLength(Double tag, ReadableMap options); + + @ReactMethod(isBlockingSynchronousMethod = true) + @DoNotStrip + public abstract WritableMap getBBox(Double tag, ReadableMap options); + + @ReactMethod(isBlockingSynchronousMethod = true) + @DoNotStrip + public abstract WritableMap getCTM(Double tag); + + @ReactMethod(isBlockingSynchronousMethod = true) + @DoNotStrip + public abstract WritableMap getScreenCTM(Double tag); + + @ReactMethod + @DoNotStrip + public abstract void getRawResource(String name, Promise promise); +} diff --git a/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/horcrux/svg/NativeSvgViewModuleSpec.java b/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/horcrux/svg/NativeSvgViewModuleSpec.java new file mode 100644 index 0000000000000..541adf3b6a3f0 --- /dev/null +++ b/android/vendored/unversioned/react-native-svg/android/src/paper/java/com/horcrux/svg/NativeSvgViewModuleSpec.java @@ -0,0 +1,28 @@ +/** + * This code was generated by + * [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + *

Do not edit this file as changes may cause incorrect behavior and will be lost once the code + * is regenerated. + * + * @generated by codegen project: GenerateModuleJavaSpec.js + * @nolint + */ +package com.horcrux.rnsvg; + +import com.facebook.proguard.annotations.DoNotStrip; +import com.facebook.react.bridge.Callback; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.bridge.ReadableMap; + +public abstract class NativeSvgViewModuleSpec extends ReactContextBaseJavaModule { + public NativeSvgViewModuleSpec(ReactApplicationContext reactContext) { + super(reactContext); + } + + @ReactMethod + @DoNotStrip + public abstract void toDataURL(Double tag, ReadableMap options, Callback callback); +} diff --git a/apps/bare-expo/ios/Podfile.lock b/apps/bare-expo/ios/Podfile.lock index 58e4dc6c86361..bfe7ad634297a 100644 --- a/apps/bare-expo/ios/Podfile.lock +++ b/apps/bare-expo/ios/Podfile.lock @@ -839,7 +839,7 @@ PODS: - React-RCTImage - RNSharedElement (0.8.8): - React-Core - - RNSVG (13.4.0): + - RNSVG (13.9.0): - React-Core - SDWebImage (5.15.8): - SDWebImage/Core (= 5.15.8) @@ -1503,7 +1503,7 @@ SPEC CHECKSUMS: RNReanimated: b4f101902606e60b4b045e813e47204c2d7b38a7 RNScreens: 218801c16a2782546d30bd2026bb625c0302d70f RNSharedElement: 504fa28a235b12505b6daedbb452a9ec96809bd0 - RNSVG: 07dbd870b0dcdecc99b3a202fa37c8ca163caec2 + RNSVG: 53c661b76829783cdaf9b7a57258f3d3b4c28315 SDWebImage: cb032eba469c54e0000e78bcb0a13cdde0a52798 SDWebImageAVIFCoder: 4aeea8fdf65af5c18525ecb5bdd8b8ed9bb45019 SDWebImageSVGCoder: 15a300a97ec1c8ac958f009c02220ac0402e936c diff --git a/apps/bare-expo/package.json b/apps/bare-expo/package.json index 1887cc4af90e7..202efc23d0b8b 100644 --- a/apps/bare-expo/package.json +++ b/apps/bare-expo/package.json @@ -87,7 +87,7 @@ "react-native-safe-area-context": "4.5.0", "react-native-screens": "~3.20.0", "react-native-shared-element": "0.8.8", - "react-native-svg": "13.4.0", + "react-native-svg": "13.9.0", "react-native-view-shot": "3.6.0", "react-native-webview": "11.26.0", "test-suite": "*" diff --git a/apps/native-component-list/package.json b/apps/native-component-list/package.json index 5b30911563cef..71b1765797f19 100644 --- a/apps/native-component-list/package.json +++ b/apps/native-component-list/package.json @@ -151,7 +151,7 @@ "react-native-safe-area-context": "4.5.0", "react-native-screens": "~3.20.0", "react-native-shared-element": "0.8.8", - "react-native-svg": "13.4.0", + "react-native-svg": "13.9.0", "react-native-view-shot": "3.6.0", "react-native-web": "~0.18.10", "react-native-webview": "11.26.0", diff --git a/dev-home-config.json b/dev-home-config.json index cefbdbc491de8..40a84851f7884 100644 --- a/dev-home-config.json +++ b/dev-home-config.json @@ -1,3 +1,3 @@ { - "url": "exp://exp.host/@expo-home-dev/expo-home-dev-08559626fd1b2000cdc491d9cfd82de83063d077" + "url": "exp://exp.host/@expo-home-dev/expo-home-dev-5461ebcc6f68405d3adf445d1ef5ace732a40b33" } diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 95e3294b2d550..d7c4b4a576b28 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -2268,7 +2268,7 @@ PODS: - RNScreens (3.20.0): - React-Core - React-RCTImage - - RNSVG (13.4.0): + - RNSVG (13.9.0): - React-Core - SDWebImage (5.15.8): - SDWebImage/Core (= 5.15.8) @@ -3803,7 +3803,7 @@ SPEC CHECKSUMS: RNGestureHandler: 42ec7c28dd02d540ed6c9159c57a98ff016492dc RNReanimated: 48794d0f278349ecb6d94490e7bb184c9cdcd86f RNScreens: 218801c16a2782546d30bd2026bb625c0302d70f - RNSVG: 07dbd870b0dcdecc99b3a202fa37c8ca163caec2 + RNSVG: 53c661b76829783cdaf9b7a57258f3d3b4c28315 SDWebImage: cb032eba469c54e0000e78bcb0a13cdde0a52798 SDWebImageAVIFCoder: 4aeea8fdf65af5c18525ecb5bdd8b8ed9bb45019 SDWebImageSVGCoder: 15a300a97ec1c8ac958f009c02220ac0402e936c diff --git a/ios/vendored/unversioned/react-native-svg/RNSVG.podspec.json b/ios/vendored/unversioned/react-native-svg/RNSVG.podspec.json index bd3e268a067a9..4656084892cc0 100644 --- a/ios/vendored/unversioned/react-native-svg/RNSVG.podspec.json +++ b/ios/vendored/unversioned/react-native-svg/RNSVG.podspec.json @@ -1,6 +1,6 @@ { "name": "RNSVG", - "version": "13.4.0", + "version": "13.9.0", "summary": "SVG library for react-native", "license": "MIT", "homepage": "https://github.com/react-native-community/react-native-svg", @@ -12,7 +12,7 @@ }, "source": { "git": "https://github.com/react-native-community/react-native-svg.git", - "tag": "v13.4.0" + "tag": "v13.9.0" }, "source_files": "apple/**/*.{h,m,mm}", "exclude_files": "apple/Utils/RNSVGFabricConversions.h", diff --git a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGClipPath.mm b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGClipPath.mm index 15a4dfc86d3e1..8b2dcf8be3682 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGClipPath.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGClipPath.mm @@ -8,17 +8,17 @@ #import "RNSVGClipPath.h" -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import #import "RNSVGFabricConversions.h" -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @implementation RNSVGClipPath -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED using namespace facebook::react; - (instancetype)initWithFrame:(CGRect)frame @@ -48,7 +48,7 @@ - (void)prepareForRecycle { [super prepareForRecycle]; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED - (void)parseReference { @@ -70,9 +70,9 @@ - (BOOL)isSimpleClipPath @end -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED Class RNSVGClipPathCls(void) { return RNSVGClipPath.class; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGDefs.mm b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGDefs.mm index 6692ae4ae70d7..67e905a3a3d15 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGDefs.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGDefs.mm @@ -7,17 +7,17 @@ */ #import "RNSVGDefs.h" -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import #import "RNSVGFabricConversions.h" -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @implementation RNSVGDefs -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED using namespace facebook::react; - (instancetype)initWithFrame:(CGRect)frame @@ -35,7 +35,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider { return concreteComponentDescriptorProvider(); } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED - (void)renderTo:(CGContextRef)context { @@ -60,9 +60,9 @@ - (RNSVGPlatformView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event @end -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED Class RNSVGDefsCls(void) { return RNSVGDefs.class; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGForeignObject.mm b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGForeignObject.mm index efe93dc7e77aa..8fb44c6b7a159 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGForeignObject.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGForeignObject.mm @@ -10,17 +10,17 @@ #import "RNSVGMask.h" #import "RNSVGNode.h" -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import #import "RNSVGFabricConversions.h" -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @implementation RNSVGForeignObject -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED using namespace facebook::react; - (instancetype)initWithFrame:(CGRect)frame @@ -68,7 +68,7 @@ - (void)prepareForRecycle _foreignObjectheight = nil; _foreignObjectwidth = nil; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED - (RNSVGPlatformView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { return nil; @@ -211,9 +211,9 @@ - (void)setForeignObjectheight:(RNSVGLength *)foreignObjectheight @end -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED Class RNSVGForeignObjectCls(void) { return RNSVGForeignObject.class; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGGroup.mm b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGGroup.mm index 880b0671bac69..17138e6dd8fe0 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGGroup.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGGroup.mm @@ -10,19 +10,19 @@ #import "RNSVGClipPath.h" #import "RNSVGMask.h" -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import #import "RNSVGFabricConversions.h" -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @implementation RNSVGGroup { RNSVGGlyphContext *_glyphContext; } -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED using namespace facebook::react; - (instancetype)initWithFrame:(CGRect)frame @@ -55,7 +55,7 @@ - (void)prepareForRecycle _font = nil; _glyphContext = nil; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED - (void)setFont:(NSDictionary *)font { @@ -293,9 +293,9 @@ - (void)resetProperties @end -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED Class RNSVGGroupCls(void) { return RNSVGGroup.class; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGImage.h b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGImage.h index 6afcef62289cf..a220e26544773 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGImage.h +++ b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGImage.h @@ -15,7 +15,14 @@ #import +#ifdef RCT_NEW_ARCH_ENABLED +#import +#endif + @interface RNSVGImage : RNSVGRenderable +#ifdef RCT_NEW_ARCH_ENABLED + +#endif @property (nonatomic, weak) RCTBridge *bridge; @property (nonatomic, assign) RCTImageSource *src; @@ -26,6 +33,4 @@ @property (nonatomic, strong) NSString *align; @property (nonatomic, assign) RNSVGVBMOS meetOrSlice; -- (void)setImageSrc:(RCTImageSource *)source request:(NSURLRequest *)request; - @end diff --git a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGImage.mm b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGImage.mm index ca06d77286b4f..1b71165849342 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGImage.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGImage.mm @@ -20,42 +20,45 @@ #import #import -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED #import #import #import "RNSVGViewBox.h" -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import #import +#import #import #import #import #import +#import #import "RNSVGFabricConversions.h" -// Some RN private method hacking below similar to how it is done in RNScreens: -// https://github.com/software-mansion/react-native-screens/blob/90e548739f35b5ded2524a9d6410033fc233f586/ios/RNSScreenStackHeaderConfig.mm#L30 -@interface RCTBridge (Private) -+ (RCTBridge *)currentBridge; -@end - -#endif // RN_FABRIC_ENABLED +using namespace facebook::react; +#endif // RCT_NEW_ARCH_ENABLED @implementation RNSVGImage { CGImageRef _image; CGSize _imageSize; RCTImageLoaderCancellationBlock _reloadImageCancellationBlock; + +#ifdef RCT_NEW_ARCH_ENABLED + RNSVGImageShadowNode::ConcreteState::Shared _state; + RCTImageResponseObserverProxy _imageResponseObserverProxy; +#endif // RCT_NEW_ARCH_ENABLED } -#ifdef RN_FABRIC_ENABLED -using namespace facebook::react; +#ifdef RCT_NEW_ARCH_ENABLED - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { static const auto defaultProps = std::make_shared(); _props = defaultProps; + + _imageResponseObserverProxy = RCTImageResponseObserverProxy(self); } return self; } @@ -70,7 +73,6 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { const auto &newProps = *std::static_pointer_cast(props); - const auto &oldImageProps = *std::static_pointer_cast(oldProps); self.x = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.x)]; self.y = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.y)]; @@ -80,15 +82,6 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & if (RCTNSStringFromStringNilIfEmpty(newProps.width)) { self.imagewidth = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.width)]; } - - if (oldProps == nullptr || oldImageProps.src != newProps.src) { - // TODO: make it the same as in e.g. slider - NSURLRequest *request = NSURLRequestFromImageSource(newProps.src); - CGSize size = RCTCGSizeFromSize(newProps.src.size); - CGFloat scale = newProps.src.scale; - RCTImageSource *imageSource = [[RCTImageSource alloc] initWithURLRequest:request size:size scale:scale]; - [self setImageSrc:imageSource request:request]; - } self.align = RCTNSStringFromStringNilIfEmpty(newProps.align); self.meetOrSlice = intToRNSVGVBMOS(newProps.meetOrSlice); @@ -96,9 +89,68 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & _props = std::static_pointer_cast(props); } +- (void)updateState:(State::Shared const &)state oldState:(State::Shared const &)oldState +{ + RCTAssert(state, @"`state` must not be null."); + RCTAssert( + std::dynamic_pointer_cast(state), + @"`state` must be a pointer to `RNSVGImageShadowNode::ConcreteState`."); + + auto oldImageState = std::static_pointer_cast(_state); + auto newImageState = std::static_pointer_cast(state); + + [self _setStateAndResubscribeImageResponseObserver:newImageState]; +} + +- (void)_setStateAndResubscribeImageResponseObserver:(RNSVGImageShadowNode::ConcreteState::Shared const &)state +{ + if (_state) { + auto &observerCoordinator = _state->getData().getImageRequest().getObserverCoordinator(); + observerCoordinator.removeObserver(_imageResponseObserverProxy); + } + + _state = state; + + if (_state) { + auto &observerCoordinator = _state->getData().getImageRequest().getObserverCoordinator(); + observerCoordinator.addObserver(_imageResponseObserverProxy); + } +} + +#pragma mark - RCTImageResponseDelegate + +- (void)didReceiveImage:(UIImage *)image metadata:(id)metadata fromObserver:(void const *)observer +{ + if (!_eventEmitter || !_state) { + // Notifications are delivered asynchronously and might arrive after the view is already recycled. + // In the future, we should incorporate an `EventEmitter` into a separate object owned by `ImageRequest` or `State`. + // See for more info: T46311063. + return; + } + dispatch_async(dispatch_get_main_queue(), ^{ + self->_image = CGImageRetain(image.CGImage); + self->_imageSize = CGSizeMake(CGImageGetWidth(self->_image), CGImageGetHeight(self->_image)); + [self invalidate]; + }); +} + +- (void)didReceiveProgress:(float)progress fromObserver:(void const *)observer +{ +} + +- (void)didReceiveFailureFromObserver:(void const *)observer +{ + if (_image) { + CGImageRelease(_image); + } + _image = nil; +} + - (void)prepareForRecycle { [super prepareForRecycle]; + [self _setStateAndResubscribeImageResponseObserver:nullptr]; + _x = nil; _y = nil; _imageheight = nil; @@ -114,10 +166,12 @@ - (void)prepareForRecycle _imageSize = CGSizeZero; _reloadImageCancellationBlock = nil; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED -- (void)setImageSrc:(RCTImageSource *)src request:(NSURLRequest *)request +- (void)setSrc:(RCTImageSource *)src { +#ifdef RCT_NEW_ARCH_ENABLED +#else if (src == _src) { return; } @@ -136,24 +190,16 @@ - (void)setImageSrc:(RCTImageSource *)src request:(NSURLRequest *)request _reloadImageCancellationBlock = nil; } - _reloadImageCancellationBlock = [[ -#ifdef RN_FABRIC_ENABLED - [RCTBridge currentBridge] -#else - self.bridge -#endif // RN_FABRIC_ENABLED - moduleForName:@"ImageLoader"] loadImageWithURLRequest:request callback:^(NSError *error, UIImage *image) { - dispatch_async(dispatch_get_main_queue(), ^{ - self->_image = CGImageRetain(image.CGImage); - self->_imageSize = CGSizeMake(CGImageGetWidth(self->_image), CGImageGetHeight(self->_image)); - [self invalidate]; - }); - }]; -} - -- (void)setSrc:(RCTImageSource *)src -{ - [self setImageSrc:src request:src.request]; + _reloadImageCancellationBlock = [[self.bridge moduleForName:@"ImageLoader"] + loadImageWithURLRequest:src.request + callback:^(NSError *error, UIImage *image) { + dispatch_async(dispatch_get_main_queue(), ^{ + self->_image = CGImageRetain(image.CGImage); + self->_imageSize = CGSizeMake(CGImageGetWidth(self->_image), CGImageGetHeight(self->_image)); + [self invalidate]; + }); + }]; +#endif // RCT_NEW_ARCH_ENABLED } - (void)setX:(RNSVGLength *)x @@ -289,9 +335,9 @@ - (CGPathRef)getPath:(CGContextRef)context @end -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED Class RNSVGImageCls(void) { return RNSVGImage.class; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGLinearGradient.mm b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGLinearGradient.mm index 0d72e198805c5..ea891a4d4bb01 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGLinearGradient.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGLinearGradient.mm @@ -9,17 +9,17 @@ #import "RNSVGBrushType.h" #import "RNSVGPainter.h" -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import #import "RNSVGFabricConversions.h" -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @implementation RNSVGLinearGradient -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED using namespace facebook::react; - (instancetype)initWithFrame:(CGRect)frame @@ -79,7 +79,7 @@ - (void)prepareForRecycle _gradientUnits = kRNSVGUnitsObjectBoundingBox; _gradientTransform = CGAffineTransformIdentity; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED - (instancetype)init { @@ -177,9 +177,9 @@ - (void)parseReference } @end -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED Class RNSVGLinearGradientCls(void) { return RNSVGLinearGradient.class; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGMarker.mm b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGMarker.mm index 3d7d38e9bde93..b899554ac98a8 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGMarker.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGMarker.mm @@ -11,17 +11,17 @@ #import "RNSVGPainter.h" #import "RNSVGViewBox.h" -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import #import "RNSVGFabricConversions.h" -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @implementation RNSVGMarker -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED using namespace facebook::react; - (instancetype)initWithFrame:(CGRect)frame @@ -79,7 +79,7 @@ - (void)prepareForRecycle _align = nil; _meetOrSlice = kRNSVGVBMOSMeet; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED - (RNSVGPlatformView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { @@ -271,9 +271,9 @@ - (void)renderMarker:(CGContextRef)context @end -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED Class RNSVGMarkerCls(void) { return RNSVGMarker.class; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGMask.h b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGMask.h index a710c76b90ac3..bea4e4d75fccb 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGMask.h +++ b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGMask.h @@ -10,6 +10,5 @@ @property (nonatomic, strong) RNSVGLength *maskheight; @property (nonatomic, assign) RNSVGUnits maskUnits; @property (nonatomic, assign) RNSVGUnits maskContentUnits; -@property (nonatomic, assign) CGAffineTransform maskTransform; @end diff --git a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGMask.mm b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGMask.mm index 7c58b13bf3cbf..f80a8e9cb93a7 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGMask.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGMask.mm @@ -10,17 +10,17 @@ #import "RNSVGNode.h" #import "RNSVGPainter.h" -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import #import "RNSVGFabricConversions.h" -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @implementation RNSVGMask -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED using namespace facebook::react; - (instancetype)initWithFrame:(CGRect)frame @@ -53,15 +53,6 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & } self.maskUnits = newProps.maskUnits == 0 ? kRNSVGUnitsObjectBoundingBox : kRNSVGUnitsUserSpaceOnUse; self.maskContentUnits = newProps.maskUnits == 0 ? kRNSVGUnitsObjectBoundingBox : kRNSVGUnitsUserSpaceOnUse; - if (newProps.maskTransform.size() == 6) { - self.maskTransform = CGAffineTransformMake( - newProps.maskTransform.at(0), - newProps.maskTransform.at(1), - newProps.maskTransform.at(2), - newProps.maskTransform.at(3), - newProps.maskTransform.at(4), - newProps.maskTransform.at(5)); - } setCommonGroupProps(newProps, self); _props = std::static_pointer_cast(props); @@ -76,9 +67,8 @@ - (void)prepareForRecycle _maskwidth = nil; _maskUnits = kRNSVGUnitsObjectBoundingBox; _maskContentUnits = kRNSVGUnitsObjectBoundingBox; - _maskTransform = CGAffineTransformIdentity; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED - (RNSVGPlatformView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { @@ -151,17 +141,11 @@ - (void)setMaskContentUnits:(RNSVGUnits)maskContentUnits [self invalidate]; } -- (void)setMaskTransform:(CGAffineTransform)maskTransform -{ - _maskTransform = maskTransform; - [self invalidate]; -} - @end -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED Class RNSVGMaskCls(void) { return RNSVGMask.class; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGPath.mm b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGPath.mm index 6e82934140820..1bc92f17d2414 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGPath.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGPath.mm @@ -8,19 +8,19 @@ #import "RNSVGPath.h" -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import #import "RNSVGFabricConversions.h" -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @implementation RNSVGPath { CGPathRef _path; } -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED using namespace facebook::react; - (instancetype)initWithFrame:(CGRect)frame @@ -57,7 +57,7 @@ - (void)prepareForRecycle _path = nil; _d = nil; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED - (void)setD:(RNSVGPathParser *)d { @@ -83,9 +83,9 @@ - (void)dealloc @end -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED Class RNSVGPathCls(void) { return RNSVGPath.class; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGPattern.mm b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGPattern.mm index 3bd7a053563ff..0c6ff0acabd75 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGPattern.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGPattern.mm @@ -10,17 +10,17 @@ #import "RNSVGNode.h" #import "RNSVGPainter.h" -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import #import "RNSVGFabricConversions.h" -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @implementation RNSVGPattern -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED using namespace facebook::react; - (instancetype)initWithFrame:(CGRect)frame @@ -52,7 +52,8 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & self.patternwidth = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.width)]; } self.patternUnits = newProps.patternUnits == 0 ? kRNSVGUnitsObjectBoundingBox : kRNSVGUnitsUserSpaceOnUse; - self.patternContentUnits = newProps.patternUnits == 0 ? kRNSVGUnitsObjectBoundingBox : kRNSVGUnitsUserSpaceOnUse; + self.patternContentUnits = + newProps.patternContentUnits == 0 ? kRNSVGUnitsObjectBoundingBox : kRNSVGUnitsUserSpaceOnUse; if (newProps.patternTransform.size() == 6) { self.patternTransform = CGAffineTransformMake( newProps.patternTransform.at(0), @@ -91,7 +92,7 @@ - (void)prepareForRecycle _align = nil; _meetOrSlice = kRNSVGVBMOSMeet; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED - (instancetype)init { @@ -251,9 +252,9 @@ - (void)setMeetOrSlice:(RNSVGVBMOS)meetOrSlice @end -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED Class RNSVGPatternCls(void) { return RNSVGPattern.class; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGRadialGradient.mm b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGRadialGradient.mm index 3865aa5489f59..d7ed4afb804b0 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGRadialGradient.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGRadialGradient.mm @@ -7,17 +7,17 @@ */ #import "RNSVGRadialGradient.h" -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import #import "RNSVGFabricConversions.h" -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @implementation RNSVGRadialGradient -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED using namespace facebook::react; - (instancetype)initWithFrame:(CGRect)frame @@ -81,7 +81,7 @@ - (void)prepareForRecycle _gradientUnits = kRNSVGUnitsObjectBoundingBox; _gradientTransform = CGAffineTransformIdentity; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED - (instancetype)init { if (self = [super init]) { @@ -199,9 +199,9 @@ - (void)parseReference @end -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED Class RNSVGRadialGradientCls(void) { return RNSVGRadialGradient.class; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGSvgView.h b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGSvgView.h index 0af6323698730..d3c88ffd180f5 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGSvgView.h +++ b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGSvgView.h @@ -12,18 +12,18 @@ #import "RNSVGPainter.h" #import "RNSVGVBMOS.h" -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @class RNSVGNode; @interface RNSVGSvgView : -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED RCTViewComponentView #else RNSVGView -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @property (nonatomic, strong) RNSVGLength *bbWidth; @property (nonatomic, strong) RNSVGLength *bbHeight; diff --git a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGSvgView.mm b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGSvgView.mm index 67cc13361bbb4..51fa1ee9eeb01 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGSvgView.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGSvgView.mm @@ -11,13 +11,13 @@ #import "RNSVGNode.h" #import "RNSVGViewBox.h" -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import #import "RNSVGFabricConversions.h" -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @implementation RNSVGSvgView { NSMutableDictionary *_clipPaths; @@ -29,9 +29,9 @@ @implementation RNSVGSvgView { bool rendered; } -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED using namespace facebook::react; -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED - (instancetype)initWithFrame:(CGRect)frame { @@ -42,17 +42,19 @@ - (instancetype)initWithFrame:(CGRect)frame self.contentMode = UIViewContentModeRedraw; #endif // TARGET_OS_OSX rendered = false; -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED static const auto defaultProps = std::make_shared(); _props = defaultProps; +#if !TARGET_OS_OSX // On macOS, views are transparent by default // TODO: think if we can do it better self.opaque = NO; -#endif // RN_FABRIC_ENABLED +#endif // TARGET_OS_OSX +#endif // RCT_NEW_ARCH_ENABLED } return self; } -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #pragma mark - RCTComponentViewProtocol + (ComponentDescriptorProvider)componentDescriptorProvider @@ -78,7 +80,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & if (RCTUIColorFromSharedColor(newProps.color)) { self.tintColor = RCTUIColorFromSharedColor(newProps.color); } - _props = std::static_pointer_cast(props); + [super updateProps:props oldProps:oldProps]; } - (void)prepareForRecycle @@ -108,7 +110,7 @@ - (void)prepareForRecycle _invviewBoxTransform = CGAffineTransformIdentity; rendered = NO; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED - (void)insertReactSubview:(RNSVGView *)subview atIndex:(NSInteger)atIndex { @@ -253,6 +255,9 @@ - (void)setMeetOrSlice:(RNSVGVBMOS)meetOrSlice - (void)drawToContext:(CGContextRef)context withRect:(CGRect)rect { rendered = true; + _clipPaths = nil; + _templates = nil; + _painters = nil; self.initialCTM = CGContextGetCTM(context); self.invInitialCTM = CGAffineTransformInvert(self.initialCTM); if (self.align) { @@ -264,10 +269,14 @@ - (void)drawToContext:(CGContextRef)context withRect:(CGRect)rect _viewBoxTransform = CGAffineTransformIdentity; _invviewBoxTransform = CGAffineTransformIdentity; } - for (RNSVGView *node in self.subviews) { if ([node isKindOfClass:[RNSVGNode class]]) { RNSVGNode *svg = (RNSVGNode *)node; + if (svg.responsible && !self.responsible) { + self.responsible = YES; + } + + [svg parseReference]; [svg renderTo:context rect:rect]; } else { [node drawRect:rect]; @@ -281,24 +290,9 @@ - (void)drawRect:(CGRect)rect if ([parent isKindOfClass:[RNSVGNode class]]) { return; } - rendered = true; - _clipPaths = nil; - _templates = nil; - _painters = nil; _boundingBox = rect; CGContextRef context = UIGraphicsGetCurrentContext(); - for (RNSVGPlatformView *node in self.subviews) { - if ([node isKindOfClass:[RNSVGNode class]]) { - RNSVGNode *svg = (RNSVGNode *)node; - if (svg.responsible && !self.responsible) { - self.responsible = YES; - } - - [svg parseReference]; - } - } - [self drawToContext:context withRect:rect]; } @@ -435,9 +429,9 @@ - (CGAffineTransform)getViewBoxTransform @end -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED Class RNSVGSvgViewCls(void) { return RNSVGSvgView.class; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGSymbol.mm b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGSymbol.mm index 4fef56d6aeb44..a81bc3945c814 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGSymbol.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGSymbol.mm @@ -8,17 +8,17 @@ #import "RNSVGSymbol.h" #import "RNSVGViewBox.h" -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import #import "RNSVGFabricConversions.h" -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @implementation RNSVGSymbol -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED using namespace facebook::react; - (instancetype)initWithFrame:(CGRect)frame @@ -63,7 +63,7 @@ - (void)prepareForRecycle _align = nil; _meetOrSlice = kRNSVGVBMOSMeet; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED - (void)setMinX:(CGFloat)minX { @@ -148,9 +148,9 @@ - (void)renderSymbolTo:(CGContextRef)context width:(CGFloat)width height:(CGFloa @end -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED Class RNSVGSymbolCls(void) { return RNSVGSymbol.class; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGUse.mm b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGUse.mm index 15b3d49602a38..d0485b7bb8546 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGUse.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/Elements/RNSVGUse.mm @@ -9,17 +9,17 @@ #import #import "RNSVGSymbol.h" -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import #import "RNSVGFabricConversions.h" -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @implementation RNSVGUse -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED using namespace facebook::react; - (instancetype)initWithFrame:(CGRect)frame @@ -65,7 +65,7 @@ - (void)prepareForRecycle _usewidth = nil; _href = nil; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED - (void)setHref:(NSString *)href { @@ -204,9 +204,9 @@ - (CGPathRef)getPath:(CGContextRef)context @end -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED Class RNSVGUseCls(void) { return RNSVGUse.class; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/vendored/unversioned/react-native-svg/apple/RNSVGNode.h b/ios/vendored/unversioned/react-native-svg/apple/RNSVGNode.h index e5e9d72976a20..3c65e102edf38 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/RNSVGNode.h +++ b/ios/vendored/unversioned/react-native-svg/apple/RNSVGNode.h @@ -12,9 +12,9 @@ #import #import -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @class RNSVGGroup; @@ -24,11 +24,11 @@ */ @interface RNSVGNode : -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED RCTViewComponentView #else RNSVGView -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED /* N[1/Sqrt[2], 36] The inverse of the square root of 2. diff --git a/ios/vendored/unversioned/react-native-svg/apple/RNSVGNode.mm b/ios/vendored/unversioned/react-native-svg/apple/RNSVGNode.mm index f3479be999560..2966a1ec52544 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/RNSVGNode.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/RNSVGNode.mm @@ -34,7 +34,9 @@ - (instancetype)init { if (self = [super init]) { self.opacity = 1; +#if !TARGET_OS_OSX // On macOS, views are transparent by default self.opaque = false; +#endif self.matrix = CGAffineTransformIdentity; self.transforms = CGAffineTransformIdentity; self.invTransform = CGAffineTransformIdentity; @@ -238,6 +240,16 @@ - (void)setClientRect:(CGRect)clientRect return; } _clientRect = clientRect; +#ifdef RCT_NEW_ARCH_ENABLED + if (_eventEmitter != nullptr) { + facebook::react::LayoutMetrics customLayoutMetrics = _layoutMetrics; + customLayoutMetrics.frame.size.width = _clientRect.size.width; + customLayoutMetrics.frame.size.height = _clientRect.size.height; + customLayoutMetrics.frame.origin.x = _clientRect.origin.x; + customLayoutMetrics.frame.origin.y = _clientRect.origin.y; + _eventEmitter->onLayout(customLayoutMetrics); + } +#else if (self.onLayout) { self.onLayout(@{ @"layout" : @{ @@ -248,6 +260,7 @@ - (void)setClientRect:(CGRect)clientRect } }); } +#endif } - (void)setClipPath:(NSString *)clipPath @@ -590,13 +603,15 @@ - (void)dealloc CGPathRelease(_path); } -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED - (void)prepareForRecycle { [super prepareForRecycle]; self.opacity = 1; +#if !TARGET_OS_OSX // On macOS, views are transparent by default self.opaque = false; +#endif self.matrix = CGAffineTransformIdentity; self.transforms = CGAffineTransformIdentity; self.invTransform = CGAffineTransformIdentity; @@ -652,6 +667,6 @@ - (void)prepareForRecycle CGPathRelease(_path); _path = nil; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @end diff --git a/ios/vendored/unversioned/react-native-svg/apple/RNSVGRenderable.mm b/ios/vendored/unversioned/react-native-svg/apple/RNSVGRenderable.mm index 4ac4fe14a1bf9..d69b9745209e4 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/RNSVGRenderable.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/RNSVGRenderable.mm @@ -185,7 +185,7 @@ - (void)dealloc _strokeDashArrayData = nil; } -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED - (void)prepareForRecycle { [super prepareForRecycle]; @@ -220,7 +220,7 @@ - (void)prepareForRecycle _vectorEffect = kRNSVGVectorEffectDefault; _propList = nil; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED UInt32 saturate(CGFloat value) { diff --git a/ios/vendored/unversioned/react-native-svg/apple/RNSVGRenderableModule.h b/ios/vendored/unversioned/react-native-svg/apple/RNSVGRenderableModule.h new file mode 100644 index 0000000000000..478ecf626b276 --- /dev/null +++ b/ios/vendored/unversioned/react-native-svg/apple/RNSVGRenderableModule.h @@ -0,0 +1,21 @@ +/** + * Copyright (c) 2015-present, Horcrux. + * All rights reserved. + * + * This source code is licensed under the MIT-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#ifdef RCT_NEW_ARCH_ENABLED +#import +#else +#import +#endif + +@interface RNSVGRenderableModule : NSObject +#ifdef RCT_NEW_ARCH_ENABLED + +#else + +#endif +@end diff --git a/ios/vendored/unversioned/react-native-svg/apple/RNSVGRenderableModule.mm b/ios/vendored/unversioned/react-native-svg/apple/RNSVGRenderableModule.mm new file mode 100644 index 0000000000000..f6af102b3351a --- /dev/null +++ b/ios/vendored/unversioned/react-native-svg/apple/RNSVGRenderableModule.mm @@ -0,0 +1,219 @@ +/** + * Copyright (c) 2015-present, Horcrux. + * All rights reserved. + * + * This source code is licensed under the MIT-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "RNSVGRenderableModule.h" +#import +#import +#import +#import "RNSVGPathMeasure.h" +#import "RNSVGRenderable.h" + +#import "RCTConvert+RNSVG.h" +#import "RNSVGCGFCRule.h" + +@implementation RNSVGRenderableModule + +RCT_EXPORT_MODULE() + +#ifdef RCT_NEW_ARCH_ENABLED +@synthesize viewRegistry_DEPRECATED = _viewRegistry_DEPRECATED; +#endif // RCT_NEW_ARCH_ENABLED +@synthesize bridge = _bridge; + +RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(isPointInFill : (nonnull NSNumber *)reactTag options : (NSDictionary *)options) +{ + RNSVGPlatformView *view = [self getRenderableView:reactTag]; + + if (![view isKindOfClass:[RNSVGRenderable class]]) { + RCTLogError(@"Invalid svg returned from registry, expecting RNSVGRenderable, got: %@", view); + return [NSNumber numberWithBool:false]; + } + if (options == nil) { + RCTLogError(@"Invalid options given to isPointInFill, got: %@", options); + return [NSNumber numberWithBool:false]; + } + id xo = [options objectForKey:@"x"]; + id yo = [options objectForKey:@"y"]; + if (![xo isKindOfClass:NSNumber.class] || ![yo isKindOfClass:NSNumber.class]) { + RCTLogError(@"Invalid x or y given to isPointInFill"); + return [NSNumber numberWithBool:false]; + } + RNSVGRenderable *svg = (RNSVGRenderable *)view; + CGFloat x = (CGFloat)[xo doubleValue]; + CGFloat y = (CGFloat)[yo doubleValue]; + CGPoint point = CGPointMake(x, y); + RNSVGPlatformView *target = [svg hitTest:point withEvent:nil]; + BOOL hit = target != nil; + return [NSNumber numberWithBool:hit]; +} + +RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(isPointInStroke : (nonnull NSNumber *)reactTag options : (NSDictionary *)options) +{ + RNSVGPlatformView *view = [self getRenderableView:reactTag]; + + if (![view isKindOfClass:[RNSVGRenderable class]]) { + RCTLogError(@"Invalid svg returned from registry, expecting RNSVGRenderable, got: %@", view); + return [NSNumber numberWithBool:false]; + } + if (options == nil) { + RCTLogError(@"Invalid options given to isPointInFill, got: %@", options); + return [NSNumber numberWithBool:false]; + } + id xo = [options objectForKey:@"x"]; + id yo = [options objectForKey:@"y"]; + if (![xo isKindOfClass:NSNumber.class] || ![yo isKindOfClass:NSNumber.class]) { + RCTLogError(@"Invalid x or y given to isPointInFill"); + return [NSNumber numberWithBool:false]; + } + RNSVGRenderable *svg = (RNSVGRenderable *)view; + CGFloat x = (CGFloat)[xo doubleValue]; + CGFloat y = (CGFloat)[yo doubleValue]; + CGPoint point = CGPointMake(x, y); + BOOL hit = CGPathContainsPoint(svg.strokePath, nil, point, NO); + + return [NSNumber numberWithBool:hit]; +} + +RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getTotalLength : (nonnull NSNumber *)reactTag) +{ + RNSVGPlatformView *view = [self getRenderableView:reactTag]; + + if (![view isKindOfClass:[RNSVGRenderable class]]) { + RCTLogError(@"Invalid svg returned from registry, expecting RNSVGRenderable, got: %@", view); + return [NSNumber numberWithDouble:0]; + } + + RNSVGPathMeasure *measure = [[RNSVGPathMeasure alloc] init]; + RNSVGRenderable *svg = (RNSVGRenderable *)view; + CGPathRef target = [svg getPath:nil]; + [measure extractPathData:target]; + + return [NSNumber numberWithDouble:measure.pathLength]; +} + +RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getPointAtLength + : (nonnull NSNumber *)reactTag options + : (NSDictionary *)options) +{ + RNSVGPlatformView *view = [self getRenderableView:reactTag]; + + if (![view isKindOfClass:[RNSVGRenderable class]]) { + RCTLogError(@"Invalid svg returned from registry, expecting RNSVGRenderable, got: %@", view); + return nil; + } + + CGFloat position = (CGFloat)[[options objectForKey:@"length"] doubleValue]; + RNSVGPathMeasure *measure = [[RNSVGPathMeasure alloc] init]; + RNSVGRenderable *svg = (RNSVGRenderable *)view; + CGPathRef target = [svg getPath:nil]; + [measure extractPathData:target]; + + CGFloat x; + CGFloat y; + CGFloat angle; + double midPoint = fmax(0, fmin(position, measure.pathLength)); + [measure getPosAndTan:&angle midPoint:midPoint x:&x y:&y]; + + return @{@"x" : @(x), @"y" : @(y), @"angle" : @(angle)}; +} + +RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getBBox : (nonnull NSNumber *)reactTag options : (NSDictionary *)options) +{ + RNSVGPlatformView *view = [self getRenderableView:reactTag]; + + if (![view isKindOfClass:[RNSVGRenderable class]]) { + RCTLogError(@"Invalid svg returned from registry, expecting RNSVGRenderable, got: %@", view); + return nil; + } + + RNSVGRenderable *svg = (RNSVGRenderable *)view; + BOOL fill = [[options objectForKey:@"fill"] boolValue]; + BOOL stroke = [[options objectForKey:@"stroke"] boolValue]; + BOOL markers = [[options objectForKey:@"markers"] boolValue]; + BOOL clipped = [[options objectForKey:@"clipped"] boolValue]; + [svg getPath:nil]; + + CGRect bounds = CGRectZero; + if (fill) { + bounds = CGRectUnion(bounds, svg.fillBounds); + } + if (stroke) { + bounds = CGRectUnion(bounds, svg.strokeBounds); + } + if (markers) { + bounds = CGRectUnion(bounds, svg.markerBounds); + } + if (clipped) { + CGPathRef clipPath = [svg getClipPath]; + CGRect clipBounds = CGPathGetBoundingBox(clipPath); + if (clipPath && !CGRectIsEmpty(clipBounds)) { + bounds = CGRectIntersection(bounds, clipBounds); + } + } + + CGPoint origin = bounds.origin; + CGSize size = bounds.size; + return @{@"x" : @(origin.x), @"y" : @(origin.y), @"width" : @(size.width), @"height" : @(size.height)}; +} + +RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getCTM : (nonnull NSNumber *)reactTag) +{ + RNSVGPlatformView *view = [self getRenderableView:reactTag]; + + if (![view isKindOfClass:[RNSVGRenderable class]]) { + RCTLogError(@"Invalid svg returned from registry, expecting RNSVGRenderable, got: %@", view); + return nil; + } + + RNSVGRenderable *svg = (RNSVGRenderable *)view; + CGAffineTransform ctm = svg.ctm; + return @{@"a" : @(ctm.a), @"b" : @(ctm.b), @"c" : @(ctm.c), @"d" : @(ctm.d), @"e" : @(ctm.tx), @"f" : @(ctm.ty)}; +} + +RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getScreenCTM : (nonnull NSNumber *)reactTag) +{ + RNSVGPlatformView *view = [self getRenderableView:reactTag]; + + if (![view isKindOfClass:[RNSVGRenderable class]]) { + RCTLogError(@"Invalid svg returned from registry, expecting RNSVGRenderable, got: %@", view); + return nil; + } + + RNSVGRenderable *svg = (RNSVGRenderable *)view; + CGAffineTransform ctm = svg.ctm; + return @{@"a" : @(ctm.a), @"b" : @(ctm.b), @"c" : @(ctm.c), @"d" : @(ctm.d), @"e" : @(ctm.tx), @"f" : @(ctm.ty)}; +} + +- (void)getRawResource:(NSString *)name resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject +{ +} + +- (RNSVGPlatformView *)getRenderableView:(NSNumber *)reactTag +{ + __block RNSVGPlatformView *view; +#ifdef RCT_NEW_ARCH_ENABLED + dispatch_sync(dispatch_get_main_queue(), ^{ + view = [self.viewRegistry_DEPRECATED viewForReactTag:reactTag]; + }); +#else + dispatch_sync(dispatch_get_main_queue(), ^{ + view = [self.bridge.uiManager viewForReactTag:reactTag]; + }); +#endif // RCT_NEW_ARCH_ENABLED + return view; +} + +#ifdef RCT_NEW_ARCH_ENABLED +- (std::shared_ptr)getTurboModule: + (const facebook::react::ObjCTurboModule::InitParams &)params +{ + return std::make_shared(params); +} +#endif + +@end diff --git a/ios/vendored/unversioned/react-native-svg/apple/RNSVGSvgViewModule.h b/ios/vendored/unversioned/react-native-svg/apple/RNSVGSvgViewModule.h new file mode 100644 index 0000000000000..85b2f0fa3eea4 --- /dev/null +++ b/ios/vendored/unversioned/react-native-svg/apple/RNSVGSvgViewModule.h @@ -0,0 +1,21 @@ +/** + * Copyright (c) 2015-present, Horcrux. + * All rights reserved. + * + * This source code is licensed under the MIT-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#ifdef RCT_NEW_ARCH_ENABLED +#import +#else +#import +#endif + +@interface RNSVGSvgViewModule : NSObject +#ifdef RCT_NEW_ARCH_ENABLED + +#else + +#endif +@end diff --git a/ios/vendored/unversioned/react-native-svg/apple/RNSVGSvgViewModule.mm b/ios/vendored/unversioned/react-native-svg/apple/RNSVGSvgViewModule.mm new file mode 100644 index 0000000000000..231940e7d2e9c --- /dev/null +++ b/ios/vendored/unversioned/react-native-svg/apple/RNSVGSvgViewModule.mm @@ -0,0 +1,94 @@ +/** + * Copyright (c) 2015-present, Horcrux. + * All rights reserved. + * + * This source code is licensed under the MIT-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "RNSVGSvgViewModule.h" +#import +#import +#import +#import "RNSVGSvgView.h" + +@implementation RNSVGSvgViewModule + +RCT_EXPORT_MODULE() + +#ifdef RCT_NEW_ARCH_ENABLED +@synthesize viewRegistry_DEPRECATED = _viewRegistry_DEPRECATED; +#endif // RCT_NEW_ARCH_ENABLED +@synthesize bridge = _bridge; + +- (void)toDataURL:(nonnull NSNumber *)reactTag + options:(NSDictionary *)options + callback:(RCTResponseSenderBlock)callback + attempt:(int)attempt +{ + void (^block)(void) = ^{ +#ifdef RCT_NEW_ARCH_ENABLED + [self.viewRegistry_DEPRECATED addUIBlock:^(RCTViewRegistry *viewRegistry) { + __kindof RNSVGPlatformView *view = [viewRegistry viewForReactTag:reactTag]; +#else + [self.bridge.uiManager + addUIBlock:^(RCTUIManager *uiManager, NSDictionary *viewRegistry) { + __kindof RNSVGPlatformView *view = [uiManager viewForReactTag:reactTag]; +#endif // RCT_NEW_ARCH_ENABLED + NSString *b64; + if ([view isKindOfClass:[RNSVGSvgView class]]) { + RNSVGSvgView *svg = view; + if (options == nil) { + b64 = [svg getDataURL]; + } else { + id width = [options objectForKey:@"width"]; + id height = [options objectForKey:@"height"]; + if (![width isKindOfClass:NSNumber.class] || ![height isKindOfClass:NSNumber.class]) { + RCTLogError(@"Invalid width or height given to toDataURL"); + return; + } + NSNumber *w = width; + NSInteger wi = (NSInteger)[w intValue]; + NSNumber *h = height; + NSInteger hi = (NSInteger)[h intValue]; + + CGRect bounds = CGRectMake(0, 0, wi, hi); + b64 = [svg getDataURLwithBounds:bounds]; + } + } else { + RCTLogError(@"Invalid svg returned from registry, expecting RNSVGSvgView, got: %@", view); + return; + } + if (b64) { + callback(@[ b64 ]); + } else if (attempt < 1) { + [self toDataURL:reactTag options:options callback:callback attempt:(attempt + 1)]; + } else { + callback(@[]); + } + }]; + }; + if (self.bridge) { + dispatch_async(RCTGetUIManagerQueue(), block); + } else { + dispatch_async(dispatch_get_main_queue(), block); + } +} + +RCT_EXPORT_METHOD(toDataURL + : (nonnull NSNumber *)reactTag options + : (NSDictionary *)options callback + : (RCTResponseSenderBlock)callback) +{ + [self toDataURL:reactTag options:options callback:callback attempt:0]; +} + +#ifdef RCT_NEW_ARCH_ENABLED +- (std::shared_ptr)getTurboModule: + (const facebook::react::ObjCTurboModule::InitParams &)params +{ + return std::make_shared(params); +} +#endif + +@end diff --git a/ios/vendored/unversioned/react-native-svg/apple/Shapes/RNSVGCircle.mm b/ios/vendored/unversioned/react-native-svg/apple/Shapes/RNSVGCircle.mm index 3040ae9d5afc8..f92960beb9403 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Shapes/RNSVGCircle.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/Shapes/RNSVGCircle.mm @@ -9,17 +9,17 @@ #import "RNSVGCircle.h" #import -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import #import "RNSVGFabricConversions.h" -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @implementation RNSVGCircle -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED using namespace facebook::react; - (instancetype)initWithFrame:(CGRect)frame @@ -57,7 +57,7 @@ - (void)prepareForRecycle _cy = nil; _r = nil; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED - (void)setCx:(RNSVGLength *)cx { @@ -98,9 +98,9 @@ - (CGPathRef)getPath:(CGContextRef)context @end -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED Class RNSVGCircleCls(void) { return RNSVGCircle.class; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/vendored/unversioned/react-native-svg/apple/Shapes/RNSVGEllipse.mm b/ios/vendored/unversioned/react-native-svg/apple/Shapes/RNSVGEllipse.mm index 3b627e3aac9a9..05ebf3d62cac7 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Shapes/RNSVGEllipse.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/Shapes/RNSVGEllipse.mm @@ -9,17 +9,17 @@ #import "RNSVGEllipse.h" #import -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import #import "RNSVGFabricConversions.h" -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @implementation RNSVGEllipse -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED using namespace facebook::react; - (instancetype)initWithFrame:(CGRect)frame @@ -59,7 +59,7 @@ - (void)prepareForRecycle _rx = nil; _ry = nil; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED - (void)setCx:(RNSVGLength *)cx { @@ -110,9 +110,9 @@ - (CGPathRef)getPath:(CGContextRef)context @end -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED Class RNSVGEllipseCls(void) { return RNSVGEllipse.class; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/vendored/unversioned/react-native-svg/apple/Shapes/RNSVGLine.mm b/ios/vendored/unversioned/react-native-svg/apple/Shapes/RNSVGLine.mm index 542ed04778f83..789cdc5234139 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Shapes/RNSVGLine.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/Shapes/RNSVGLine.mm @@ -9,17 +9,17 @@ #import "RNSVGLine.h" #import -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import #import "RNSVGFabricConversions.h" -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @implementation RNSVGLine -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED using namespace facebook::react; - (instancetype)initWithFrame:(CGRect)frame @@ -59,7 +59,7 @@ - (void)prepareForRecycle _x2 = nil; _y2 = nil; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED - (void)setX1:(RNSVGLength *)x1 { @@ -112,9 +112,9 @@ - (CGPathRef)getPath:(CGContextRef)context @end -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED Class RNSVGLineCls(void) { return RNSVGLine.class; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/vendored/unversioned/react-native-svg/apple/Shapes/RNSVGRect.mm b/ios/vendored/unversioned/react-native-svg/apple/Shapes/RNSVGRect.mm index 7ee4e0ba1f02d..bfc6833d58cf1 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Shapes/RNSVGRect.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/Shapes/RNSVGRect.mm @@ -9,17 +9,17 @@ #import "RNSVGRect.h" #import -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import #import "RNSVGFabricConversions.h" -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @implementation RNSVGRect -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED using namespace facebook::react; - (instancetype)initWithFrame:(CGRect)frame @@ -69,7 +69,7 @@ - (void)prepareForRecycle _ry = nil; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED - (void)setX:(RNSVGLength *)x { @@ -165,9 +165,9 @@ - (CGPathRef)getPath:(CGContextRef)context @end -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED Class RNSVGRectCls(void) { return RNSVGRect.class; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/vendored/unversioned/react-native-svg/apple/Text/RNSVGTSpan.mm b/ios/vendored/unversioned/react-native-svg/apple/Text/RNSVGTSpan.mm index 64722dfbaed2d..a2fee5f95d6f4 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Text/RNSVGTSpan.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/Text/RNSVGTSpan.mm @@ -17,13 +17,13 @@ static NSCharacterSet *RNSVGTSpan_separators = nil; static CGFloat RNSVGTSpan_radToDeg = 180 / (CGFloat)M_PI; -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import #import "RNSVGFabricConversions.h" -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @implementation RNSVGTSpan { CGFloat startOffset; @@ -37,7 +37,7 @@ @implementation RNSVGTSpan { RNSVGPathMeasure *measure; } -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED using namespace facebook::react; - (instancetype)initWithFrame:(CGRect)frame @@ -88,7 +88,7 @@ - (void)prepareForRecycle measure = [[RNSVGPathMeasure alloc] init]; RNSVGTSpan_separators = [NSCharacterSet whitespaceCharacterSet]; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED - (id)init { @@ -1117,9 +1117,9 @@ - (void)setupTextPath:(CGContextRef)context @end -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED Class RNSVGTSpanCls(void) { return RNSVGTSpan.class; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/vendored/unversioned/react-native-svg/apple/Text/RNSVGText.mm b/ios/vendored/unversioned/react-native-svg/apple/Text/RNSVGText.mm index 5f789149a3038..3119141442348 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Text/RNSVGText.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/Text/RNSVGText.mm @@ -13,13 +13,13 @@ #import "RNSVGTextPath.h" #import "RNSVGTextProperties.h" -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import #import "RNSVGFabricConversions.h" -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @implementation RNSVGText { RNSVGGlyphContext *_glyphContext; @@ -28,7 +28,7 @@ @implementation RNSVGText { CGFloat cachedAdvance; } -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED using namespace facebook::react; - (instancetype)initWithFrame:(CGRect)frame @@ -75,7 +75,7 @@ - (void)prepareForRecycle _baselineShift = nil; cachedAdvance = 0; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED - (void)invalidate { @@ -357,9 +357,9 @@ - (CGFloat)getSubtreeTextChunksTotalAdvance @end -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED Class RNSVGTextCls(void) { return RNSVGText.class; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/vendored/unversioned/react-native-svg/apple/Text/RNSVGTextPath.mm b/ios/vendored/unversioned/react-native-svg/apple/Text/RNSVGTextPath.mm index 443d07a4fe7a3..a7cc4e6215f65 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Text/RNSVGTextPath.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/Text/RNSVGTextPath.mm @@ -8,17 +8,17 @@ #import "RNSVGTextPath.h" -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import #import "RNSVGFabricConversions.h" -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED @implementation RNSVGTextPath -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED using namespace facebook::react; - (instancetype)initWithFrame:(CGRect)frame @@ -63,7 +63,7 @@ - (void)prepareForRecycle _spacing = nil; _startOffset = nil; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED - (void)setHref:(NSString *)href { @@ -141,9 +141,9 @@ - (void)popGlyphContext @end -#ifdef RN_FABRIC_ENABLED +#ifdef RCT_NEW_ARCH_ENABLED Class RNSVGTextPathCls(void) { return RNSVGTextPath.class; } -#endif // RN_FABRIC_ENABLED +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/vendored/unversioned/react-native-svg/apple/Text/RNSVGTopAlignedLabel.h b/ios/vendored/unversioned/react-native-svg/apple/Text/RNSVGTopAlignedLabel.h index 8984e4982f5ef..d356d0f8496ed 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Text/RNSVGTopAlignedLabel.h +++ b/ios/vendored/unversioned/react-native-svg/apple/Text/RNSVGTopAlignedLabel.h @@ -8,6 +8,7 @@ @property NSString *text; @property NSTextAlignment textAlignment; #else +#import @interface RNSVGTopAlignedLabel : UILabel #endif @end diff --git a/ios/vendored/unversioned/react-native-svg/apple/Utils/RNSVGCGFCRule.h b/ios/vendored/unversioned/react-native-svg/apple/Utils/RNSVGCGFCRule.h index b49dd7b009f52..17f31d0484f45 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Utils/RNSVGCGFCRule.h +++ b/ios/vendored/unversioned/react-native-svg/apple/Utils/RNSVGCGFCRule.h @@ -5,8 +5,9 @@ * This source code is licensed under the MIT-style license found in the * LICENSE file in the root directory of this source tree. */ +#import typedef CF_ENUM(int32_t, RNSVGCGFCRule) { kRNSVGCGFCRuleEvenodd, kRNSVGCGFCRuleNonzero -}; \ No newline at end of file +}; diff --git a/ios/vendored/unversioned/react-native-svg/apple/Utils/RNSVGFabricConversions.h b/ios/vendored/unversioned/react-native-svg/apple/Utils/RNSVGFabricConversions.h index ab4da0a51fdaf..e2973f52c8b17 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/Utils/RNSVGFabricConversions.h +++ b/ios/vendored/unversioned/react-native-svg/apple/Utils/RNSVGFabricConversions.h @@ -82,6 +82,9 @@ void setCommonNodeProps(T nodeProps, RNSVGNode *node) } else { node.pointerEvents = RCTPointerEventsUnspecified; } + node.accessibilityIdentifier = RCTNSStringFromStringNilIfEmpty(nodeProps.testId); + node.isAccessibilityElement = nodeProps.accessible; + node.accessibilityLabel = RCTNSStringFromStringNilIfEmpty(nodeProps.accessibilityLabel); } static NSMutableArray *createLengthArrayFromStrings(std::vector stringArray) diff --git a/ios/vendored/unversioned/react-native-svg/apple/ViewManagers/RNSVGMaskManager.mm b/ios/vendored/unversioned/react-native-svg/apple/ViewManagers/RNSVGMaskManager.mm index bcc5325706929..8dbe8e7c460fb 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/ViewManagers/RNSVGMaskManager.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/ViewManagers/RNSVGMaskManager.mm @@ -30,6 +30,5 @@ - (RNSVGMask *)node } RCT_EXPORT_VIEW_PROPERTY(maskUnits, RNSVGUnits) RCT_EXPORT_VIEW_PROPERTY(maskContentUnits, RNSVGUnits) -RCT_EXPORT_VIEW_PROPERTY(maskTransform, CGAffineTransform) @end diff --git a/ios/vendored/unversioned/react-native-svg/apple/ViewManagers/RNSVGNodeManager.mm b/ios/vendored/unversioned/react-native-svg/apple/ViewManagers/RNSVGNodeManager.mm index c77937ffbd1c7..f670bc0101ee1 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/ViewManagers/RNSVGNodeManager.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/ViewManagers/RNSVGNodeManager.mm @@ -7,139 +7,12 @@ */ #import "RNSVGNodeManager.h" - #import "RNSVGNode.h" -static const NSUInteger kMatrixArrayLength = 4 * 4; +#import @implementation RNSVGNodeManager -+ (CGFloat)convertToRadians:(id)json -{ - if ([json isKindOfClass:[NSString class]]) { - NSString *stringValue = (NSString *)json; - if ([stringValue hasSuffix:@"deg"]) { - CGFloat degrees = [[stringValue substringToIndex:stringValue.length - 3] floatValue]; - return degrees * (CGFloat)M_PI / 180; - } - if ([stringValue hasSuffix:@"rad"]) { - return [[stringValue substringToIndex:stringValue.length - 3] floatValue]; - } - } - return [json floatValue]; -} - -+ (CATransform3D)CATransform3DFromMatrix:(id)json -{ - CATransform3D transform = CATransform3DIdentity; - if (!json) { - return transform; - } - if (![json isKindOfClass:[NSArray class]]) { - RCTLogConvertError(json, @"a CATransform3D. Expected array for transform matrix."); - return transform; - } - NSArray *array = json; - if ([array count] != kMatrixArrayLength) { - RCTLogConvertError(json, @"a CATransform3D. Expected 4x4 matrix array."); - return transform; - } - for (NSUInteger i = 0; i < kMatrixArrayLength; i++) { - ((CGFloat *)&transform)[i] = [RCTConvert CGFloat:array[i]]; - } - return transform; -} - -+ (CATransform3D)CATransform3D:(id)json -{ - CATransform3D transform = CATransform3DIdentity; - if (!json) { - return transform; - } - if (![json isKindOfClass:[NSArray class]]) { - RCTLogConvertError(json, @"a CATransform3D. Did you pass something other than an array?"); - return transform; - } - // legacy matrix support - if ([(NSArray *)json count] == kMatrixArrayLength && [json[0] isKindOfClass:[NSNumber class]]) { - RCTLogWarn( - @"[RCTConvert CATransform3D:] has deprecated a matrix as input. Pass an array of configs (which can contain a matrix key) instead."); - return [self CATransform3DFromMatrix:json]; - } - - CGFloat zeroScaleThreshold = FLT_EPSILON; - - for (NSDictionary *transformConfig in (NSArray *)json) { - if (transformConfig.count != 1) { - RCTLogConvertError(json, @"a CATransform3D. You must specify exactly one property per transform object."); - return transform; - } - NSString *property = transformConfig.allKeys[0]; - id value = transformConfig[property]; - - if ([property isEqualToString:@"matrix"]) { - transform = [self CATransform3DFromMatrix:value]; - - } else if ([property isEqualToString:@"perspective"]) { - transform.m34 = -1 / [value floatValue]; - - } else if ([property isEqualToString:@"rotateX"]) { - CGFloat rotate = [self convertToRadians:value]; - transform = CATransform3DRotate(transform, rotate, 1, 0, 0); - - } else if ([property isEqualToString:@"rotateY"]) { - CGFloat rotate = [self convertToRadians:value]; - transform = CATransform3DRotate(transform, rotate, 0, 1, 0); - - } else if ([property isEqualToString:@"rotate"] || [property isEqualToString:@"rotateZ"]) { - CGFloat rotate = [self convertToRadians:value]; - transform = CATransform3DRotate(transform, rotate, 0, 0, 1); - - } else if ([property isEqualToString:@"scale"]) { - CGFloat scale = [value floatValue]; - scale = ABS(scale) < zeroScaleThreshold ? zeroScaleThreshold : scale; - transform = CATransform3DScale(transform, scale, scale, 1); - - } else if ([property isEqualToString:@"scaleX"]) { - CGFloat scale = [value floatValue]; - scale = ABS(scale) < zeroScaleThreshold ? zeroScaleThreshold : scale; - transform = CATransform3DScale(transform, scale, 1, 1); - - } else if ([property isEqualToString:@"scaleY"]) { - CGFloat scale = [value floatValue]; - scale = ABS(scale) < zeroScaleThreshold ? zeroScaleThreshold : scale; - transform = CATransform3DScale(transform, 1, scale, 1); - - } else if ([property isEqualToString:@"translate"]) { - NSArray *array = (NSArray *)value; - CGFloat translateX = [array[0] floatValue]; - CGFloat translateY = [array[1] floatValue]; - CGFloat translateZ = array.count > 2 ? [array[2] floatValue] : 0; - transform = CATransform3DTranslate(transform, translateX, translateY, translateZ); - - } else if ([property isEqualToString:@"translateX"]) { - CGFloat translate = [value floatValue]; - transform = CATransform3DTranslate(transform, translate, 0, 0); - - } else if ([property isEqualToString:@"translateY"]) { - CGFloat translate = [value floatValue]; - transform = CATransform3DTranslate(transform, 0, translate, 0); - - } else if ([property isEqualToString:@"skewX"]) { - CGFloat skew = [self convertToRadians:value]; - transform.m21 = tanf((float)skew); - - } else if ([property isEqualToString:@"skewY"]) { - CGFloat skew = [self convertToRadians:value]; - transform.m12 = tanf((float)skew); - - } else { - RCTLogError(@"Unsupported transform type for a CATransform3D: %@.", property); - } - } - return transform; -} - RCT_EXPORT_MODULE() - (RNSVGNode *)node @@ -157,7 +30,7 @@ - (RNSVGView *)view RCT_EXPORT_VIEW_PROPERTY(matrix, CGAffineTransform) RCT_CUSTOM_VIEW_PROPERTY(transform, CATransform3D, RNSVGNode) { - CATransform3D transform3d = json ? [RNSVGNodeManager CATransform3D:json] : defaultView.layer.transform; + CATransform3D transform3d = json ? [RCTConvert CATransform3D:json] : defaultView.layer.transform; CGAffineTransform transform = CATransform3DGetAffineTransform(transform3d); view.invTransform = CGAffineTransformInvert(transform); view.transforms = transform; diff --git a/ios/vendored/unversioned/react-native-svg/apple/ViewManagers/RNSVGRenderableManager.mm b/ios/vendored/unversioned/react-native-svg/apple/ViewManagers/RNSVGRenderableManager.mm index 3352e23dbcc4b..3bbf5913a37ee 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/ViewManagers/RNSVGRenderableManager.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/ViewManagers/RNSVGRenderableManager.mm @@ -38,177 +38,4 @@ - (RNSVGRenderable *)node RCT_EXPORT_VIEW_PROPERTY(vectorEffect, int) RCT_EXPORT_VIEW_PROPERTY(propList, NSArray) -RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(isPointInFill : (nonnull NSNumber *)reactTag options : (NSDictionary *)options) -{ - RNSVGPlatformView *view = [self getRenderableView:reactTag]; - - if (![view isKindOfClass:[RNSVGRenderable class]]) { - RCTLogError(@"Invalid svg returned from registry, expecting RNSVGRenderable, got: %@", view); - return [NSNumber numberWithBool:false]; - } - if (options == nil) { - RCTLogError(@"Invalid options given to isPointInFill, got: %@", options); - return [NSNumber numberWithBool:false]; - } - id xo = [options objectForKey:@"x"]; - id yo = [options objectForKey:@"y"]; - if (![xo isKindOfClass:NSNumber.class] || ![yo isKindOfClass:NSNumber.class]) { - RCTLogError(@"Invalid x or y given to isPointInFill"); - return [NSNumber numberWithBool:false]; - } - RNSVGRenderable *svg = (RNSVGRenderable *)view; - CGFloat x = (CGFloat)[xo doubleValue]; - CGFloat y = (CGFloat)[yo doubleValue]; - CGPoint point = CGPointMake(x, y); - RNSVGPlatformView *target = [svg hitTest:point withEvent:nil]; - BOOL hit = target != nil; - return [NSNumber numberWithBool:hit]; -} - -RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(isPointInStroke : (nonnull NSNumber *)reactTag options : (NSDictionary *)options) -{ - RNSVGPlatformView *view = [self getRenderableView:reactTag]; - - if (![view isKindOfClass:[RNSVGRenderable class]]) { - RCTLogError(@"Invalid svg returned from registry, expecting RNSVGRenderable, got: %@", view); - return [NSNumber numberWithBool:false]; - } - if (options == nil) { - RCTLogError(@"Invalid options given to isPointInFill, got: %@", options); - return [NSNumber numberWithBool:false]; - } - id xo = [options objectForKey:@"x"]; - id yo = [options objectForKey:@"y"]; - if (![xo isKindOfClass:NSNumber.class] || ![yo isKindOfClass:NSNumber.class]) { - RCTLogError(@"Invalid x or y given to isPointInFill"); - return [NSNumber numberWithBool:false]; - } - RNSVGRenderable *svg = (RNSVGRenderable *)view; - CGFloat x = (CGFloat)[xo doubleValue]; - CGFloat y = (CGFloat)[yo doubleValue]; - CGPoint point = CGPointMake(x, y); - BOOL hit = CGPathContainsPoint(svg.strokePath, nil, point, NO); - - return [NSNumber numberWithBool:hit]; -} - -RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getTotalLength : (nonnull NSNumber *)reactTag) -{ - RNSVGPlatformView *view = [self getRenderableView:reactTag]; - - if (![view isKindOfClass:[RNSVGRenderable class]]) { - RCTLogError(@"Invalid svg returned from registry, expecting RNSVGRenderable, got: %@", view); - return [NSNumber numberWithDouble:0]; - } - - RNSVGPathMeasure *measure = [[RNSVGPathMeasure alloc] init]; - RNSVGRenderable *svg = (RNSVGRenderable *)view; - CGPathRef target = [svg getPath:nil]; - [measure extractPathData:target]; - - return [NSNumber numberWithDouble:measure.pathLength]; -} - -RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getPointAtLength - : (nonnull NSNumber *)reactTag options - : (NSDictionary *)options) -{ - RNSVGPlatformView *view = [self getRenderableView:reactTag]; - - if (![view isKindOfClass:[RNSVGRenderable class]]) { - RCTLogError(@"Invalid svg returned from registry, expecting RNSVGRenderable, got: %@", view); - return nil; - } - - CGFloat position = (CGFloat)[[options objectForKey:@"length"] doubleValue]; - RNSVGPathMeasure *measure = [[RNSVGPathMeasure alloc] init]; - RNSVGRenderable *svg = (RNSVGRenderable *)view; - CGPathRef target = [svg getPath:nil]; - [measure extractPathData:target]; - - CGFloat x; - CGFloat y; - CGFloat angle; - double midPoint = fmax(0, fmin(position, measure.pathLength)); - [measure getPosAndTan:&angle midPoint:midPoint x:&x y:&y]; - - return @{@"x" : @(x), @"y" : @(y), @"angle" : @(angle)}; -} - -RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getBBox : (nonnull NSNumber *)reactTag options : (NSDictionary *)options) -{ - RNSVGPlatformView *view = [self getRenderableView:reactTag]; - - if (![view isKindOfClass:[RNSVGRenderable class]]) { - RCTLogError(@"Invalid svg returned from registry, expecting RNSVGRenderable, got: %@", view); - return nil; - } - - RNSVGRenderable *svg = (RNSVGRenderable *)view; - BOOL fill = [[options objectForKey:@"fill"] boolValue]; - BOOL stroke = [[options objectForKey:@"stroke"] boolValue]; - BOOL markers = [[options objectForKey:@"markers"] boolValue]; - BOOL clipped = [[options objectForKey:@"clipped"] boolValue]; - [svg getPath:nil]; - - CGRect bounds = CGRectZero; - if (fill) { - bounds = CGRectUnion(bounds, svg.fillBounds); - } - if (stroke) { - bounds = CGRectUnion(bounds, svg.strokeBounds); - } - if (markers) { - bounds = CGRectUnion(bounds, svg.markerBounds); - } - if (clipped) { - CGPathRef clipPath = [svg getClipPath]; - CGRect clipBounds = CGPathGetBoundingBox(clipPath); - if (clipPath && !CGRectIsEmpty(clipBounds)) { - bounds = CGRectIntersection(bounds, clipBounds); - } - } - - CGPoint origin = bounds.origin; - CGSize size = bounds.size; - return @{@"x" : @(origin.x), @"y" : @(origin.y), @"width" : @(size.width), @"height" : @(size.height)}; -} - -RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getCTM : (nonnull NSNumber *)reactTag) -{ - RNSVGPlatformView *view = [self getRenderableView:reactTag]; - - if (![view isKindOfClass:[RNSVGRenderable class]]) { - RCTLogError(@"Invalid svg returned from registry, expecting RNSVGRenderable, got: %@", view); - return nil; - } - - RNSVGRenderable *svg = (RNSVGRenderable *)view; - CGAffineTransform ctm = svg.ctm; - return @{@"a" : @(ctm.a), @"b" : @(ctm.b), @"c" : @(ctm.c), @"d" : @(ctm.d), @"e" : @(ctm.tx), @"f" : @(ctm.ty)}; -} - -RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getScreenCTM : (nonnull NSNumber *)reactTag) -{ - RNSVGPlatformView *view = [self getRenderableView:reactTag]; - - if (![view isKindOfClass:[RNSVGRenderable class]]) { - RCTLogError(@"Invalid svg returned from registry, expecting RNSVGRenderable, got: %@", view); - return nil; - } - - RNSVGRenderable *svg = (RNSVGRenderable *)view; - CGAffineTransform ctm = svg.ctm; - return @{@"a" : @(ctm.a), @"b" : @(ctm.b), @"c" : @(ctm.c), @"d" : @(ctm.d), @"e" : @(ctm.tx), @"f" : @(ctm.ty)}; -} - -- (RNSVGPlatformView *)getRenderableView:(NSNumber *)reactTag -{ - __block RNSVGPlatformView *view; - dispatch_sync(dispatch_get_main_queue(), ^{ - view = [self.bridge.uiManager viewForReactTag:reactTag]; - }); - return view; -} - @end diff --git a/ios/vendored/unversioned/react-native-svg/apple/ViewManagers/RNSVGSvgViewManager.mm b/ios/vendored/unversioned/react-native-svg/apple/ViewManagers/RNSVGSvgViewManager.mm index b7291122f06bc..203b14270f39c 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/ViewManagers/RNSVGSvgViewManager.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/ViewManagers/RNSVGSvgViewManager.mm @@ -7,9 +7,6 @@ */ #import "RNSVGSvgViewManager.h" -#import -#import -#import #import "RNSVGSvgView.h" @implementation RNSVGSvgViewManager @@ -32,58 +29,4 @@ - (RNSVGView *)view RCT_EXPORT_VIEW_PROPERTY(tintColor, UIColor) RCT_REMAP_VIEW_PROPERTY(color, tintColor, UIColor) -- (void)toDataURL:(nonnull NSNumber *)reactTag - options:(NSDictionary *)options - callback:(RCTResponseSenderBlock)callback - attempt:(int)attempt -{ - [self.bridge.uiManager - addUIBlock:^(RCTUIManager *uiManager, NSDictionary *viewRegistry) { - __kindof RNSVGPlatformView *view = [uiManager viewForReactTag:reactTag]; - NSString *b64; - if ([view isKindOfClass:[RNSVGSvgView class]]) { - RNSVGSvgView *svg = view; - if (options == nil) { - b64 = [svg getDataURL]; - } else { - id width = [options objectForKey:@"width"]; - id height = [options objectForKey:@"height"]; - if (![width isKindOfClass:NSNumber.class] || ![height isKindOfClass:NSNumber.class]) { - RCTLogError(@"Invalid width or height given to toDataURL"); - return; - } - NSNumber *w = width; - NSInteger wi = (NSInteger)[w intValue]; - NSNumber *h = height; - NSInteger hi = (NSInteger)[h intValue]; - - CGRect bounds = CGRectMake(0, 0, wi, hi); - b64 = [svg getDataURLwithBounds:bounds]; - } - } else { - RCTLogError(@"Invalid svg returned from registry, expecting RNSVGSvgView, got: %@", view); - return; - } - if (b64) { - callback(@[ b64 ]); - } else if (attempt < 1) { - void (^retryBlock)(void) = ^{ - [self toDataURL:reactTag options:options callback:callback attempt:(attempt + 1)]; - }; - - RCTExecuteOnUIManagerQueue(retryBlock); - } else { - callback(@[]); - } - }]; -} - -RCT_EXPORT_METHOD(toDataURL - : (nonnull NSNumber *)reactTag options - : (NSDictionary *)options callback - : (RCTResponseSenderBlock)callback) -{ - [self toDataURL:reactTag options:options callback:callback attempt:0]; -} - @end diff --git a/ios/vendored/unversioned/react-native-svg/apple/ViewManagers/RNSVGTextManager.mm b/ios/vendored/unversioned/react-native-svg/apple/ViewManagers/RNSVGTextManager.mm index f95a646b3d9cd..cf6aeab5f602a 100644 --- a/ios/vendored/unversioned/react-native-svg/apple/ViewManagers/RNSVGTextManager.mm +++ b/ios/vendored/unversioned/react-native-svg/apple/ViewManagers/RNSVGTextManager.mm @@ -32,7 +32,6 @@ - (RNSVGRenderable *)node { view.positionX = [RCTConvert RNSVGLengthArray:json]; } - RCT_CUSTOM_VIEW_PROPERTY(y, id, RNSVGText) { view.positionY = [RCTConvert RNSVGLengthArray:json]; diff --git a/packages/expo-stories/package.json b/packages/expo-stories/package.json index 521f26e1eb679..92c07b6be9a7d 100644 --- a/packages/expo-stories/package.json +++ b/packages/expo-stories/package.json @@ -33,7 +33,7 @@ "react-native-gesture-handler": "~2.10.1", "react-native-safe-area-context": "4.5.0", "react-native-screens": "~3.20.0", - "react-native-svg": "13.4.0", + "react-native-svg": "13.9.0", "sane": "^5.0.1" } } diff --git a/packages/expo/bundledNativeModules.json b/packages/expo/bundledNativeModules.json index a9996cdab9f5e..18e53cfc99e03 100644 --- a/packages/expo/bundledNativeModules.json +++ b/packages/expo/bundledNativeModules.json @@ -93,7 +93,7 @@ "react-native-screens": "~3.20.0", "react-native-safe-area-context": "4.5.0", "react-native-shared-element": "0.8.8", - "react-native-svg": "13.4.0", + "react-native-svg": "13.9.0", "react-native-view-shot": "3.6.0", "react-native-webview": "11.26.0", "sentry-expo": "~6.2.0", diff --git a/yarn.lock b/yarn.lock index 19d6d1221f6e5..fdf3e3735ea9e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15963,10 +15963,10 @@ react-native-shared-element@0.8.8: resolved "https://registry.yarnpkg.com/react-native-shared-element/-/react-native-shared-element-0.8.8.tgz#1a86ff54d7a96e22d270254d3e642869c7cb3ff3" integrity sha512-ZjnsI9IXckzX5CFl2lbVX8Izn93zBfYw6knUtW41NZ/HAPVq6wlFuSxAhvFNJ4HRZ3FX6b8gUMDYuUfX7djj0A== -react-native-svg@13.4.0: - version "13.4.0" - resolved "https://registry.yarnpkg.com/react-native-svg/-/react-native-svg-13.4.0.tgz#82399ba0956c454144618aa581e2d748dd3f010a" - integrity sha512-B3TwK+H0+JuRhYPzF21AgqMt4fjhCwDZ9QUtwNstT5XcslJBXC0FoTkdZo8IEb1Sv4suSqhZwlAY6lwOv3tHag== +react-native-svg@13.9.0: + version "13.9.0" + resolved "https://registry.yarnpkg.com/react-native-svg/-/react-native-svg-13.9.0.tgz#8df8a690dd00362601f074dec5d3a86dd0f99c7f" + integrity sha512-Ey18POH0dA0ob/QiwCBVrxIiwflhYuw0P0hBlOHeY4J5cdbs8ngdKHeWC/Kt9+ryP6fNoEQ1PUgPYw2Bs/rp5Q== dependencies: css-select "^5.1.0" css-tree "^1.1.3"