diff --git a/README.md b/README.md index e7581e99..95c0527f 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,10 @@ npx react-native init MyApp --template react-native-template-typescript ### Usage with older versions of React Native -#### e.g. `react-native@0.67.x` +#### e.g. `react-native@0.69.x` ```sh -npx react-native init MyApp --template react-native-template-typescript@6.9.* +npx react-native init MyApp --template react-native-template-typescript@6.11.9 ``` See the below table to find out which version of the template to use. @@ -43,6 +43,7 @@ See the below table to find out which version of the template to use. | React Native | Template | | ------------ | -------- | +| 0.70 | 6.12.\* | | 0.69 | 6.11.\* | | 0.68 | 6.10.\* | | 0.67 | 6.9.\* | diff --git a/template/App.tsx b/template/App.tsx index e21ce8db..753aeb86 100644 --- a/template/App.tsx +++ b/template/App.tsx @@ -66,7 +66,10 @@ const App = () => { return ( - + diff --git a/template/_gitignore b/template/_gitignore index 344481b2..2423126f 100644 --- a/template/_gitignore +++ b/template/_gitignore @@ -30,6 +30,7 @@ build/ local.properties *.iml *.hprof +.cxx/ # node.js # diff --git a/template/_node-version b/template/_node-version new file mode 100644 index 00000000..b6a7d89c --- /dev/null +++ b/template/_node-version @@ -0,0 +1 @@ +16 diff --git a/template/android/app/build.gradle b/template/android/app/build.gradle index 3081a1f2..0914473b 100644 --- a/template/android/app/build.gradle +++ b/template/android/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: "com.android.application" import com.android.build.OutputFile +import org.apache.tools.ant.taskdefs.condition.Os /** * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets @@ -78,7 +79,7 @@ import com.android.build.OutputFile */ project.ext.react = [ - enableHermes: false, // clean and rebuild if changing + enableHermes: true, // clean and rebuild if changing ] apply from: "../../node_modules/react-native/react.gradle" @@ -142,22 +143,14 @@ android { buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() if (isNewArchitectureEnabled()) { - // We configure the NDK build only if you decide to opt-in for the New Architecture. + // We configure the CMake build only if you decide to opt-in for the New Architecture. externalNativeBuild { - ndkBuild { - arguments "APP_PLATFORM=android-21", - "APP_STL=c++_shared", - "NDK_TOOLCHAIN_VERSION=clang", - "GENERATED_SRC_DIR=$buildDir/generated/source", - "PROJECT_BUILD_DIR=$buildDir", - "REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid", - "REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build", - "NODE_MODULES_DIR=$rootDir/../node_modules" - cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1" - cppFlags "-std=c++17" - // Make sure this target name is the same you specify inside the - // src/main/jni/Android.mk file for the `LOCAL_MODULE` variable. - targets "helloworld_appmodules" + 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) { @@ -171,8 +164,8 @@ android { if (isNewArchitectureEnabled()) { // We configure the NDK build only if you decide to opt-in for the New Architecture. externalNativeBuild { - ndkBuild { - path "$projectDir/src/main/jni/Android.mk" + cmake { + path "$projectDir/src/main/jni/CMakeLists.txt" } } def reactAndroidProjectDir = project(':ReactAndroid').projectDir @@ -194,15 +187,15 @@ android { preReleaseBuild.dependsOn(packageReactNdkReleaseLibs) // Due to a bug inside AGP, we have to explicitly set a dependency - // between configureNdkBuild* tasks and the preBuild tasks. + // between configureCMakeDebug* tasks and the preBuild tasks. // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732 - configureNdkBuildRelease.dependsOn(preReleaseBuild) - configureNdkBuildDebug.dependsOn(preDebugBuild) + configureCMakeRelWithDebInfo.dependsOn(preReleaseBuild) + configureCMakeDebug.dependsOn(preDebugBuild) reactNativeArchitectures().each { architecture -> - tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure { + tasks.findByName("configureCMakeDebug[${architecture}]")?.configure { dependsOn("preDebugBuild") } - tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure { + tasks.findByName("configureCMakeRelWithDebInfo[${architecture}]")?.configure { dependsOn("preReleaseBuild") } } diff --git a/template/android/app/src/main/jni/Android.mk b/template/android/app/src/main/jni/Android.mk deleted file mode 100644 index cda13912..00000000 --- a/template/android/app/src/main/jni/Android.mk +++ /dev/null @@ -1,48 +0,0 @@ -THIS_DIR := $(call my-dir) - -include $(REACT_ANDROID_DIR)/Android-prebuilt.mk - -# If you wish to add a custom TurboModule or Fabric component in your app you -# will have to include the following autogenerated makefile. -# include $(GENERATED_SRC_DIR)/codegen/jni/Android.mk -include $(CLEAR_VARS) - -LOCAL_PATH := $(THIS_DIR) - -# You can customize the name of your application .so file here. -LOCAL_MODULE := helloworld_appmodules - -LOCAL_C_INCLUDES := $(LOCAL_PATH) -LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) -LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) - -# If you wish to add a custom TurboModule or Fabric component in your app you -# will have to uncomment those lines to include the generated source -# files from the codegen (placed in $(GENERATED_SRC_DIR)/codegen/jni) -# -# LOCAL_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni -# LOCAL_SRC_FILES += $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp) -# LOCAL_EXPORT_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni - -# Here you should add any native library you wish to depend on. -LOCAL_SHARED_LIBRARIES := \ - libfabricjni \ - libfbjni \ - libfolly_runtime \ - libglog \ - libjsi \ - libreact_codegen_rncore \ - libreact_debug \ - libreact_nativemodule_core \ - libreact_render_componentregistry \ - libreact_render_core \ - libreact_render_debug \ - libreact_render_graphics \ - librrc_view \ - libruntimeexecutor \ - libturbomodulejsijni \ - libyoga - -LOCAL_CFLAGS := -DLOG_TAG=\"ReactNative\" -fexceptions -frtti -std=c++17 -Wall - -include $(BUILD_SHARED_LIBRARY) diff --git a/template/android/app/src/main/jni/CMakeLists.txt b/template/android/app/src/main/jni/CMakeLists.txt new file mode 100644 index 00000000..d2cad3a3 --- /dev/null +++ b/template/android/app/src/main/jni/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.13) + +# Define the library name here. +project(helloworld_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/template/android/app/src/main/jni/MainApplicationModuleProvider.cpp b/template/android/app/src/main/jni/MainApplicationModuleProvider.cpp index 0ac23cc6..26162dd8 100644 --- a/template/android/app/src/main/jni/MainApplicationModuleProvider.cpp +++ b/template/android/app/src/main/jni/MainApplicationModuleProvider.cpp @@ -1,12 +1,13 @@ #include "MainApplicationModuleProvider.h" +#include #include namespace facebook { namespace react { std::shared_ptr MainApplicationModuleProvider( - const std::string moduleName, + 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 @@ -17,6 +18,13 @@ std::shared_ptr MainApplicationModuleProvider( // 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); } diff --git a/template/android/app/src/main/jni/MainApplicationModuleProvider.h b/template/android/app/src/main/jni/MainApplicationModuleProvider.h index 0fa43fa6..b38ccf53 100644 --- a/template/android/app/src/main/jni/MainApplicationModuleProvider.h +++ b/template/android/app/src/main/jni/MainApplicationModuleProvider.h @@ -9,7 +9,7 @@ namespace facebook { namespace react { std::shared_ptr MainApplicationModuleProvider( - const std::string moduleName, + const std::string &moduleName, const JavaTurboModule::InitParams ¶ms); } // namespace react diff --git a/template/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp b/template/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp index dbbdc3d1..5fd688c5 100644 --- a/template/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp +++ b/template/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp @@ -22,21 +22,21 @@ void MainApplicationTurboModuleManagerDelegate::registerNatives() { std::shared_ptr MainApplicationTurboModuleManagerDelegate::getTurboModule( - const std::string name, - const std::shared_ptr jsInvoker) { + 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 std::string &name, const JavaTurboModule::InitParams ¶ms) { return MainApplicationModuleProvider(name, params); } bool MainApplicationTurboModuleManagerDelegate::canCreateTurboModule( - std::string name) { + const std::string &name) { return getTurboModule(name, nullptr) != nullptr || getTurboModule(name, {.moduleName = name}) != nullptr; } diff --git a/template/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h b/template/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h index 25f27722..9ee38a81 100644 --- a/template/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h +++ b/template/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h @@ -21,17 +21,17 @@ class MainApplicationTurboModuleManagerDelegate static void registerNatives(); std::shared_ptr getTurboModule( - const std::string name, - const std::shared_ptr jsInvoker) override; + const std::string &name, + const std::shared_ptr &jsInvoker) override; std::shared_ptr getTurboModule( - const std::string name, + 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(std::string name); + bool canCreateTurboModule(const std::string &name); }; } // namespace react diff --git a/template/android/app/src/main/jni/MainComponentsRegistry.cpp b/template/android/app/src/main/jni/MainComponentsRegistry.cpp index 8f7edffd..54f598a4 100644 --- a/template/android/app/src/main/jni/MainComponentsRegistry.cpp +++ b/template/android/app/src/main/jni/MainComponentsRegistry.cpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace facebook { namespace react { @@ -14,6 +15,9 @@ 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. // diff --git a/template/android/build.gradle b/template/android/build.gradle index c9bc539d..8569fee3 100644 --- a/template/android/build.gradle +++ b/template/android/build.gradle @@ -1,5 +1,3 @@ -import org.apache.tools.ant.taskdefs.condition.Os - // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { @@ -22,7 +20,7 @@ buildscript { mavenCentral() } dependencies { - classpath("com.android.tools.build:gradle:7.1.1") + classpath("com.android.tools.build:gradle:7.2.1") classpath("com.facebook.react:react-native-gradle-plugin") classpath("de.undercouch:gradle-download-task:5.0.1") // NOTE: Do not place your application dependencies here; they belong diff --git a/template/android/gradle/wrapper/gradle-wrapper.jar b/template/android/gradle/wrapper/gradle-wrapper.jar index 7454180f..41d9927a 100644 Binary files a/template/android/gradle/wrapper/gradle-wrapper.jar and b/template/android/gradle/wrapper/gradle-wrapper.jar differ diff --git a/template/android/gradle/wrapper/gradle-wrapper.properties b/template/android/gradle/wrapper/gradle-wrapper.properties index 669386b8..8fad3f5a 100644 --- a/template/android/gradle/wrapper/gradle-wrapper.properties +++ b/template/android/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/template/ios/Podfile b/template/ios/Podfile index 92194221..92e7ee19 100644 --- a/template/ios/Podfile +++ b/template/ios/Podfile @@ -4,8 +4,6 @@ require_relative '../node_modules/@react-native-community/cli-platform-ios/nativ platform :ios, '12.4' install! 'cocoapods', :deterministic_uuids => false -production = ENV["PRODUCTION"] == "1" - target 'HelloWorld' do config = use_native_modules! @@ -14,10 +12,15 @@ target 'HelloWorld' do use_react_native!( :path => config[:reactNativePath], - # to enable hermes on iOS, change `false` to `true` and then install pods - :production => production, - :hermes_enabled => flags[:hermes_enabled], + # Hermes is now enabled by default. Disable by setting this flag to false. + # Upcoming versions of React Native may rely on get_default_flags(), but + # we make it explicit here to aid in the React Native upgrade process. + :hermes_enabled => true, :fabric_enabled => flags[:fabric_enabled], + # Enables Flipper. + # + # Note that if you have use_frameworks! enabled, Flipper will not work and + # you should disable the next line. :flipper_configuration => FlipperConfiguration.enabled, # An absolute path to your application root. :app_path => "#{Pod::Config.instance.installation_root}/.." @@ -29,7 +32,12 @@ target 'HelloWorld' do end post_install do |installer| - react_native_post_install(installer) + react_native_post_install( + installer, + # Set `mac_catalyst_enabled` to `true` in order to apply patches + # necessary for Mac Catalyst builds + :mac_catalyst_enabled => false + ) __apply_Xcode_12_5_M1_post_install_workaround(installer) end end diff --git a/template/package.json b/template/package.json index 9d22ec1d..5573885d 100644 --- a/template/package.json +++ b/template/package.json @@ -10,8 +10,8 @@ "lint": "eslint . --ext .js,.jsx,.ts,.tsx" }, "dependencies": { - "react": "18.0.0", - "react-native": "0.69.5" + "react": "18.1.0", + "react-native": "0.70.0" }, "devDependencies": { "@babel/core": "^7.12.9", @@ -19,16 +19,16 @@ "@react-native-community/eslint-config": "^2.0.0", "@tsconfig/react-native": "^2.0.2", "@types/jest": "^26.0.23", - "@types/react-native": "^0.69.5", + "@types/react-native": "^0.69.6", "@types/react-test-renderer": "^18.0.0", - "@typescript-eslint/eslint-plugin": "^5.29.0", - "@typescript-eslint/parser": "^5.29.0", + "@typescript-eslint/eslint-plugin": "^5.36.2", + "@typescript-eslint/parser": "^5.36.2", "babel-jest": "^26.6.3", "eslint": "^7.32.0", "jest": "^26.6.3", - "metro-react-native-babel-preset": "^0.70.3", - "react-test-renderer": "18.0.0", - "typescript": "^4.4.4" + "metro-react-native-babel-preset": "^0.72.1", + "react-test-renderer": "18.1.0", + "typescript": "^4.8.2" }, "jest": { "preset": "react-native",