diff --git a/.bundle/config b/.bundle/config new file mode 100644 index 00000000000..848943bb527 --- /dev/null +++ b/.bundle/config @@ -0,0 +1,2 @@ +BUNDLE_PATH: "vendor/bundle" +BUNDLE_FORCE_RUBY_PLATFORM: 1 diff --git a/.flowconfig b/.flowconfig deleted file mode 100644 index 4320b7070ea..00000000000 --- a/.flowconfig +++ /dev/null @@ -1,65 +0,0 @@ -[ignore] -; We fork some components by platform -.*/*[.]android.js - -; Ignore "BUCK" generated dirs -/\.buckd/ - -; Ignore polyfills -node_modules/react-native/Libraries/polyfills/.* - -; Flow doesn't support platforms -.*/Libraries/Utilities/LoadingView.js - -[untyped] -.*/node_modules/@react-native-community/cli/.*/.* - -[include] - -[libs] -node_modules/react-native/interface.js -node_modules/react-native/flow/ - -[options] -emoji=true - -exact_by_default=true - -format.bracket_spacing=false - -module.file_ext=.js -module.file_ext=.json -module.file_ext=.ios.js - -munge_underscores=true - -module.name_mapper='^react-native/\(.*\)$' -> '/node_modules/react-native/\1' -module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '/node_modules/react-native/Libraries/Image/RelativeImageStub' - -suppress_type=$FlowIssue -suppress_type=$FlowFixMe -suppress_type=$FlowFixMeProps -suppress_type=$FlowFixMeState - -[lints] -sketchy-null-number=warn -sketchy-null-mixed=warn -sketchy-number=warn -untyped-type-import=warn -nonstrict-import=warn -deprecated-type=warn -unsafe-getters-setters=warn -unnecessary-invariant=warn -signature-verification-failure=warn - -[strict] -deprecated-type -nonstrict-import -sketchy-null -unclear-type -unsafe-getters-setters -untyped-import -untyped-type-import - -[version] -^0.158.0 diff --git a/README.md b/README.md index e1fc0ad0f5a..d91f3539f65 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ The code is built using React-Native and running code locally requires a Mac or - Install [cocoapods](https://guides.cocoapods.org/using/getting-started.html) by running: ```bash -sudo gem install cocoapods -v 1.12.0 +sudo gem install cocoapods -v 1.12.1 ``` @@ -50,7 +50,7 @@ sudo gem install cocoapods -v 1.12.0 - Select `SDK Tools` tab - Check `Show Package Details` option below the tools list to show available versions - Locate `NDK (Side-by-side)` option in the tools list - - Check NDK version `21.4.7075529` + - Check NDK version `21.4.7075529` - Locate `CMake` option in the tools list - Check CMake version `3.10.2` - Click "Apply" or "OK" to download @@ -216,11 +216,11 @@ On Bitrise CI, the wallet is created using the secret recovery phrase from secre For local testing, the wallet is created using the secret recovery phrase from the `.e2e.env` file. ##### iOS -All tests live within the e2e/specs folder. +All tests live within the e2e/specs folder. Prerequisites for running tests: -- Make sure to install `detox-cli` by referring to the instructions mentioned [here](https://wix.github.io/Detox/docs/introduction/getting-started/#detox-prerequisites). -- Additionally, install `applesimutils` by following the guidelines provided [here](https://github.com/wix/AppleSimulatorUtils). +- Make sure to install `detox-cli` by referring to the instructions mentioned [here](https://wix.github.io/Detox/docs/introduction/getting-started/#detox-prerequisites). +- Additionally, install `applesimutils` by following the guidelines provided [here](https://github.com/wix/AppleSimulatorUtils). - Before running any tests, it's recommended to refer to the `iOS section` above and check the latest simulator device specified under `Install the correct simulator`. - Make sure that Metro is running. Use this command to launch the metro server: @@ -228,7 +228,7 @@ Prerequisites for running tests: yarn watch ``` -You can trigger the tests against a `release` or `debug` build. It recommended that you trigger the tests against a debug build. +You can trigger the tests against a `release` or `debug` build. It recommended that you trigger the tests against a debug build. To trigger the tests on a debug build run this command: @@ -247,25 +247,25 @@ If you have already built the application for Detox and want to run a specific t ```bash yarn test:e2e:ios:debug:single e2e/specs/TEST_NAME.spec.js ``` -To run tests associated with a certain tag, you can do so using the `--testNamePattern` flag. For example: +To run tests associated with a certain tag, you can do so using the `--testNamePattern` flag. For example: ```bash yarn test:e2e:ios:debug --testNamePattern="Smoke" ``` -This runs all tests that are tagged "Smoke" +This runs all tests that are tagged "Smoke" ##### Android -All android tests live within the wdio/feature folder. +All android tests live within the wdio/feature folder. By default the tests use an avd named `Android 11 - Pixel 4a API 31`, with API `Level 30` (Android 11). You can modify the emulator and platform version by navigating to `wdio/config/android.config.debug.js` and adjusting the values of `deviceName` to match your emulator's name, and `platformVersion` to match your operating system's version. Make sure to verify that the config file accurately represents your emulator settings before executing any tests. The sequence in which you should run tests: create a test build using this command: -```bash -yarn start:android:qa +```bash +yarn start:android:qa ``` -Then run tests using this command: +Then run tests using this command: ```bash yarn test:wdio:android @@ -273,7 +273,7 @@ yarn test:wdio:android If you want to run a specific test, you can include the `--spec` flag in the aforementioned command. For example: ```bash -yarn test:wdio:android --spec ./wdio/features/Onboarding/CreateNewWallet.feature +yarn test:wdio:android --spec ./wdio/features/Onboarding/CreateNewWallet.feature ``` ### Changing dependencies diff --git a/android/app/build.gradle b/android/app/build.gradle index fa09f2621a9..ab5b848c8d6 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -1,3 +1,61 @@ +apply plugin: "com.android.application" +apply plugin: "com.facebook.react" + +import com.android.build.OutputFile + +/** + * This is the configuration block to customize your React Native Android app. + * By default you don't need to apply any configuration, just uncomment the lines you need. + */ +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"] +} + + project.ext.sentryCli = [ + logLevel: "debug", + sentryProperties: System.getenv('SENTRY_PROPERTIES') ? System.getenv('SENTRY_PROPERTIES') : '../../sentry.properties' +] + +apply from: "../../node_modules/@sentry/react-native/sentry.gradle" + def getPassword(String currentUser, String keyChain) { def stdout = new ByteArrayOutputStream() def stderr = new ByteArrayOutputStream() @@ -24,299 +82,168 @@ def getPassword(String currentUser, String keyChain) { stdout.toString().trim() } -apply plugin: "com.android.application" - -import com.android.build.OutputFile - /** - * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets - * and bundleReleaseJsAndAssets). - * These basically call `react-native bundle` with the correct arguments during the Android build - * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the - * bundle directly from the development server. Below you can see all the possible configurations - * and their defaults. If you decide to add a configuration block, make sure to add it before the - * `apply from: "../../node_modules/react-native/react.gradle"` line. - * - * project.ext.react = [ - * // the name of the generated asset file containing your JS bundle - * bundleAssetName: "index.android.bundle", - * - * // the entry file for bundle generation. If none specified and - * // "index.android.js" exists, it will be used. Otherwise "index.js" is - * // default. Can be overridden with ENTRY_FILE environment variable. - * entryFile: "index.android.js", - * - * // https://reactnative.dev/docs/performance#enable-the-ram-format - * bundleCommand: "ram-bundle", - * - * // whether to bundle JS and assets in debug mode - * bundleInDebug: false, - * - * // whether to bundle JS and assets in release mode - * bundleInRelease: true, - * - * // whether to bundle JS and assets in another build variant (if configured). - * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants - * // The configuration property can be in the following formats - * // 'bundleIn${productFlavor}${buildType}' - * // 'bundleIn${buildType}' - * // bundleInFreeDebug: true, - * // bundleInPaidRelease: true, - * // bundleInBeta: true, - * - * // whether to disable dev mode in custom build variants (by default only disabled in release) - * // for example: to disable dev mode in the staging build type (if configured) - * devDisabledInStaging: true, - * // The configuration property can be in the following formats - * // 'devDisabledIn${productFlavor}${buildType}' - * // 'devDisabledIn${buildType}' - * - * // the root of your project, i.e. where "package.json" lives - * root: "../../", - * - * // where to put the JS bundle asset in debug mode - * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", - * - * // where to put the JS bundle asset in release mode - * jsBundleDirRelease: "$buildDir/intermediates/assets/release", - * - * // where to put drawable resources / React Native assets, e.g. the ones you use via - * // require('./image.png')), in debug mode - * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", - * - * // where to put drawable resources / React Native assets, e.g. the ones you use via - * // require('./image.png')), in release mode - * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", - * - * // by default the gradle tasks are skipped if none of the JS files or assets change; this means - * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to - * // date; if you have any other folders that you want to ignore for performance reasons (gradle - * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ - * // for example, you might want to remove it from here. - * inputExcludes: ["android/**", "ios/**"], - * - * // override which node gets called and with what additional arguments - * nodeExecutableAndArgs: ["node"], - * - * // supply additional arguments to the packager - * extraPackagerArgs: [] - * ] + * Set this to true to create four separate APKs instead of one, + * one for each native architecture. This is useful if you don't + * use App Bundles (https://developer.android.com/guide/app-bundle/) + * and want to have separate APKs to upload to the Play Store. */ - -project.ext.react = [ - entryFile: "index.js", - enableHermes: false //System.getenv('METAMASK_ENVIRONMENT') == 'production' -] - -apply from: "../../node_modules/react-native/react.gradle" - project.ext.sentryCli = [ - logLevel: "debug", - sentryProperties: System.getenv('SENTRY_PROPERTIES') ? System.getenv('SENTRY_PROPERTIES') : '../../sentry.properties' -] - -apply from: "../../node_modules/@sentry/react-native/sentry.gradle" +def enableSeparateBuildPerCPUArchitecture = false /** - * Set this to true to create two separate APKs instead of one: - * - An APK that only works on ARM devices - * - An APK that only works on x86 devices - * The advantage is the size of the APK is reduced by about 4MB. - * Upload all the APKs to the Play Store and people will download - * the correct one based on the CPU architecture of their device. + * Set this to true to Run Proguard on Release builds to minify the Java bytecode. */ -def enableSeparateBuildPerCPUArchitecture = true +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-intl:+' +def jscFlavor = 'org.webkit:android-jsc:+' + /** - * Whether to enable the Hermes VM. - * - * This should be set on project.ext.react and mirrored here. If it is not set - * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode - * and the benefits of using Hermes will therefore be sharply reduced. + * Private function to get the list of Native Architectures you want to build. + * This reads the value from reactNativeArchitectures in your gradle.properties + * file and works together with the --active-arch-only flag of react-native run-android. */ -def enableHermes = project.ext.react.get("enableHermes", false) +def reactNativeArchitectures() { + def value = project.getProperties().get("reactNativeArchitectures") + return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] +} /** - * Architectures to build native code for in debug. - */ -def nativeArchitectures = project.getProperties().get("reactNativeDebugArchitectures") +* Adding function that will retuen the Bitrise ndkPath if it is a QA or Production Build +*/ +def ndkPath() { + return System.getenv('METAMASK_ENVIRONMENT') == 'qa' || System.getenv('METAMASK_ENVIRONMENT') == 'production' ? rootProject.ext.bitriseNdkPath : "" +} + android { + ndkVersion rootProject.ext.ndkVersion + compileSdkVersion rootProject.ext.compileSdkVersion - defaultConfig { + namespace"io.metamask" + defaultConfig { applicationId "io.metamask" - minSdkVersion rootProject.ext.minSdkVersion - targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 1136 + minSdkVersion rootProject.ext.minSdkVersion + targetSdkVersion rootProject.ext.targetSdkVersion + versionCode 1136 versionName "7.1.0" - multiDexEnabled true - testBuildType System.getProperty('testBuildType', 'debug') - missingDimensionStrategy "minReactNative", "minReactNative46" - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - ndk { - abiFilters "armeabi-v7a", "x86", "arm64-v8a", "x86_64" - } - dexOptions { - javaMaxHeapSize "2048M" - } - - manifestPlaceholders = [ - MM_BRANCH_KEY_TEST: "$System.env.MM_BRANCH_KEY_TEST", - MM_BRANCH_KEY_LIVE: "$System.env.MM_BRANCH_KEY_LIVE", - MM_MIXPANEL_TOKEN: "$System.env.MM_MIXPANEL_TOKEN" - ] - missingDimensionStrategy 'react-native-camera', 'general' - } - - packagingOptions { - exclude 'META-INF/DEPENDENCIES' - } - - signingConfigs { - release { - storeFile file('../keystores/release.keystore') - storePassword System.getenv("BITRISEIO_ANDROID_KEYSTORE_PASSWORD") - keyAlias System.getenv("BITRISEIO_ANDROID_KEYSTORE_ALIAS") - keyPassword System.getenv("BITRISEIO_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD") - } - qa { - storeFile file('../keystores/internalRelease.keystore') - storePassword System.getenv("BITRISEIO_ANDROID_QA_KEYSTORE_PASSWORD") - keyAlias System.getenv("BITRISEIO_ANDROID_QA_KEYSTORE_ALIAS") - keyPassword System.getenv("BITRISEIO_ANDROID_QA_KEYSTORE_PRIVATE_KEY_PASSWORD") + testBuildType System.getProperty('testBuildType', 'debug') + missingDimensionStrategy 'react-native-camera', 'general' + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + manifestPlaceholders.MM_BRANCH_KEY_TEST = "$System.env.MM_BRANCH_KEY_TEST" + manifestPlaceholders.MM_BRANCH_KEY_LIVE = "$System.env.MM_BRANCH_KEY_LIVE" + manifestPlaceholders.MM_MIXPANEL_TOKEN = "$System.env.MM_MIXPANEL_TOKEN" } - debug { - storeFile file('debug.keystore') - storePassword 'android' - keyAlias 'androiddebugkey' - keyPassword 'android' - } - } - splits { - abi { - reset() - enable enableSeparateBuildPerCPUArchitecture - universalApk false // If true, also generate a universal APK - } - } + packagingOptions { + exclude 'META-INF/DEPENDENCIES' + } - buildTypes { - debug { - manifestPlaceholders = [isDebug:true] - if (nativeArchitectures) { - ndk { - abiFilters nativeArchitectures.split(',') - } - } - multiDexEnabled true - signingConfig signingConfigs.debug - } + signingConfigs { release { - manifestPlaceholders = [isDebug:false] - minifyEnabled true - multiDexEnabled true - shrinkResources true - proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" + storeFile file('../keystores/release.keystore') + storePassword System.getenv("BITRISEIO_ANDROID_KEYSTORE_PASSWORD") + keyAlias System.getenv("BITRISEIO_ANDROID_KEYSTORE_ALIAS") + keyPassword System.getenv("BITRISEIO_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD") } - } - - flavorDimensions "version" - productFlavors { qa { - dimension "version" - applicationIdSuffix ".qa" - applicationId "io.metamask" - signingConfig signingConfigs.qa + storeFile file('../keystores/internalRelease.keystore') + storePassword System.getenv("BITRISEIO_ANDROID_QA_KEYSTORE_PASSWORD") + keyAlias System.getenv("BITRISEIO_ANDROID_QA_KEYSTORE_ALIAS") + keyPassword System.getenv("BITRISEIO_ANDROID_QA_KEYSTORE_PRIVATE_KEY_PASSWORD") } - prod { - dimension "version" - applicationId "io.metamask" - signingConfig signingConfigs.release + debug { + storeFile file('debug.keystore') + storePassword 'android' + keyAlias 'androiddebugkey' + keyPassword 'android' } - } + } + + splits { + abi { + reset() + enable enableSeparateBuildPerCPUArchitecture + universalApk false // If true, also generate a universal APK + include (*reactNativeArchitectures()) + } + } - buildTypes.each { - it.buildConfigField 'String', 'foxCode', "\"$System.env.MM_FOX_CODE\"" + buildTypes { + debug { + manifestPlaceholders.isDebug = true + signingConfig signingConfigs.debug + } + release { + manifestPlaceholders.isDebug = false + minifyEnabled enableProguardInReleaseBuilds + proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" + } + } - } - // applicationVariants are e.g. debug, release - applicationVariants.all { variant -> - variant.outputs.each { output -> + flavorDimensions "version" + productFlavors { + qa { + dimension "version" + applicationIdSuffix ".qa" + applicationId "io.metamask" + signingConfig signingConfigs.qa + } + prod { + dimension "version" + applicationId "io.metamask" + signingConfig signingConfigs.release + } + } + + buildTypes.each { + it.buildConfigField 'String', 'foxCode', "\"$System.env.MM_FOX_CODE\"" + + } + // 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 = - defaultConfig.versionCode * 1000 + versionCodes.get(abi) - } - } - } -} + // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc. + 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 = + defaultConfig.versionCode * 1000 + versionCodes.get(abi) + } -configurations.all { - exclude group: 'com.facebook.react', module: 'react-native' + } + } } dependencies { - implementation project(':lottie-react-native') - - implementation project(':react-native-gesture-handler') - - implementation 'androidx.multidex:multidex:2.0.1' - implementation 'androidx.annotation:annotation:1.1.0' - implementation 'androidx.appcompat:appcompat:1.2.0' - // Replace 'com.facebook.react:react-native:+' with project(':ReactAndroid') to respect changes that we make in native Android code - implementation project(':ReactAndroid') - implementation 'org.chromium:v8-android:+' - implementation 'com.google.android.gms:play-services-wallet:18.0.0' - implementation "io.branch.sdk.android:library:5.+" - implementation 'com.mixpanel.android:mixpanel-android:5.+' - androidTestImplementation('com.wix:detox:+') { transitive = true } - androidTestImplementation 'junit:junit:4.12' - implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" - implementation "com.android.installreferrer:installreferrer:2.2" - - debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") { - exclude group:'com.facebook.fbjni' - } - + // The version of react-native is set by the React Native Gradle Plugin + implementation("com.facebook.react:react-android") + implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0") + implementation('com.mixpanel.android:mixpanel-android:5.+') + debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { - exclude group:'com.facebook.flipper' exclude group:'com.squareup.okhttp3', module:'okhttp' } - debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") { - exclude group:'com.facebook.flipper' - } - - if (enableHermes) { - def hermesPath = "../../node_modules/hermes-engine/android/"; - debugImplementation files(hermesPath + "hermes-debug.aar") - releaseImplementation files(hermesPath + "hermes-release.aar") - + debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") + if (hermesEnabled.toBoolean()) { + implementation("com.facebook.react:hermes-android") } else { implementation jscFlavor } } -// Run this once to be able to run the application with BUCK -// puts all compile dependencies into folder libs for BUCK to use -task copyDownloadableDepsToLibs(type: Copy) { - from configurations.implementation - into 'libs' -} - apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) diff --git a/android/app/proguard-rules.pro b/android/app/proguard-rules.pro index f6aa1671d73..53acc5e2d50 100644 --- a/android/app/proguard-rules.pro +++ b/android/app/proguard-rules.pro @@ -30,8 +30,8 @@ -keep class com.facebook.react.turbomodule.** { *; } # Hermes -# -keep class com.facebook.hermes.unicode.** { *; } -# -keep class com.facebook.jni.** { *; }# +-keep class com.facebook.hermes.unicode.** { *; } +-keep class com.facebook.jni.** { *; }# # react-native-webrt https://github.com/react-native-webrtc/react-native-webrtc/issues/590 -keep class org.webrtc.** { *; } diff --git a/android/app/src/debug/AndroidManifest.xml b/android/app/src/debug/AndroidManifest.xml index 925639a6135..df9ac798856 100644 --- a/android/app/src/debug/AndroidManifest.xml +++ b/android/app/src/debug/AndroidManifest.xml @@ -8,7 +8,7 @@ android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning"> - + diff --git a/android/app/src/debug/java/com/flipper/ReactNativeFlipper.java b/android/app/src/debug/java/io/metamask/ReactNativeFlipper.java similarity index 69% rename from android/app/src/debug/java/com/flipper/ReactNativeFlipper.java rename to android/app/src/debug/java/io/metamask/ReactNativeFlipper.java index 1a4ae4b591b..657cbb80081 100644 --- a/android/app/src/debug/java/com/flipper/ReactNativeFlipper.java +++ b/android/app/src/debug/java/io/metamask/ReactNativeFlipper.java @@ -1,10 +1,10 @@ /** - * Copyright (c) Facebook, Inc. and its affiliates. + * 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.flipper; +package io.metamask; import android.content.Context; import com.facebook.flipper.android.AndroidFlipperClient; @@ -17,32 +17,35 @@ 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.react.ReactFlipperPlugin; 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 ReactFlipperPlugin()); 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)); - } - }); + new NetworkingModule.CustomClientBuilder() { + @Override + public void apply(OkHttpClient.Builder builder) { + builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin)); + } + }); client.addPlugin(networkFlipperPlugin); client.start(); @@ -51,19 +54,19 @@ public void apply(OkHttpClient.Builder builder) { ReactContext reactContext = reactInstanceManager.getCurrentReactContext(); if (reactContext == null) { reactInstanceManager.addReactInstanceEventListener( - new ReactInstanceManager.ReactInstanceEventListener() { - @Override - public void onReactContextInitialized(ReactContext reactContext) { - reactInstanceManager.removeReactInstanceEventListener(this); - reactContext.runOnNativeModulesQueueThread( - new Runnable() { - @Override - public void run() { - client.addPlugin(new FrescoFlipperPlugin()); - } - }); - } - }); + 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()); } diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 33d991cd5b3..fd99e850b84 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ @@ -39,7 +38,7 @@ android:launchMode="singleTask" android:name=".MainActivity" android:label="@string/app_name" - android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" + android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" android:windowSoftInputMode="adjustResize" android:screenOrientation="portrait" android:exported="true" diff --git a/android/app/src/main/java/io/metamask/MainActivity.java b/android/app/src/main/java/io/metamask/MainActivity.java index 56b86058cb1..da6aafc9128 100644 --- a/android/app/src/main/java/io/metamask/MainActivity.java +++ b/android/app/src/main/java/io/metamask/MainActivity.java @@ -1,23 +1,23 @@ package io.metamask; -import com.facebook.react.ReactActivityDelegate; import com.facebook.react.ReactActivity; -import com.facebook.react.ReactRootView; +import com.facebook.react.ReactActivityDelegate; +import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; +import com.facebook.react.defaults.DefaultReactActivityDelegate; import com.mixpanel.android.mpmetrics.MixpanelAPI; -import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView; - -import io.branch.rnbranch.*; -import android.content.Intent; - import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; -import android.os.Bundle; import android.util.Log; -import androidx.annotation.NonNull; +import io.branch.rnbranch.*; +import android.content.Intent; +import android.os.Bundle; import org.devio.rn.splashscreen.SplashScreen; +import java.util.ArrayList; +import java.util.Arrays; + public class MainActivity extends ReactActivity { /** @@ -52,43 +52,40 @@ protected void onCreate(Bundle savedInstanceState) { @Override public void onNewIntent(Intent intent) { - super.onNewIntent(intent); - /* - if activity is in foreground (or in backstack but partially visible) launch the same - activity will skip onStart, handle this case with reInit - if reInit() is called without this flag, you will see the following message: - BRANCH_SDK: Warning. Session initialization already happened. - To force a new session, - set intent extra, "branch_force_new_session", to true. - */ - if (intent != null && - intent.hasExtra("branch_force_new_session") && - intent.getBooleanExtra("branch_force_new_session", false)) { - RNBranchModule.onNewIntent(intent); - } + super.onNewIntent(intent); + /* + if activity is in foreground (or in backstack but partially visible) launch the same + activity will skip onStart, handle this case with reInit + if reInit() is called without this flag, you will see the following message: + BRANCH_SDK: Warning. Session initialization already happened. + To force a new session, + set intent extra, "branch_force_new_session", to true. + */ + if (intent != null && + intent.hasExtra("branch_force_new_session") && + intent.getBooleanExtra("branch_force_new_session", false)) { + RNBranchModule.onNewIntent(intent); + } } - + + /** + * 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 ReactActivityDelegate(this, getMainComponentName()) { - @NonNull - @Override - protected Bundle getLaunchOptions() { - Bundle bundle = new Bundle(); - if(BuildConfig.foxCode != null){ - bundle.putString("foxCode", BuildConfig.foxCode); - } else { - bundle.putString("foxCode", "debug"); - } - return bundle; - } - @Override - protected ReactRootView createRootView() { - return new RNGestureHandlerEnabledRootView(MainActivity.this); + @Override + protected Bundle getLaunchOptions() { + Bundle initialProperties = new Bundle(); + if (BuildConfig.foxCode != null) { + initialProperties.putString("foxCode", BuildConfig.foxCode); + } else { + initialProperties.putString("foxCode", "debug"); } + return initialProperties; + } }; } - - - } diff --git a/android/app/src/main/java/io/metamask/MainApplication.java b/android/app/src/main/java/io/metamask/MainApplication.java index fbeafe10a93..4c177c9923d 100644 --- a/android/app/src/main/java/io/metamask/MainApplication.java +++ b/android/app/src/main/java/io/metamask/MainApplication.java @@ -1,34 +1,36 @@ package io.metamask; +import android.app.Application; import com.facebook.react.ReactApplication; -import com.cmcewen.blurview.BlurViewPackage; import com.brentvatne.react.ReactVideoPackage; -import android.content.Context; import com.facebook.react.PackageList; -import com.facebook.react.ReactInstanceManager; import com.airbnb.android.react.lottie.LottiePackage; -import com.swmansion.gesturehandler.react.RNGestureHandlerPackage; + +import cl.json.ShareApplication; import io.branch.rnbranch.RNBranchModule; +import io.metamask.nativeModules.RCTMinimizerPackage; import io.metamask.nativeModules.RCTAnalyticsPackage; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; import com.facebook.soloader.SoLoader; -import cl.json.ShareApplication; -import java.lang.reflect.InvocationTargetException; +import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; +import com.facebook.react.defaults.DefaultReactNativeHost; import java.util.List; import io.metamask.nativeModules.PreventScreenshotPackage; import android.webkit.WebView; - -import androidx.multidex.MultiDexApplication; +import android.os.Bundle; import android.database.CursorWindow; import java.lang.reflect.Field; -import com.facebook.react.bridge.JSIModulePackage; -import com.swmansion.reanimated.ReanimatedJSIModulePackage; -public class MainApplication extends MultiDexApplication implements ShareApplication, ReactApplication { +public class MainApplication extends Application implements ShareApplication, ReactApplication { + + @Override + public String getFileProviderAuthority() { + return BuildConfig.APPLICATION_ID + ".provider"; + } - private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { + private final ReactNativeHost mReactNativeHost = new DefaultReactNativeHost(this) { @Override public boolean getUseDeveloperSupport() { return BuildConfig.DEBUG; @@ -36,26 +38,30 @@ public boolean getUseDeveloperSupport() { @Override protected List getPackages() { - @SuppressWarnings("UnnecessaryLocalVariable") - List packages = new PackageList(this).getPackages(); + @SuppressWarnings("UnnecessaryLocalVariable") + List packages = new PackageList(this).getPackages(); packages.add(new LottiePackage()); - packages.add(new RNGestureHandlerPackage()); - packages.add(new RCTAnalyticsPackage()); packages.add(new PreventScreenshotPackage()); packages.add(new ReactVideoPackage()); + packages.add(new RCTAnalyticsPackage()); + packages.add(new RCTMinimizerPackage()); - return packages; + return packages; } + @Override + protected boolean isNewArchEnabled() { + return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; + } + @Override + protected Boolean isHermesEnabled() { + return BuildConfig.IS_HERMES_ENABLED; + } + @Override protected String getJSMainModuleName() { return "index"; } - - @Override - protected JSIModulePackage getJSIModulePackage() { - return new ReanimatedJSIModulePackage(); - } }; @Override @@ -81,43 +87,11 @@ public void onCreate() { } SoLoader.init(this, /* native exopackage */ false); - initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); + 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(); } - /** - * Loads Flipper in React Native templates. Call this in the onCreate method with something like - * initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); - * - * @param context - * @param reactInstanceManager - */ - private static void initializeFlipper( - Context context, ReactInstanceManager reactInstanceManager) { - if (BuildConfig.DEBUG) { - try { - /* - We use reflection here to pick up the class that initializes Flipper, - since Flipper library is not available in release mode - */ - Class aClass = Class.forName("com.flipper.ReactNativeFlipper"); - aClass - .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class) - .invoke(null, context, reactInstanceManager); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } - } + ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); } - - - @Override - public String getFileProviderAuthority() { - return BuildConfig.APPLICATION_ID + ".provider"; - } } diff --git a/android/app/src/main/java/io/metamask/nativeModules/RCTMinimizer.java b/android/app/src/main/java/io/metamask/nativeModules/RCTMinimizer.java new file mode 100644 index 00000000000..42b18827e05 --- /dev/null +++ b/android/app/src/main/java/io/metamask/nativeModules/RCTMinimizer.java @@ -0,0 +1,27 @@ +package io.metamask.nativeModules; + +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.facebook.react.bridge.ReactMethod; +import android.util.Log; + +public class RCTMinimizer extends ReactContextBaseJavaModule { + private ReactApplicationContext reactContext; + RCTMinimizer(ReactApplicationContext context) { + super(context); + this.reactContext = reactContext; + } + + @Override + public String getName() { + return "Minimizer"; + } + + @ReactMethod + public void goBack() { + android.app.Activity activity = getCurrentActivity(); + if (activity != null) { + activity.moveTaskToBack(true); + } + } +} diff --git a/android/app/src/main/java/io/metamask/nativeModules/RCTMinimizerPackage.java b/android/app/src/main/java/io/metamask/nativeModules/RCTMinimizerPackage.java new file mode 100644 index 00000000000..a61fcd78996 --- /dev/null +++ b/android/app/src/main/java/io/metamask/nativeModules/RCTMinimizerPackage.java @@ -0,0 +1,29 @@ +package io.metamask.nativeModules; + +import com.facebook.react.ReactPackage; +import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.uimanager.ViewManager; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class RCTMinimizerPackage implements ReactPackage { + + @Override + public List createViewManagers(ReactApplicationContext reactContext) { + return Collections.emptyList(); + } + + @Override + public List createNativeModules( + ReactApplicationContext reactContext) { + List modules = new ArrayList<>(); + + modules.add(new RCTMinimizer(reactContext)); + + return modules; + } + +} diff --git a/android/app/src/main/java/io/metamask/newarchitecture/MainApplicationReactNativeHost.java b/android/app/src/main/java/io/metamask/newarchitecture/MainApplicationReactNativeHost.java new file mode 100644 index 00000000000..01f3d168484 --- /dev/null +++ b/android/app/src/main/java/io/metamask/newarchitecture/MainApplicationReactNativeHost.java @@ -0,0 +1,116 @@ +package io.metamask.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 io.metamask.BuildConfig; +import io.metamask.newarchitecture.components.MainComponentsRegistry; +import io.metamask.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; + } + }; + } +} diff --git a/android/app/src/main/java/io/metamask/newarchitecture/components/MainComponentsRegistry.java b/android/app/src/main/java/io/metamask/newarchitecture/components/MainComponentsRegistry.java new file mode 100644 index 00000000000..f6ac1c2d8c6 --- /dev/null +++ b/android/app/src/main/java/io/metamask/newarchitecture/components/MainComponentsRegistry.java @@ -0,0 +1,36 @@ +package io.metamask.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); + } +} diff --git a/android/app/src/main/java/io/metamask/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java b/android/app/src/main/java/io/metamask/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java new file mode 100644 index 00000000000..3991d2ad035 --- /dev/null +++ b/android/app/src/main/java/io/metamask/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java @@ -0,0 +1,48 @@ +package io.metamask.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("rndiffapp_appmodules"); + sIsSoLibraryLoaded = true; + } + } +} diff --git a/android/app/src/main/jni/CMakeLists.txt b/android/app/src/main/jni/CMakeLists.txt new file mode 100644 index 00000000000..6e63f482b8c --- /dev/null +++ b/android/app/src/main/jni/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.13) + +# Define the library name here. +project(rndiffapp_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) diff --git a/android/app/src/main/jni/MainApplicationModuleProvider.cpp b/android/app/src/main/jni/MainApplicationModuleProvider.cpp new file mode 100644 index 00000000000..26162dd8723 --- /dev/null +++ b/android/app/src/main/jni/MainApplicationModuleProvider.cpp @@ -0,0 +1,32 @@ +#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 diff --git a/android/app/src/main/jni/MainApplicationModuleProvider.h b/android/app/src/main/jni/MainApplicationModuleProvider.h new file mode 100644 index 00000000000..b38ccf53fd4 --- /dev/null +++ b/android/app/src/main/jni/MainApplicationModuleProvider.h @@ -0,0 +1,16 @@ +#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 diff --git a/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp b/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp new file mode 100644 index 00000000000..5fd688c509d --- /dev/null +++ b/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp @@ -0,0 +1,45 @@ +#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 diff --git a/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h b/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h new file mode 100644 index 00000000000..e9b48a3205a --- /dev/null +++ b/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h @@ -0,0 +1,38 @@ +#include +#include + +#include +#include + +namespace facebook { +namespace react { + +class MainApplicationTurboModuleManagerDelegate + : public jni::HybridClass< + MainApplicationTurboModuleManagerDelegate, + TurboModuleManagerDelegate> { + public: + // Adapt it to the package you used for your Java class. + static constexpr auto kJavaDescriptor = + "Lio/metamask/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate;"; + + static jni::local_ref initHybrid(jni::alias_ref); + + static void registerNatives(); + + std::shared_ptr getTurboModule( + const std::string &name, + const std::shared_ptr &jsInvoker) override; + std::shared_ptr getTurboModule( + const std::string &name, + const JavaTurboModule::InitParams ¶ms) override; + + /** + * Test-only method. Allows user to verify whether a TurboModule can be + * created by instances of this class. + */ + bool canCreateTurboModule(const std::string &name); +}; + +} // namespace react +} // namespace facebook diff --git a/android/app/src/main/jni/MainComponentsRegistry.cpp b/android/app/src/main/jni/MainComponentsRegistry.cpp new file mode 100644 index 00000000000..54f598a486a --- /dev/null +++ b/android/app/src/main/jni/MainComponentsRegistry.cpp @@ -0,0 +1,65 @@ +#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 diff --git a/android/app/src/main/jni/MainComponentsRegistry.h b/android/app/src/main/jni/MainComponentsRegistry.h new file mode 100644 index 00000000000..eeaced297aa --- /dev/null +++ b/android/app/src/main/jni/MainComponentsRegistry.h @@ -0,0 +1,32 @@ +#pragma once + +#include +#include +#include +#include + +namespace facebook { +namespace react { + +class MainComponentsRegistry + : public facebook::jni::HybridClass { + public: + // Adapt it to the package you used for your Java class. + constexpr static auto kJavaDescriptor = + "Lio/metamask/newarchitecture/components/MainComponentsRegistry;"; + + static void registerNatives(); + + MainComponentsRegistry(ComponentFactory *delegate); + + private: + static std::shared_ptr + sharedProviderRegistry(); + + static jni::local_ref initHybrid( + jni::alias_ref, + ComponentFactory *delegate); +}; + +} // namespace react +} // namespace facebook diff --git a/android/app/src/main/jni/OnLoad.cpp b/android/app/src/main/jni/OnLoad.cpp new file mode 100644 index 00000000000..c569b6e865d --- /dev/null +++ b/android/app/src/main/jni/OnLoad.cpp @@ -0,0 +1,11 @@ +#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(); + }); +} diff --git a/android/app/src/main/res/drawable/rn_edit_text_material.xml b/android/app/src/main/res/drawable/rn_edit_text_material.xml new file mode 100644 index 00000000000..a902b2a3a60 --- /dev/null +++ b/android/app/src/main/res/drawable/rn_edit_text_material.xml @@ -0,0 +1,29 @@ + + + + + + + + + diff --git a/android/app/src/main/res/values/styles.xml b/android/app/src/main/res/values/styles.xml index 28a1d507e55..bb293472079 100644 --- a/android/app/src/main/res/values/styles.xml +++ b/android/app/src/main/res/values/styles.xml @@ -3,6 +3,7 @@