diff --git a/android/src/main/java/com/horcrux/svg/SvgViewManager.java b/android/src/main/java/com/horcrux/svg/SvgViewManager.java index 4a8452f52..76d4d6759 100644 --- a/android/src/main/java/com/horcrux/svg/SvgViewManager.java +++ b/android/src/main/java/com/horcrux/svg/SvgViewManager.java @@ -8,20 +8,16 @@ 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.ViewGroupManager; 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; @@ -32,7 +28,7 @@ * 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 +class SvgViewManager extends ViewGroupManager implements RNSVGSvgViewAndroidManagerInterface { public static final String REACT_CLASS = "RNSVGSvgViewAndroid"; @@ -42,12 +38,12 @@ class SvgViewManager extends ReactViewManager private final ViewManagerDelegate mDelegate; - protected ViewManagerDelegate getDelegate() { + protected ViewManagerDelegate getDelegate() { return mDelegate; } public SvgViewManager() { - mDelegate = new RNSVGSvgViewAndroidManagerDelegate(this); + mDelegate = new RNSVGSvgViewAndroidManagerDelegate<>(this); } static void setSvgView(int tag, SvgView svg) { @@ -75,18 +71,18 @@ public String getName() { @Nonnull @Override - public ReactViewGroup createViewInstance(ThemedReactContext reactContext) { + public SvgView createViewInstance(ThemedReactContext reactContext) { return new SvgView(reactContext); } @Override - public void updateExtraData(ReactViewGroup root, Object extraData) { + public void updateExtraData(SvgView root, Object extraData) { super.updateExtraData(root, extraData); root.invalidate(); } @Override - public void onDropViewInstance(@Nonnull ReactViewGroup view) { + public void onDropViewInstance(@Nonnull SvgView view) { super.onDropViewInstance(view); mTagToSvgView.remove(view.getId()); } @@ -168,211 +164,4 @@ 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 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, 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); - } - - @Override - public void setBorderEndEndRadius(SvgView view, double value) { - super.setBorderRadius(view, 9, (float) value); - } - - @Override - public void setBorderEndStartRadius(SvgView view, double value) { - super.setBorderRadius(view, 10, (float) value); - } - - @Override - public void setBorderStartEndRadius(SvgView view, double value) { - super.setBorderRadius(view, 11, (float) value); - } - - @Override - public void setBorderStartStartRadius(SvgView view, double value) { - super.setBorderRadius(view, 12, (float) value); - } } 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 376fbd60c..f88a8d9cf 100644 --- a/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewAndroidManagerDelegate.java +++ b/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewAndroidManagerDelegate.java @@ -13,7 +13,6 @@ import androidx.annotation.Nullable; import com.facebook.react.bridge.ColorPropConverter; import com.facebook.react.bridge.DynamicFromObject; -import com.facebook.react.bridge.ReadableMap; import com.facebook.react.uimanager.BaseViewManagerDelegate; import com.facebook.react.uimanager.BaseViewManagerInterface; @@ -57,120 +56,6 @@ public void setProperty(T view, String propName, @Nullable Object value) { 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; - case "borderBlockColor": - mViewManager.setBorderBlockColor(view, ColorPropConverter.getColor(value, view.getContext())); - break; - case "borderBlockEndColor": - mViewManager.setBorderBlockEndColor(view, ColorPropConverter.getColor(value, view.getContext())); - break; - case "borderBlockStartColor": - mViewManager.setBorderBlockStartColor(view, ColorPropConverter.getColor(value, view.getContext())); - break; - case "borderEndEndRadius": - mViewManager.setBorderEndEndRadius(view, value == null ? 0f : ((Double) value).doubleValue()); - break; - case "borderEndStartRadius": - mViewManager.setBorderEndStartRadius(view, value == null ? 0f : ((Double) value).doubleValue()); - break; - case "borderStartEndRadius": - mViewManager.setBorderStartEndRadius(view, value == null ? 0f : ((Double) value).doubleValue()); - break; - case "borderStartStartRadius": - mViewManager.setBorderStartStartRadius(view, value == null ? 0f : ((Double) value).doubleValue()); - 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 4214009b7..e43804d2a 100644 --- a/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewAndroidManagerInterface.java +++ b/android/src/paper/java/com/facebook/react/viewmanagers/RNSVGSvgViewAndroidManagerInterface.java @@ -12,7 +12,6 @@ import android.view.View; import androidx.annotation.Nullable; import com.facebook.react.bridge.Dynamic; -import com.facebook.react.bridge.ReadableMap; public interface RNSVGSvgViewAndroidManagerInterface { void setBbWidth(T view, Dynamic value); @@ -26,42 +25,4 @@ public interface RNSVGSvgViewAndroidManagerInterface { 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); - 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); } diff --git a/android/src/paper/java/com/horcrux/svg/NativeSvgRenderableModuleSpec.java b/android/src/paper/java/com/horcrux/svg/NativeSvgRenderableModuleSpec.java index b7184d3d0..39f80986c 100644 --- a/android/src/paper/java/com/horcrux/svg/NativeSvgRenderableModuleSpec.java +++ b/android/src/paper/java/com/horcrux/svg/NativeSvgRenderableModuleSpec.java @@ -1,13 +1,15 @@ + /** - * This code was generated by - * [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * 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. + * 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.svg; import com.facebook.proguard.annotations.DoNotStrip; @@ -21,8 +23,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -public abstract class NativeSvgRenderableModuleSpec extends ReactContextBaseJavaModule - implements TurboModule { +public abstract class NativeSvgRenderableModuleSpec extends ReactContextBaseJavaModule implements TurboModule { public static final String NAME = "RNSVGRenderableModule"; public NativeSvgRenderableModuleSpec(ReactApplicationContext reactContext) { diff --git a/src/fabric/AndroidSvgViewNativeComponent.ts b/src/fabric/AndroidSvgViewNativeComponent.ts index bf654d6d7..c1d7ed4db 100644 --- a/src/fabric/AndroidSvgViewNativeComponent.ts +++ b/src/fabric/AndroidSvgViewNativeComponent.ts @@ -1,29 +1,11 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; import type { ColorValue } from 'react-native'; -import type { - Double, - Float, - Int32, -} from 'react-native/Libraries/Types/CodegenTypes'; +import type { Float, Int32 } from 'react-native/Libraries/Types/CodegenTypes'; import type { ViewProps } from './utils'; import type { UnsafeMixed } from './codegenUtils'; import { NumberProp } from '../lib/extract/types'; -type NativeBackgroundProp = Readonly<{ - type?: string; - color?: Float; - borderless?: boolean; - rippleRadius?: Float; -}>; - -type HitSlop = Readonly<{ - left?: Float; - top?: Float; - right?: Float; - bottom?: Float; -}>; - interface NativeProps extends ViewProps { bbWidth?: UnsafeMixed; bbHeight?: UnsafeMixed; @@ -36,50 +18,6 @@ interface NativeProps extends ViewProps { tintColor?: ColorValue; color?: ColorValue; pointerEvents?: string; - - // props needed for Android SvgView - hasTVPreferredFocus?: boolean; - borderTopEndRadius?: Float; - borderBottomStartRadius?: Float; - borderBottomColor?: ColorValue; - nextFocusDown?: Int32; - borderRightColor?: ColorValue; - nextFocusRight?: Int32; - borderLeftColor?: ColorValue; - borderColor?: ColorValue; - removeClippedSubviews?: boolean; - nextFocusForward?: Int32; - 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; - needsOffscreenAlphaCompositing?: boolean; - hitSlop?: HitSlop; - 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. - borderTopRightRadius?: Double; - borderBottomRightRadius?: Double; - borderRadius?: Double; - borderBottomLeftRadius?: Double; - borderTopLeftRadius?: Double; - borderBlockColor?: ColorValue; - borderBlockEndColor?: ColorValue; - borderBlockStartColor?: ColorValue; - borderEndEndRadius?: Double; - borderEndStartRadius?: Double; - borderStartEndRadius?: Double; - borderStartStartRadius?: Double; } export default codegenNativeComponent('RNSVGSvgViewAndroid', {