From 6e1d8890edf8783a2ff2e5613af0f968e3b1d02c Mon Sep 17 00:00:00 2001 From: Muhamad Rizki Date: Wed, 15 Mar 2023 11:48:20 +0700 Subject: [PATCH 1/5] feat: add RN Fabric support --- android/build.gradle | 13 ++++- .../FastShadowViewManagerImpl.java | 56 +++++++++++++++++++ .../FastShadowViewManager.java | 31 ++++------ .../FastShadowViewManager.java | 56 +++++++++++++++++++ src/FastShadowView.ts | 7 ++- src/FastShadowViewNativeComponent.js | 18 ++++++ 6 files changed, 157 insertions(+), 24 deletions(-) create mode 100644 android/src/main/java/com/reactnativefastshadow/FastShadowViewManagerImpl.java rename android/src/{main => newarch}/java/com/reactnativefastshadow/FastShadowViewManager.java (66%) create mode 100644 android/src/oldarch/java/com/reactnativefastshadow/FastShadowViewManager.java create mode 100644 src/FastShadowViewNativeComponent.js diff --git a/android/build.gradle b/android/build.gradle index 07f6357..84a86c5 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -35,6 +35,17 @@ android { targetSdkVersion getExtOrIntegerDefault('targetSdkVersion') buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() } + + sourceSets { + main { + if (isNewArchitectureEnabled()) { + java.srcDirs += ['src/newarch'] + } else { + java.srcDirs += ['src/oldarch'] + } + } + } + buildTypes { release { minifyEnabled false @@ -131,7 +142,7 @@ dependencies { if (isNewArchitectureEnabled()) { react { jsRootDir = file("../src/") - libraryName = "FastShadow" + libraryName = "FastShadowView" codegenJavaPackageName = "com.reactnativefastshadow" } } diff --git a/android/src/main/java/com/reactnativefastshadow/FastShadowViewManagerImpl.java b/android/src/main/java/com/reactnativefastshadow/FastShadowViewManagerImpl.java new file mode 100644 index 0000000..c4cc7c1 --- /dev/null +++ b/android/src/main/java/com/reactnativefastshadow/FastShadowViewManagerImpl.java @@ -0,0 +1,56 @@ +package com.reactnativefastshadow; + +import android.graphics.Color; + +import androidx.annotation.NonNull; + +import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.uimanager.ThemedReactContext; +import com.facebook.react.uimanager.annotations.ReactProp; +import com.facebook.react.views.view.ReactViewGroup; +import com.facebook.react.views.view.ReactViewManager; + +public class FastShadowViewManagerImpl { + + public static final String NAME = "FastShadowView"; + + public static FastShadowView createViewInstance(ThemedReactContext context) { + return new FastShadowView(context); + } + + public static void onDropViewInstance(@NonNull ReactViewGroup view) { + ((FastShadowView) view).releaseShadow(); + } + + public static void setShadowColor(FastShadowView view, int color) { + view.setColor(color); + } + + public static void setShadowOpacity(FastShadowView view, float opacity) { + view.setOpacity(opacity); + } + + public static void setShadowRadius(FastShadowView view, float radius) { + view.setRadius(radius); + } + + public static void setShadowOffset(FastShadowView view, ReadableMap offset) { + if (offset == null) { + view.resetOffset(); + } else { + view.setOffset( + (float) offset.getDouble("width"), + (float) offset.getDouble("height") + ); + } + } + + public static void setCornerRadii(FastShadowView view, ReadableMap borderRadius) { + view.setCornerRadii(new float[]{ + (float) borderRadius.getDouble("topLeft"), + (float) borderRadius.getDouble("topRight"), + (float) borderRadius.getDouble("bottomRight"), + (float) borderRadius.getDouble("bottomLeft") + }); + } +} diff --git a/android/src/main/java/com/reactnativefastshadow/FastShadowViewManager.java b/android/src/newarch/java/com/reactnativefastshadow/FastShadowViewManager.java similarity index 66% rename from android/src/main/java/com/reactnativefastshadow/FastShadowViewManager.java rename to android/src/newarch/java/com/reactnativefastshadow/FastShadowViewManager.java index 8341ad3..fec7089 100644 --- a/android/src/main/java/com/reactnativefastshadow/FastShadowViewManager.java +++ b/android/src/newarch/java/com/reactnativefastshadow/FastShadowViewManager.java @@ -9,61 +9,50 @@ import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.react.views.view.ReactViewGroup; import com.facebook.react.views.view.ReactViewManager; +import com.facebook.react.module.annotations.ReactModule; +@ReactModule(name = FastShadowViewManagerImpl.NAME) public class FastShadowViewManager extends ReactViewManager { - public static final String REACT_CLASS = "FastShadowView"; @Override @NonNull public String getName() { - return REACT_CLASS; + return FastShadowViewManagerImpl.NAME; } @Override public FastShadowView createViewInstance(ThemedReactContext context) { - return new FastShadowView(context); + return FastShadowViewManagerImpl.createViewInstance(context); } @Override public void onDropViewInstance(@NonNull ReactViewGroup view) { super.onDropViewInstance(view); - ((FastShadowView) view).releaseShadow(); + FastShadowViewManagerImpl.onDropViewInstance(view); } @ReactProp(name = "shadowColor", customType = "Color", defaultInt = Color.BLACK) public void setShadowColor(FastShadowView view, int color) { - view.setColor(color); + FastShadowViewManagerImpl.setShadowColor(view, color); } @ReactProp(name = "shadowOpacity", defaultFloat = 0) public void setShadowOpacity(FastShadowView view, float opacity) { - view.setOpacity(opacity); + FastShadowViewManagerImpl.setShadowOpacity(view, opacity); } @ReactProp(name = "shadowRadius", defaultFloat = 3) public void setShadowRadius(FastShadowView view, float radius) { - view.setRadius(radius); + FastShadowViewManagerImpl.setShadowRadius(view, radius); } @ReactProp(name = "shadowOffset") public void setShadowOffset(FastShadowView view, ReadableMap offset) { - if (offset == null) { - view.resetOffset(); - } else { - view.setOffset( - (float) offset.getDouble("width"), - (float) offset.getDouble("height") - ); - } + FastShadowViewManagerImpl.setShadowOffset(view, offset); } @ReactProp(name = "cornerRadii") public void setCornerRadii(FastShadowView view, ReadableMap borderRadius) { - view.setCornerRadii(new float[]{ - (float) borderRadius.getDouble("topLeft"), - (float) borderRadius.getDouble("topRight"), - (float) borderRadius.getDouble("bottomRight"), - (float) borderRadius.getDouble("bottomLeft") - }); + FastShadowViewManagerImpl.setCornerRadii(view, borderRadius); } } diff --git a/android/src/oldarch/java/com/reactnativefastshadow/FastShadowViewManager.java b/android/src/oldarch/java/com/reactnativefastshadow/FastShadowViewManager.java new file mode 100644 index 0000000..dcc591a --- /dev/null +++ b/android/src/oldarch/java/com/reactnativefastshadow/FastShadowViewManager.java @@ -0,0 +1,56 @@ +package com.reactnativefastshadow; + +import android.graphics.Color; + +import androidx.annotation.NonNull; + +import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.uimanager.ThemedReactContext; +import com.facebook.react.uimanager.annotations.ReactProp; +import com.facebook.react.views.view.ReactViewGroup; +import com.facebook.react.views.view.ReactViewManager; + +public class FastShadowViewManager extends ReactViewManager { + + @Override + @NonNull + public String getName() { + return FastShadowViewManagerImpl.NAME; + } + + @Override + public FastShadowView createViewInstance(ThemedReactContext context) { + return FastShadowViewManagerImpl.createViewInstance(context); + } + + @Override + public void onDropViewInstance(@NonNull ReactViewGroup view) { + super.onDropViewInstance(view); + FastShadowViewManagerImpl.onDropViewInstance(view); + } + + @ReactProp(name = "shadowColor", customType = "Color", defaultInt = Color.BLACK) + public void setShadowColor(FastShadowView view, int color) { + FastShadowViewManagerImpl.setShadowColor(view, color); + } + + @ReactProp(name = "shadowOpacity", defaultFloat = 0) + public void setShadowOpacity(FastShadowView view, float opacity) { + FastShadowViewManagerImpl.setShadowOpacity(view, opacity); + } + + @ReactProp(name = "shadowRadius", defaultFloat = 3) + public void setShadowRadius(FastShadowView view, float radius) { + FastShadowViewManagerImpl.setShadowRadius(view, radius); + } + + @ReactProp(name = "shadowOffset") + public void setShadowOffset(FastShadowView view, ReadableMap offset) { + FastShadowViewManagerImpl.setShadowOffset(view, offset); + } + + @ReactProp(name = "cornerRadii") + public void setCornerRadii(FastShadowView view, ReadableMap borderRadius) { + FastShadowViewManagerImpl.setCornerRadii(view, borderRadius); + } +} diff --git a/src/FastShadowView.ts b/src/FastShadowView.ts index 290b1b0..8071844 100644 --- a/src/FastShadowView.ts +++ b/src/FastShadowView.ts @@ -9,5 +9,8 @@ export type FastShadowViewProps = ViewProps & { }; }; -export const FastShadowView = - requireNativeComponent('FastShadowView'); +const isFabricEnabled = (global as any).nativeFabricUIManager != null; + +export const FastShadowView: React.FC = isFabricEnabled + ? require('./FastShadowViewNativeComponent').default + : requireNativeComponent('FastShadowView'); diff --git a/src/FastShadowViewNativeComponent.js b/src/FastShadowViewNativeComponent.js new file mode 100644 index 0000000..cf784c9 --- /dev/null +++ b/src/FastShadowViewNativeComponent.js @@ -0,0 +1,18 @@ +// @flow +import type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes'; +import type { HostComponent } from 'react-native'; +import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; + +export type FastShadowViewProps = $ReadOnly<{| + ...ViewProps, + cornerRadii: $ReadOnly<{| + topLeft: Int32, + topRight: Int32, + bottomLeft: Int32, + bottomRight: Int32, + |}>, +|}>; + +export default (codegenNativeComponent( + 'FastShadowView' +): HostComponent); From 0b95386b16895e816d06f9b093e13145cd6a6897 Mon Sep 17 00:00:00 2001 From: Muhamad Rizki Date: Sun, 26 Mar 2023 13:48:47 +0700 Subject: [PATCH 2/5] chore: update example using fabric arch --- example/android/app/src/main/jni/Android.mk | 54 ++++++++++++++++ .../src/main/jni/MainComponentsRegistry.cpp | 63 +++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 example/android/app/src/main/jni/Android.mk create mode 100644 example/android/app/src/main/jni/MainComponentsRegistry.cpp diff --git a/example/android/app/src/main/jni/Android.mk b/example/android/app/src/main/jni/Android.mk new file mode 100644 index 0000000..253de65 --- /dev/null +++ b/example/android/app/src/main/jni/Android.mk @@ -0,0 +1,54 @@ +THIS_DIR := $(call my-dir) + +include $(REACT_ANDROID_DIR)/Android-prebuilt.mk + +# If you wish to add a custom TurboModule or Fabric component in your app you +# will have to include the following autogenerated makefile. +# include $(GENERATED_SRC_DIR)/codegen/jni/Android.mk + +# Includes the MK file for `react-native-fast-shadow` +include $(NODE_MODULES_DIR)/../../android/build/generated/source/codegen/jni/Android.mk + +include $(CLEAR_VARS) + +LOCAL_PATH := $(THIS_DIR) + +# You can customize the name of your application .so file here. +LOCAL_MODULE := example_appmodules + +LOCAL_C_INCLUDES := $(LOCAL_PATH) +LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) + +# If you wish to add a custom TurboModule or Fabric component in your app you +# will have to uncomment those lines to include the generated source +# files from the codegen (placed in $(GENERATED_SRC_DIR)/codegen/jni) +# +# LOCAL_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni +# LOCAL_SRC_FILES += $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp) +# LOCAL_EXPORT_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni + +# Here you should add any native library you wish to depend on. +LOCAL_SHARED_LIBRARIES := \ + libfabricjni \ + libfbjni \ + libfolly_futures \ + libfolly_json \ + libglog \ + libjsi \ + libreact_codegen_rncore \ + libreact_codegen_FastShadowView \ + libreact_debug \ + libreact_nativemodule_core \ + libreact_render_componentregistry \ + libreact_render_core \ + libreact_render_debug \ + libreact_render_graphics \ + librrc_view \ + libruntimeexecutor \ + libturbomodulejsijni \ + libyoga + +LOCAL_CFLAGS := -DLOG_TAG=\"ReactNative\" -fexceptions -frtti -std=c++17 -Wall + +include $(BUILD_SHARED_LIBRARY) diff --git a/example/android/app/src/main/jni/MainComponentsRegistry.cpp b/example/android/app/src/main/jni/MainComponentsRegistry.cpp new file mode 100644 index 0000000..3cd79b4 --- /dev/null +++ b/example/android/app/src/main/jni/MainComponentsRegistry.cpp @@ -0,0 +1,63 @@ +#include "MainComponentsRegistry.h" + +#include +#include +#include +#include +#include + +namespace facebook { +namespace react { + +MainComponentsRegistry::MainComponentsRegistry(ComponentFactory *delegate) {} + +std::shared_ptr +MainComponentsRegistry::sharedProviderRegistry() { + auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry(); + + // Custom Fabric Components go here. You can register custom + // components coming from your App or from 3rd party libraries here. + // + // providerRegistry->add(concreteComponentDescriptorProvider< + // AocViewerComponentDescriptor>()); + providerRegistry->add(concreteComponentDescriptorProvider()); + return providerRegistry; +} + +jni::local_ref +MainComponentsRegistry::initHybrid( + jni::alias_ref, + ComponentFactory *delegate) { + auto instance = makeCxxInstance(delegate); + + auto buildRegistryFunction = + [](EventDispatcher::Weak const &eventDispatcher, + ContextContainer::Shared const &contextContainer) + -> ComponentDescriptorRegistry::Shared { + auto registry = MainComponentsRegistry::sharedProviderRegistry() + ->createComponentDescriptorRegistry( + {eventDispatcher, contextContainer}); + + auto mutableRegistry = + std::const_pointer_cast(registry); + + mutableRegistry->setFallbackComponentDescriptor( + std::make_shared( + ComponentDescriptorParameters{ + eventDispatcher, contextContainer, nullptr})); + + return registry; + }; + + delegate->buildRegistryFunction = buildRegistryFunction; + return instance; +} + +void MainComponentsRegistry::registerNatives() { + registerHybrid({ + makeNativeMethod("initHybrid", MainComponentsRegistry::initHybrid), + }); +} + +} // namespace react +} // namespace facebook From 6c362e719798fbbbe08d03783087482c06c1d277 Mon Sep 17 00:00:00 2001 From: Muhamad Rizki Date: Thu, 10 Oct 2024 04:49:30 +0700 Subject: [PATCH 3/5] revert: split implementation for oldarch and newarch --- android/build.gradle | 10 ---- .../FastShadowViewManager.java | 32 +++++++---- .../FastShadowViewManagerImpl.java | 56 ------------------- .../FastShadowViewManager.java | 56 ------------------- 4 files changed, 22 insertions(+), 132 deletions(-) rename android/src/{newarch => main}/java/com/reactnativefastshadow/FastShadowViewManager.java (65%) delete mode 100644 android/src/main/java/com/reactnativefastshadow/FastShadowViewManagerImpl.java delete mode 100644 android/src/oldarch/java/com/reactnativefastshadow/FastShadowViewManager.java diff --git a/android/build.gradle b/android/build.gradle index 84a86c5..3deece3 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -36,16 +36,6 @@ android { buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() } - sourceSets { - main { - if (isNewArchitectureEnabled()) { - java.srcDirs += ['src/newarch'] - } else { - java.srcDirs += ['src/oldarch'] - } - } - } - buildTypes { release { minifyEnabled false diff --git a/android/src/newarch/java/com/reactnativefastshadow/FastShadowViewManager.java b/android/src/main/java/com/reactnativefastshadow/FastShadowViewManager.java similarity index 65% rename from android/src/newarch/java/com/reactnativefastshadow/FastShadowViewManager.java rename to android/src/main/java/com/reactnativefastshadow/FastShadowViewManager.java index fec7089..71e419d 100644 --- a/android/src/newarch/java/com/reactnativefastshadow/FastShadowViewManager.java +++ b/android/src/main/java/com/reactnativefastshadow/FastShadowViewManager.java @@ -9,50 +9,62 @@ import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.react.views.view.ReactViewGroup; import com.facebook.react.views.view.ReactViewManager; -import com.facebook.react.module.annotations.ReactModule; -@ReactModule(name = FastShadowViewManagerImpl.NAME) public class FastShadowViewManager extends ReactViewManager { + public static final String NAME = "FastShadowView"; + @Override @NonNull public String getName() { - return FastShadowViewManagerImpl.NAME; + return FastShadowViewManager.NAME; } @Override public FastShadowView createViewInstance(ThemedReactContext context) { - return FastShadowViewManagerImpl.createViewInstance(context); + return new FastShadowView(context); } @Override public void onDropViewInstance(@NonNull ReactViewGroup view) { super.onDropViewInstance(view); - FastShadowViewManagerImpl.onDropViewInstance(view); + ((FastShadowView) view).releaseShadow(); } @ReactProp(name = "shadowColor", customType = "Color", defaultInt = Color.BLACK) public void setShadowColor(FastShadowView view, int color) { - FastShadowViewManagerImpl.setShadowColor(view, color); + view.setColor(color); } @ReactProp(name = "shadowOpacity", defaultFloat = 0) public void setShadowOpacity(FastShadowView view, float opacity) { - FastShadowViewManagerImpl.setShadowOpacity(view, opacity); + view.setOpacity(opacity); } @ReactProp(name = "shadowRadius", defaultFloat = 3) public void setShadowRadius(FastShadowView view, float radius) { - FastShadowViewManagerImpl.setShadowRadius(view, radius); + view.setRadius(radius); } @ReactProp(name = "shadowOffset") public void setShadowOffset(FastShadowView view, ReadableMap offset) { - FastShadowViewManagerImpl.setShadowOffset(view, offset); + if (offset == null) { + view.resetOffset(); + } else { + view.setOffset( + (float) offset.getDouble("width"), + (float) offset.getDouble("height") + ); + } } @ReactProp(name = "cornerRadii") public void setCornerRadii(FastShadowView view, ReadableMap borderRadius) { - FastShadowViewManagerImpl.setCornerRadii(view, borderRadius); + view.setCornerRadii(new float[]{ + (float) borderRadius.getDouble("topLeft"), + (float) borderRadius.getDouble("topRight"), + (float) borderRadius.getDouble("bottomRight"), + (float) borderRadius.getDouble("bottomLeft") + }); } } diff --git a/android/src/main/java/com/reactnativefastshadow/FastShadowViewManagerImpl.java b/android/src/main/java/com/reactnativefastshadow/FastShadowViewManagerImpl.java deleted file mode 100644 index c4cc7c1..0000000 --- a/android/src/main/java/com/reactnativefastshadow/FastShadowViewManagerImpl.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.reactnativefastshadow; - -import android.graphics.Color; - -import androidx.annotation.NonNull; - -import com.facebook.react.bridge.ReadableMap; -import com.facebook.react.uimanager.ThemedReactContext; -import com.facebook.react.uimanager.annotations.ReactProp; -import com.facebook.react.views.view.ReactViewGroup; -import com.facebook.react.views.view.ReactViewManager; - -public class FastShadowViewManagerImpl { - - public static final String NAME = "FastShadowView"; - - public static FastShadowView createViewInstance(ThemedReactContext context) { - return new FastShadowView(context); - } - - public static void onDropViewInstance(@NonNull ReactViewGroup view) { - ((FastShadowView) view).releaseShadow(); - } - - public static void setShadowColor(FastShadowView view, int color) { - view.setColor(color); - } - - public static void setShadowOpacity(FastShadowView view, float opacity) { - view.setOpacity(opacity); - } - - public static void setShadowRadius(FastShadowView view, float radius) { - view.setRadius(radius); - } - - public static void setShadowOffset(FastShadowView view, ReadableMap offset) { - if (offset == null) { - view.resetOffset(); - } else { - view.setOffset( - (float) offset.getDouble("width"), - (float) offset.getDouble("height") - ); - } - } - - public static void setCornerRadii(FastShadowView view, ReadableMap borderRadius) { - view.setCornerRadii(new float[]{ - (float) borderRadius.getDouble("topLeft"), - (float) borderRadius.getDouble("topRight"), - (float) borderRadius.getDouble("bottomRight"), - (float) borderRadius.getDouble("bottomLeft") - }); - } -} diff --git a/android/src/oldarch/java/com/reactnativefastshadow/FastShadowViewManager.java b/android/src/oldarch/java/com/reactnativefastshadow/FastShadowViewManager.java deleted file mode 100644 index dcc591a..0000000 --- a/android/src/oldarch/java/com/reactnativefastshadow/FastShadowViewManager.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.reactnativefastshadow; - -import android.graphics.Color; - -import androidx.annotation.NonNull; - -import com.facebook.react.bridge.ReadableMap; -import com.facebook.react.uimanager.ThemedReactContext; -import com.facebook.react.uimanager.annotations.ReactProp; -import com.facebook.react.views.view.ReactViewGroup; -import com.facebook.react.views.view.ReactViewManager; - -public class FastShadowViewManager extends ReactViewManager { - - @Override - @NonNull - public String getName() { - return FastShadowViewManagerImpl.NAME; - } - - @Override - public FastShadowView createViewInstance(ThemedReactContext context) { - return FastShadowViewManagerImpl.createViewInstance(context); - } - - @Override - public void onDropViewInstance(@NonNull ReactViewGroup view) { - super.onDropViewInstance(view); - FastShadowViewManagerImpl.onDropViewInstance(view); - } - - @ReactProp(name = "shadowColor", customType = "Color", defaultInt = Color.BLACK) - public void setShadowColor(FastShadowView view, int color) { - FastShadowViewManagerImpl.setShadowColor(view, color); - } - - @ReactProp(name = "shadowOpacity", defaultFloat = 0) - public void setShadowOpacity(FastShadowView view, float opacity) { - FastShadowViewManagerImpl.setShadowOpacity(view, opacity); - } - - @ReactProp(name = "shadowRadius", defaultFloat = 3) - public void setShadowRadius(FastShadowView view, float radius) { - FastShadowViewManagerImpl.setShadowRadius(view, radius); - } - - @ReactProp(name = "shadowOffset") - public void setShadowOffset(FastShadowView view, ReadableMap offset) { - FastShadowViewManagerImpl.setShadowOffset(view, offset); - } - - @ReactProp(name = "cornerRadii") - public void setCornerRadii(FastShadowView view, ReadableMap borderRadius) { - FastShadowViewManagerImpl.setCornerRadii(view, borderRadius); - } -} From b99aea89c703e4f5c376fc4cc42ca7db8cd5c37c Mon Sep 17 00:00:00 2001 From: Muhamad Rizki Date: Thu, 10 Oct 2024 05:09:53 +0700 Subject: [PATCH 4/5] chore: update example --- example/android/gradle.properties | 2 +- example/src/App.tsx | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/example/android/gradle.properties b/example/android/gradle.properties index a46a5b9..99fc223 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -34,7 +34,7 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64 # your application. You should enable this flag either if you want # to write custom TurboModules/Fabric components OR use libraries that # are providing them. -newArchEnabled=false +newArchEnabled=true # Use this property to enable or disable the Hermes JS engine. # If set to false, you will be using JSC instead. diff --git a/example/src/App.tsx b/example/src/App.tsx index bbff416..cb149d8 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -1,6 +1,6 @@ import React, { useEffect } from 'react'; -import { Image, View, ScrollView } from 'react-native'; +import { Image, View, ScrollView, Text } from 'react-native'; import { ShadowedView, shadowStyle } from 'react-native-fast-shadow'; import Animated, { useSharedValue, @@ -39,8 +39,11 @@ export default function App() { height: `${animatedHeight.value}%`, })); + const uiManager = (global as any)?.nativeFabricUIManager ? 'Fabric' : 'Paper'; + return ( + This View is {uiManager} Date: Thu, 10 Oct 2024 05:25:40 +0700 Subject: [PATCH 5/5] fix: remove android jni on example --- example/android/app/src/main/jni/Android.mk | 54 ---------------- .../src/main/jni/MainComponentsRegistry.cpp | 63 ------------------- 2 files changed, 117 deletions(-) delete mode 100644 example/android/app/src/main/jni/Android.mk delete mode 100644 example/android/app/src/main/jni/MainComponentsRegistry.cpp diff --git a/example/android/app/src/main/jni/Android.mk b/example/android/app/src/main/jni/Android.mk deleted file mode 100644 index 253de65..0000000 --- a/example/android/app/src/main/jni/Android.mk +++ /dev/null @@ -1,54 +0,0 @@ -THIS_DIR := $(call my-dir) - -include $(REACT_ANDROID_DIR)/Android-prebuilt.mk - -# If you wish to add a custom TurboModule or Fabric component in your app you -# will have to include the following autogenerated makefile. -# include $(GENERATED_SRC_DIR)/codegen/jni/Android.mk - -# Includes the MK file for `react-native-fast-shadow` -include $(NODE_MODULES_DIR)/../../android/build/generated/source/codegen/jni/Android.mk - -include $(CLEAR_VARS) - -LOCAL_PATH := $(THIS_DIR) - -# You can customize the name of your application .so file here. -LOCAL_MODULE := example_appmodules - -LOCAL_C_INCLUDES := $(LOCAL_PATH) -LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) -LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) - -# If you wish to add a custom TurboModule or Fabric component in your app you -# will have to uncomment those lines to include the generated source -# files from the codegen (placed in $(GENERATED_SRC_DIR)/codegen/jni) -# -# LOCAL_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni -# LOCAL_SRC_FILES += $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp) -# LOCAL_EXPORT_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni - -# Here you should add any native library you wish to depend on. -LOCAL_SHARED_LIBRARIES := \ - libfabricjni \ - libfbjni \ - libfolly_futures \ - libfolly_json \ - libglog \ - libjsi \ - libreact_codegen_rncore \ - libreact_codegen_FastShadowView \ - libreact_debug \ - libreact_nativemodule_core \ - libreact_render_componentregistry \ - libreact_render_core \ - libreact_render_debug \ - libreact_render_graphics \ - librrc_view \ - libruntimeexecutor \ - libturbomodulejsijni \ - libyoga - -LOCAL_CFLAGS := -DLOG_TAG=\"ReactNative\" -fexceptions -frtti -std=c++17 -Wall - -include $(BUILD_SHARED_LIBRARY) diff --git a/example/android/app/src/main/jni/MainComponentsRegistry.cpp b/example/android/app/src/main/jni/MainComponentsRegistry.cpp deleted file mode 100644 index 3cd79b4..0000000 --- a/example/android/app/src/main/jni/MainComponentsRegistry.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "MainComponentsRegistry.h" - -#include -#include -#include -#include -#include - -namespace facebook { -namespace react { - -MainComponentsRegistry::MainComponentsRegistry(ComponentFactory *delegate) {} - -std::shared_ptr -MainComponentsRegistry::sharedProviderRegistry() { - auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry(); - - // Custom Fabric Components go here. You can register custom - // components coming from your App or from 3rd party libraries here. - // - // providerRegistry->add(concreteComponentDescriptorProvider< - // AocViewerComponentDescriptor>()); - providerRegistry->add(concreteComponentDescriptorProvider()); - return providerRegistry; -} - -jni::local_ref -MainComponentsRegistry::initHybrid( - jni::alias_ref, - ComponentFactory *delegate) { - auto instance = makeCxxInstance(delegate); - - auto buildRegistryFunction = - [](EventDispatcher::Weak const &eventDispatcher, - ContextContainer::Shared const &contextContainer) - -> ComponentDescriptorRegistry::Shared { - auto registry = MainComponentsRegistry::sharedProviderRegistry() - ->createComponentDescriptorRegistry( - {eventDispatcher, contextContainer}); - - auto mutableRegistry = - std::const_pointer_cast(registry); - - mutableRegistry->setFallbackComponentDescriptor( - std::make_shared( - ComponentDescriptorParameters{ - eventDispatcher, contextContainer, nullptr})); - - return registry; - }; - - delegate->buildRegistryFunction = buildRegistryFunction; - return instance; -} - -void MainComponentsRegistry::registerNatives() { - registerHybrid({ - makeNativeMethod("initHybrid", MainComponentsRegistry::initHybrid), - }); -} - -} // namespace react -} // namespace facebook