Skip to content

Instantly share code, notes, and snippets.

@arnaudambro
Last active December 13, 2020 21:36
Show Gist options
  • Save arnaudambro/ed4ca08e0dc3292f77b10ee4143e72a4 to your computer and use it in GitHub Desktop.
Save arnaudambro/ed4ca08e0dc3292f77b10ee4143e72a4 to your computer and use it in GitHub Desktop.
Adding the notifications code
import React from 'react';
import {SafeAreaView, StyleSheet, View, Text, StatusBar, TouchableOpacity, Platform} from 'react-native';
import Notifications from './NotificationService'
class App extends React.Component {
constructor(props) {
super(props);
Notifications.init(this.handleRegister);
}
handleRegister = token => {
console.log('Device Token Received ', token)
// Make your API call to save the token here
}
componentDidMount() {
Notifications.listen(notification => console.log('do what you need to do', notification);
}
componentWillUnmount() {
Notifications.delete();
}
render() {
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView style={styles.body}>
<TouchableOpacity
accessibilityRole={'button'}
onPress={this.handleNotificationPressWithDelay(10000)}
style={styles.linkContainer}>
<Text style={styles.link}>Notification in 10 seconds</Text>
</TouchableOpacity>
<View style={styles.separator} />
<TouchableOpacity
accessibilityRole={'button'}
onPress={this.handleNotificationPressWithDelay(0)}
style={styles.linkContainer}>
<Text style={styles.link}>Notification now</Text>
</TouchableOpacity>
</SafeAreaView>
</>
);
}
}
// styles in https://github.com/arnaudambro/push-notifications-test/blob/master/front/App.js
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment