Commit 465347be authored by Libin Lu's avatar Libin Lu

combine local and remote event android

parent aba18fd0
......@@ -120,8 +120,8 @@
<orderEntry type="library" exported="" name="firebase-iid-9.4.0" level="project" />
<orderEntry type="library" exported="" name="okio-1.9.0" level="project" />
<orderEntry type="library" exported="" name="jsr305-3.0.0" level="project" />
<orderEntry type="library" exported="" name="bolts-tasks-1.4.0" level="project" />
<orderEntry type="library" exported="" name="okhttp-3.4.1" level="project" />
<orderEntry type="library" exported="" name="bolts-tasks-1.4.0" level="project" />
<orderEntry type="library" exported="" name="firebase-common-9.4.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.0.1" level="project" />
<orderEntry type="library" exported="" name="firebase-core-9.4.0" level="project" />
......
......@@ -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();
......
......@@ -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));
}
}
......@@ -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() {
......
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