Skip to content

Commit 87448a0

Browse files
committed
Update example project to RN 0.70
1 parent b40272c commit 87448a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3932
-2462
lines changed

example/.bundle/config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BUNDLE_PATH: "vendor/bundle"
2+
BUNDLE_FORCE_RUBY_PLATFORM: 1

example/.eslintrc.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
module.exports = {
22
root: true,
33
extends: '@react-native-community',
4+
parser: '@typescript-eslint/parser',
5+
plugins: ['@typescript-eslint'],
6+
overrides: [
7+
{
8+
files: ['*.ts', '*.tsx'],
9+
rules: {
10+
'@typescript-eslint/no-shadow': ['error'],
11+
'no-shadow': 'off',
12+
'no-undef': 'off',
13+
},
14+
},
15+
],
416
};

example/.gitattributes

Lines changed: 0 additions & 3 deletions
This file was deleted.

example/.gitignore

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ DerivedData
2020
*.hmap
2121
*.ipa
2222
*.xcuserstate
23+
ios/.xcode.env.local
2324

2425
# Android/IntelliJ
2526
#
@@ -28,6 +29,8 @@ build/
2829
.gradle
2930
local.properties
3031
*.iml
32+
*.hprof
33+
.cxx/
3134

3235
# node.js
3336
#
@@ -48,12 +51,14 @@ buck-out/
4851
# For more information about the recommended setup visit:
4952
# https://docs.fastlane.tools/best-practices/source-control/
5053

51-
*/fastlane/report.xml
52-
*/fastlane/Preview.html
53-
*/fastlane/screenshots
54+
**/fastlane/report.xml
55+
**/fastlane/Preview.html
56+
**/fastlane/screenshots
57+
**/fastlane/test_output
5458

5559
# Bundle artifact
5660
*.jsbundle
5761

58-
# CocoaPods
62+
# Ruby / CocoaPods
5963
/ios/Pods/
64+
/vendor/bundle/

example/.prettierrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
2+
arrowParens: 'avoid',
3+
bracketSameLine: true,
24
bracketSpacing: true,
3-
jsxBracketSameLine: false,
45
singleQuote: true,
56
trailingComma: 'all',
67
};

example/.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.7.5

example/@types/index.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
declare module '@voximplant/react-native-foreground-service' {
2+
export default class VIForegroundService {
3+
static getInstance(): VIForegroundService;
4+
5+
async createNotificationChannel(channelConfig: any);
6+
7+
async startService(notificationConfig: any);
8+
9+
async stopService();
10+
}
11+
}

example/Gemfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source 'https://rubygems.org'
2+
3+
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
4+
ruby '2.7.5'
5+
6+
gem 'cocoapods', '~> 1.11', '>= 1.11.2'

example/_node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16

example/android/app/build.gradle

Lines changed: 103 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
apply plugin: "com.android.application"
22

33
import com.android.build.OutputFile
4+
import org.apache.tools.ant.taskdefs.condition.Os
45

56
/**
67
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
@@ -78,7 +79,7 @@ import com.android.build.OutputFile
7879
*/
7980

8081
project.ext.react = [
81-
enableHermes: false, // clean and rebuild if changing
82+
enableHermes: true, // clean and rebuild if changing
8283
]
8384

8485
apply from: "../../node_modules/react-native/react.gradle"
@@ -114,12 +115,20 @@ def jscFlavor = 'org.webkit:android-jsc:+'
114115
/**
115116
* Whether to enable the Hermes VM.
116117
*
117-
* This should be set on project.ext.react and mirrored here. If it is not set
118+
* This should be set on project.ext.react and that value will be read here. If it is not set
118119
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
119120
* and the benefits of using Hermes will therefore be sharply reduced.
120121
*/
121122
def enableHermes = project.ext.react.get("enableHermes", false);
122123

124+
/**
125+
* Architectures to build native code for.
126+
*/
127+
def reactNativeArchitectures() {
128+
def value = project.getProperties().get("reactNativeArchitectures")
129+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
130+
}
131+
123132
android {
124133
ndkVersion rootProject.ext.ndkVersion
125134

@@ -131,13 +140,74 @@ android {
131140
targetSdkVersion rootProject.ext.targetSdkVersion
132141
versionCode 1
133142
versionName "1.0"
143+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
144+
145+
if (isNewArchitectureEnabled()) {
146+
// We configure the CMake build only if you decide to opt-in for the New Architecture.
147+
externalNativeBuild {
148+
cmake {
149+
arguments "-DPROJECT_BUILD_DIR=$buildDir",
150+
"-DREACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
151+
"-DREACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
152+
"-DNODE_MODULES_DIR=$rootDir/../node_modules",
153+
"-DANDROID_STL=c++_shared"
154+
}
155+
}
156+
if (!enableSeparateBuildPerCPUArchitecture) {
157+
ndk {
158+
abiFilters (*reactNativeArchitectures())
159+
}
160+
}
161+
}
162+
}
163+
164+
if (isNewArchitectureEnabled()) {
165+
// We configure the NDK build only if you decide to opt-in for the New Architecture.
166+
externalNativeBuild {
167+
cmake {
168+
path "$projectDir/src/main/jni/CMakeLists.txt"
169+
}
170+
}
171+
def reactAndroidProjectDir = project(':ReactAndroid').projectDir
172+
def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) {
173+
dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck")
174+
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
175+
into("$buildDir/react-ndk/exported")
176+
}
177+
def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) {
178+
dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck")
179+
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
180+
into("$buildDir/react-ndk/exported")
181+
}
182+
afterEvaluate {
183+
// If you wish to add a custom TurboModule or component locally,
184+
// you should uncomment this line.
185+
// preBuild.dependsOn("generateCodegenArtifactsFromSchema")
186+
preDebugBuild.dependsOn(packageReactNdkDebugLibs)
187+
preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)
188+
189+
// Due to a bug inside AGP, we have to explicitly set a dependency
190+
// between configureCMakeDebug* tasks and the preBuild tasks.
191+
// This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
192+
configureCMakeRelWithDebInfo.dependsOn(preReleaseBuild)
193+
configureCMakeDebug.dependsOn(preDebugBuild)
194+
reactNativeArchitectures().each { architecture ->
195+
tasks.findByName("configureCMakeDebug[${architecture}]")?.configure {
196+
dependsOn("preDebugBuild")
197+
}
198+
tasks.findByName("configureCMakeRelWithDebInfo[${architecture}]")?.configure {
199+
dependsOn("preReleaseBuild")
200+
}
201+
}
202+
}
134203
}
204+
135205
splits {
136206
abi {
137207
reset()
138208
enable enableSeparateBuildPerCPUArchitecture
139209
universalApk false // If true, also generate a universal APK
140-
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
210+
include (*reactNativeArchitectures())
141211
}
142212
}
143213
signingConfigs {
@@ -180,13 +250,14 @@ android {
180250

181251
dependencies {
182252
implementation fileTree(dir: "libs", include: ["*.jar"])
253+
183254
//noinspection GradleDynamicVersion
184255
implementation "com.facebook.react:react-native:+" // From node_modules
185256

186257
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
187258

188259
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
189-
exclude group:'com.facebook.fbjni'
260+
exclude group:'com.facebook.fbjni'
190261
}
191262

192263
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
@@ -199,14 +270,31 @@ dependencies {
199270
}
200271

201272
if (enableHermes) {
202-
def hermesPath = "../../node_modules/hermes-engine/android/";
203-
debugImplementation files(hermesPath + "hermes-debug.aar")
204-
releaseImplementation files(hermesPath + "hermes-release.aar")
273+
//noinspection GradleDynamicVersion
274+
implementation("com.facebook.react:hermes-engine:+") { // From node_modules
275+
exclude group:'com.facebook.fbjni'
276+
}
205277
} else {
206278
implementation jscFlavor
207279
}
208280
}
209281

282+
if (isNewArchitectureEnabled()) {
283+
// If new architecture is enabled, we let you build RN from source
284+
// Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
285+
// This will be applied to all the imported transtitive dependency.
286+
configurations.all {
287+
resolutionStrategy.dependencySubstitution {
288+
substitute(module("com.facebook.react:react-native"))
289+
.using(project(":ReactAndroid"))
290+
.because("On New Architecture we're building React Native from source")
291+
substitute(module("com.facebook.react:hermes-engine"))
292+
.using(project(":ReactAndroid:hermes-engine"))
293+
.because("On New Architecture we're building Hermes from source")
294+
}
295+
}
296+
}
297+
210298
// Run this once to be able to run the application with BUCK
211299
// puts all compile dependencies into folder libs for BUCK to use
212300
task copyDownloadableDepsToLibs(type: Copy) {
@@ -215,3 +303,11 @@ task copyDownloadableDepsToLibs(type: Copy) {
215303
}
216304

217305
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
306+
307+
def isNewArchitectureEnabled() {
308+
// To opt-in for the New Architecture, you can either:
309+
// - Set `newArchEnabled` to true inside the `gradle.properties` file
310+
// - Invoke gradle with `-newArchEnabled=true`
311+
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
312+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
313+
}

0 commit comments

Comments
 (0)