diff --git a/examples/demo-react-native/android/app/src/main/AndroidManifest.xml b/examples/demo-react-native/android/app/src/main/AndroidManifest.xml index f18334724c..677f07596b 100644 --- a/examples/demo-react-native/android/app/src/main/AndroidManifest.xml +++ b/examples/demo-react-native/android/app/src/main/AndroidManifest.xml @@ -11,6 +11,7 @@ android:targetSdkVersion="22" /> getPackages() { - return Arrays.asList( - new MainReactPackage() - ); - } } diff --git a/examples/demo-react-native/android/app/src/main/java/com/example/MainApplication.java b/examples/demo-react-native/android/app/src/main/java/com/example/MainApplication.java new file mode 100644 index 0000000000..902c9c3fd9 --- /dev/null +++ b/examples/demo-react-native/android/app/src/main/java/com/example/MainApplication.java @@ -0,0 +1,42 @@ +package com.example; + +import android.app.Application; +import android.util.Log; + +import com.facebook.react.ReactApplication; +import com.facebook.react.ReactInstanceManager; +import com.facebook.react.ReactNativeHost; +import com.facebook.react.ReactPackage; +import com.facebook.react.shell.MainReactPackage; +import com.facebook.soloader.SoLoader; + +import java.util.Arrays; +import java.util.List; + +public class MainApplication extends Application implements ReactApplication { + + private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { + @Override + protected boolean getUseDeveloperSupport() { + return BuildConfig.DEBUG; + } + + @Override + protected List getPackages() { + return Arrays.asList( + new MainReactPackage() + ); + } + }; + + @Override + public ReactNativeHost getReactNativeHost() { + return mReactNativeHost; + } + + @Override + public void onCreate() { + super.onCreate(); + SoLoader.init(this, /* native exopackage */ false); + } +} diff --git a/examples/demo-react-native/index.android.js b/examples/demo-react-native/index.android.js index f843700d16..c9c34b08c5 100644 --- a/examples/demo-react-native/index.android.js +++ b/examples/demo-react-native/index.android.js @@ -9,44 +9,47 @@ import { AppRegistry, StyleSheet, Text, - View + View, + TouchableOpacity } from 'react-native'; class example extends Component { + constructor(props) { + super(props); + this.state = { + greeting: undefined + }; + } render() { + if (this.state.greeting) return this.renderAfterButton(); return ( - - - Welcome to React Native! - - - To get started, edit index.android.js + + + Welcome - - Shake or press menu button for dev menu + + Say Hello + + + Say World + + + ); + } + renderAfterButton() { + return ( + + + {this.state.greeting}!!! ); } + onButtonPress(greeting) { + this.setState({ + greeting: greeting + }); + } } -const styles = StyleSheet.create({ - container: { - flex: 1, - justifyContent: 'center', - alignItems: 'center', - backgroundColor: '#F5FCFF', - }, - welcome: { - fontSize: 20, - textAlign: 'center', - margin: 10, - }, - instructions: { - textAlign: 'center', - color: '#333333', - marginBottom: 5, - }, -}); - AppRegistry.registerComponent('example', () => example);