Last active
January 5, 2019 01:22
-
-
Save ryardley/9a8d2489e2291ad44b945a4dc0ab9f59 to your computer and use it in GitHub Desktop.
React Native the polyglot platform 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
import React, { Component } from "react"; | |
import { NativeModules, StyleSheet, Text, View } from "react-native"; | |
type Props = {}; | |
type State = { message: string }; | |
const { HelloWorld } = NativeModules; | |
export default class App extends Component<Props, State> { | |
state = { | |
message: "loading..." | |
}; | |
async componentDidMount() { | |
try { | |
const message = await HelloWorld.sayHello(); | |
this.setState({ | |
message | |
}); | |
} catch(e) { | |
alert(e); | |
} | |
} | |
render() { | |
const { message } = this.state; | |
return ( | |
<View style={styles.container}> | |
<Text style={styles.welcome}>Message from Native:</Text> | |
<Text style={styles.welcome}>"{message}"</Text> | |
</View> | |
); | |
} | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
justifyContent: "center", | |
alignItems: "center", | |
backgroundColor: "#F5FCFF" | |
}, | |
welcome: { | |
fontSize: 20, | |
textAlign: "center", | |
margin: 10 | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment