Skip to content

Instantly share code, notes, and snippets.

@ryardley
Last active January 5, 2019 01:22
Show Gist options
  • Save ryardley/9a8d2489e2291ad44b945a4dc0ab9f59 to your computer and use it in GitHub Desktop.
Save ryardley/9a8d2489e2291ad44b945a4dc0ab9f59 to your computer and use it in GitHub Desktop.
React Native the polyglot platform 2
// @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