Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Notifications } from 'expo';
- import React from 'react';
- import { StackNavigator } from 'react-navigation';
- import { TouchableOpacity } from 'react-native';
- import { Entypo } from '@expo/vector-icons';
- import MainTabNavigator from './MainTabNavigator';
- import registerForPushNotificationsAsync from '../api/registerForPushNotificationsAsync';
- import HomeScreen from '../screens/HomeScreen';
- const RootStackNavigator = StackNavigator(
- {
- HomeScreen: {
- screen: HomeScreen,
- navigationOptions: {
- tabBarVisible: false
- }
- },
- Main: {
- screen: MainTabNavigator,
- }
- // other routes objects
- },
- {
- // initialRoute: 'HomeScreen',
- navigationOptions: ({ navigation }) => ({
- headerTitleStyle: {
- fontWeight: 'normal',
- },
- headerLeft:
- <TouchableOpacity
- onPress={() => {
- if(navigation.state.index === 0) {
- navigation.navigate('DrawerOpen');
- } else {
- navigation.navigate('DrawerClose');
- }
- }}
- style={{ padding: 10 }}>
- <Entypo name={navigation.state.index === 0 ? 'menu' : 'chevron-small-left'} size={32} color="#000" >
- </TouchableOpacity>
- }),
- }
- );
- export default class RootNavigator extends React.Component {
- componentDidMount() {
- this._notificationSubscription = this._registerForPushNotifications();
- }
- componentWillUnmount() {
- this._notificationSubscription && this._notificationSubscription.remove();
- }
- render() {
- return <RootStackNavigator />;
- }
- _registerForPushNotifications() {
- // Send our push token over to our backend so we can receive notifications
- // You can comment the following line out if you want to stop receiving
- // a notification every time you open the app. Check out the source
- // for this function in api/registerForPushNotificationsAsync.js
- registerForPushNotificationsAsync();
- // Watch for incoming notifications
- this._notificationSubscription = Notifications.addListener(this._handleNotification);
- }
- _handleNotification = ({ origin, data }) => {
- console.log(`Push notification ${origin} with data: ${JSON.stringify(data)}`);
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement