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()`)
- 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
......
......@@ -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<String, Object> getConstants() {
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;
}
......@@ -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
......
......@@ -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;
......@@ -27,9 +27,7 @@ RCT_EXPORT_MODULE()
- (NSDictionary<NSString *, id> *)constantsToExport
{
NSDictionary<NSString *, id> *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
......
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