From be48bed044a59cebdf1f8828e91ab885ed4a2655 Mon Sep 17 00:00:00 2001 From: Libin Lu Date: Mon, 11 Jul 2016 17:41:05 -0400 Subject: [PATCH] remove initAction and get init data through onResume --- CHANGELOG.md | 3 +- .../evollu/react/fcm/FIRMessagingModule.java | 46 ++++++++----------- index.js | 10 ++-- ios/RNFIRMesssaging.m | 4 +- 4 files changed, 30 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7ba15c..c0cf768 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ -### 1.0.12 +### 1.0.12 BREAKING CHANGES - get initial intent inside module, support rn 0.29.0 (for people upgrading from older version, change `new FIRMessagingPackage(getIntent())` back to `new FIRMessagingPackage()`) +- remove initAction as it is just duplication of initData ### 1.0.11 - change android library version to use 9.+ instead of 9.0.1 so it lives well with other libraries 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 d13cfb8..0a926e9 100644 --- a/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java +++ b/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java @@ -27,13 +27,10 @@ import java.util.Set; public class FIRMessagingModule extends ReactContextBaseJavaModule implements LifecycleEventListener { private final static String TAG = FIRMessagingModule.class.getCanonicalName(); - Intent mIntent; + Intent currentIntent; public FIRMessagingModule(ReactApplicationContext reactContext) { super(reactContext); - - mIntent = getCurrentActivity().getIntent(); - getReactApplicationContext().addLifecycleEventListener(this); registerTokenRefreshHandler(); registerMessageHandler(); @@ -42,18 +39,6 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li @Override public Map getConstants() { Map constants = new HashMap<>(); - if (mIntent != null) { - if(mIntent.getExtras() != null) { - Map extra = new HashMap<>(); - Bundle data = mIntent.getExtras(); - Set keysIterator = data.keySet(); - for(String key: keysIterator){ - extra.put(key, data.get(key)); - } - constants.put("initialData", extra); - } - constants.put("initialAction", mIntent.getAction()); - } return constants; } @@ -130,17 +115,26 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li @Override public void onHostResume() { Intent newIntent = getCurrentActivity().getIntent(); - if(newIntent != mIntent && newIntent != null){ - Bundle extras = newIntent.getExtras(); - if (extras != null) { - WritableMap params = Arguments.fromBundle(extras); - WritableMap fcm = Arguments.createMap(); - fcm.putString("action", newIntent.getAction()); - params.putMap("fcm", fcm); - sendEvent("FCMNotificationReceived", params); - } + if(newIntent == currentIntent){ + return; + } + WritableMap params; + Bundle extras = newIntent.getExtras(); + if (extras != null) { + params = Arguments.fromBundle(extras); + } else { + params = Arguments.createMap(); + } + WritableMap fcm = Arguments.createMap(); + fcm.putString("action", newIntent.getAction()); + params.putMap("fcm", fcm); + if (currentIntent == null){ + //the first intent is initial intent that opens the app + sendEvent("FCMInitData", params); + } else { + sendEvent("FCMNotificationReceived", params); } - mIntent = newIntent; + currentIntent = newIntent; } @Override diff --git a/index.js b/index.js index 3200504..d73264d 100644 --- a/index.js +++ b/index.js @@ -29,13 +29,17 @@ FCM.on = (event, callback) => { FCM.subscribeToTopic = (topic) => { FIRMessaging.subscribeToTopic(topic); -} +}; FCM.unsubscribeFromTopic = (topic) => { FIRMessaging.unsubscribeFromTopic(topic); -} +}; + +//once doesn't seem to work +DeviceEventEmitter.addListener('FCMInitData', (data)=>{ + FCM.initialData = data; +}); FCM.initialData = FIRMessaging.initialData; -FCM.initialAction = FIRMessaging.initialAction; module.exports = FCM; diff --git a/ios/RNFIRMesssaging.m b/ios/RNFIRMesssaging.m index f12b5b5..b7d1aa3 100644 --- a/ios/RNFIRMesssaging.m +++ b/ios/RNFIRMesssaging.m @@ -27,9 +27,7 @@ RCT_EXPORT_MODULE() - (NSDictionary *)constantsToExport { NSDictionary *initialNotification = [_bridge.launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] copy]; - - NSString *initialAction = [[initialNotification objectForKey:@"aps"] objectForKey:@"category"]; - return @{@"initialData": RCTNullIfNil(initialNotification), @"initialAction": RCTNullIfNil(initialAction)}; + return @{@"initialData": RCTNullIfNil(initialNotification)}; } - (void)dealloc -- 2.26.2