expo-template-bare-minimum 44.0.10 → 45.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/android/app/build.gradle +134 -10
  2. package/android/app/src/main/AndroidManifest.xml +2 -2
  3. package/android/app/src/main/java/com/helloworld/MainApplication.java +12 -3
  4. package/android/app/src/main/java/com/helloworld/newarchitecture/MainApplicationReactNativeHost.java +116 -0
  5. package/android/app/src/main/java/com/helloworld/newarchitecture/components/MainComponentsRegistry.java +36 -0
  6. package/android/app/src/main/java/com/helloworld/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java +48 -0
  7. package/android/app/src/main/jni/Android.mk +49 -0
  8. package/android/app/src/main/jni/MainApplicationModuleProvider.cpp +24 -0
  9. package/android/app/src/main/jni/MainApplicationModuleProvider.h +16 -0
  10. package/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp +45 -0
  11. package/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h +38 -0
  12. package/android/app/src/main/jni/MainComponentsRegistry.cpp +61 -0
  13. package/android/app/src/main/jni/MainComponentsRegistry.h +32 -0
  14. package/android/app/src/main/jni/OnLoad.cpp +11 -0
  15. package/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -0
  16. package/android/app/src/main/res/values/styles.xml +1 -0
  17. package/android/build.gradle +27 -8
  18. package/android/gitignore +21 -0
  19. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  20. package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
  21. package/android/gradle.properties +16 -4
  22. package/android/gradlew +154 -103
  23. package/android/gradlew.bat +89 -103
  24. package/android/settings.gradle +6 -0
  25. package/ios/HelloWorld/AppDelegate.mm +143 -0
  26. package/ios/HelloWorld.xcodeproj/project.pbxproj +8 -6
  27. package/ios/Podfile +12 -14
  28. package/ios/gitignore +29 -0
  29. package/package.json +7 -7
  30. package/ios/HelloWorld/AppDelegate.m +0 -76
@@ -1,6 +1,7 @@
1
1
  apply plugin: "com.android.application"
2
2
 
3
3
  import com.android.build.OutputFile
4
+ import org.apache.tools.ant.taskdefs.condition.Os
4
5
 
5
6
  /**
6
7
  * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
@@ -77,7 +78,10 @@ import com.android.build.OutputFile
77
78
  * ]
78
79
  */
79
80
 
81
+ def projectRoot = rootDir.getAbsoluteFile().getParentFile().getAbsolutePath()
82
+
80
83
  project.ext.react = [
84
+ entryFile: ["node", "-e", "require('expo/scripts/resolveAppEntry')", projectRoot, "android"].execute(null, rootDir).text.trim(),
81
85
  enableHermes: (findProperty('expo.jsEngine') ?: "jsc") == "hermes",
82
86
  cliPath: new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() + "/cli.js",
83
87
  hermesCommand: new File(["node", "--print", "require.resolve('hermes-engine/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() + "/%OS-BIN%/hermesc",
@@ -117,19 +121,24 @@ def jscFlavor = 'org.webkit:android-jsc:+'
117
121
  /**
118
122
  * Whether to enable the Hermes VM.
119
123
  *
120
- * This should be set on project.ext.react and mirrored here. If it is not set
124
+ * This should be set on project.ext.react and that value will be read here. If it is not set
121
125
  * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
122
126
  * and the benefits of using Hermes will therefore be sharply reduced.
123
127
  */
124
128
  def enableHermes = project.ext.react.get("enableHermes", false);
125
129
 
130
+ /**
131
+ * Architectures to build native code for.
132
+ */
133
+ def reactNativeArchitectures() {
134
+ def value = project.getProperties().get("reactNativeArchitectures")
135
+ return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
136
+ }
137
+
126
138
  android {
127
- compileSdkVersion rootProject.ext.compileSdkVersion
139
+ ndkVersion rootProject.ext.ndkVersion
128
140
 
129
- compileOptions {
130
- sourceCompatibility JavaVersion.VERSION_1_8
131
- targetCompatibility JavaVersion.VERSION_1_8
132
- }
141
+ compileSdkVersion rootProject.ext.compileSdkVersion
133
142
 
134
143
  defaultConfig {
135
144
  applicationId "com.helloworld"
@@ -137,13 +146,87 @@ android {
137
146
  targetSdkVersion rootProject.ext.targetSdkVersion
138
147
  versionCode 1
139
148
  versionName "1.0"
149
+ buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
150
+
151
+ if (isNewArchitectureEnabled()) {
152
+ // We configure the NDK build only if you decide to opt-in for the New Architecture.
153
+ externalNativeBuild {
154
+ ndkBuild {
155
+ arguments "APP_PLATFORM=android-21",
156
+ "APP_STL=c++_shared",
157
+ "NDK_TOOLCHAIN_VERSION=clang",
158
+ "GENERATED_SRC_DIR=$buildDir/generated/source",
159
+ "PROJECT_BUILD_DIR=$buildDir",
160
+ "REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
161
+ "REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build"
162
+ cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
163
+ cppFlags "-std=c++17"
164
+ // Make sure this target name is the same you specify inside the
165
+ // src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
166
+ targets "helloworld_appmodules"
167
+
168
+ // Fix for windows limit on number of character in file paths and in command lines
169
+ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
170
+ arguments "NDK_OUT=${rootProject.projectDir.getParent()}\\.cxx",
171
+ "NDK_APP_SHORT_COMMANDS=true"
172
+ }
173
+ }
174
+ }
175
+ if (!enableSeparateBuildPerCPUArchitecture) {
176
+ ndk {
177
+ abiFilters (*reactNativeArchitectures())
178
+ }
179
+ }
180
+ }
181
+ }
182
+
183
+ if (isNewArchitectureEnabled()) {
184
+ // We configure the NDK build only if you decide to opt-in for the New Architecture.
185
+ externalNativeBuild {
186
+ ndkBuild {
187
+ path "$projectDir/src/main/jni/Android.mk"
188
+ }
189
+ }
190
+ def reactAndroidProjectDir = project(':ReactAndroid').projectDir
191
+ def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) {
192
+ dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck")
193
+ from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
194
+ into("$buildDir/react-ndk/exported")
195
+ }
196
+ def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) {
197
+ dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck")
198
+ from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
199
+ into("$buildDir/react-ndk/exported")
200
+ }
201
+ afterEvaluate {
202
+ // If you wish to add a custom TurboModule or component locally,
203
+ // you should uncomment this line.
204
+ // preBuild.dependsOn("generateCodegenArtifactsFromSchema")
205
+ preDebugBuild.dependsOn(packageReactNdkDebugLibs)
206
+ preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)
207
+
208
+ // Due to a bug inside AGP, we have to explicitly set a dependency
209
+ // between configureNdkBuild* tasks and the preBuild tasks.
210
+ // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
211
+ configureNdkBuildRelease.dependsOn(preReleaseBuild)
212
+ configureNdkBuildDebug.dependsOn(preDebugBuild)
213
+ reactNativeArchitectures().each { architecture ->
214
+ tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure {
215
+ dependsOn("preDebugBuild")
216
+ }
217
+ tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure {
218
+ dependsOn("preReleaseBuild")
219
+ }
220
+ }
221
+ }
140
222
  }
223
+
141
224
  splits {
142
225
  abi {
143
226
  reset()
144
227
  enable enableSeparateBuildPerCPUArchitecture
145
228
  universalApk false // If true, also generate a universal APK
146
- include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
229
+ include (*reactNativeArchitectures())
147
230
  }
148
231
  }
149
232
  signingConfigs {
@@ -183,8 +266,29 @@ android {
183
266
  }
184
267
  }
185
268
 
269
+ // Apply static values from `gradle.properties` to the `android.packagingOptions`
270
+ // Accepts values in comma delimited lists, example:
271
+ // android.packagingOptions.pickFirsts=/LICENSE,**/picasa.ini
272
+ ["pickFirsts", "excludes", "merges", "doNotStrip"].each { prop ->
273
+ // Split option: 'foo,bar' -> ['foo', 'bar']
274
+ def options = (findProperty("android.packagingOptions.$prop") ?: "").split(",");
275
+ // Trim all elements in place.
276
+ for (i in 0..<options.size()) options[i] = options[i].trim();
277
+ // `[] - ""` is essentially `[""].filter(Boolean)` removing all empty strings.
278
+ options -= ""
279
+
280
+ if (options.length > 0) {
281
+ println "android.packagingOptions.$prop += $options ($options.length)"
282
+ // Ex: android.packagingOptions.pickFirsts += '**/SCCS/**'
283
+ options.each {
284
+ android.packagingOptions[prop] += it
285
+ }
286
+ }
287
+ }
288
+
186
289
  dependencies {
187
290
  implementation fileTree(dir: "libs", include: ["*.jar"])
291
+
188
292
  //noinspection GradleDynamicVersion
189
293
  implementation "com.facebook.react:react-native:+" // From node_modules
190
294
 
@@ -212,10 +316,10 @@ dependencies {
212
316
  implementation 'com.facebook.fresco:animated-webp:2.0.0'
213
317
  }
214
318
  }
215
-
319
+
216
320
  implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
217
321
  debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
218
- exclude group:'com.facebook.fbjni'
322
+ exclude group:'com.facebook.fbjni'
219
323
  }
220
324
  debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
221
325
  exclude group:'com.facebook.flipper'
@@ -233,12 +337,32 @@ dependencies {
233
337
  }
234
338
  }
235
339
 
340
+ if (isNewArchitectureEnabled()) {
341
+ // If new architecture is enabled, we let you build RN from source
342
+ // Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
343
+ // This will be applied to all the imported transtitive dependency.
344
+ configurations.all {
345
+ resolutionStrategy.dependencySubstitution {
346
+ substitute(module("com.facebook.react:react-native"))
347
+ .using(project(":ReactAndroid")).because("On New Architecture we're building React Native from source")
348
+ }
349
+ }
350
+ }
351
+
236
352
  // Run this once to be able to run the application with BUCK
237
353
  // puts all compile dependencies into folder libs for BUCK to use
238
354
  task copyDownloadableDepsToLibs(type: Copy) {
239
- from configurations.compile
355
+ from configurations.implementation
240
356
  into 'libs'
241
357
  }
242
358
 
243
359
  apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
244
360
  applyNativeModulesAppBuildGradle(project)
361
+
362
+ def isNewArchitectureEnabled() {
363
+ // To opt-in for the New Architecture, you can either:
364
+ // - Set `newArchEnabled` to true inside the `gradle.properties` file
365
+ // - Invoke gradle with `-newArchEnabled=true`
366
+ // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
367
+ return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
368
+ }
@@ -21,12 +21,12 @@
21
21
  <application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:theme="@style/AppTheme" android:usesCleartextTraffic="true">
22
22
  <meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="YOUR-APP-URL-HERE"/>
23
23
  <meta-data android:name="expo.modules.updates.EXPO_SDK_VERSION" android:value="YOUR-APP-SDK-VERSION-HERE"/>
24
- <activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen">
24
+ <activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:exported="true">
25
25
  <intent-filter>
26
26
  <action android:name="android.intent.action.MAIN"/>
27
27
  <category android:name="android.intent.category.LAUNCHER"/>
28
28
  </intent-filter>
29
29
  </activity>
30
- <activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/>
30
+ <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false"/>
31
31
  </application>
32
32
  </manifest>
@@ -10,13 +10,13 @@ import com.facebook.react.ReactApplication;
10
10
  import com.facebook.react.ReactInstanceManager;
11
11
  import com.facebook.react.ReactNativeHost;
12
12
  import com.facebook.react.ReactPackage;
13
+ import com.facebook.react.config.ReactFeatureFlags;
13
14
  import com.facebook.soloader.SoLoader;
15
+ import com.helloworld.newarchitecture.MainApplicationReactNativeHost;
14
16
 
15
17
  import expo.modules.ApplicationLifecycleDispatcher;
16
18
  import expo.modules.ReactNativeHostWrapper;
17
19
 
18
- import com.facebook.react.bridge.JSIModulePackage;
19
-
20
20
  import java.lang.reflect.InvocationTargetException;
21
21
  import java.util.List;
22
22
 
@@ -44,14 +44,23 @@ public class MainApplication extends Application implements ReactApplication {
44
44
  }
45
45
  });
46
46
 
47
+ private final ReactNativeHost mNewArchitectureNativeHost =
48
+ new ReactNativeHostWrapper(this, new MainApplicationReactNativeHost(this));
49
+
47
50
  @Override
48
51
  public ReactNativeHost getReactNativeHost() {
49
- return mReactNativeHost;
52
+ if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
53
+ return mNewArchitectureNativeHost;
54
+ } else {
55
+ return mReactNativeHost;
56
+ }
50
57
  }
51
58
 
52
59
  @Override
53
60
  public void onCreate() {
54
61
  super.onCreate();
62
+ // If you opted-in for the New Architecture, we enable the TurboModule system
63
+ ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
55
64
  SoLoader.init(this, /* native exopackage */ false);
56
65
 
57
66
  initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
@@ -0,0 +1,116 @@
1
+ package com.helloworld.newarchitecture;
2
+
3
+ import android.app.Application;
4
+ import androidx.annotation.NonNull;
5
+ import com.facebook.react.PackageList;
6
+ import com.facebook.react.ReactInstanceManager;
7
+ import com.facebook.react.ReactNativeHost;
8
+ import com.facebook.react.ReactPackage;
9
+ import com.facebook.react.ReactPackageTurboModuleManagerDelegate;
10
+ import com.facebook.react.bridge.JSIModulePackage;
11
+ import com.facebook.react.bridge.JSIModuleProvider;
12
+ import com.facebook.react.bridge.JSIModuleSpec;
13
+ import com.facebook.react.bridge.JSIModuleType;
14
+ import com.facebook.react.bridge.JavaScriptContextHolder;
15
+ import com.facebook.react.bridge.ReactApplicationContext;
16
+ import com.facebook.react.bridge.UIManager;
17
+ import com.facebook.react.fabric.ComponentFactory;
18
+ import com.facebook.react.fabric.CoreComponentsRegistry;
19
+ import com.facebook.react.fabric.EmptyReactNativeConfig;
20
+ import com.facebook.react.fabric.FabricJSIModuleProvider;
21
+ import com.facebook.react.uimanager.ViewManagerRegistry;
22
+ import com.helloworld.BuildConfig;
23
+ import com.helloworld.newarchitecture.components.MainComponentsRegistry;
24
+ import com.helloworld.newarchitecture.modules.MainApplicationTurboModuleManagerDelegate;
25
+ import java.util.ArrayList;
26
+ import java.util.List;
27
+
28
+ /**
29
+ * A {@link ReactNativeHost} that helps you load everything needed for the New Architecture, both
30
+ * TurboModule delegates and the Fabric Renderer.
31
+ *
32
+ * <p>Please note that this class is used ONLY if you opt-in for the New Architecture (see the
33
+ * `newArchEnabled` property). Is ignored otherwise.
34
+ */
35
+ public class MainApplicationReactNativeHost extends ReactNativeHost {
36
+ public MainApplicationReactNativeHost(Application application) {
37
+ super(application);
38
+ }
39
+
40
+ @Override
41
+ public boolean getUseDeveloperSupport() {
42
+ return BuildConfig.DEBUG;
43
+ }
44
+
45
+ @Override
46
+ protected List<ReactPackage> getPackages() {
47
+ List<ReactPackage> packages = new PackageList(this).getPackages();
48
+ // Packages that cannot be autolinked yet can be added manually here, for example:
49
+ // packages.add(new MyReactNativePackage());
50
+ // TurboModules must also be loaded here providing a valid TurboReactPackage implementation:
51
+ // packages.add(new TurboReactPackage() { ... });
52
+ // If you have custom Fabric Components, their ViewManagers should also be loaded here
53
+ // inside a ReactPackage.
54
+ return packages;
55
+ }
56
+
57
+ @Override
58
+ protected String getJSMainModuleName() {
59
+ return "index";
60
+ }
61
+
62
+ @NonNull
63
+ @Override
64
+ protected ReactPackageTurboModuleManagerDelegate.Builder
65
+ getReactPackageTurboModuleManagerDelegateBuilder() {
66
+ // Here we provide the ReactPackageTurboModuleManagerDelegate Builder. This is necessary
67
+ // for the new architecture and to use TurboModules correctly.
68
+ return new MainApplicationTurboModuleManagerDelegate.Builder();
69
+ }
70
+
71
+ @Override
72
+ protected JSIModulePackage getJSIModulePackage() {
73
+ return new JSIModulePackage() {
74
+ @Override
75
+ public List<JSIModuleSpec> getJSIModules(
76
+ final ReactApplicationContext reactApplicationContext,
77
+ final JavaScriptContextHolder jsContext) {
78
+ final List<JSIModuleSpec> specs = new ArrayList<>();
79
+
80
+ // Here we provide a new JSIModuleSpec that will be responsible of providing the
81
+ // custom Fabric Components.
82
+ specs.add(
83
+ new JSIModuleSpec() {
84
+ @Override
85
+ public JSIModuleType getJSIModuleType() {
86
+ return JSIModuleType.UIManager;
87
+ }
88
+
89
+ @Override
90
+ public JSIModuleProvider<UIManager> getJSIModuleProvider() {
91
+ final ComponentFactory componentFactory = new ComponentFactory();
92
+ CoreComponentsRegistry.register(componentFactory);
93
+
94
+ // Here we register a Components Registry.
95
+ // The one that is generated with the template contains no components
96
+ // and just provides you the one from React Native core.
97
+ MainComponentsRegistry.register(componentFactory);
98
+
99
+ final ReactInstanceManager reactInstanceManager = getReactInstanceManager();
100
+
101
+ ViewManagerRegistry viewManagerRegistry =
102
+ new ViewManagerRegistry(
103
+ reactInstanceManager.getOrCreateViewManagers(reactApplicationContext));
104
+
105
+ return new FabricJSIModuleProvider(
106
+ reactApplicationContext,
107
+ componentFactory,
108
+ new EmptyReactNativeConfig(),
109
+ viewManagerRegistry);
110
+ }
111
+ });
112
+ return specs;
113
+ }
114
+ };
115
+ }
116
+ }
@@ -0,0 +1,36 @@
1
+ package com.helloworld.newarchitecture.components;
2
+
3
+ import com.facebook.jni.HybridData;
4
+ import com.facebook.proguard.annotations.DoNotStrip;
5
+ import com.facebook.react.fabric.ComponentFactory;
6
+ import com.facebook.soloader.SoLoader;
7
+
8
+ /**
9
+ * Class responsible to load the custom Fabric Components. This class has native methods and needs a
10
+ * corresponding C++ implementation/header file to work correctly (already placed inside the jni/
11
+ * folder for you).
12
+ *
13
+ * <p>Please note that this class is used ONLY if you opt-in for the New Architecture (see the
14
+ * `newArchEnabled` property). Is ignored otherwise.
15
+ */
16
+ @DoNotStrip
17
+ public class MainComponentsRegistry {
18
+ static {
19
+ SoLoader.loadLibrary("fabricjni");
20
+ }
21
+
22
+ @DoNotStrip private final HybridData mHybridData;
23
+
24
+ @DoNotStrip
25
+ private native HybridData initHybrid(ComponentFactory componentFactory);
26
+
27
+ @DoNotStrip
28
+ private MainComponentsRegistry(ComponentFactory componentFactory) {
29
+ mHybridData = initHybrid(componentFactory);
30
+ }
31
+
32
+ @DoNotStrip
33
+ public static MainComponentsRegistry register(ComponentFactory componentFactory) {
34
+ return new MainComponentsRegistry(componentFactory);
35
+ }
36
+ }
@@ -0,0 +1,48 @@
1
+ package com.helloworld.newarchitecture.modules;
2
+
3
+ import com.facebook.jni.HybridData;
4
+ import com.facebook.react.ReactPackage;
5
+ import com.facebook.react.ReactPackageTurboModuleManagerDelegate;
6
+ import com.facebook.react.bridge.ReactApplicationContext;
7
+ import com.facebook.soloader.SoLoader;
8
+ import java.util.List;
9
+
10
+ /**
11
+ * Class responsible to load the TurboModules. This class has native methods and needs a
12
+ * corresponding C++ implementation/header file to work correctly (already placed inside the jni/
13
+ * folder for you).
14
+ *
15
+ * <p>Please note that this class is used ONLY if you opt-in for the New Architecture (see the
16
+ * `newArchEnabled` property). Is ignored otherwise.
17
+ */
18
+ public class MainApplicationTurboModuleManagerDelegate
19
+ extends ReactPackageTurboModuleManagerDelegate {
20
+
21
+ private static volatile boolean sIsSoLibraryLoaded;
22
+
23
+ protected MainApplicationTurboModuleManagerDelegate(
24
+ ReactApplicationContext reactApplicationContext, List<ReactPackage> packages) {
25
+ super(reactApplicationContext, packages);
26
+ }
27
+
28
+ protected native HybridData initHybrid();
29
+
30
+ native boolean canCreateTurboModule(String moduleName);
31
+
32
+ public static class Builder extends ReactPackageTurboModuleManagerDelegate.Builder {
33
+ protected MainApplicationTurboModuleManagerDelegate build(
34
+ ReactApplicationContext context, List<ReactPackage> packages) {
35
+ return new MainApplicationTurboModuleManagerDelegate(context, packages);
36
+ }
37
+ }
38
+
39
+ @Override
40
+ protected synchronized void maybeLoadOtherSoLibraries() {
41
+ if (!sIsSoLibraryLoaded) {
42
+ // If you change the name of your application .so file in the Android.mk file,
43
+ // make sure you update the name here as well.
44
+ SoLoader.loadLibrary("helloworld_appmodules");
45
+ sIsSoLibraryLoaded = true;
46
+ }
47
+ }
48
+ }
@@ -0,0 +1,49 @@
1
+ THIS_DIR := $(call my-dir)
2
+
3
+ include $(REACT_ANDROID_DIR)/Android-prebuilt.mk
4
+
5
+ # If you wish to add a custom TurboModule or Fabric component in your app you
6
+ # will have to include the following autogenerated makefile.
7
+ # include $(GENERATED_SRC_DIR)/codegen/jni/Android.mk
8
+ include $(CLEAR_VARS)
9
+
10
+ LOCAL_PATH := $(THIS_DIR)
11
+
12
+ # You can customize the name of your application .so file here.
13
+ LOCAL_MODULE := helloworld_appmodules
14
+
15
+ LOCAL_C_INCLUDES := $(LOCAL_PATH)
16
+ LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp)
17
+ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
18
+
19
+ # If you wish to add a custom TurboModule or Fabric component in your app you
20
+ # will have to uncomment those lines to include the generated source
21
+ # files from the codegen (placed in $(GENERATED_SRC_DIR)/codegen/jni)
22
+ #
23
+ # LOCAL_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni
24
+ # LOCAL_SRC_FILES += $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp)
25
+ # LOCAL_EXPORT_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni
26
+
27
+ # Here you should add any native library you wish to depend on.
28
+ LOCAL_SHARED_LIBRARIES := \
29
+ libfabricjni \
30
+ libfbjni \
31
+ libfolly_futures \
32
+ libfolly_json \
33
+ libglog \
34
+ libjsi \
35
+ libreact_codegen_rncore \
36
+ libreact_debug \
37
+ libreact_nativemodule_core \
38
+ libreact_render_componentregistry \
39
+ libreact_render_core \
40
+ libreact_render_debug \
41
+ libreact_render_graphics \
42
+ librrc_view \
43
+ libruntimeexecutor \
44
+ libturbomodulejsijni \
45
+ libyoga
46
+
47
+ LOCAL_CFLAGS := -DLOG_TAG=\"ReactNative\" -fexceptions -frtti -std=c++17 -Wall
48
+
49
+ include $(BUILD_SHARED_LIBRARY)
@@ -0,0 +1,24 @@
1
+ #include "MainApplicationModuleProvider.h"
2
+
3
+ #include <rncore.h>
4
+
5
+ namespace facebook {
6
+ namespace react {
7
+
8
+ std::shared_ptr<TurboModule> MainApplicationModuleProvider(
9
+ const std::string moduleName,
10
+ const JavaTurboModule::InitParams &params) {
11
+ // Here you can provide your own module provider for TurboModules coming from
12
+ // either your application or from external libraries. The approach to follow
13
+ // is similar to the following (for a library called `samplelibrary`:
14
+ //
15
+ // auto module = samplelibrary_ModuleProvider(moduleName, params);
16
+ // if (module != nullptr) {
17
+ // return module;
18
+ // }
19
+ // return rncore_ModuleProvider(moduleName, params);
20
+ return rncore_ModuleProvider(moduleName, params);
21
+ }
22
+
23
+ } // namespace react
24
+ } // namespace facebook
@@ -0,0 +1,16 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <string>
5
+
6
+ #include <ReactCommon/JavaTurboModule.h>
7
+
8
+ namespace facebook {
9
+ namespace react {
10
+
11
+ std::shared_ptr<TurboModule> MainApplicationModuleProvider(
12
+ const std::string moduleName,
13
+ const JavaTurboModule::InitParams &params);
14
+
15
+ } // namespace react
16
+ } // namespace facebook
@@ -0,0 +1,45 @@
1
+ #include "MainApplicationTurboModuleManagerDelegate.h"
2
+ #include "MainApplicationModuleProvider.h"
3
+
4
+ namespace facebook {
5
+ namespace react {
6
+
7
+ jni::local_ref<MainApplicationTurboModuleManagerDelegate::jhybriddata>
8
+ MainApplicationTurboModuleManagerDelegate::initHybrid(
9
+ jni::alias_ref<jhybridobject>) {
10
+ return makeCxxInstance();
11
+ }
12
+
13
+ void MainApplicationTurboModuleManagerDelegate::registerNatives() {
14
+ registerHybrid({
15
+ makeNativeMethod(
16
+ "initHybrid", MainApplicationTurboModuleManagerDelegate::initHybrid),
17
+ makeNativeMethod(
18
+ "canCreateTurboModule",
19
+ MainApplicationTurboModuleManagerDelegate::canCreateTurboModule),
20
+ });
21
+ }
22
+
23
+ std::shared_ptr<TurboModule>
24
+ MainApplicationTurboModuleManagerDelegate::getTurboModule(
25
+ const std::string name,
26
+ const std::shared_ptr<CallInvoker> jsInvoker) {
27
+ // Not implemented yet: provide pure-C++ NativeModules here.
28
+ return nullptr;
29
+ }
30
+
31
+ std::shared_ptr<TurboModule>
32
+ MainApplicationTurboModuleManagerDelegate::getTurboModule(
33
+ const std::string name,
34
+ const JavaTurboModule::InitParams &params) {
35
+ return MainApplicationModuleProvider(name, params);
36
+ }
37
+
38
+ bool MainApplicationTurboModuleManagerDelegate::canCreateTurboModule(
39
+ std::string name) {
40
+ return getTurboModule(name, nullptr) != nullptr ||
41
+ getTurboModule(name, {.moduleName = name}) != nullptr;
42
+ }
43
+
44
+ } // namespace react
45
+ } // namespace facebook
@@ -0,0 +1,38 @@
1
+ #include <memory>
2
+ #include <string>
3
+
4
+ #include <ReactCommon/TurboModuleManagerDelegate.h>
5
+ #include <fbjni/fbjni.h>
6
+
7
+ namespace facebook {
8
+ namespace react {
9
+
10
+ class MainApplicationTurboModuleManagerDelegate
11
+ : public jni::HybridClass<
12
+ MainApplicationTurboModuleManagerDelegate,
13
+ TurboModuleManagerDelegate> {
14
+ public:
15
+ // Adapt it to the package you used for your Java class.
16
+ static constexpr auto kJavaDescriptor =
17
+ "Lcom/helloworld/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate;";
18
+
19
+ static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject>);
20
+
21
+ static void registerNatives();
22
+
23
+ std::shared_ptr<TurboModule> getTurboModule(
24
+ const std::string name,
25
+ const std::shared_ptr<CallInvoker> jsInvoker) override;
26
+ std::shared_ptr<TurboModule> getTurboModule(
27
+ const std::string name,
28
+ const JavaTurboModule::InitParams &params) override;
29
+
30
+ /**
31
+ * Test-only method. Allows user to verify whether a TurboModule can be
32
+ * created by instances of this class.
33
+ */
34
+ bool canCreateTurboModule(std::string name);
35
+ };
36
+
37
+ } // namespace react
38
+ } // namespace facebook