-
-
Save spencercarli/bcaf2621e4bb646f85942ee5c5bb98f7 to your computer and use it in GitHub Desktop.
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
| import React, { Component } from 'react'; | |
| import { | |
| StyleSheet, | |
| Text, | |
| View, | |
| Platform, | |
| TouchableOpacity, | |
| Alert, | |
| } from 'react-native'; | |
| import OneSignal from 'react-native-onesignal'; | |
| import Toast from 'react-native-root-toast'; | |
| class App extends Component { | |
| componentDidMount() { | |
| OneSignal.configure({ | |
| onNotificationOpened: this.handleNotification, | |
| }); | |
| } | |
| handleNotification(message, data, isActive) { | |
| if (isActive) { | |
| Toast.show(message); | |
| } else { | |
| // TODO: Go to the room | |
| } | |
| } | |
| render() { | |
| return ( | |
| <View style={styles.container}> | |
| <Text style={styles.welcome}> | |
| Welcome to the OneSignal Example! | |
| </Text> | |
| <Text style={styles.instructions}> | |
| Using {Platform.OS}? Cool. | |
| </Text> | |
| {Platform.OS === 'ios' ? | |
| <TouchableOpacity | |
| onPress={() => OneSignal.registerForPushNotifications()} | |
| style={{ padding: 20, backgroundColor: '#3B5998' }} | |
| > | |
| <Text style={{ color: '#fff' }}>Request Push Notification Permission</Text> | |
| </TouchableOpacity> | |
| : null} | |
| </View> | |
| ); | |
| } | |
| } | |
| 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, | |
| }, | |
| }); | |
| export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment