Skip to content

Commit 2cc547a

Browse files
committed
add new React Native
1 parent 2194d89 commit 2cc547a

File tree

19 files changed

+340
-0
lines changed

19 files changed

+340
-0
lines changed

reactapp/.gitignore

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

reactapp/build.gradle

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
apply plugin: 'com.android.application'
2+
android {
3+
compileSdkVersion 23
4+
buildToolsVersion "23.0.2"
5+
6+
defaultConfig {
7+
applicationId "com.allen.reactapp"
8+
minSdkVersion 16
9+
targetSdkVersion 22
10+
versionCode 1
11+
versionName "1.0"
12+
13+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14+
15+
}
16+
buildTypes {
17+
release {
18+
19+
minifyEnabled true
20+
zipAlignEnabled true
21+
pseudoLocalesEnabled true
22+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23+
}
24+
}
25+
}
26+
27+
dependencies {
28+
compile fileTree(dir: 'libs', include: ['*.jar'])
29+
30+
compile 'com.android.support:appcompat-v7:24.1.1'
31+
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha1'
32+
testCompile 'junit:junit:4.12'
33+
compile"com.facebook.react:react-native:+"
34+
35+
}

reactapp/proguard-rules.pro

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
18+
19+
# Disabling obfuscation is useful if you collect stack traces from production crashes
20+
# (unless you are using a system that supports de-obfuscate the stack traces).
21+
-dontobfuscate
22+
23+
# React Native
24+
25+
# Keep our interfaces so they can be used by other ProGuard rules.
26+
# See http://sourceforge.net/p/proguard/bugs/466/
27+
-keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip
28+
-keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters
29+
30+
# Do not strip any method/class that is annotated with @DoNotStrip
31+
-keep @com.facebook.proguard.annotations.DoNotStrip class *
32+
-keepclassmembers class * {
33+
@com.facebook.proguard.annotations.DoNotStrip *;
34+
}
35+
36+
-keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * {
37+
void set*(***);
38+
*** get*();
39+
}
40+
41+
-keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }
42+
-keep class * extends com.facebook.react.bridge.NativeModule { *; }
43+
-keepclassmembers,includedescriptorclasses class * { native <methods>; }
44+
-keepclassmembers class * { @com.facebook.react.uimanager.UIProp <fields>; }
45+
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp <methods>; }
46+
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup <methods>; }
47+
48+
-dontwarn com.facebook.react.**
49+
50+
# okhttp
51+
52+
-keepattributes Signature
53+
-keepattributes *Annotation*
54+
-keep class com.squareup.okhttp.** { *; }
55+
-keep interface com.squareup.okhttp.** { *; }
56+
-dontwarn com.squareup.okhttp.**
57+
58+
# okio
59+
60+
-keep class sun.misc.Unsafe { *; }
61+
-dontwarn java.nio.file.*
62+
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
63+
-dontwarn okio.**
64+
65+
# stetho
66+
67+
-dontwarn com.facebook.stetho.**
68+
69+
# https://github.com/facebook/react-native/issues/6624#
70+
-keep class com.facebook.react.bridge.queue.NativeRunnable { *; }
71+
72+
-keep class com.facebook.imagepipeline.gif.** { *; }
73+
-keep class com.facebook.imagepipeline.webp.** { *; }
74+
75+
-keep class com.tencent.mm.sdk.** {
76+
*;
77+
}
78+
79+
-dontwarn com.tencent.bugly.**
80+
-keep public class com.tencent.bugly.**{*;}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.allen.reactapp;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.allen.reactapp", appContext.getPackageName());
25+
}
26+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest package="com.allen.reactapp"
3+
xmlns:android="http://schemas.android.com/apk/res/android">
4+
<uses-permission android:name="android.permission.INTERNET"/>
5+
/**设置调试 的权限**/
6+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
7+
<application
8+
android:allowBackup="true"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:supportsRtl="true"
12+
android:theme="@style/AppTheme">
13+
<activity android:name=".MainActivity">
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN"/>
16+
17+
<category android:name="android.intent.category.LAUNCHER"/>
18+
</intent-filter>
19+
</activity>
20+
<activity android:name="com.allen.reactapp.MyReactActivity"/>
21+
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/>
22+
23+
</application>
24+
25+
</manifest>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.allen.reactapp;
2+
3+
import android.content.Intent;
4+
import android.os.Bundle;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.view.View;
7+
import android.widget.Button;
8+
9+
public class MainActivity extends AppCompatActivity {
10+
11+
private Button mButton;
12+
13+
@Override
14+
protected void onCreate(Bundle savedInstanceState) {
15+
super.onCreate(savedInstanceState);
16+
setContentView(R.layout.activity_main);
17+
mButton = (Button) findViewById(R.id.btn);
18+
mButton.setOnClickListener(new View.OnClickListener() {
19+
@Override
20+
public void onClick(View view) {
21+
Intent mIntent = new Intent(MainActivity.this,MyReactActivity.class);
22+
startActivity(mIntent);
23+
}
24+
});
25+
}
26+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.allen.reactapp;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
6+
import com.facebook.react.LifecycleState;
7+
import com.facebook.react.ReactInstanceManager;
8+
import com.facebook.react.ReactRootView;
9+
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
10+
import com.facebook.react.shell.MainReactPackage;
11+
12+
/**
13+
* 作者: allen on 16/7/31.
14+
*/
15+
public class MyReactActivity extends Activity implements DefaultHardwareBackBtnHandler {
16+
private ReactRootView mReactRootView;
17+
private ReactInstanceManager mReactInstanceManager;
18+
19+
@Override
20+
protected void onCreate(Bundle savedInstanceState) {
21+
super.onCreate(savedInstanceState);
22+
23+
mReactRootView = new ReactRootView(this);
24+
mReactInstanceManager = ReactInstanceManager.builder()
25+
.setApplication(getApplication())
26+
.setBundleAssetName("index.android.bundle")
27+
.setJSMainModuleName("index.android")
28+
.addPackage(new MainReactPackage())
29+
/**
30+
* http://stackoverflow.com/questions/37951246/react-native-cannot-find-development-server-integrating-existing-android-app
31+
* 调试模式下,建议直接写成 true 吧,我就因为这个错误,调了两天原因
32+
*/
33+
// .setUseDeveloperSupport(BuildConfig.DEBUG)
34+
.setUseDeveloperSupport(true)
35+
.setInitialLifecycleState(LifecycleState.RESUMED)
36+
.build();
37+
mReactRootView.startReactApplication(mReactInstanceManager, "myreactactivity", null);
38+
39+
setContentView(mReactRootView);
40+
}
41+
42+
@Override
43+
public void invokeDefaultOnBackPressed() {
44+
super.onBackPressed();
45+
}
46+
@Override
47+
protected void onPause() {
48+
super.onPause();
49+
50+
if (mReactInstanceManager != null) {
51+
mReactInstanceManager.onHostPause();
52+
}
53+
}
54+
55+
@Override
56+
protected void onResume() {
57+
super.onResume();
58+
59+
if (mReactInstanceManager != null) {
60+
mReactInstanceManager.onHostResume(this, this);
61+
}
62+
}
63+
64+
@Override
65+
public void onBackPressed() {
66+
if (mReactInstanceManager != null) {
67+
mReactInstanceManager.onBackPressed();
68+
} else {
69+
super.onBackPressed();
70+
}
71+
}
72+
73+
74+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.constraint.ConstraintLayout
3+
android:id="@+id/activity_main"
4+
xmlns:android="http://schemas.android.com/apk/res/android"
5+
xmlns:app="http://schemas.android.com/apk/res-auto"
6+
xmlns:tools="http://schemas.android.com/tools"
7+
android:layout_width="match_parent"
8+
android:layout_height="match_parent"
9+
tools:context="com.allen.reactapp.MainActivity">
10+
11+
<Button
12+
android:layout_width="wrap_content"
13+
android:id="@+id/btn"
14+
android:layout_height="wrap_content"
15+
android:text="点我跳转到 ReactNative"
16+
app:layout_constraintLeft_toLeftOf="@+id/activity_main"
17+
android:layout_marginLeft="30dp"
18+
android:layout_marginStart="30dp"
19+
app:layout_constraintTop_toTopOf="@+id/activity_main"
20+
app:layout_constraintRight_toRightOf="@+id/activity_main"
21+
android:layout_marginRight="16dp"
22+
android:layout_marginEnd="16dp"
23+
app:layout_constraintBottom_toBottomOf="@+id/activity_main"/>
24+
25+
</android.support.constraint.ConstraintLayout>
3.34 KB
Loading
2.15 KB
Loading

0 commit comments

Comments
 (0)