From 279064201032cc3867b31114b8e6349e1d8459fd Mon Sep 17 00:00:00 2001 From: Amit Davidi Date: Wed, 16 Nov 2016 16:16:33 +0200 Subject: [PATCH] Fix initial notification react-method --- .../proguard-rules.pro | 3 +++ example/index.android.js | 24 ++++++++++++------- example/notifications.android.js | 4 ++-- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/example/android/reactnativenotification/proguard-rules.pro b/example/android/reactnativenotification/proguard-rules.pro index d603615..57dcf0f 100644 --- a/example/android/reactnativenotification/proguard-rules.pro +++ b/example/android/reactnativenotification/proguard-rules.pro @@ -15,3 +15,6 @@ #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} + +-keep class * extends com.facebook.react.bridge.JavaScriptModule { *; } +-keep class * extends com.facebook.react.bridge.NativeModule { *; } diff --git a/example/index.android.js b/example/index.android.js index dd4f177..c63a5d3 100644 --- a/example/index.android.js +++ b/example/index.android.js @@ -16,8 +16,13 @@ const styles = StyleSheet.create({ flex: 1, justifyContent: 'center', }, - mainText: { - fontSize: 20, + titleText: { + fontSize: 22, + textAlign: 'center', + margin: 10, + }, + bodyText: { + fontSize: 18, textAlign: 'center', margin: 10, }, @@ -38,8 +43,13 @@ class MainComponent extends Component { NotificationsAndroid.setRegistrationTokenUpdateListener(this.onPushRegistered.bind(this)); NotificationsAndroid.setNotificationOpenedListener(this.onNotificationOpened.bind(this)); NotificationsAndroid.setNotificationReceivedListener(this.onNotificationReceived.bind(this)); + } + componentDidMount() { 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() { @@ -49,12 +59,10 @@ class MainComponent extends Component { render() { return ( - {console.log("Touch")}}> - Wix React Native Notifications - - Last notification: - {this.state.lastNotification ? this.state.lastNotification.body + ` (opened at ''${this.state.notificationRxTime})` : "N/A"} - Time elapsed: {this.state.elapsed} + Wix React Native Notifications + {this.state.initialNotification ? 'Opened from notification' : ''} + Last notification: {this.state.lastNotification ? '\n'+this.state.lastNotification.body + ` (opened at ''${this.state.notificationRxTime})` : "N/A"} + Time elapsed: {this.state.elapsed} ) } diff --git a/example/notifications.android.js b/example/notifications.android.js index 374df89..1fc1026 100644 --- a/example/notifications.android.js +++ b/example/notifications.android.js @@ -1,7 +1,7 @@ require('react'); import {NativeModules, DeviceEventEmitter} from 'react-native'; -const RNNotifications = NativeModules.WixRNNotification; +const RNNotifications = NativeModules.WixRNNotifications; let notificationReceivedListener; let notificationOpenedListener; @@ -63,7 +63,7 @@ export class NotificationsAndroid { } } - export class PendingNotifications { +export class PendingNotifications { static async getInitialNotification() { return new NotificationAndroid(await RNNotifications.getInitialNotification()); } -- 2.26.2