From 465347be0d0edf93656c9600c91c81ae7af80613 Mon Sep 17 00:00:00 2001 From: Libin Lu Date: Wed, 21 Sep 2016 22:55:11 -0400 Subject: [PATCH] combine local and remote event android --- android/react-native-fcm.iml | 2 +- .../java/com/evollu/react/fcm/FIRLocalMessagingHelper.java | 1 - .../main/java/com/evollu/react/fcm/FIRMessagingModule.java | 6 ++---- index.js | 6 ++++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/android/react-native-fcm.iml b/android/react-native-fcm.iml index fa71af8..17bc181 100644 --- a/android/react-native-fcm.iml +++ b/android/react-native-fcm.iml @@ -120,8 +120,8 @@ - + diff --git a/android/src/main/java/com/evollu/react/fcm/FIRLocalMessagingHelper.java b/android/src/main/java/com/evollu/react/fcm/FIRLocalMessagingHelper.java index cbc7bc6..cb2faa7 100644 --- a/android/src/main/java/com/evollu/react/fcm/FIRLocalMessagingHelper.java +++ b/android/src/main/java/com/evollu/react/fcm/FIRLocalMessagingHelper.java @@ -159,7 +159,6 @@ public class FIRLocalMessagingHelper { Intent intent = new Intent(mContext, intentClass); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtras(bundle); - intent.putExtra("localNotification", true); intent.setAction(bundle.getString("click_action")); int notificationID = bundle.containsKey("id") ? bundle.getString("id", "").hashCode() : (int) System.currentTimeMillis(); diff --git a/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java b/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java index a26c6ea..7878692 100644 --- a/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java +++ b/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java @@ -157,7 +157,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li @Override public void onReceive(Context context, Intent intent) { if (getReactApplicationContext().hasActiveCatalystInstance()) { - sendEvent("FCMLocalNotificationReceived", Arguments.fromBundle(intent.getExtras())); + sendEvent("FCMNotificationReceived", Arguments.fromBundle(intent.getExtras())); abortBroadcast(); } } @@ -206,8 +206,6 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li @Override public void onNewIntent(Intent intent){ - Bundle bundle = intent.getExtras(); - Boolean isLocalNotification = bundle != null && bundle.getBoolean("localNotification", false); - sendEvent(isLocalNotification ? "FCMLocalNotificationReceived" : "FCMNotificationReceived", parseIntent(intent)); + sendEvent("FCMNotificationReceived", parseIntent(intent)); } } diff --git a/index.js b/index.js index 14203c2..0d29f00 100644 --- a/index.js +++ b/index.js @@ -2,8 +2,7 @@ import {NativeModules, DeviceEventEmitter, Platform} from 'react-native'; const eventsMap = { refreshToken: 'FCMTokenRefreshed', - notification: 'FCMNotificationReceived', - localNotification: 'FCMLocalNotificationReceived' + notification: 'FCMNotificationReceived' }; const RNFIRMessaging = NativeModules.RNFIRMessaging; @@ -57,6 +56,9 @@ FCM.getBadgeNumber = () => { FCM.on = (event, callback) => { const nativeEvent = eventsMap[event]; + if (!nativeEvent) { + throw new Error('FCM invalid event'); + } const listener = DeviceEventEmitter.addListener(nativeEvent, callback); return function remove() { -- 2.26.2