Commit 27906420 authored by Amit Davidi's avatar Amit Davidi

Fix initial notification react-method

parent d5682e8b
...@@ -15,3 +15,6 @@ ...@@ -15,3 +15,6 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *; # public *;
#} #}
-keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }
-keep class * extends com.facebook.react.bridge.NativeModule { *; }
...@@ -16,8 +16,13 @@ const styles = StyleSheet.create({ ...@@ -16,8 +16,13 @@ const styles = StyleSheet.create({
flex: 1, flex: 1,
justifyContent: 'center', justifyContent: 'center',
}, },
mainText: { titleText: {
fontSize: 20, fontSize: 22,
textAlign: 'center',
margin: 10,
},
bodyText: {
fontSize: 18,
textAlign: 'center', textAlign: 'center',
margin: 10, margin: 10,
}, },
...@@ -38,8 +43,13 @@ class MainComponent extends Component { ...@@ -38,8 +43,13 @@ class MainComponent extends Component {
NotificationsAndroid.setRegistrationTokenUpdateListener(this.onPushRegistered.bind(this)); NotificationsAndroid.setRegistrationTokenUpdateListener(this.onPushRegistered.bind(this));
NotificationsAndroid.setNotificationOpenedListener(this.onNotificationOpened.bind(this)); NotificationsAndroid.setNotificationOpenedListener(this.onNotificationOpened.bind(this));
NotificationsAndroid.setNotificationReceivedListener(this.onNotificationReceived.bind(this)); NotificationsAndroid.setNotificationReceivedListener(this.onNotificationReceived.bind(this));
}
componentDidMount() {
setInterval(this.onTick.bind(this), 1000); setInterval(this.onTick.bind(this), 1000);
PendingNotifications.getInitialNotification()
.then((notification) => {console.log("getInitialNotification:", notification); this.setState({initialNotification: notification.getData()});})
.catch((err) => console.error("getInitialNotifiation failed", err));
} }
onTick() { onTick() {
...@@ -49,12 +59,10 @@ class MainComponent extends Component { ...@@ -49,12 +59,10 @@ class MainComponent extends Component {
render() { render() {
return ( return (
<View style={styles.container}> <View style={styles.container}>
<TouchableHighlight onPress={() => {console.log("Touch")}}> <Text style={styles.titleText}>Wix React Native Notifications</Text>
<Text style={styles.mainText}>Wix React Native Notifications</Text> <Text style={styles.bodyText}>{this.state.initialNotification ? 'Opened from notification' : ''}</Text>
</TouchableHighlight> <Text style={styles.bodyText}>Last notification: {this.state.lastNotification ? '\n'+this.state.lastNotification.body + ` (opened at ''${this.state.notificationRxTime})` : "N/A"}</Text>
<Text style={styles.mainText}>Last notification:</Text> <Text style={styles.bodyText}>Time elapsed: {this.state.elapsed}</Text>
<Text style={styles.mainText}>{this.state.lastNotification ? this.state.lastNotification.body + ` (opened at ''${this.state.notificationRxTime})` : "N/A"}</Text>
<Text style={styles.mainText}>Time elapsed: {this.state.elapsed}</Text>
</View> </View>
) )
} }
......
require('react'); require('react');
import {NativeModules, DeviceEventEmitter} from 'react-native'; import {NativeModules, DeviceEventEmitter} from 'react-native';
const RNNotifications = NativeModules.WixRNNotification; const RNNotifications = NativeModules.WixRNNotifications;
let notificationReceivedListener; let notificationReceivedListener;
let notificationOpenedListener; let notificationOpenedListener;
...@@ -63,7 +63,7 @@ export class NotificationsAndroid { ...@@ -63,7 +63,7 @@ export class NotificationsAndroid {
} }
} }
export class PendingNotifications { export class PendingNotifications {
static async getInitialNotification() { static async getInitialNotification() {
return new NotificationAndroid(await RNNotifications.getInitialNotification()); return new NotificationAndroid(await RNNotifications.getInitialNotification());
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment