Skip to content

Commit d6d4faf

Browse files
authored
fix: make RNF compatible with RNWC CxxTurboModule (#197)
1 parent 63b8666 commit d6d4faf

File tree

13 files changed

+141
-82
lines changed

13 files changed

+141
-82
lines changed

package/android/CMakeLists.txt

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
project(RNFilament)
22
cmake_minimum_required(VERSION 3.9.0)
33

4-
set(PACKAGE_NAME "RNFilament")
4+
set(PACKAGE_NAME "react-native-filament")
55
set(BUILD_DIR ${CMAKE_SOURCE_DIR}/build)
66
set(CMAKE_VERBOSE_MAKEFILE ON)
77
set(CMAKE_CXX_STANDARD 17)
@@ -125,15 +125,23 @@ target_link_libraries(
125125
EGL # <-- OpenGL (EGL)
126126
)
127127

128-
# We have a hard dependency on react-native-worklets-core, so fail if its not found
129-
find_package(react-native-worklets-core REQUIRED CONFIG)
130-
message("RN Filament: react-native-worklets core found! Enabling Worklets support...")
131-
message("RN Filament: react-native-worklets-core found in ${react-native-worklets-core_DIR}")
132-
133-
target_link_libraries(
134-
${PACKAGE_NAME}
135-
react-native-worklets-core::rnworklets # <-- react-native-worklets-core
136-
)
128+
# Link with RNWC:
129+
if (IS_OLD_ARCHITECTURE_ENABLED)
130+
# On the old arch RNWC publishes a prefab that we need to find (and it has a different name):
131+
find_package(react-native-worklets-core REQUIRED CONFIG)
132+
message("RN Filament: react-native-worklets core found! Enabling Worklets support...")
133+
message("RN Filament: react-native-worklets-core found in ${react-native-worklets-core_DIR}")
134+
target_link_libraries(
135+
${PACKAGE_NAME}
136+
react-native-worklets-core::rnworklets
137+
)
138+
else ()
139+
target_link_libraries(
140+
${PACKAGE_NAME}
141+
react_codegen_rnfilament # link against the codegen generated library of rnf (needed so this module is compiled correctly)
142+
react-native-worklets-core
143+
)
144+
endif()
137145
add_definitions(-DHAS_WORKLETS=1)
138146

139147
# Filament (local CMake project as a git submodule)

package/android/build.gradle

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,26 @@ android {
9393
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
9494
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
9595

96-
externalNativeBuild {
97-
cmake {
98-
cppFlags "-O2 -frtti -fexceptions -Wall -Wno-unused-variable -fstack-protector-all"
99-
arguments "-DANDROID_STL=c++_shared",
100-
"-DRNF_ENABLE_LOGS=${enableLogs ? "ON" : "OFF"}",
101-
"-DNODE_MODULES_DIR=${nodeModules}"
96+
// On the old arch, we need to build the c++ module ourselves
97+
if (!isNewArchitectureEnabled()) {
98+
externalNativeBuild {
99+
cmake {
100+
cppFlags "-O2 -frtti -fexceptions -Wall -Wno-unused-variable -fstack-protector-all"
101+
arguments "-DANDROID_STL=c++_shared",
102+
"-DRNF_ENABLE_LOGS=${enableLogs ? "ON" : "OFF"}",
103+
"-DNODE_MODULES_DIR=${nodeModules}",
104+
"-DIS_OLD_ARCHITECTURE_ENABLED=ON"
105+
}
102106
}
103107
}
104108
}
105109

106-
externalNativeBuild {
107-
cmake {
108-
path "CMakeLists.txt"
110+
// On the old arch, we need to build the c++ module ourselves
111+
if (!isNewArchitectureEnabled()) {
112+
externalNativeBuild {
113+
cmake {
114+
path "CMakeLists.txt"
115+
}
109116
}
110117
}
111118

package/android/src/main/java/com/margelo/filament/FilamentModuleImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public class FilamentModuleImpl {
88
static {
9-
System.loadLibrary("RNFilament");
9+
System.loadLibrary("react-native-filament");
1010
}
1111

1212
private @Nullable FilamentProxy proxy = null;

package/android/src/newarch/com/margelo/filament/FilamentViewManager.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616

1717
@ReactModule(name = FilamentViewManager.NAME)
1818
public class FilamentViewManager extends ViewGroupManager<FilamentView> implements FilamentViewManagerInterface<FilamentView> {
19-
static {
20-
System.loadLibrary("RNFilament");
21-
}
22-
2319
public static final String NAME = "FilamentView";
2420

2521
private final FilamentViewManagerDelegate<FilamentView, FilamentViewManager> mDelegate;

package/android/src/oldarch/com/margelo/filament/FilamentViewManager.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414

1515
@ReactModule(name = FilamentViewManager.NAME)
1616
public class FilamentViewManager extends ViewGroupManager<FilamentView> {
17-
static {
18-
System.loadLibrary("RNFilament");
19-
}
20-
2117
public FilamentViewManager(ReactApplicationContext reactContext) {
2218
super();
2319
}

package/cpp/RNFFilamentProxy.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@
2424
#include <ReactCommon/CallInvoker.h>
2525

2626
#ifdef HAS_WORKLETS
27+
#if __has_include(<react-native-worklets-core/WKTJsiWorkletContext.h>)
28+
// Old arch & CocoaPod headers on apple
2729
#include <react-native-worklets-core/WKTJsiWorkletContext.h>
30+
#else
31+
// New arch android, where RNWC and RNF c++ modules are build inside the app's project
32+
#include "WKTJsiWorkletContext.h"
2833
#endif
34+
#endif // HAS_WORKLETS
2935

3036
namespace margelo {
3137

@@ -83,7 +89,6 @@ class FilamentProxy : public HybridObject {
8389
std::optional<std::unordered_map<std::string, int>> arguments = std::nullopt);
8490
std::shared_ptr<BulletWrapper> createBullet();
8591
bool getHasWorklets();
86-
// std::shared_ptr<ChoreographerWrapper> createChoreographerWrapper();
8792
jsi::Value createChoreographerWrapper(jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count);
8893

8994
#if HAS_WORKLETS

package/example/AppExampleFabric/ios/Podfile.lock

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ PODS:
935935
- React-Mapbuffer (0.74.1):
936936
- glog
937937
- React-debug
938-
- react-native-filament (0.41.1):
938+
- react-native-filament (0.42.0):
939939
- DoubleConversion
940940
- glog
941941
- hermes-engine
@@ -949,16 +949,16 @@ PODS:
949949
- React-featureflags
950950
- React-graphics
951951
- React-ImageManager
952-
- react-native-filament/camutils (= 0.41.1)
953-
- react-native-filament/filamat (= 0.41.1)
954-
- react-native-filament/filament (= 0.41.1)
955-
- react-native-filament/gltfio_core (= 0.41.1)
956-
- react-native-filament/image (= 0.41.1)
957-
- react-native-filament/ktxreader (= 0.41.1)
958-
- react-native-filament/math (= 0.41.1)
959-
- react-native-filament/tsl (= 0.41.1)
960-
- react-native-filament/uberz (= 0.41.1)
961-
- react-native-filament/utils (= 0.41.1)
952+
- react-native-filament/camutils (= 0.42.0)
953+
- react-native-filament/filamat (= 0.42.0)
954+
- react-native-filament/filament (= 0.42.0)
955+
- react-native-filament/gltfio_core (= 0.42.0)
956+
- react-native-filament/image (= 0.42.0)
957+
- react-native-filament/ktxreader (= 0.42.0)
958+
- react-native-filament/math (= 0.42.0)
959+
- react-native-filament/tsl (= 0.42.0)
960+
- react-native-filament/uberz (= 0.42.0)
961+
- react-native-filament/utils (= 0.42.0)
962962
- react-native-worklets-core
963963
- React-NativeModulesApple
964964
- React-RCTFabric
@@ -967,7 +967,7 @@ PODS:
967967
- ReactCommon/turbomodule/bridging
968968
- ReactCommon/turbomodule/core
969969
- Yoga
970-
- react-native-filament/camutils (0.41.1):
970+
- react-native-filament/camutils (0.42.0):
971971
- DoubleConversion
972972
- glog
973973
- hermes-engine
@@ -990,7 +990,7 @@ PODS:
990990
- ReactCommon/turbomodule/bridging
991991
- ReactCommon/turbomodule/core
992992
- Yoga
993-
- react-native-filament/filamat (0.41.1):
993+
- react-native-filament/filamat (0.42.0):
994994
- DoubleConversion
995995
- glog
996996
- hermes-engine
@@ -1014,7 +1014,7 @@ PODS:
10141014
- ReactCommon/turbomodule/bridging
10151015
- ReactCommon/turbomodule/core
10161016
- Yoga
1017-
- react-native-filament/filament (0.41.1):
1017+
- react-native-filament/filament (0.42.0):
10181018
- DoubleConversion
10191019
- glog
10201020
- hermes-engine
@@ -1038,7 +1038,7 @@ PODS:
10381038
- ReactCommon/turbomodule/bridging
10391039
- ReactCommon/turbomodule/core
10401040
- Yoga
1041-
- react-native-filament/gltfio_core (0.41.1):
1041+
- react-native-filament/gltfio_core (0.42.0):
10421042
- DoubleConversion
10431043
- glog
10441044
- hermes-engine
@@ -1063,7 +1063,7 @@ PODS:
10631063
- ReactCommon/turbomodule/bridging
10641064
- ReactCommon/turbomodule/core
10651065
- Yoga
1066-
- react-native-filament/image (0.41.1):
1066+
- react-native-filament/image (0.42.0):
10671067
- DoubleConversion
10681068
- glog
10691069
- hermes-engine
@@ -1086,7 +1086,7 @@ PODS:
10861086
- ReactCommon/turbomodule/bridging
10871087
- ReactCommon/turbomodule/core
10881088
- Yoga
1089-
- react-native-filament/ktxreader (0.41.1):
1089+
- react-native-filament/ktxreader (0.42.0):
10901090
- DoubleConversion
10911091
- glog
10921092
- hermes-engine
@@ -1110,7 +1110,7 @@ PODS:
11101110
- ReactCommon/turbomodule/bridging
11111111
- ReactCommon/turbomodule/core
11121112
- Yoga
1113-
- react-native-filament/math (0.41.1):
1113+
- react-native-filament/math (0.42.0):
11141114
- DoubleConversion
11151115
- glog
11161116
- hermes-engine
@@ -1132,7 +1132,7 @@ PODS:
11321132
- ReactCommon/turbomodule/bridging
11331133
- ReactCommon/turbomodule/core
11341134
- Yoga
1135-
- react-native-filament/tsl (0.41.1):
1135+
- react-native-filament/tsl (0.42.0):
11361136
- DoubleConversion
11371137
- glog
11381138
- hermes-engine
@@ -1154,7 +1154,7 @@ PODS:
11541154
- ReactCommon/turbomodule/bridging
11551155
- ReactCommon/turbomodule/core
11561156
- Yoga
1157-
- react-native-filament/uberz (0.41.1):
1157+
- react-native-filament/uberz (0.42.0):
11581158
- DoubleConversion
11591159
- glog
11601160
- hermes-engine
@@ -1179,7 +1179,7 @@ PODS:
11791179
- ReactCommon/turbomodule/bridging
11801180
- ReactCommon/turbomodule/core
11811181
- Yoga
1182-
- react-native-filament/utils (0.41.1):
1182+
- react-native-filament/utils (0.42.0):
11831183
- DoubleConversion
11841184
- glog
11851185
- hermes-engine
@@ -1311,13 +1311,27 @@ PODS:
13111311
- ReactCommon/turbomodule/bridging
13121312
- ReactCommon/turbomodule/core
13131313
- Yoga
1314-
- react-native-worklets-core (1.3.3):
1315-
- RCT-Folly
1314+
- react-native-worklets-core (2.0.0-beta.4):
1315+
- DoubleConversion
1316+
- glog
1317+
- hermes-engine
1318+
- RCT-Folly (= 2024.01.01.00)
13161319
- RCTRequired
13171320
- RCTTypeSafety
13181321
- React-Codegen
13191322
- React-Core
1323+
- React-debug
1324+
- React-Fabric
1325+
- React-featureflags
1326+
- React-graphics
1327+
- React-ImageManager
1328+
- React-NativeModulesApple
1329+
- React-RCTFabric
1330+
- React-rendererdebug
1331+
- React-utils
1332+
- ReactCommon/turbomodule/bridging
13201333
- ReactCommon/turbomodule/core
1334+
- Yoga
13211335
- React-nativeconfig (0.74.1)
13221336
- React-NativeModulesApple (0.74.1):
13231337
- glog
@@ -1862,10 +1876,10 @@ SPEC CHECKSUMS:
18621876
React-jsitracing: 233d1a798fe0ff33b8e630b8f00f62c4a8115fbc
18631877
React-logger: 7e7403a2b14c97f847d90763af76b84b152b6fce
18641878
React-Mapbuffer: 11029dcd47c5c9e057a4092ab9c2a8d10a496a33
1865-
react-native-filament: 2f63b053f508bb398e9215235a688bd06bf3ecee
1879+
react-native-filament: 8620e1fe4866598ac5d7c5e85120af5446113583
18661880
react-native-safe-area-context: 7f54ad0a774de306ab790c70d9d950321e5c5449
18671881
react-native-video: ef5d99175a532dbe6cbcb33c849a2d1ecc9bac2e
1868-
react-native-worklets-core: 80d4a9b195d3e806c5e02942cfb5a43c6f99d02d
1882+
react-native-worklets-core: f5cdd75d46976ffa253adce0701218313de9cf09
18691883
React-nativeconfig: b0073a590774e8b35192fead188a36d1dca23dec
18701884
React-NativeModulesApple: df46ff3e3de5b842b30b4ca8a6caae6d7c8ab09f
18711885
React-perflogger: 3d31e0d1e8ad891e43a09ac70b7b17a79773003a

package/example/AppExampleFabric/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"react-native-safe-area-context": "^4.10.1",
2323
"react-native-screens": "^3.31.1",
2424
"react-native-video": "^6.1.2",
25-
"react-native-worklets-core": "^1.3.3",
25+
"react-native-worklets-core": "^2.0.0-beta.4",
2626
"shared": "workspace:^"
2727
},
2828
"devDependencies": {

0 commit comments

Comments
 (0)