Commit be48bed0 authored by Libin Lu's avatar Libin Lu

remove initAction and get init data through onResume

parent caa64471
### 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()`) - 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 ### 1.0.11
- change android library version to use 9.+ instead of 9.0.1 so it lives well with other libraries - change android library version to use 9.+ instead of 9.0.1 so it lives well with other libraries
......
...@@ -27,13 +27,10 @@ import java.util.Set; ...@@ -27,13 +27,10 @@ import java.util.Set;
public class FIRMessagingModule extends ReactContextBaseJavaModule implements LifecycleEventListener { public class FIRMessagingModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
private final static String TAG = FIRMessagingModule.class.getCanonicalName(); private final static String TAG = FIRMessagingModule.class.getCanonicalName();
Intent mIntent; Intent currentIntent;
public FIRMessagingModule(ReactApplicationContext reactContext) { public FIRMessagingModule(ReactApplicationContext reactContext) {
super(reactContext); super(reactContext);
mIntent = getCurrentActivity().getIntent();
getReactApplicationContext().addLifecycleEventListener(this); getReactApplicationContext().addLifecycleEventListener(this);
registerTokenRefreshHandler(); registerTokenRefreshHandler();
registerMessageHandler(); registerMessageHandler();
...@@ -42,18 +39,6 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -42,18 +39,6 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
@Override @Override
public Map<String, Object> getConstants() { public Map<String, Object> getConstants() {
Map<String, Object> constants = new HashMap<>(); Map<String, Object> constants = new HashMap<>();
if (mIntent != null) {
if(mIntent.getExtras() != null) {
Map<String, Object> extra = new HashMap<>();
Bundle data = mIntent.getExtras();
Set<String> keysIterator = data.keySet();
for(String key: keysIterator){
extra.put(key, data.get(key));
}
constants.put("initialData", extra);
}
constants.put("initialAction", mIntent.getAction());
}
return constants; return constants;
} }
...@@ -130,17 +115,26 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -130,17 +115,26 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
@Override @Override
public void onHostResume() { public void onHostResume() {
Intent newIntent = getCurrentActivity().getIntent(); Intent newIntent = getCurrentActivity().getIntent();
if(newIntent != mIntent && newIntent != null){ if(newIntent == currentIntent){
Bundle extras = newIntent.getExtras(); return;
if (extras != null) { }
WritableMap params = Arguments.fromBundle(extras); WritableMap params;
WritableMap fcm = Arguments.createMap(); Bundle extras = newIntent.getExtras();
fcm.putString("action", newIntent.getAction()); if (extras != null) {
params.putMap("fcm", fcm); params = Arguments.fromBundle(extras);
sendEvent("FCMNotificationReceived", params); } 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 @Override
......
...@@ -29,13 +29,17 @@ FCM.on = (event, callback) => { ...@@ -29,13 +29,17 @@ FCM.on = (event, callback) => {
FCM.subscribeToTopic = (topic) => { FCM.subscribeToTopic = (topic) => {
FIRMessaging.subscribeToTopic(topic); FIRMessaging.subscribeToTopic(topic);
} };
FCM.unsubscribeFromTopic = (topic) => { FCM.unsubscribeFromTopic = (topic) => {
FIRMessaging.unsubscribeFromTopic(topic); FIRMessaging.unsubscribeFromTopic(topic);
} };
//once doesn't seem to work
DeviceEventEmitter.addListener('FCMInitData', (data)=>{
FCM.initialData = data;
});
FCM.initialData = FIRMessaging.initialData; FCM.initialData = FIRMessaging.initialData;
FCM.initialAction = FIRMessaging.initialAction;
module.exports = FCM; module.exports = FCM;
...@@ -27,9 +27,7 @@ RCT_EXPORT_MODULE() ...@@ -27,9 +27,7 @@ RCT_EXPORT_MODULE()
- (NSDictionary<NSString *, id> *)constantsToExport - (NSDictionary<NSString *, id> *)constantsToExport
{ {
NSDictionary<NSString *, id> *initialNotification = [_bridge.launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] copy]; NSDictionary<NSString *, id> *initialNotification = [_bridge.launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] copy];
return @{@"initialData": RCTNullIfNil(initialNotification)};
NSString *initialAction = [[initialNotification objectForKey:@"aps"] objectForKey:@"category"];
return @{@"initialData": RCTNullIfNil(initialNotification), @"initialAction": RCTNullIfNil(initialAction)};
} }
- (void)dealloc - (void)dealloc
......
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