Skip to content

Commit 91332eb

Browse files
authored
Merge pull request #79 from funnyzak/feat/rnlatest
2 parents 85032bc + 87edfbf commit 91332eb

39 files changed

+3930
-2767
lines changed

.flowconfig

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
[ignore]
2+
; We fork some components by platform
3+
.*/*[.]android.js
4+
5+
; Ignore "BUCK" generated dirs
6+
<PROJECT_ROOT>/\.buckd/
7+
8+
; Ignore polyfills
9+
node_modules/react-native/Libraries/polyfills/.*
10+
11+
; Flow doesn't support platforms
12+
.*/Libraries/Utilities/LoadingView.js
13+
14+
.*/node_modules/resolve/test/resolver/malformed_package_json/package\.json$
15+
16+
[untyped]
17+
.*/node_modules/@react-native-community/cli/.*/.*
18+
19+
[include]
20+
21+
[libs]
22+
node_modules/react-native/interface.js
23+
node_modules/react-native/flow/
24+
25+
[options]
26+
emoji=true
27+
28+
exact_by_default=true
29+
30+
format.bracket_spacing=false
31+
32+
module.file_ext=.js
33+
module.file_ext=.json
34+
module.file_ext=.ios.js
35+
36+
munge_underscores=true
37+
38+
module.name_mapper='^react-native/\(.*\)$' -> '<PROJECT_ROOT>/node_modules/react-native/\1'
39+
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\)$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/Image/RelativeImageStub'
40+
41+
suppress_type=$FlowIssue
42+
suppress_type=$FlowFixMe
43+
suppress_type=$FlowFixMeProps
44+
suppress_type=$FlowFixMeState
45+
46+
[lints]
47+
sketchy-null-number=warn
48+
sketchy-null-mixed=warn
49+
sketchy-number=warn
50+
untyped-type-import=warn
51+
nonstrict-import=warn
52+
deprecated-type=warn
53+
unsafe-getters-setters=warn
54+
unnecessary-invariant=warn
55+
56+
[strict]
57+
deprecated-type
58+
nonstrict-import
59+
sketchy-null
60+
unclear-type
61+
unsafe-getters-setters
62+
untyped-import
63+
untyped-type-import
64+
65+
[version]
66+
^0.176.3

.gitignore

Lines changed: 5 additions & 8 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
#
@@ -50,9 +51,10 @@ buck-out/
5051
# For more information about the recommended setup visit:
5152
# https://docs.fastlane.tools/best-practices/source-control/
5253

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

5759
# Bundle artifact
5860
*.jsbundle
@@ -62,8 +64,3 @@ buck-out/
6264
/vendor/bundle/
6365

6466
.eslintcache
65-
66-
**/fastlane/report.xml
67-
**/fastlane/Preview.html
68-
**/fastlane/screenshots
69-
**/fastlane/test_output

.ruby-version

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

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
{
22
"search.exclude": {
33
"**/node_modules": false
4+
},
5+
"[gradle]": {
6+
"files.trimTrailingWhitespace": false,
7+
"spotlessGradle.diagnostics.enable": true,
8+
"spotlessGradle.format.enable": true,
9+
"editor.defaultFormatter": "richardwillis.vscode-spotless-gradle",
10+
"editor.codeActionsOnSave": {
11+
"source.fixAll.spotlessGradle": true
12+
}
413
}
514
}

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
## TODO
4141

42-
- [ ] 升级 RN 到到 **0.69.4**
42+
- [x] 升级 RN 到到 **0.69.4**
4343
- [ ] 升级提醒
4444
- [ ] 上架 App Store、Google Play
4545
- [ ] 通过 cheerio,获取更多的数据,开发交互功能
@@ -57,7 +57,7 @@
5757

5858
## Features
5959

60-
1. 基于 React Native 0.67.2 版本。
60+
1. 基于 React Native 0.69.4 版本。
6161
2. 引入 TypeScript 强类型检查,保证维护性、可读性、稳定性。
6262
3. eslint 代码规范检查,prettier 代码美化、Husky 作为 git hooks 进行代码格式化、规范校验。
6363
4. i18n 集成,支持多国语言。实现了语言切换功能。
@@ -84,7 +84,7 @@
8484

8585
在 MacOS 下开发,在 iOS 为 13+ 的 iPhone Simulator/iPhone 12、Android 9.0 的 AVD 模拟器/Mi Phone 均编译成功运行。
8686

87-
必须安装 NodeJS(16.0+)、Yarn、[Watchman](https://reactnative.cn/docs/environment-setup)
87+
必须安装 NodeJS(16.0+)、Yarn、[Watchman](https://reactnative.cn/docs/environment-setup)JDK 最低要求 11。
8888

8989
- iOS:[CocoaPods](https://reactnative.cn/docs/environment-setup)、Xcode、iOS Simulator。
9090
- Android:Java JDK、Android Studio、Gradle、Android SDK、[Android Home 配置](https://reactnative.cn/docs/environment-setup)[Android 真机](https://reactnative.cn/docs/running-on-device)[Android AVD](https://developer.android.com/studio/run/managing-avds)(建议用真机)。
@@ -110,6 +110,9 @@ $ git clone https://github.com/funnyzak/react-native-v2ex.git && cd react-native
110110
# deps install
111111
$ yarn
112112

113+
# 依赖包额外补丁
114+
yarn postinstall
115+
113116
# ios build
114117
npx pod-install
115118

@@ -265,6 +268,7 @@ cd android
265268
- [react-native-skeleton-placeholder](https://github.com/chramos/react-native-skeleton-placeholder)
266269
- [react-native-actions-sheet](https://github.com/ammarahm-ed/react-native-actions-sheet)
267270
- prettier
271+
- (patch-package)[https://github.com/ds300/patch-package]
268272

269273
## Reference
270274

@@ -288,7 +292,8 @@ cd android
288292
- [v2ex api](https://www.v2ex.com/p/7v9TEc53)
289293
- [v2ex token](https://www.v2ex.com/settings/tokens)
290294
- [react native sample](https://github.com/facebook/react-native)
291-
- [react native typescript sample](https://github.com/react-native-community/react-native-template-typescript) |
295+
- [react native typescript sample](https://github.com/react-native-community/react-native-template-typescript)
296+
- [React Native Upgrade Helper](https://react-native-community.github.io/upgrade-helper/)
292297

293298
## License
294299

android/app/build.gradle

Lines changed: 105 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,12 @@ def jscFlavor = 'org.webkit:android-jsc:+'
121121
def enableHermes = project.ext.react.get("enableHermes", false);
122122

123123
/**
124-
* Architectures to build native code for in debug.
124+
* Architectures to build native code for.
125125
*/
126-
def nativeArchitectures = project.getProperties().get("reactNativeDebugArchitectures")
126+
def reactNativeArchitectures() {
127+
def value = project.getProperties().get("reactNativeArchitectures")
128+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
129+
}
127130

128131
android {
129132
ndkVersion rootProject.ext.ndkVersion
@@ -134,15 +137,84 @@ android {
134137
applicationId "github.funnyzak.v2ex"
135138
minSdkVersion rootProject.ext.minSdkVersion
136139
targetSdkVersion rootProject.ext.targetSdkVersion
137-
versionCode 30
138-
versionName "0.6.5"
140+
versionCode 31
141+
versionName "0.6.6"
142+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
143+
144+
if (isNewArchitectureEnabled()) {
145+
// We configure the NDK build only if you decide to opt-in for the New Architecture.
146+
externalNativeBuild {
147+
ndkBuild {
148+
arguments "APP_PLATFORM=android-21",
149+
"APP_STL=c++_shared",
150+
"NDK_TOOLCHAIN_VERSION=clang",
151+
"GENERATED_SRC_DIR=$buildDir/generated/source",
152+
"PROJECT_BUILD_DIR=$buildDir",
153+
"REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
154+
"REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
155+
"NODE_MODULES_DIR=$rootDir/../node_modules"
156+
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
157+
cppFlags "-std=c++17"
158+
// Make sure this target name is the same you specify inside the
159+
// src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
160+
targets "rntest_appmodules"
161+
}
162+
}
163+
if (!enableSeparateBuildPerCPUArchitecture) {
164+
ndk {
165+
abiFilters (*reactNativeArchitectures())
166+
}
167+
}
168+
}
169+
}
170+
171+
if (isNewArchitectureEnabled()) {
172+
// We configure the NDK build only if you decide to opt-in for the New Architecture.
173+
externalNativeBuild {
174+
ndkBuild {
175+
path "$projectDir/src/main/jni/Android.mk"
176+
}
177+
}
178+
def reactAndroidProjectDir = project(':ReactAndroid').projectDir
179+
def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) {
180+
dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck")
181+
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
182+
into("$buildDir/react-ndk/exported")
183+
}
184+
def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) {
185+
dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck")
186+
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
187+
into("$buildDir/react-ndk/exported")
188+
}
189+
afterEvaluate {
190+
// If you wish to add a custom TurboModule or component locally,
191+
// you should uncomment this line.
192+
// preBuild.dependsOn("generateCodegenArtifactsFromSchema")
193+
preDebugBuild.dependsOn(packageReactNdkDebugLibs)
194+
preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)
195+
196+
// Due to a bug inside AGP, we have to explicitly set a dependency
197+
// between configureNdkBuild* tasks and the preBuild tasks.
198+
// This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
199+
configureNdkBuildRelease.dependsOn(preReleaseBuild)
200+
configureNdkBuildDebug.dependsOn(preDebugBuild)
201+
reactNativeArchitectures().each { architecture ->
202+
tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure {
203+
dependsOn("preDebugBuild")
204+
}
205+
tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure {
206+
dependsOn("preReleaseBuild")
207+
}
208+
}
209+
}
139210
}
211+
140212
splits {
141213
abi {
142214
reset()
143215
enable enableSeparateBuildPerCPUArchitecture
144216
universalApk false // If true, also generate a universal APK
145-
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
217+
include (*reactNativeArchitectures())
146218
}
147219
}
148220
signingConfigs {
@@ -165,11 +237,6 @@ android {
165237
buildTypes {
166238
debug {
167239
signingConfig signingConfigs.debug
168-
if (nativeArchitectures) {
169-
ndk {
170-
abiFilters nativeArchitectures.split(',')
171-
}
172-
}
173240
}
174241
release {
175242
// Caution! In production, you need to generate your own keystore file.
@@ -218,14 +285,31 @@ dependencies {
218285
}
219286

220287
if (enableHermes) {
221-
def hermesPath = "../../node_modules/hermes-engine/android/";
222-
debugImplementation files(hermesPath + "hermes-debug.aar")
223-
releaseImplementation files(hermesPath + "hermes-release.aar")
288+
//noinspection GradleDynamicVersion
289+
implementation("com.facebook.react:hermes-engine:+") { // From node_modules
290+
exclude group:'com.facebook.fbjni'
291+
}
224292
} else {
225293
implementation jscFlavor
226294
}
227295
}
228296

297+
if (isNewArchitectureEnabled()) {
298+
// If new architecture is enabled, we let you build RN from source
299+
// Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
300+
// This will be applied to all the imported transtitive dependency.
301+
configurations.all {
302+
resolutionStrategy.dependencySubstitution {
303+
substitute(module("com.facebook.react:react-native"))
304+
.using(project(":ReactAndroid"))
305+
.because("On New Architecture we're building React Native from source")
306+
substitute(module("com.facebook.react:hermes-engine"))
307+
.using(project(":ReactAndroid:hermes-engine"))
308+
.because("On New Architecture we're building Hermes from source")
309+
}
310+
}
311+
}
312+
229313
// Run this once to be able to run the application with BUCK
230314
// puts all compile dependencies into folder libs for BUCK to use
231315
task copyDownloadableDepsToLibs(type: Copy) {
@@ -234,3 +318,11 @@ task copyDownloadableDepsToLibs(type: Copy) {
234318
}
235319

236320
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
321+
322+
def isNewArchitectureEnabled() {
323+
// To opt-in for the New Architecture, you can either:
324+
// - Set `newArchEnabled` to true inside the `gradle.properties` file
325+
// - Invoke gradle with `-newArchEnabled=true`
326+
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
327+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
328+
}

android/app/src/debug/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
android:usesCleartextTraffic="true"
99
tools:targetApi="28"
1010
tools:ignore="GoogleAppIndexingWarning">
11-
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
11+
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false" />
1212
</application>
1313
</manifest>

android/app/src/debug/java/github/funnyzak/v2ex/ReactNativeFlipper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) Facebook, Inc. and its affiliates.
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
33
*
44
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
55
* directory of this source tree.
@@ -19,6 +19,7 @@
1919
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin;
2020
import com.facebook.flipper.plugins.react.ReactFlipperPlugin;
2121
import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin;
22+
import com.facebook.react.ReactInstanceEventListener;
2223
import com.facebook.react.ReactInstanceManager;
2324
import com.facebook.react.bridge.ReactContext;
2425
import com.facebook.react.modules.network.NetworkingModule;
@@ -51,7 +52,7 @@ public void apply(OkHttpClient.Builder builder) {
5152
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
5253
if (reactContext == null) {
5354
reactInstanceManager.addReactInstanceEventListener(
54-
new ReactInstanceManager.ReactInstanceEventListener() {
55+
new ReactInstanceEventListener() {
5556
@Override
5657
public void onReactContextInitialized(ReactContext reactContext) {
5758
reactInstanceManager.removeReactInstanceEventListener(this);

android/app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
<activity
1414
android:name=".MainActivity"
1515
android:label="@string/app_name"
16-
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
16+
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
1717
android:launchMode="singleTask"
18-
android:windowSoftInputMode="adjustResize">
18+
android:windowSoftInputMode="adjustResize"
19+
android:exported="true">
1920
<intent-filter>
2021
<action android:name="android.intent.action.MAIN" />
2122
<category android:name="android.intent.category.LAUNCHER" />

0 commit comments

Comments
 (0)