From cc14c5bffc7cdfeaa9443df8598530a683812eae Mon Sep 17 00:00:00 2001 From: Jakub Grzywacz Date: Mon, 30 Sep 2024 12:24:37 +0200 Subject: [PATCH 1/4] feat: convert android borderRadiuses from Double/Float to Dynamic --- .../RNSVGSvgViewAndroidManagerDelegate.java | 60 +++++++++---------- .../RNSVGSvgViewAndroidManagerInterface.java | 26 ++++---- src/fabric/AndroidSvgViewNativeComponent.ts | 26 ++++---- 3 files changed, 56 insertions(+), 56 deletions(-) diff --git a/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewAndroidManagerDelegate.java b/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewAndroidManagerDelegate.java index 5d8b614f0..b9c436d67 100644 --- a/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewAndroidManagerDelegate.java +++ b/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewAndroidManagerDelegate.java @@ -60,12 +60,6 @@ public void setProperty(T view, String propName, @Nullable Object value) { 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; @@ -99,9 +93,6 @@ public void setProperty(T view, String propName, @Nullable Object value) { 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; @@ -111,9 +102,6 @@ public void setProperty(T view, String propName, @Nullable Object value) { 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; @@ -135,41 +123,53 @@ public void setProperty(T view, String propName, @Nullable Object value) { case "nextFocusLeft": mViewManager.setNextFocusLeft(view, value == null ? 0 : ((Double) value).intValue()); break; - case "borderTopRightRadius": - mViewManager.setBorderTopRightRadius(view, value == null ? 0f : ((Double) value).doubleValue()); + case "borderBlockColor": + mViewManager.setBorderBlockColor(view, ColorPropConverter.getColor(value, view.getContext())); break; - case "borderBottomRightRadius": - mViewManager.setBorderBottomRightRadius(view, value == null ? 0f : ((Double) value).doubleValue()); + case "borderBlockEndColor": + mViewManager.setBorderBlockEndColor(view, ColorPropConverter.getColor(value, view.getContext())); + break; + case "borderBlockStartColor": + mViewManager.setBorderBlockStartColor(view, ColorPropConverter.getColor(value, view.getContext())); break; case "borderRadius": - mViewManager.setBorderRadius(view, value == null ? 0f : ((Double) value).doubleValue()); + mViewManager.setBorderRadius(view, new DynamicFromObject(value)); + break; + case "borderTopLeftRadius": + mViewManager.setBorderTopLeftRadius(view, new DynamicFromObject(value)); + break; + case "borderTopRightRadius": + mViewManager.setBorderTopRightRadius(view, new DynamicFromObject(value)); + break; + case "borderBottomRightRadius": + mViewManager.setBorderBottomRightRadius(view, new DynamicFromObject(value)); break; case "borderBottomLeftRadius": - mViewManager.setBorderBottomLeftRadius(view, value == null ? 0f : ((Double) value).doubleValue()); + mViewManager.setBorderBottomLeftRadius(view, new DynamicFromObject(value)); break; - case "borderTopLeftRadius": - mViewManager.setBorderTopLeftRadius(view, value == null ? 0f : ((Double) value).doubleValue()); + case "borderTopStartRadius": + mViewManager.setBorderTopStartRadius(view, new DynamicFromObject(value)); break; - case "borderBlockColor": - mViewManager.setBorderBlockColor(view, ColorPropConverter.getColor(value, view.getContext())); + case "borderTopEndRadius": + mViewManager.setBorderTopEndRadius(view, new DynamicFromObject(value)); break; - case "borderBlockEndColor": - mViewManager.setBorderBlockEndColor(view, ColorPropConverter.getColor(value, view.getContext())); + case "borderBottomStartRadius": + mViewManager.setBorderBottomStartRadius(view, new DynamicFromObject(value)); break; - case "borderBlockStartColor": - mViewManager.setBorderBlockStartColor(view, ColorPropConverter.getColor(value, view.getContext())); + case "borderBottomEndRadius": + mViewManager.setBorderBottomEndRadius(view, new DynamicFromObject(value)); break; case "borderEndEndRadius": - mViewManager.setBorderEndEndRadius(view, value == null ? 0f : ((Double) value).doubleValue()); + mViewManager.setBorderEndEndRadius(view, new DynamicFromObject(value)); break; case "borderEndStartRadius": - mViewManager.setBorderEndStartRadius(view, value == null ? 0f : ((Double) value).doubleValue()); + mViewManager.setBorderEndStartRadius(view, new DynamicFromObject(value)); break; case "borderStartEndRadius": - mViewManager.setBorderStartEndRadius(view, value == null ? 0f : ((Double) value).doubleValue()); + mViewManager.setBorderStartEndRadius(view, new DynamicFromObject(value)); break; case "borderStartStartRadius": - mViewManager.setBorderStartStartRadius(view, value == null ? 0f : ((Double) value).doubleValue()); + mViewManager.setBorderStartStartRadius(view, new DynamicFromObject(value)); break; default: super.setProperty(view, propName, value); diff --git a/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewAndroidManagerInterface.java b/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewAndroidManagerInterface.java index 857220f1a..2b7162999 100644 --- a/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewAndroidManagerInterface.java +++ b/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewAndroidManagerInterface.java @@ -27,8 +27,6 @@ public interface RNSVGSvgViewAndroidManagerInterface { 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); @@ -40,11 +38,9 @@ public interface RNSVGSvgViewAndroidManagerInterface { 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); @@ -52,16 +48,20 @@ public interface RNSVGSvgViewAndroidManagerInterface { void setHitSlop(T view, Dynamic 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); void setBorderBlockColor(T view, @Nullable Integer value); void setBorderBlockEndColor(T view, @Nullable Integer value); void setBorderBlockStartColor(T view, @Nullable Integer value); - void setBorderEndEndRadius(T view, double value); - void setBorderEndStartRadius(T view, double value); - void setBorderStartEndRadius(T view, double value); - void setBorderStartStartRadius(T view, double value); + void setBorderRadius(T view, Dynamic value); + void setBorderTopLeftRadius(T view, Dynamic value); + void setBorderTopRightRadius(T view, Dynamic value); + void setBorderBottomRightRadius(T view, Dynamic value); + void setBorderBottomLeftRadius(T view, Dynamic value); + void setBorderTopStartRadius(T view, Dynamic value); + void setBorderTopEndRadius(T view, Dynamic value); + void setBorderBottomStartRadius(T view, Dynamic value); + void setBorderBottomEndRadius(T view, Dynamic value); + void setBorderEndEndRadius(T view, Dynamic value); + void setBorderEndStartRadius(T view, Dynamic value); + void setBorderStartEndRadius(T view, Dynamic value); + void setBorderStartStartRadius(T view, Dynamic value); } diff --git a/src/fabric/AndroidSvgViewNativeComponent.ts b/src/fabric/AndroidSvgViewNativeComponent.ts index 3800c0d0e..1410dedb0 100644 --- a/src/fabric/AndroidSvgViewNativeComponent.ts +++ b/src/fabric/AndroidSvgViewNativeComponent.ts @@ -39,8 +39,6 @@ interface NativeProps extends ViewProps { // props needed for Android SvgView hasTVPreferredFocus?: boolean; - borderTopEndRadius?: Float; - borderBottomStartRadius?: Float; borderBottomColor?: ColorValue; nextFocusDown?: Int32; borderRightColor?: ColorValue; @@ -52,11 +50,9 @@ interface NativeProps extends ViewProps { nextFocusUp?: Int32; accessible?: boolean; borderStartColor?: ColorValue; - borderBottomEndRadius?: Float; borderEndColor?: ColorValue; focusable?: boolean; nativeBackgroundAndroid?: NativeBackgroundProp; // maybe there should a value accepted by codegen for this? - borderTopStartRadius?: Float; nativeForegroundAndroid?: NativeBackgroundProp; // maybe there should a value accepted by codegen for this? backfaceVisibility?: string; borderStyle?: string; @@ -68,18 +64,22 @@ interface NativeProps extends ViewProps { // (https://github.com/facebook/react-native/blob/35556dba600fbb28e0f41340a74b6c4a59bc6018/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java#L613) // and static view config validator says that they are missing. // We pass them as doubles although they should be floats, and cast them to floats again on the native side. - borderTopRightRadius?: Double; - borderBottomRightRadius?: Double; - borderRadius?: Double; - borderBottomLeftRadius?: Double; - borderTopLeftRadius?: Double; borderBlockColor?: ColorValue; borderBlockEndColor?: ColorValue; borderBlockStartColor?: ColorValue; - borderEndEndRadius?: Double; - borderEndStartRadius?: Double; - borderStartEndRadius?: Double; - borderStartStartRadius?: Double; + borderRadius: UnsafeMixed; + borderTopLeftRadius: UnsafeMixed; + borderTopRightRadius: UnsafeMixed; + borderBottomRightRadius: UnsafeMixed; + borderBottomLeftRadius: UnsafeMixed; + borderTopStartRadius: UnsafeMixed; + borderTopEndRadius: UnsafeMixed; + borderBottomStartRadius: UnsafeMixed; + borderBottomEndRadius: UnsafeMixed; + borderEndEndRadius: UnsafeMixed; + borderEndStartRadius: UnsafeMixed; + borderStartEndRadius: UnsafeMixed; + borderStartStartRadius: UnsafeMixed; } export default codegenNativeComponent('RNSVGSvgViewAndroid', { From 04f67b3465db7abda9c2146c6ee1afab7fbef778 Mon Sep 17 00:00:00 2001 From: Jakub Grzywacz Date: Mon, 30 Sep 2024 12:26:31 +0200 Subject: [PATCH 2/4] refactor: use dynamic for border radius --- .../java/com/horcrux/svg/SvgViewManager.java | 85 ++++++++++--------- 1 file changed, 47 insertions(+), 38 deletions(-) diff --git a/android/src/transformRn73/java/com/horcrux/svg/SvgViewManager.java b/android/src/transformRn73/java/com/horcrux/svg/SvgViewManager.java index 2f21dec98..51e263f56 100644 --- a/android/src/transformRn73/java/com/horcrux/svg/SvgViewManager.java +++ b/android/src/transformRn73/java/com/horcrux/svg/SvgViewManager.java @@ -13,6 +13,7 @@ import com.facebook.common.logging.FLog; import com.facebook.react.bridge.Dynamic; import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.bridge.ReadableType; import com.facebook.react.common.ReactConstants; import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.PointerEvents; @@ -176,16 +177,6 @@ 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); @@ -241,11 +232,6 @@ 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); @@ -261,11 +247,6 @@ 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); @@ -346,48 +327,76 @@ public void setBorderBlockStartColor(SvgView view, @Nullable Integer value) { super.setBorderColor(view, 11, value); } + public void setBorderRadius(ReactViewGroup view, int index, Dynamic rawBorderRadius) { + double test = 0; + if (rawBorderRadius.getType() == ReadableType.Number) { + test = rawBorderRadius.asDouble(); + } + super.setBorderRadius(view, index, (float) test); + } + + @Override + public void setBorderRadius(SvgView view, Dynamic rawBorderRadius) { + this.setBorderRadius(view, 0, rawBorderRadius); + } + + @Override + public void setBorderTopLeftRadius(SvgView view, Dynamic rawBorderRadius) { + this.setBorderRadius(view, 1, rawBorderRadius); + } + + @Override + public void setBorderTopRightRadius(SvgView view, Dynamic rawBorderRadius) { + this.setBorderRadius(view, 2, rawBorderRadius); + } + + @Override + public void setBorderBottomRightRadius(SvgView view, Dynamic rawBorderRadius) { + this.setBorderRadius(view, 3, rawBorderRadius); + } + @Override - public void setBorderRadius(SvgView view, double value) { - super.setBorderRadius(view, 0, (float) value); + public void setBorderBottomLeftRadius(SvgView view, Dynamic rawBorderRadius) { + this.setBorderRadius(view, 4, rawBorderRadius); } @Override - public void setBorderTopLeftRadius(SvgView view, double value) { - super.setBorderRadius(view, 1, (float) value); + public void setBorderTopStartRadius(SvgView view, Dynamic rawBorderRadius) { + this.setBorderRadius(view, 5, rawBorderRadius); } @Override - public void setBorderTopRightRadius(SvgView view, double value) { - super.setBorderRadius(view, 2, (float) value); + public void setBorderTopEndRadius(SvgView view, Dynamic rawBorderRadius) { + this.setBorderRadius(view, 6, rawBorderRadius); } @Override - public void setBorderBottomRightRadius(SvgView view, double value) { - super.setBorderRadius(view, 3, (float) value); + public void setBorderBottomStartRadius(SvgView view, Dynamic rawBorderRadius) { + this.setBorderRadius(view, 7, rawBorderRadius); } @Override - public void setBorderBottomLeftRadius(SvgView view, double value) { - super.setBorderRadius(view, 4, (float) value); + public void setBorderBottomEndRadius(SvgView view, Dynamic rawBorderRadius) { + this.setBorderRadius(view, 8, rawBorderRadius); } @Override - public void setBorderEndEndRadius(SvgView view, double value) { - super.setBorderRadius(view, 9, (float) value); + public void setBorderEndEndRadius(SvgView view, Dynamic rawBorderRadius) { + this.setBorderRadius(view, 9, rawBorderRadius); } @Override - public void setBorderEndStartRadius(SvgView view, double value) { - super.setBorderRadius(view, 10, (float) value); + public void setBorderEndStartRadius(SvgView view, Dynamic rawBorderRadius) { + this.setBorderRadius(view, 10, rawBorderRadius); } @Override - public void setBorderStartEndRadius(SvgView view, double value) { - super.setBorderRadius(view, 11, (float) value); + public void setBorderStartEndRadius(SvgView view, Dynamic rawBorderRadius) { + this.setBorderRadius(view, 11, rawBorderRadius); } @Override - public void setBorderStartStartRadius(SvgView view, double value) { - super.setBorderRadius(view, 12, (float) value); + public void setBorderStartStartRadius(SvgView view, Dynamic rawBorderRadius) { + this.setBorderRadius(view, 12, rawBorderRadius); } } From c8b5c43ed99861dac291f277b12e172d69a8ce48 Mon Sep 17 00:00:00 2001 From: Jakub Grzywacz Date: Mon, 30 Sep 2024 12:27:06 +0200 Subject: [PATCH 3/4] feat: add sourceSet to use dynamic directly on RN 75+ --- android/build.gradle | 4 +- .../java/com/horcrux/svg/SvgViewManager.java | 394 ++++++++++++++++++ 2 files changed, 397 insertions(+), 1 deletion(-) create mode 100644 android/src/borderRadiusRn75/java/com/horcrux/svg/SvgViewManager.java diff --git a/android/build.gradle b/android/build.gradle index 1926a0fdf..0cada99a9 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -118,7 +118,9 @@ android { "src/paper/java", ] } - if (getReactNativeMinorVersion() >= 73) { + if (getReactNativeMinorVersion() >= 75) { + srcDirs += "src/borderRadiusRn75/java" + } else if (getReactNativeMinorVersion() >= 73) { srcDirs += "src/transformRn73/java" } else { srcDirs += "src/deprecated/java" diff --git a/android/src/borderRadiusRn75/java/com/horcrux/svg/SvgViewManager.java b/android/src/borderRadiusRn75/java/com/horcrux/svg/SvgViewManager.java new file mode 100644 index 000000000..f7108c02b --- /dev/null +++ b/android/src/borderRadiusRn75/java/com/horcrux/svg/SvgViewManager.java @@ -0,0 +1,394 @@ +/* + * 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. + */ + +package com.horcrux.svg; + +import android.graphics.Rect; +import android.util.SparseArray; +import com.facebook.common.logging.FLog; +import com.facebook.react.bridge.Dynamic; +import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.bridge.ReadableType; +import com.facebook.react.common.ReactConstants; +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.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; +import java.lang.reflect.Method; +import java.util.Locale; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * 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 RNSVGSvgViewAndroidManagerInterface { + + public static final String REACT_CLASS = "RNSVGSvgViewAndroid"; + + private static final SparseArray mTagToSvgView = new SparseArray<>(); + private static final SparseArray mTagToRunnable = new SparseArray<>(); + + private final ViewManagerDelegate mDelegate; + + protected ViewManagerDelegate getDelegate() { + return mDelegate; + } + + public SvgViewManager() { + mDelegate = new RNSVGSvgViewAndroidManagerDelegate(this); + } + + static void setSvgView(int tag, SvgView svg) { + mTagToSvgView.put(tag, svg); + Runnable task = mTagToRunnable.get(tag); + if (task != null) { + task.run(); + mTagToRunnable.delete(tag); + } + } + + static void runWhenViewIsAvailable(int tag, Runnable task) { + mTagToRunnable.put(tag, task); + } + + static @Nullable SvgView getSvgViewByTag(int tag) { + return mTagToSvgView.get(tag); + } + + @Nonnull + @Override + public String getName() { + return REACT_CLASS; + } + + @Nonnull + @Override + public ReactViewGroup createViewInstance(ThemedReactContext reactContext) { + return new SvgView(reactContext); + } + + @Override + public void updateExtraData(ReactViewGroup root, Object extraData) { + super.updateExtraData(root, extraData); + root.invalidate(); + } + + @Override + public void onDropViewInstance(@Nonnull ReactViewGroup view) { + super.onDropViewInstance(view); + mTagToSvgView.remove(view.getId()); + } + + @Override + public boolean needsCustomLayoutForChildren() { + return true; + } + + @ReactProp(name = "tintColor", customType = "Color") + @Override + public void setTintColor(SvgView node, Integer tintColor) { + node.setTintColor(tintColor); + } + + @ReactProp(name = "color", customType = "Color") + @Override + public void setColor(SvgView node, Integer color) { + node.setTintColor(color); + } + + @ReactProp(name = "minX") + @Override + public void setMinX(SvgView node, float minX) { + node.setMinX(minX); + } + + @ReactProp(name = "minY") + @Override + public void setMinY(SvgView node, float minY) { + node.setMinY(minY); + } + + @ReactProp(name = "vbWidth") + @Override + public void setVbWidth(SvgView node, float vbWidth) { + node.setVbWidth(vbWidth); + } + + @ReactProp(name = "vbHeight") + @Override + public void setVbHeight(SvgView node, float vbHeight) { + node.setVbHeight(vbHeight); + } + + @ReactProp(name = "bbWidth") + public void setBbWidth(SvgView node, Dynamic bbWidth) { + node.setBbWidth(bbWidth); + } + + @ReactProp(name = "bbHeight") + public void setBbHeight(SvgView node, Dynamic bbHeight) { + node.setBbHeight(bbHeight); + } + + @ReactProp(name = "align") + @Override + public void setAlign(SvgView node, String align) { + node.setAlign(align); + } + + @ReactProp(name = "meetOrSlice") + @Override + public void setMeetOrSlice(SvgView node, int meetOrSlice) { + node.setMeetOrSlice(meetOrSlice); + } + + @ReactProp(name = ViewProps.POINTER_EVENTS) + public void setPointerEvents(SvgView view, @Nullable String pointerEventsStr) { + try { + Class superclass = view.getClass().getSuperclass(); + if (superclass != null) { + Method method = superclass.getDeclaredMethod("setPointerEvents", PointerEvents.class); + method.setAccessible(true); + method.invoke( + view, PointerEvents.valueOf(pointerEventsStr.toUpperCase(Locale.US).replace("-", "_"))); + } + } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + e.printStackTrace(); + } + } + + @Override + public void setHasTVPreferredFocus(SvgView view, boolean value) { + super.setTVPreferredFocus(view, 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 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 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, Dynamic hitSlop) { + // we don't call super here since its signature changed in RN 0.69 and we want backwards + // compatibility + switch (hitSlop.getType()) { + case Map: + ReadableMap hitSlopMap = hitSlop.asMap(); + 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)); + break; + case Number: + int hitSlopValue = (int) PixelUtil.toPixelFromDIP(hitSlop.asDouble()); + view.setHitSlopRect(new Rect(hitSlopValue, hitSlopValue, hitSlopValue, hitSlopValue)); + break; + default: + FLog.w(ReactConstants.TAG, "Invalid type for 'hitSlop' value " + hitSlop.getType()); + /* falls through */ + case Null: + view.setHitSlopRect(null); + break; + } + } + + @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 setBorderBlockColor(SvgView view, @Nullable Integer value) { + super.setBorderColor(view, 9, value); + } + + @Override + public void setBorderBlockEndColor(SvgView view, @Nullable Integer value) { + super.setBorderColor(view, 10, value); + } + + @Override + public void setBorderBlockStartColor(SvgView view, @Nullable Integer value) { + super.setBorderColor(view, 11, value); + } + + @Override + public void setBorderRadius(SvgView view, Dynamic rawBorderRadius) { + super.setBorderRadius(view, 0, rawBorderRadius); + } + + @Override + public void setBorderTopLeftRadius(SvgView view, Dynamic rawBorderRadius) { + super.setBorderRadius(view, 1, rawBorderRadius); + } + + @Override + public void setBorderTopRightRadius(SvgView view, Dynamic rawBorderRadius) { + super.setBorderRadius(view, 2, rawBorderRadius); + } + + @Override + public void setBorderBottomRightRadius(SvgView view, Dynamic rawBorderRadius) { + super.setBorderRadius(view, 3, rawBorderRadius); + } + + @Override + public void setBorderBottomLeftRadius(SvgView view, Dynamic rawBorderRadius) { + super.setBorderRadius(view, 4, rawBorderRadius); + } + + @Override + public void setBorderTopStartRadius(SvgView view, Dynamic rawBorderRadius) { + super.setBorderRadius(view, 5, rawBorderRadius); + } + + @Override + public void setBorderTopEndRadius(SvgView view, Dynamic rawBorderRadius) { + super.setBorderRadius(view, 6, rawBorderRadius); + } + + @Override + public void setBorderBottomStartRadius(SvgView view, Dynamic rawBorderRadius) { + super.setBorderRadius(view, 7, rawBorderRadius); + } + + @Override + public void setBorderBottomEndRadius(SvgView view, Dynamic rawBorderRadius) { + super.setBorderRadius(view, 8, rawBorderRadius); + } + + @Override + public void setBorderEndEndRadius(SvgView view, Dynamic rawBorderRadius) { + super.setBorderRadius(view, 9, rawBorderRadius); + } + + @Override + public void setBorderEndStartRadius(SvgView view, Dynamic rawBorderRadius) { + super.setBorderRadius(view, 10, rawBorderRadius); + } + + @Override + public void setBorderStartEndRadius(SvgView view, Dynamic rawBorderRadius) { + super.setBorderRadius(view, 11, rawBorderRadius); + } + + @Override + public void setBorderStartStartRadius(SvgView view, Dynamic rawBorderRadius) { + super.setBorderRadius(view, 12, rawBorderRadius); + } +} From da2eb86972c3f9eb0b39bbf34e282b7159374977 Mon Sep 17 00:00:00 2001 From: Jakub Grzywacz Date: Mon, 30 Sep 2024 12:51:54 +0200 Subject: [PATCH 4/4] fix: make border radiuses optional --- src/fabric/AndroidSvgViewNativeComponent.ts | 30 +++++++++------------ 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/fabric/AndroidSvgViewNativeComponent.ts b/src/fabric/AndroidSvgViewNativeComponent.ts index 1410dedb0..252b2276c 100644 --- a/src/fabric/AndroidSvgViewNativeComponent.ts +++ b/src/fabric/AndroidSvgViewNativeComponent.ts @@ -60,26 +60,22 @@ interface NativeProps extends ViewProps { hitSlop?: UnsafeMixed; borderTopColor?: ColorValue; nextFocusLeft?: Int32; - // TODO: those props are present in the `ReactPropGroup` but are not supported - // (https://github.com/facebook/react-native/blob/35556dba600fbb28e0f41340a74b6c4a59bc6018/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java#L613) - // and static view config validator says that they are missing. - // We pass them as doubles although they should be floats, and cast them to floats again on the native side. borderBlockColor?: ColorValue; borderBlockEndColor?: ColorValue; borderBlockStartColor?: ColorValue; - borderRadius: UnsafeMixed; - borderTopLeftRadius: UnsafeMixed; - borderTopRightRadius: UnsafeMixed; - borderBottomRightRadius: UnsafeMixed; - borderBottomLeftRadius: UnsafeMixed; - borderTopStartRadius: UnsafeMixed; - borderTopEndRadius: UnsafeMixed; - borderBottomStartRadius: UnsafeMixed; - borderBottomEndRadius: UnsafeMixed; - borderEndEndRadius: UnsafeMixed; - borderEndStartRadius: UnsafeMixed; - borderStartEndRadius: UnsafeMixed; - borderStartStartRadius: UnsafeMixed; + borderRadius?: UnsafeMixed; + borderTopLeftRadius?: UnsafeMixed; + borderTopRightRadius?: UnsafeMixed; + borderBottomRightRadius?: UnsafeMixed; + borderBottomLeftRadius?: UnsafeMixed; + borderTopStartRadius?: UnsafeMixed; + borderTopEndRadius?: UnsafeMixed; + borderBottomStartRadius?: UnsafeMixed; + borderBottomEndRadius?: UnsafeMixed; + borderEndEndRadius?: UnsafeMixed; + borderEndStartRadius?: UnsafeMixed; + borderStartEndRadius?: UnsafeMixed; + borderStartStartRadius?: UnsafeMixed; } export default codegenNativeComponent('RNSVGSvgViewAndroid', {