├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── values │ │ │ │ ├── ids.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── styles.xml │ │ │ │ └── strings.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ ├── activity_test_view.xml │ │ │ │ ├── activity_main.xml │ │ │ │ └── activity_welcome.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── cmacking │ │ │ │ └── reactnativeandroiddemo │ │ │ │ ├── MainActivity.java │ │ │ │ ├── util │ │ │ │ ├── ThemeUtile.java │ │ │ │ └── JSONHelper.java │ │ │ │ ├── RnView │ │ │ │ ├── TestViewActivity.java │ │ │ │ ├── CommonActivity.java │ │ │ │ └── MyRnViewActivity.java │ │ │ │ ├── MyReactPackage.java │ │ │ │ ├── MainApplication.java │ │ │ │ ├── MyActivity.java │ │ │ │ ├── WelcomeActivity.java │ │ │ │ └── MyIntentModule.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── cmacking │ │ │ └── reactnativeandroiddemo │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── example │ │ └── cmacking │ │ └── reactnativeandroiddemo │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── .gitattributes ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── vcs.xml ├── runConfigurations.xml ├── gradle.xml ├── misc.xml └── codeStyles │ └── Project.xml ├── settings.gradle ├── .gitignore ├── index.js ├── package.json ├── gradle.properties ├── README.md ├── src ├── TestView.js ├── RnCommonActivity.js ├── GetAllNativeModules.js └── HelloWorld.js ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | .js linguist-language=JavaScript 2 | .java linguist-language=Android 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenl/ReactNativeAndroidDemo/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenl/ReactNativeAndroidDemo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenl/ReactNativeAndroidDemo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenl/ReactNativeAndroidDemo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenl/ReactNativeAndroidDemo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenl/ReactNativeAndroidDemo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenl/ReactNativeAndroidDemo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenl/ReactNativeAndroidDemo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenl/ReactNativeAndroidDemo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenl/ReactNativeAndroidDemo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenl/ReactNativeAndroidDemo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | include ':react-native-android-fragment' 3 | project(':react-native-android-fragment').projectDir = new File(rootProject.projectDir, 'node_modules/react-native-android-fragment/android') 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/libraries 5 | /.idea/modules.xml 6 | /.idea/workspace.xml 7 | /.idea/caches 8 | /node_modules 9 | .DS_Store 10 | /build 11 | /captures 12 | .externalNativeBuild 13 | -------------------------------------------------------------------------------- /app/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | btn_jumpactivity_str 4 | btn_change_theme_str 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Sep 14 18:12:19 CST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | #21B0DF 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/cmacking/reactnativeandroiddemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.cmacking.reactnativeandroiddemo; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | public class MainActivity extends AppCompatActivity { 7 | 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.activity_main); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_test_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/test/java/com/example/cmacking/reactnativeandroiddemo/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.example.cmacking.reactnativeandroiddemo; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import { AppRegistry } from 'react-native'; 2 | import HelloWorld from './src/HelloWorld'; 3 | import TestView from './src/TestView'; 4 | import GetAllNativeModules from './src/GetAllNativeModules'; 5 | import RnCommonActivity from './src/RnCommonActivity'; 6 | 7 | AppRegistry.registerComponent('HelloWorld', () => HelloWorld); 8 | AppRegistry.registerComponent('TestView', () => TestView); 9 | AppRegistry.registerComponent('GetAllNativeModules', () => GetAllNativeModules); 10 | 11 | AppRegistry.registerComponent('RnCommonActivity', () => RnCommonActivity); 12 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/cmacking/reactnativeandroiddemo/util/ThemeUtile.java: -------------------------------------------------------------------------------- 1 | package com.example.cmacking.reactnativeandroiddemo.util; 2 | 3 | import android.app.Activity; 4 | 5 | import com.example.cmacking.reactnativeandroiddemo.R; 6 | 7 | /** 8 | * 切换主题——工具 9 | */ 10 | 11 | public class ThemeUtile { 12 | 13 | public static boolean night = false; 14 | 15 | 16 | public static void changeTheme(Activity activity){ 17 | if (ThemeUtile.night){ 18 | activity.setTheme(R.style.APPThemeNight); 19 | }else{ 20 | activity.setTheme(R.style.AppTheme); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react_native_demo", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "start": "node node_modules/react-native/local-cli/cli.js start", 7 | "start-by-custom": "node node_modules/react-native/local-cli/cli.js start --port 8082 --host 172.17.3.3", 8 | "test": "jest" 9 | }, 10 | "dependencies": { 11 | "react": "16.4.1", 12 | "react-native": "0.56.0", 13 | "react-native-android-fragment": "^1.1.0" 14 | }, 15 | "devDependencies": { 16 | "babel-jest": "23.4.2", 17 | "babel-preset-react-native": "^5", 18 | "jest": "23.5.0", 19 | "react-test-renderer": "16.4.1" 20 | }, 21 | "jest": { 22 | "preset": "react-native" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ReactNativeAndroidDemo 2 | 3 | ReactNative 基于 Android 中的集成、两端事件调用、Fragment 集成、Callback/Promise 使用 4 | 5 | ## Usage 6 | 7 | step 1:通过 clone 本项目后 `npm install` 安装相关依赖; 8 | 9 | step 2:修改 `~/ReactNativeAndroidDemo/local.properties` 下的 `sdk.dir=/Users/[your computer name]/Library/Android/sdk` ; 10 | 11 | step 3:`npm start` 即可 12 | 13 | ```javascript 14 | NativeModules.MyIntentModule.startActivityFromJSGetResult( 15 | 'com.example.cmacking.reactnativeandroiddemo.MyActivity', 16 | 200, 17 | msg => { 18 | ToastAndroid.show( 19 | 'JS界面:从Activity中传输过来的数据为:' + msg, 20 | ToastAndroid.SHORT 21 | ); 22 | }, 23 | result => { 24 | ToastAndroid.show('JS界面:错误信息为:' + result, ToastAndroid.SHORT); 25 | } 26 | ); 27 | 28 | 项目中使用的 [com.example.cmacking...] 为 Android 项目命名空间 29 | ``` 30 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/cmacking/reactnativeandroiddemo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.cmacking.reactnativeandroiddemo; 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 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.example.cmacking.reactnativeandroiddemo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/cmacking/reactnativeandroiddemo/RnView/TestViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.cmacking.reactnativeandroiddemo.RnView; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | import com.example.cmacking.reactnativeandroiddemo.R; 7 | import com.facebook.react.ReactActivity; 8 | 9 | //public class TestViewActivity extends AppCompatActivity { 10 | // 11 | // @Override 12 | // protected void onCreate(Bundle savedInstanceState) { 13 | // super.onCreate(savedInstanceState); 14 | // setContentView(R.layout.activity_test_view2); 15 | // } 16 | //} 17 | 18 | public class TestViewActivity extends ReactActivity { 19 | 20 | /** 21 | * Returns the name of the main component registered from JavaScript. 22 | * This is used to schedule rendering of the component. 23 | */ 24 | @Override 25 | protected String getMainComponentName() { 26 | return "TestView"; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/TestView.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { 3 | StyleSheet, 4 | Text, 5 | View, 6 | NativeModules, 7 | TouchableNativeFeedback, 8 | Button, 9 | ToastAndroid 10 | } from 'react-native'; 11 | 12 | class TestView extends React.Component { 13 | render() { 14 | return ( 15 | 16 |