diff --git a/.gitignore b/.gitignore index dd38c18b10..40344938d4 100644 --- a/.gitignore +++ b/.gitignore @@ -326,13 +326,6 @@ gradle-app.setting # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 # gradle/wrapper/gradle-wrapper.properties -### ReactNative.Buck Stack ### -buck-out/ -.buckconfig.local -.buckd/ -.buckversion -.fakebuckversion - ### ReactNative.Linux Stack ### # temporary files which can be created if a process still has a handle open of a deleted file @@ -564,3 +557,6 @@ spelling.json # Gatsby / Website website/.cache website/public + +# Temporary files created by Metro to check the health of the file watcher +.metro-health-check* \ No newline at end of file diff --git a/jest.setup.ts b/jest.setup.ts index 5a50e60d51..6f2688d906 100644 --- a/jest.setup.ts +++ b/jest.setup.ts @@ -44,6 +44,7 @@ jest.doMock('react-native', () => { }, addAuthStateListener: jest.fn(), addIdTokenListener: jest.fn(), + setTenantId: jest.fn(), useEmulator: jest.fn(), }, RNFBCrashlyticsModule: {}, diff --git a/metro.config.js b/metro.config.js index 4c276fd6a6..3e425c8f61 100644 --- a/metro.config.js +++ b/metro.config.js @@ -1 +1,10 @@ -module.exports = require('./tests/metro.config'); +const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config'); +/** + * Metro configuration + * https://facebook.github.io/metro/docs/configuration + * + * @type {import('metro-config').MetroConfig} + */ +const config = require('./tests/metro.config'); + +module.exports = mergeConfig(getDefaultConfig(__dirname), config); diff --git a/package.json b/package.json index bed5e4fef8..088788cfdc 100644 --- a/package.json +++ b/package.json @@ -52,12 +52,15 @@ }, "devDependencies": { "@babel/core": "^7.22.5", - "@babel/preset-env": "^7.22.5", + "@babel/plugin-proposal-class-properties": "^7.18.6", + "@babel/plugin-proposal-private-methods": "^7.18.6", "@babel/plugin-proposal-private-property-in-object": "^7.21.11", + "@babel/plugin-transform-class-properties": "^7.22.5", + "@babel/preset-env": "^7.22.5", "@octokit/core": "^4.2.4", "@tsconfig/node12": "^1.0.11", "@types/react": "^18.2.14", - "@types/react-native": "^0.70.7", + "@types/react-native": "^0.72.2", "@typescript-eslint/eslint-plugin": "^5.60.1", "@typescript-eslint/parser": "^5.60.1", "babel-jest": "^29.5.0", @@ -122,6 +125,8 @@ "**/react/**", "**/react-native", "**/react-native/**", + "**/metro-react-native-babel-preset", + "**/metro-react-native-babel-preset/**", "**/metro-runtime", "**/metro-runtime/**", "**/stacktrace-js", diff --git a/tests/android/app/build.gradle b/tests/android/app/build.gradle index 54f7de0106..9605bfe2f8 100644 --- a/tests/android/app/build.gradle +++ b/tests/android/app/build.gradle @@ -1,55 +1,76 @@ apply plugin: 'com.android.application' +apply plugin: "com.facebook.react" apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.firebase.crashlytics' apply plugin: 'com.google.firebase.firebase-perf' apply plugin: 'com.google.firebase.appdistribution' -import com.android.build.OutputFile -import org.apache.tools.ant.taskdefs.condition.Os import groovy.json.JsonSlurper -project.ext.react = [ - enableHermes: true, // clean and rebuild if changing -] +react { + /* Folders */ + // The root of your project, i.e. where "package.json" lives. Default is '..' + // root = file("../") + // The folder where the react-native NPM package is. Default is ../node_modules/react-native + // reactNativeDir = file("../node_modules/react-native") + // The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen + // codegenDir = file("../node_modules/@react-native/codegen") + // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js + // cliFile = file("../node_modules/react-native/cli.js") + /* Variants */ + // The list of variants to that are debuggable. For those we're going to + // skip the bundling of the JS bundle and the assets. By default is just 'debug'. + // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants. + // debuggableVariants = ["liteDebug", "prodDebug"] + /* Bundling */ + // A list containing the node command and its flags. Default is just 'node'. + // nodeExecutableAndArgs = ["node"] + // + // The command to run when bundling. By default is 'bundle' + // bundleCommand = "ram-bundle" + // + // The path to the CLI configuration file. Default is empty. + // bundleConfig = file(../rn-cli.config.js) + // + // The name of the generated asset file containing your JS bundle + // bundleAssetName = "MyApplication.android.bundle" + // + // The entry file for bundle generation. Default is 'index.android.js' or 'index.js' + // entryFile = file("../js/MyApplication.android.js") + // + // A list of extra flags to pass to the 'bundle' commands. + // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle + // extraPackagerArgs = [] + /* Hermes Commands */ + // The hermes compiler command to run. By default it is 'hermesc' + // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc" + // + // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map" + // hermesFlags = ["-O", "-output-source-map"] +} -// up to mono root -apply from: '../../node_modules/react-native/react.gradle' +/** + * Set this to true to Run Proguard on Release builds to minify the Java bytecode. + */ +def enableProguardInReleaseBuilds = true /** - * The preferred build flavor of JavaScriptCore. + * The preferred build flavor of JavaScriptCore (JSC) * * For example, to use the international variant, you can use: * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` * * The international variant includes ICU i18n library and necessary data * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that - * give correct results when using with locales other than en-US. Note that + * give correct results when using with locales other than en-US. Note that * this variant is about 6MiB larger per architecture than default. */ def jscFlavor = 'org.webkit:android-jsc:+' -def enableSeparateBuildPerCPUArchitecture = false - -/** - * Use international variant JavaScriptCore - * International variant includes ICU i18n library and necessary data allowing to use - * e.g. Date.toLocaleString and String.localeCompare that give correct results - * when using with locales other than en-US. - * Note that this variant is about 6MiB larger per architecture than default. - */ -def useIntlJsc = false - -/** - * Architectures to build native code for. - */ -def reactNativeArchitectures() { - def value = project.getProperties().get("reactNativeArchitectures") - return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] -} - android { ndkVersion rootProject.ext.ndkVersion compileSdkVersion rootProject.ext.compileSdkVersion + namespace "com.invertase.testing" aaptOptions { // https://firebase.google.com/docs/ml/android/use-custom-models#local_model noCompress 'tflite' @@ -60,24 +81,6 @@ android { targetSdkVersion rootProject.ext.targetSdkVersion versionCode 200 versionName '1.0' - buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() - if (isNewArchitectureEnabled()) { - // We configure the CMake build only if you decide to opt-in for the New Architecture. - externalNativeBuild { - cmake { - arguments "-DPROJECT_BUILD_DIR=$buildDir", - "-DREACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid", - "-DREACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build", - "-DNODE_MODULES_DIR=$rootDir/../node_modules", - "-DANDROID_STL=c++_shared" - } - } - if (!enableSeparateBuildPerCPUArchitecture) { - ndk { - abiFilters (*reactNativeArchitectures()) - } - } - } // detox items testBuildType System.getProperty('testBuildType', 'debug') @@ -85,55 +88,6 @@ android { missingDimensionStrategy 'detox', 'full' } - if (isNewArchitectureEnabled()) { - // We configure the NDK build only if you decide to opt-in for the New Architecture. - externalNativeBuild { - cmake { - path "$projectDir/src/main/jni/CMakeLists.txt" - } - } - def reactAndroidProjectDir = project(':ReactAndroid').projectDir - def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) { - dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck") - from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib") - into("$buildDir/react-ndk/exported") - } - def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) { - dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck") - from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib") - into("$buildDir/react-ndk/exported") - } - afterEvaluate { - // If you wish to add a custom TurboModule or component locally, - // you should uncomment this line. - // preBuild.dependsOn("generateCodegenArtifactsFromSchema") - preDebugBuild.dependsOn(packageReactNdkDebugLibs) - preReleaseBuild.dependsOn(packageReactNdkReleaseLibs) - // Due to a bug inside AGP, we have to explicitly set a dependency - // between configureCMakeDebug* tasks and the preBuild tasks. - // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732 - configureCMakeRelWithDebInfo.dependsOn(preReleaseBuild) - configureCMakeDebug.dependsOn(preDebugBuild) - reactNativeArchitectures().each { architecture -> - tasks.findByName("configureCMakeDebug[${architecture}]")?.configure { - dependsOn("preDebugBuild") - } - tasks.findByName("configureCMakeRelWithDebInfo[${architecture}]")?.configure { - dependsOn("preReleaseBuild") - } - } - } - } - - splits { - abi { - reset() - enable enableSeparateBuildPerCPUArchitecture - universalApk false // If true, also generate a universal APK - include (*reactNativeArchitectures()) - } - } - signingConfigs { release { storeFile file('keystore.jks') @@ -150,7 +104,7 @@ android { signingConfig signingConfigs.release // sign with shared SHA256; configured in firebase dynamic-links } release { - minifyEnabled true + minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro" signingConfig signingConfigs.release @@ -166,28 +120,13 @@ android { includeAndroidResources = true } } - - // applicationVariants are e.g. debug, release - applicationVariants.all { variant -> - variant.outputs.each { output -> - // For each separate APK per architecture, set a unique version code as described here: - // https://developer.android.com/studio/build/configure-apk-splits.html - def versionCodes = ['armeabi-v7a': 1, 'x86': 2, 'arm64-v8a': 3, 'x86_64': 4] - def abi = output.getFilter(OutputFile.ABI) - if (abi != null) { // null for the universal-debug, universal-release variants - output.versionCodeOverride = - versionCodes.get(abi) * 1048576 + defaultConfig.versionCode - } - } - } } apply from: './jacoco.gradle' dependencies { - implementation fileTree(include: ['*.jar'], dir: 'libs') - //noinspection GradleDynamicVersion - implementation 'com.facebook.react:react-native:+' + // The version of react-native is set by the React Native Gradle Plugin + implementation("com.facebook.react:react-android") implementation("androidx.annotation:annotation:${rootProject.ext.androidxAnnotationVersion}") implementation("androidx.appcompat:appcompat:${rootProject.ext.appCompatVersion}") @@ -199,31 +138,18 @@ dependencies { implementation("androidx.vectordrawable:vectordrawable-animated:${rootProject.ext.vectordrawableVersion}") implementation("androidx.vectordrawable:vectordrawable:${rootProject.ext.vectordrawableVersion}") - if (project.ext.react.enableHermes) { - //noinspection GradleDynamicVersion - implementation("com.facebook.react:hermes-engine:+") { // From node_modules - exclude group:'com.facebook.fbjni' - } + debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") + debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { + exclude group:'com.squareup.okhttp3', module:'okhttp' + } + + debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") + if (hermesEnabled.toBoolean()) { + implementation("com.facebook.react:hermes-android") } else { implementation jscFlavor } - - if (isNewArchitectureEnabled()) { - // If new architecture is enabled, we let you build RN from source - // Otherwise we fallback to a prebuilt .aar bundled in the NPM package. - // This will be applied to all the imported transtitive dependency. - configurations.all { - resolutionStrategy.dependencySubstitution { - substitute(module("com.facebook.react:react-native")) - .using(project(":ReactAndroid")) - .because("On New Architecture we're building React Native from source") - substitute(module("com.facebook.react:hermes-engine")) - .using(project(":ReactAndroid:hermes-engine")) - .because("On New Architecture we're building Hermes from source") - } - } -} - + /* ------------------------ * TESTING SDKS/LIBRARIES * ------------------------ */ @@ -235,11 +161,3 @@ dependencies { } apply from: file('../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle'); applyNativeModulesAppBuildGradle(project) - -def isNewArchitectureEnabled() { - // To opt-in for the New Architecture, you can either: - // - Set `newArchEnabled` to true inside the `gradle.properties` file - // - Invoke gradle with `-newArchEnabled=true` - // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true` - return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" -} \ No newline at end of file diff --git a/tests/android/app/jacoco.gradle b/tests/android/app/jacoco.gradle index 081f8ec2d5..d6350252e4 100644 --- a/tests/android/app/jacoco.gradle +++ b/tests/android/app/jacoco.gradle @@ -67,7 +67,7 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'conn } reports { - xml.enabled = true + xml.required = true html.destination htmlOutDir } @@ -97,7 +97,7 @@ task jacocoUnitTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest']) } reports { - xml.enabled = true + xml.required = true html.destination htmlOutDir } @@ -122,7 +122,7 @@ task jacocoAndroidTestReport(type: JacocoReport) { } reports { - xml.enabled = true + xml.required = true html.destination htmlOutDir } diff --git a/tests/android/app/src/main/AndroidManifest.xml b/tests/android/app/src/main/AndroidManifest.xml index c96bcd2ed8..f289ea18fc 100644 --- a/tests/android/app/src/main/AndroidManifest.xml +++ b/tests/android/app/src/main/AndroidManifest.xml @@ -1,7 +1,5 @@ + xmlns:tools="http://schemas.android.com/tools"> diff --git a/tests/android/app/src/main/java/com/invertase/testing/MainActivity.java b/tests/android/app/src/main/java/com/invertase/testing/MainActivity.java index bbd2cd63b0..74d4c908ee 100644 --- a/tests/android/app/src/main/java/com/invertase/testing/MainActivity.java +++ b/tests/android/app/src/main/java/com/invertase/testing/MainActivity.java @@ -2,7 +2,8 @@ import com.facebook.react.ReactActivity; import com.facebook.react.ReactActivityDelegate; -import com.facebook.react.ReactRootView; +import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; +import com.facebook.react.defaults.DefaultReactActivityDelegate; public class MainActivity extends ReactActivity { @@ -16,30 +17,16 @@ protected String getMainComponentName() { } /** - * Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and - * you can specify the renderer you wish to use - the new renderer (Fabric) or the old renderer - * (Paper). + * Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link + * DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React + * (aka React 18) with two boolean flags. */ @Override protected ReactActivityDelegate createReactActivityDelegate() { - return new MainActivityDelegate(this, getMainComponentName()); - } - public static class MainActivityDelegate extends ReactActivityDelegate { - public MainActivityDelegate(ReactActivity activity, String mainComponentName) { - super(activity, mainComponentName); - } - @Override - protected ReactRootView createRootView() { - ReactRootView reactRootView = new ReactRootView(getContext()); - // If you opted-in for the New Architecture, we enable the Fabric Renderer. - reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED); - return reactRootView; - } - @Override - protected boolean isConcurrentRootEnabled() { - // If you opted-in for the New Architecture, we enable Concurrent Root (i.e. React 18). - // More on this on https://reactjs.org/blog/2022/03/29/react-v18.html - return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; - } + return new DefaultReactActivityDelegate( + this, + getMainComponentName(), + // If you opted-in for the New Architecture, we enable the Fabric Renderer. + DefaultNewArchitectureEntryPoint.getFabricEnabled()); } } diff --git a/tests/android/app/src/main/java/com/invertase/testing/MainApplication.java b/tests/android/app/src/main/java/com/invertase/testing/MainApplication.java index 1da2538008..c9efadeeab 100644 --- a/tests/android/app/src/main/java/com/invertase/testing/MainApplication.java +++ b/tests/android/app/src/main/java/com/invertase/testing/MainApplication.java @@ -1,14 +1,14 @@ package com.invertase.testing; import android.app.Application; +import android.os.Build; import com.facebook.react.PackageList; import com.facebook.react.ReactApplication; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; -import com.facebook.react.config.ReactFeatureFlags; -import com.facebook.react.devsupport.DevInternalSettings; +import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; +import com.facebook.react.defaults.DefaultReactNativeHost; import com.facebook.soloader.SoLoader; -import com.invertase.testing.newarchitecture.MainApplicationReactNativeHost; import io.invertase.firebase.app.ReactNativeFirebaseApp; import io.invertase.jet.JetPackage; @@ -16,54 +16,57 @@ public class MainApplication extends Application implements ReactApplication { - private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { - @Override - public boolean getUseDeveloperSupport() { - return BuildConfig.DEBUG; - } + + private final ReactNativeHost mReactNativeHost = + new DefaultReactNativeHost(this) { + @Override + public boolean getUseDeveloperSupport() { + return BuildConfig.DEBUG; + } - @Override - protected List getPackages() { - List packages = new PackageList(this).getPackages(); - return packages; - } + @Override + protected List getPackages() { + @SuppressWarnings("UnnecessaryLocalVariable") + List packages = new PackageList(this).getPackages(); + // Packages that cannot be autolinked yet can be added manually here, for example: + // packages.add(new MyReactNativePackage()); + return packages; + } - @Override - protected String getJSMainModuleName() { - return "index"; - } - }; + @Override + protected String getJSMainModuleName() { + return "index"; + } + + @Override + protected boolean isNewArchEnabled() { + return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; + } - private final ReactNativeHost mNewArchitectureNativeHost = - new MainApplicationReactNativeHost(this); + @Override + protected Boolean isHermesEnabled() { + return BuildConfig.IS_HERMES_ENABLED; + } + }; @Override public ReactNativeHost getReactNativeHost() { - if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { - return mNewArchitectureNativeHost; - } else { - return mReactNativeHost; - } + return mReactNativeHost; } + @Override public void onCreate() { super.onCreate(); - - // If you opted-in for the New Architecture, we enable the TurboModule system - ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; - - ReactNativeFirebaseApp.initializeSecondaryApp("secondaryFromNative", getApplicationContext()); SoLoader.init(this, /* native exopackage */ false); - -// // TODO move to jet -// DevInternalSettings settings = (DevInternalSettings) getReactNativeHost() -// .getReactInstanceManager() -// .getDevSupportManager() -// .getDevSettings(); -// -// if (settings != null) { -// settings.setBundleDeltasEnabled(false); -// } + if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { + // If you opted-in for the New Architecture, we load the native entry point for this app. + DefaultNewArchitectureEntryPoint.load(); + } + // Flipper only works on API >= 23 + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) { + ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); + } + ReactNativeFirebaseApp.initializeSecondaryApp("secondaryFromNative", getApplicationContext()); } } diff --git a/tests/android/app/src/main/java/com/invertase/testing/ReactNativeFlipper.java b/tests/android/app/src/main/java/com/invertase/testing/ReactNativeFlipper.java new file mode 100644 index 0000000000..04407b53eb --- /dev/null +++ b/tests/android/app/src/main/java/com/invertase/testing/ReactNativeFlipper.java @@ -0,0 +1,75 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + *

This source code is licensed under the MIT license found in the LICENSE file in the root + * directory of this source tree. + */ +package com.invertase.testing; + +import android.content.Context; +import com.facebook.flipper.android.AndroidFlipperClient; +import com.facebook.flipper.android.utils.FlipperUtils; +import com.facebook.flipper.core.FlipperClient; +import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin; +import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin; +import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin; +import com.facebook.flipper.plugins.inspector.DescriptorMapping; +import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin; +import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor; +import com.facebook.flipper.plugins.network.NetworkFlipperPlugin; +import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin; +import com.facebook.react.ReactInstanceEventListener; +import com.facebook.react.ReactInstanceManager; +import com.facebook.react.bridge.ReactContext; +import com.facebook.react.modules.network.NetworkingModule; +import okhttp3.OkHttpClient; + +/** + * Class responsible of loading Flipper inside your React Native application. This is the debug + * flavor of it. Here you can add your own plugins and customize the Flipper setup. + */ +public class ReactNativeFlipper { + public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { + if (FlipperUtils.shouldEnableFlipper(context)) { + final FlipperClient client = AndroidFlipperClient.getInstance(context); + + client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults())); + client.addPlugin(new DatabasesFlipperPlugin(context)); + client.addPlugin(new SharedPreferencesFlipperPlugin(context)); + client.addPlugin(CrashReporterPlugin.getInstance()); + + NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin(); + NetworkingModule.setCustomClientBuilder( + new NetworkingModule.CustomClientBuilder() { + @Override + public void apply(OkHttpClient.Builder builder) { + builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin)); + } + }); + client.addPlugin(networkFlipperPlugin); + client.start(); + + // Fresco Plugin needs to ensure that ImagePipelineFactory is initialized + // Hence we run if after all native modules have been initialized + ReactContext reactContext = reactInstanceManager.getCurrentReactContext(); + if (reactContext == null) { + reactInstanceManager.addReactInstanceEventListener( + new ReactInstanceEventListener() { + @Override + public void onReactContextInitialized(ReactContext reactContext) { + reactInstanceManager.removeReactInstanceEventListener(this); + reactContext.runOnNativeModulesQueueThread( + new Runnable() { + @Override + public void run() { + client.addPlugin(new FrescoFlipperPlugin()); + } + }); + } + }); + } else { + client.addPlugin(new FrescoFlipperPlugin()); + } + } + } +} \ No newline at end of file diff --git a/tests/android/app/src/main/java/com/invertase/testing/newarchitecture/MainApplicationReactNativeHost.java b/tests/android/app/src/main/java/com/invertase/testing/newarchitecture/MainApplicationReactNativeHost.java deleted file mode 100644 index efba2395eb..0000000000 --- a/tests/android/app/src/main/java/com/invertase/testing/newarchitecture/MainApplicationReactNativeHost.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.invertase.testing.newarchitecture; -import android.app.Application; -import androidx.annotation.NonNull; -import com.facebook.react.PackageList; -import com.facebook.react.ReactInstanceManager; -import com.facebook.react.ReactNativeHost; -import com.facebook.react.ReactPackage; -import com.facebook.react.ReactPackageTurboModuleManagerDelegate; -import com.facebook.react.bridge.JSIModulePackage; -import com.facebook.react.bridge.JSIModuleProvider; -import com.facebook.react.bridge.JSIModuleSpec; -import com.facebook.react.bridge.JSIModuleType; -import com.facebook.react.bridge.JavaScriptContextHolder; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.bridge.UIManager; -import com.facebook.react.fabric.ComponentFactory; -import com.facebook.react.fabric.CoreComponentsRegistry; -import com.facebook.react.fabric.FabricJSIModuleProvider; -import com.facebook.react.fabric.ReactNativeConfig; -import com.facebook.react.uimanager.ViewManagerRegistry; -import com.invertase.testing.BuildConfig; -import com.invertase.testing.newarchitecture.components.MainComponentsRegistry; -import com.invertase.testing.newarchitecture.modules.MainApplicationTurboModuleManagerDelegate; -import java.util.ArrayList; -import java.util.List; -/** - * A {@link ReactNativeHost} that helps you load everything needed for the New Architecture, both - * TurboModule delegates and the Fabric Renderer. - * - *

Please note that this class is used ONLY if you opt-in for the New Architecture (see the - * `newArchEnabled` property). Is ignored otherwise. - */ -public class MainApplicationReactNativeHost extends ReactNativeHost { - public MainApplicationReactNativeHost(Application application) { - super(application); - } - @Override - public boolean getUseDeveloperSupport() { - return BuildConfig.DEBUG; - } - @Override - protected List getPackages() { - List packages = new PackageList(this).getPackages(); - // Packages that cannot be autolinked yet can be added manually here, for example: - // packages.add(new MyReactNativePackage()); - // TurboModules must also be loaded here providing a valid TurboReactPackage implementation: - // packages.add(new TurboReactPackage() { ... }); - // If you have custom Fabric Components, their ViewManagers should also be loaded here - // inside a ReactPackage. - return packages; - } - @Override - protected String getJSMainModuleName() { - return "index"; - } - @NonNull - @Override - protected ReactPackageTurboModuleManagerDelegate.Builder - getReactPackageTurboModuleManagerDelegateBuilder() { - // Here we provide the ReactPackageTurboModuleManagerDelegate Builder. This is necessary - // for the new architecture and to use TurboModules correctly. - return new MainApplicationTurboModuleManagerDelegate.Builder(); - } - @Override - protected JSIModulePackage getJSIModulePackage() { - return new JSIModulePackage() { - @Override - public List getJSIModules( - final ReactApplicationContext reactApplicationContext, - final JavaScriptContextHolder jsContext) { - final List specs = new ArrayList<>(); - // Here we provide a new JSIModuleSpec that will be responsible of providing the - // custom Fabric Components. - specs.add( - new JSIModuleSpec() { - @Override - public JSIModuleType getJSIModuleType() { - return JSIModuleType.UIManager; - } - @Override - public JSIModuleProvider getJSIModuleProvider() { - final ComponentFactory componentFactory = new ComponentFactory(); - CoreComponentsRegistry.register(componentFactory); - // Here we register a Components Registry. - // The one that is generated with the template contains no components - // and just provides you the one from React Native core. - MainComponentsRegistry.register(componentFactory); - final ReactInstanceManager reactInstanceManager = getReactInstanceManager(); - ViewManagerRegistry viewManagerRegistry = - new ViewManagerRegistry( - reactInstanceManager.getOrCreateViewManagers(reactApplicationContext)); - return new FabricJSIModuleProvider( - reactApplicationContext, - componentFactory, - ReactNativeConfig.DEFAULT_CONFIG, - viewManagerRegistry); - } - }); - return specs; - } - }; - } -} \ No newline at end of file diff --git a/tests/android/app/src/main/java/com/invertase/testing/newarchitecture/components/MainComponentsRegistry.java b/tests/android/app/src/main/java/com/invertase/testing/newarchitecture/components/MainComponentsRegistry.java deleted file mode 100644 index 3b149235a3..0000000000 --- a/tests/android/app/src/main/java/com/invertase/testing/newarchitecture/components/MainComponentsRegistry.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.invertase.testing.newarchitecture.components; -import com.facebook.jni.HybridData; -import com.facebook.proguard.annotations.DoNotStrip; -import com.facebook.react.fabric.ComponentFactory; -import com.facebook.soloader.SoLoader; -/** - * Class responsible to load the custom Fabric Components. This class has native methods and needs a - * corresponding C++ implementation/header file to work correctly (already placed inside the jni/ - * folder for you). - * - *

Please note that this class is used ONLY if you opt-in for the New Architecture (see the - * `newArchEnabled` property). Is ignored otherwise. - */ -@DoNotStrip -public class MainComponentsRegistry { - static { - SoLoader.loadLibrary("fabricjni"); - } - @DoNotStrip private final HybridData mHybridData; - @DoNotStrip - private native HybridData initHybrid(ComponentFactory componentFactory); - @DoNotStrip - private MainComponentsRegistry(ComponentFactory componentFactory) { - mHybridData = initHybrid(componentFactory); - } - @DoNotStrip - public static MainComponentsRegistry register(ComponentFactory componentFactory) { - return new MainComponentsRegistry(componentFactory); - } -} \ No newline at end of file diff --git a/tests/android/app/src/main/java/com/invertase/testing/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java b/tests/android/app/src/main/java/com/invertase/testing/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java deleted file mode 100644 index e7dc208949..0000000000 --- a/tests/android/app/src/main/java/com/invertase/testing/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.invertase.testing.newarchitecture.modules; -import com.facebook.jni.HybridData; -import com.facebook.react.ReactPackage; -import com.facebook.react.ReactPackageTurboModuleManagerDelegate; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.soloader.SoLoader; -import java.util.List; -/** - * Class responsible to load the TurboModules. This class has native methods and needs a - * corresponding C++ implementation/header file to work correctly (already placed inside the jni/ - * folder for you). - * - *

Please note that this class is used ONLY if you opt-in for the New Architecture (see the - * `newArchEnabled` property). Is ignored otherwise. - */ -public class MainApplicationTurboModuleManagerDelegate - extends ReactPackageTurboModuleManagerDelegate { - private static volatile boolean sIsSoLibraryLoaded; - protected MainApplicationTurboModuleManagerDelegate( - ReactApplicationContext reactApplicationContext, List packages) { - super(reactApplicationContext, packages); - } - protected native HybridData initHybrid(); - native boolean canCreateTurboModule(String moduleName); - public static class Builder extends ReactPackageTurboModuleManagerDelegate.Builder { - protected MainApplicationTurboModuleManagerDelegate build( - ReactApplicationContext context, List packages) { - return new MainApplicationTurboModuleManagerDelegate(context, packages); - } - } - @Override - protected synchronized void maybeLoadOtherSoLibraries() { - if (!sIsSoLibraryLoaded) { - // If you change the name of your application .so file in the Android.mk file, - // make sure you update the name here as well. - SoLoader.loadLibrary("invertase_testing_appmodules"); - sIsSoLibraryLoaded = true; - } - } -} \ No newline at end of file diff --git a/tests/android/app/src/main/jni/CMakeLists.txt b/tests/android/app/src/main/jni/CMakeLists.txt deleted file mode 100644 index a685116018..0000000000 --- a/tests/android/app/src/main/jni/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -cmake_minimum_required(VERSION 3.13) -# Define the library name here. -project(invertase_testing_appmodules) -# This file includes all the necessary to let you build your application with the New Architecture. -include(${REACT_ANDROID_DIR}/cmake-utils/ReactNative-application.cmake) \ No newline at end of file diff --git a/tests/android/app/src/main/jni/MainApplicationModuleProvider.cpp b/tests/android/app/src/main/jni/MainApplicationModuleProvider.cpp deleted file mode 100644 index 47e5bd5e7a..0000000000 --- a/tests/android/app/src/main/jni/MainApplicationModuleProvider.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "MainApplicationModuleProvider.h" -#include -#include -namespace facebook { -namespace react { -std::shared_ptr MainApplicationModuleProvider( - const std::string &moduleName, - const JavaTurboModule::InitParams ¶ms) { - // Here you can provide your own module provider for TurboModules coming from - // either your application or from external libraries. The approach to follow - // is similar to the following (for a library called `samplelibrary`: - // - // auto module = samplelibrary_ModuleProvider(moduleName, params); - // if (module != nullptr) { - // return module; - // } - // return rncore_ModuleProvider(moduleName, params); - // Module providers autolinked by RN CLI - auto rncli_module = rncli_ModuleProvider(moduleName, params); - if (rncli_module != nullptr) { - return rncli_module; - } - return rncore_ModuleProvider(moduleName, params); -} -} // namespace react -} // namespace facebook \ No newline at end of file diff --git a/tests/android/app/src/main/jni/MainApplicationModuleProvider.h b/tests/android/app/src/main/jni/MainApplicationModuleProvider.h deleted file mode 100644 index 4515c40bb8..0000000000 --- a/tests/android/app/src/main/jni/MainApplicationModuleProvider.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once -#include -#include -#include -namespace facebook { -namespace react { -std::shared_ptr MainApplicationModuleProvider( - const std::string &moduleName, - const JavaTurboModule::InitParams ¶ms); -} // namespace react -} // namespace facebook \ No newline at end of file diff --git a/tests/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp b/tests/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp deleted file mode 100644 index 9cf4aa42fa..0000000000 --- a/tests/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "MainApplicationTurboModuleManagerDelegate.h" -#include "MainApplicationModuleProvider.h" -namespace facebook { -namespace react { -jni::local_ref -MainApplicationTurboModuleManagerDelegate::initHybrid( - jni::alias_ref) { - return makeCxxInstance(); -} -void MainApplicationTurboModuleManagerDelegate::registerNatives() { - registerHybrid({ - makeNativeMethod( - "initHybrid", MainApplicationTurboModuleManagerDelegate::initHybrid), - makeNativeMethod( - "canCreateTurboModule", - MainApplicationTurboModuleManagerDelegate::canCreateTurboModule), - }); -} -std::shared_ptr -MainApplicationTurboModuleManagerDelegate::getTurboModule( - const std::string &name, - const std::shared_ptr &jsInvoker) { - // Not implemented yet: provide pure-C++ NativeModules here. - return nullptr; -} -std::shared_ptr -MainApplicationTurboModuleManagerDelegate::getTurboModule( - const std::string &name, - const JavaTurboModule::InitParams ¶ms) { - return MainApplicationModuleProvider(name, params); -} -bool MainApplicationTurboModuleManagerDelegate::canCreateTurboModule( - const std::string &name) { - return getTurboModule(name, nullptr) != nullptr || - getTurboModule(name, {.moduleName = name}) != nullptr; -} -} // namespace react -} // namespace facebook \ No newline at end of file diff --git a/tests/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h b/tests/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h deleted file mode 100644 index 3b0de4dcce..0000000000 --- a/tests/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h +++ /dev/null @@ -1,51 +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(); - // Autolinked providers registered by RN CLI - rncli_registerProviders(providerRegistry); - // Custom Fabric Components go here. You can register custom - // components coming from your App or from 3rd party libraries here. - // - // providerRegistry->add(concreteComponentDescriptorProvider< - // AocViewerComponentDescriptor>()); - 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 \ No newline at end of file diff --git a/tests/android/app/src/main/jni/MainComponentsRegistry.h b/tests/android/app/src/main/jni/MainComponentsRegistry.h deleted file mode 100644 index 6f2082d2a2..0000000000 --- a/tests/android/app/src/main/jni/MainComponentsRegistry.h +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "MainApplicationTurboModuleManagerDelegate.h" -#include "MainComponentsRegistry.h" -JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { - return facebook::jni::initialize(vm, [] { - facebook::react::MainApplicationTurboModuleManagerDelegate:: - registerNatives(); - facebook::react::MainComponentsRegistry::registerNatives(); - }); -} \ No newline at end of file diff --git a/tests/android/app/src/main/res/drawable/rn_edit_text_material.xml b/tests/android/app/src/main/res/drawable/rn_edit_text_material.xml index bb6f578c3f..ab58c0f44b 100644 --- a/tests/android/app/src/main/res/drawable/rn_edit_text_material.xml +++ b/tests/android/app/src/main/res/drawable/rn_edit_text_material.xml @@ -16,7 +16,7 @@ android:insetTop="@dimen/abc_edit_text_inset_top_material" android:insetBottom="@dimen/abc_edit_text_inset_bottom_material"> -