Skip to content

Instantly share code, notes, and snippets.

@jrmcdona
Created December 26, 2016 18:04
Show Gist options
  • Save jrmcdona/eea8c6a4d952dc604563395e4975a917 to your computer and use it in GitHub Desktop.
Save jrmcdona/eea8c6a4d952dc604563395e4975a917 to your computer and use it in GitHub Desktop.
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component, AsyncStorage } from 'react';
import {
Platform,
View,
Text
} from 'react-native';
import Exponent, {
Notifications,
Permissions
} from 'exponent';
import { Provider } from 'react-redux';
import Store from 'Store';
import Router from 'Router';
import { NavigationContext, NavigationProvider, StackNavigation } from '@exponent/ex-navigation';
import registerForPushNotificationsAsync from 'RegisterForPushNotificationsAsync';
const navigationContext = new NavigationContext({ router: Router, store: Store })
export default class App extends React.Component {
state = {
notification: {},
};
componentWillMount() {
registerForPushNotificationsAsync();
// Handle notifications that are received or selected while the app
// is open. If the app was closed and then opened by tapping the
// notification (rather than just tapping the app icon to open it),
// this function will fire on the next tick after the app starts
// with the notification data.
this._notificationSubscription = Notifications.addListener(this._handleNotification);
}
_handleNotification = (notification) => {
this.setState({ notification: notification });
};
renderNotification() {
console.log('renderNotification')
console.log(this.state.notification)
if(this.state.notification != {})
{
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Origin: {this.state.notification.origin}</Text>
<Text>Data: {JSON.stringify(this.state.notification.data)}</Text>
</View>
);
}
}
render() {
return (
<View style={{ flex: 1, backgroundColor: '#000' }}>
<Provider store={Store}>
<NavigationProvider context={navigationContext}>
<StackNavigation
id="root"
navigatorUID="root"
initialRoute={Platform.OS === 'android' ? 'home' : 'home'}
/>
</NavigationProvider>
</Provider>
{this.renderNotification()}
</View>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment