Skip to content

Commit 16ac2d5

Browse files
author
caiyg
committed
升级React Native及使用ES6语法改写部分JS
1 parent 9504c19 commit 16ac2d5

File tree

18 files changed

+178
-109
lines changed

18 files changed

+178
-109
lines changed

.flowconfig

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515
# Ignore react and fbjs where there are overlaps, but don't ignore
1616
# anything that react-native relies on
1717
.*/node_modules/fbjs/lib/Map.js
18-
.*/node_modules/fbjs/lib/Promise.js
1918
.*/node_modules/fbjs/lib/fetch.js
2019
.*/node_modules/fbjs/lib/ExecutionEnvironment.js
21-
.*/node_modules/fbjs/lib/isEmpty.js
22-
.*/node_modules/fbjs/lib/crc32.js
2320
.*/node_modules/fbjs/lib/ErrorUtils.js
2421

2522
# Flow has a built-in definition for the 'react' module which we prefer to use
@@ -28,6 +25,11 @@
2825
.*/node_modules/react/lib/React.js
2926
.*/node_modules/react/lib/ReactDOM.js
3027

28+
.*/__mocks__/.*
29+
.*/__tests__/.*
30+
31+
.*/commoner/test/source/widget/share.js
32+
3133
# Ignore commoner tests
3234
.*/node_modules/commoner/test/.*
3335

@@ -40,14 +42,36 @@
4042
# Ignore Website
4143
.*/website/.*
4244

45+
.*/node_modules/is-my-json-valid/test/.*\.json
46+
.*/node_modules/iconv-lite/encodings/tables/.*\.json
47+
.*/node_modules/y18n/test/.*\.json
48+
.*/node_modules/spdx-license-ids/spdx-license-ids.json
49+
.*/node_modules/spdx-exceptions/index.json
50+
.*/node_modules/resolve/test/subdirs/node_modules/a/b/c/x.json
51+
.*/node_modules/resolve/lib/core.json
52+
.*/node_modules/jsonparse/samplejson/.*\.json
53+
.*/node_modules/json5/test/.*\.json
54+
.*/node_modules/ua-parser-js/test/.*\.json
55+
.*/node_modules/builtin-modules/builtin-modules.json
56+
.*/node_modules/binary-extensions/binary-extensions.json
57+
.*/node_modules/url-regex/tlds.json
58+
.*/node_modules/joi/.*\.json
59+
.*/node_modules/isemail/.*\.json
60+
.*/node_modules/tr46/.*\.json
61+
4362
[include]
4463

4564
[libs]
4665
node_modules/react-native/Libraries/react-native/react-native-interface.js
66+
node_modules/react-native/flow
67+
flow/
4768

4869
[options]
4970
module.system=haste
5071

72+
esproposal.class_static_fields=enable
73+
esproposal.class_instance_fields=enable
74+
5175
munge_underscores=true
5276

5377
module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub'
@@ -57,9 +81,9 @@ suppress_type=$FlowIssue
5781
suppress_type=$FlowFixMe
5882
suppress_type=$FixMe
5983

60-
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(2[0-1]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
61-
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-1]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
84+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(2[0-2]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
85+
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-2]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
6286
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
6387

6488
[version]
65-
0.21.0
89+
0.22.0

android/app/app.iml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.facebook.fresco/fresco/0.8.1/jars" />
7373
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.facebook.fresco/imagepipeline-okhttp/0.8.1/jars" />
7474
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.facebook.fresco/imagepipeline/0.8.1/jars" />
75-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.facebook.react/react-native/0.20.1/jars" />
75+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.facebook.react/react-native/0.23.0/jars" />
7676
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/org.webkit/android-jsc/r174650/jars" />
7777
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
7878
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
@@ -98,6 +98,7 @@
9898
<orderEntry type="library" exported="" name="jackson-core-2.2.3" level="project" />
9999
<orderEntry type="library" exported="" name="fbcore-0.8.1" level="project" />
100100
<orderEntry type="library" exported="" name="commons-cli-1.2" level="project" />
101+
<orderEntry type="library" exported="" name="react-native-0.23.0" level="project" />
101102
<orderEntry type="library" exported="" name="recyclerview-v7-23.0.1" level="project" />
102103
<orderEntry type="library" exported="" name="imagepipeline-0.8.1" level="project" />
103104
<orderEntry type="library" exported="" name="android-jsc-r174650" level="project" />
@@ -107,7 +108,6 @@
107108
<orderEntry type="library" exported="" name="bolts-android-1.1.4" level="project" />
108109
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
109110
<orderEntry type="library" exported="" name="drawee-0.8.1" level="project" />
110-
<orderEntry type="library" exported="" name="react-native-0.20.1" level="project" />
111111
<orderEntry type="library" exported="" name="appcompat-v7-23.0.1" level="project" />
112112
<orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" />
113113
<orderEntry type="module" module-name="react-native-camera" exported="" />

android/app/build.gradle

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ import com.android.build.OutputFile
2626
*
2727
* // whether to bundle JS and assets in another build variant (if configured).
2828
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
29-
* // The configuration property is in the format 'bundleIn${productFlavor}${buildType}'
29+
* // The configuration property can be in the following formats
30+
* // 'bundleIn${productFlavor}${buildType}'
31+
* // 'bundleIn${buildType}'
3032
* // bundleInFreeDebug: true,
3133
* // bundleInPaidRelease: true,
3234
* // bundleInBeta: true,
@@ -60,8 +62,7 @@ import com.android.build.OutputFile
6062
apply from: "react.gradle"
6163

6264
/**
63-
* Set this to true to create three separate APKs instead of one:
64-
* - A universal APK that works on all devices
65+
* Set this to true to create two separate APKs instead of one:
6566
* - An APK that only works on ARM devices
6667
* - An APK that only works on x86 devices
6768
* The advantage is the size of the APK is reduced by about 4MB.
@@ -80,9 +81,9 @@ android {
8081
buildToolsVersion "23.0.2"
8182

8283
defaultConfig {
83-
applicationId "io.jchat.android"
84+
applicationId "com.reactjchat"
8485
minSdkVersion 16
85-
targetSdkVersion 22
86+
targetSdkVersion 23
8687
versionCode 1
8788
versionName "1.0"
8889
ndk {
@@ -91,17 +92,16 @@ android {
9192
}
9293
splits {
9394
abi {
94-
enable enableSeparateBuildPerCPUArchitecture
95-
universalApk false
9695
reset()
96+
enable enableSeparateBuildPerCPUArchitecture
97+
universalApk false // If true, also generate a universal APK
9798
include "armeabi-v7a", "x86"
9899
}
99100
}
100101
buildTypes {
101102
release {
102103
minifyEnabled enableProguardInReleaseBuilds
103104
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
104-
minifyEnabled true
105105
}
106106
}
107107
sourceSets {
@@ -135,5 +135,5 @@ dependencies {
135135
compile "com.android.support:appcompat-v7:23.0.1"
136136
compile project(':react-native-camera')
137137
compile project(':Orientation')
138-
compile "com.facebook.react:react-native:0.20.+"
138+
compile "com.facebook.react:react-native:0.23.0"
139139
}

android/app/react.gradle

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,20 @@ gradle.projectsEvaluated {
3030

3131
productFlavors.each { productFlavorName ->
3232
buildTypes.each { buildTypeName ->
33-
// Create variant and source names
34-
def sourceName = "${buildTypeName}"
35-
def targetName = "${sourceName.capitalize()}"
36-
if (productFlavorName) {
37-
sourceName = "${productFlavorName}${targetName}"
38-
}
33+
// Create variant and target names
34+
def targetName = "${productFlavorName.capitalize()}${buildTypeName.capitalize()}"
35+
def targetPath = productFlavorName ?
36+
"${productFlavorName}/${buildTypeName}" :
37+
"${buildTypeName}"
3938

4039
// React js bundle directories
4140
def jsBundleDirConfigName = "jsBundleDir${targetName}"
4241
def jsBundleDir = elvisFile(config."$jsBundleDirConfigName") ?:
43-
file("$buildDir/intermediates/assets/${sourceName}")
42+
file("$buildDir/intermediates/assets/${targetPath}")
4443

45-
def resourcesDirConfigName = "jsBundleDir${targetName}"
44+
def resourcesDirConfigName = "resourcesDir${targetName}"
4645
def resourcesDir = elvisFile(config."${resourcesDirConfigName}") ?:
47-
file("$buildDir/intermediates/res/merged/${sourceName}")
46+
file("$buildDir/intermediates/res/merged/${targetPath}")
4847
def jsBundleFile = file("$jsBundleDir/$bundleAssetName")
4948

5049
// Bundle task name for variant
@@ -73,14 +72,16 @@ gradle.projectsEvaluated {
7372
// Set up dev mode
7473
def devEnabled = !targetName.toLowerCase().contains("release")
7574
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
76-
commandLine "cmd", "/c", "react-native", "bundle", "--platform", "android", "--dev", "${devEnabled}",
75+
commandLine "cmd", "/c", "node", "node_modules/react-native/local-cli/cli.js", "bundle", "--platform", "android", "--dev", "${devEnabled}",
7776
"--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir
7877
} else {
79-
commandLine "react-native", "bundle", "--platform", "android", "--dev", "${devEnabled}",
78+
commandLine "node", "node_modules/react-native/local-cli/cli.js", "bundle", "--platform", "android", "--dev", "${devEnabled}",
8079
"--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir
8180
}
8281

83-
enabled config."bundleIn${targetName}" ?: targetName.toLowerCase().contains("release")
82+
enabled config."bundleIn${targetName}" ||
83+
config."bundleIn${buildTypeName.capitalize()}" ?:
84+
targetName.toLowerCase().contains("release")
8485
}
8586

8687
// Hook bundle${productFlavor}${buildType}JsAndAssets into the android build process

android/app/src/io/jchat/android/JMessageHelper.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -277,25 +277,6 @@ public void selectImageFromLocal() {
277277

278278
}
279279

280-
/**
281-
* JS端调用的检查网络是否连接的方法
282-
* @param callback 回调返回是否显示HeaderView
283-
*/
284-
@ReactMethod
285-
public void checkNetwork(Callback callback) {
286-
mContext = getCurrentActivity();
287-
if (mContext != null) {
288-
ConnectivityManager manager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
289-
NetworkInfo activeInfo = manager.getActiveNetworkInfo();
290-
if (null == activeInfo) {
291-
//显示Header
292-
callback.invoke(true);
293-
} else {
294-
callback.invoke(false);
295-
}
296-
}
297-
}
298-
299280
/**
300281
* JS端调用的获取所有会话的方法
301282
* @param successCallback 回调返回一个Map对象

android/app/src/io/jchat/android/MainActivity.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@
22

33
import android.app.Activity;
44
import android.app.Application;
5+
import android.content.BroadcastReceiver;
6+
import android.content.Context;
57
import android.content.Intent;
8+
import android.content.IntentFilter;
69
import android.content.res.Configuration;
10+
import android.net.ConnectivityManager;
11+
import android.net.NetworkInfo;
712
import android.os.Bundle;
813
import android.view.KeyEvent;
914

15+
import com.facebook.infer.annotation.Assertions;
1016
import com.facebook.react.LifecycleState;
1117
import com.facebook.react.ReactInstanceManager;
1218
import com.facebook.react.ReactRootView;
1319
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
20+
import com.facebook.react.modules.core.DeviceEventManagerModule;
1421
import com.facebook.react.shell.MainReactPackage;
1522
import com.github.yamill.orientation.OrientationPackage;
1623
import com.lwansbrough.RCTCamera.RCTCameraPackage;
@@ -55,7 +62,7 @@ protected void onPause() {
5562
super.onPause();
5663
isForeground = false;
5764
if (mReactInstanceManager != null) {
58-
mReactInstanceManager.onPause();
65+
mReactInstanceManager.onHostPause();
5966
}
6067
JPushInterface.onPause(this);
6168
}
@@ -65,7 +72,7 @@ protected void onResume() {
6572
super.onResume();
6673
isForeground = true;
6774
if (mReactInstanceManager != null) {
68-
mReactInstanceManager.onResume(this, this);
75+
mReactInstanceManager.onHostResume(this, this);
6976
}
7077
JPushInterface.onResume(this);
7178
}
@@ -79,6 +86,11 @@ public void onBackPressed() {
7986
}
8087
}
8188

89+
@Override
90+
protected void onDestroy() {
91+
super.onDestroy();
92+
}
93+
8294
@Override
8395
public boolean onKeyUp(int keyCode, KeyEvent event) {
8496
if (keyCode == KeyEvent.KEYCODE_MENU && mReactInstanceManager != null) {

android/app/src/io/jchat/android/ReactDialogManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import android.app.Dialog;
44
import android.support.annotation.Nullable;
55

6-
import com.facebook.react.uimanager.ReactProp;
76
import com.facebook.react.uimanager.SimpleViewManager;
87
import com.facebook.react.uimanager.ThemedReactContext;
8+
import com.facebook.react.uimanager.annotations.ReactProp;
99

1010
public class ReactDialogManager extends SimpleViewManager<ReactDialog> {
1111
@Override

android/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,9 @@ allprojects {
1616
repositories {
1717
mavenLocal()
1818
jcenter()
19+
maven {
20+
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
21+
url "$projectDir/../../node_modules/react-native/android"
22+
}
1923
}
2024
}

android/gradle.properties

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@
1212
# This option should only be used with decoupled projects. More details, visit
1313
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1414
# org.gradle.parallel=true
15-
#Mon Feb 22 11:24:12 CST 2016
15+
#Wed Apr 20 15:29:16 CST 2016
1616
systemProp.http.proxyHost=192.168.6.252
1717
systemProp.http.proxyPort=18011
1818
android.useDeprecatedNdk=true
19-
MYAPP_RELEASE_STORE_FILE=../../my-release-key.keystore
20-
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
21-
MYAPP_RELEASE_STORE_PASSWORD=cyg1992
22-
MYAPP_RELEASE_KEY_PASSWORD=cyg1992

android/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ rootProject.name = 'ReactJChat'
22

33
include ':app', ':Orientation', ':react-native-camera'
44
project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android')
5-
project(':Orientation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-orientation/android')
5+
project(':Orientation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-orientation/android')

0 commit comments

Comments
 (0)