Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app, android): react-native 0.65 compatibility #5616

Merged
merged 2 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ public void eventsRemoveListener(String eventName, Boolean all) {
emitter.removeListener(eventName, all);
}

@ReactMethod
public void addListener(String eventName) {
// Keep: Required for RN built in Event Emitter Calls.
}

@ReactMethod
public void removeListeners(Integer count) {
// Keep: Required for RN built in Event Emitter Calls.
}

/** ------------------ META ------------------ */
@ReactMethod
public void metaGetAll(Promise promise) {
Expand Down
8 changes: 4 additions & 4 deletions packages/app/e2e/events.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ describe('Core -> EventEmitter', function () {

await eventsPing(eventName2, eventBody);
await Utils.sleep(500);
const nativeListenersBefore = await eventsGetListeners();
should.equal(nativeListenersBefore.events.ping, undefined);
// const nativeListenersBefore = await eventsGetListeners();
// console.error('we have listeners? ' + JSON.stringify(nativeListenersBefore));
// should.equal(nativeListenersBefore.events.ping, undefined);

const subscription = emitter.addListener(eventName2, event => {
event.foo.should.equal(eventBody.foo);
return resolve();
});

await promise;
emitter.removeSubscription(subscription);
subscription.remove();

await eventsRemoveListener(eventName2, true);
const nativeListenersAfter = await eventsGetListeners();

should.equal(nativeListenersAfter.events.ping, undefined);
});
});
Expand Down
31 changes: 29 additions & 2 deletions packages/app/lib/internal/RNFBNativeEventEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,44 @@ class RNFBNativeEventEmitter extends NativeEventEmitter {
this.ready = true;
}
RNFBAppModule.eventsAddListener(eventType);
return super.addListener(`rnfb_${eventType}`, listener, context);

let subscription = super.addListener(`rnfb_${eventType}`, listener, context);

// React Native 0.65+ altered EventEmitter:
// - removeSubscription is gone
// - addListener returns an unsubscriber instead of a more complex object with eventType etc

// make sure eventType for backwards compatibility just in case
subscription.eventType = `rnfb_${eventType}`;

// New style is to return a remove function on the object, just in csae people call that,
// we will modify it to do our native unsubscription then call the original
let originalRemove = subscription.remove;
let newRemove = () => {
RNFBAppModule.eventsRemoveListener(eventType, false);
if (super.removeSubscription != null) {
// This is for RN <= 0.64 - 65 and greater no longer have removeSubscription
super.removeSubscription(subscription);
} else if (originalRemove != null) {
// This is for RN >= 0.65
originalRemove();
}
};
subscription.remove = newRemove;
return subscription;
}

removeAllListeners(eventType) {
RNFBAppModule.eventsRemoveListener(eventType, true);
super.removeAllListeners(`rnfb_${eventType}`);
}

// This is likely no longer ever called, but it is here for backwards compatibility with RN <= 0.64
removeSubscription(subscription) {
RNFBAppModule.eventsRemoveListener(subscription.eventType.replace('rnfb_'), false);
super.removeSubscription(subscription);
if (super.removeSubscription) {
super.removeSubscription(subscription);
}
}
}

Expand Down
68 changes: 34 additions & 34 deletions tests/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -842,70 +842,70 @@ PODS:
- React-cxxreact (= 0.64.2)
- React-jsi (= 0.64.2)
- React-perflogger (= 0.64.2)
- RNFBAnalytics (12.6.1):
- RNFBAnalytics (12.7.0):
- Firebase/Analytics (= 8.6.0)
- React-Core
- RNFBApp
- RNFBApp (12.6.1):
- RNFBApp (12.7.0):
- Firebase/CoreOnly (= 8.6.0)
- React-Core
- RNFBAppCheck (12.6.1):
- RNFBAppCheck (12.7.0):
- Firebase/AppCheck (= 8.6.0)
- React-Core
- RNFBApp
- RNFBAppDistribution (12.6.1):
- RNFBAppDistribution (12.7.0):
- Firebase/AppDistribution (= 8.6.0)
- React-Core
- RNFBApp
- RNFBAuth (12.6.1):
- RNFBAuth (12.7.0):
- Firebase/Auth (= 8.6.0)
- React-Core
- RNFBApp
- RNFBCrashlytics (12.6.1):
- RNFBCrashlytics (12.7.0):
- Firebase/Crashlytics (= 8.6.0)
- React-Core
- RNFBApp
- RNFBDatabase (12.6.1):
- RNFBDatabase (12.7.0):
- Firebase/Database (= 8.6.0)
- React-Core
- RNFBApp
- RNFBDynamicLinks (12.6.1):
- RNFBDynamicLinks (12.7.0):
- Firebase/DynamicLinks (= 8.6.0)
- GoogleUtilities/AppDelegateSwizzler
- React-Core
- RNFBApp
- RNFBFirestore (12.6.1):
- RNFBFirestore (12.7.0):
- Firebase/Firestore (= 8.6.0)
- React-Core
- RNFBApp
- RNFBFunctions (12.6.1):
- RNFBFunctions (12.7.0):
- Firebase/Functions (= 8.6.0)
- React-Core
- RNFBApp
- RNFBInAppMessaging (12.6.1):
- RNFBInAppMessaging (12.7.0):
- Firebase/InAppMessaging (= 8.6.0)
- React-Core
- RNFBApp
- RNFBInstallations (12.6.1):
- RNFBInstallations (12.7.0):
- Firebase/Installations (= 8.6.0)
- React-Core
- RNFBApp
- RNFBMessaging (12.6.1):
- RNFBMessaging (12.7.0):
- Firebase/Messaging (= 8.6.0)
- React-Core
- RNFBApp
- RNFBML (12.6.1):
- RNFBML (12.7.0):
- React-Core
- RNFBApp
- RNFBPerf (12.6.1):
- RNFBPerf (12.7.0):
- Firebase/Performance (= 8.6.0)
- React-Core
- RNFBApp
- RNFBRemoteConfig (12.6.1):
- RNFBRemoteConfig (12.7.0):
- Firebase/RemoteConfig (= 8.6.0)
- React-Core
- RNFBApp
- RNFBStorage (12.6.1):
- RNFBStorage (12.7.0):
- Firebase/Storage (= 8.6.0)
- React-Core
- RNFBApp
Expand Down Expand Up @@ -1149,23 +1149,23 @@ SPEC CHECKSUMS:
React-RCTVibration: 24600e3b1aaa77126989bc58b6747509a1ba14f3
React-runtimeexecutor: a9904c6d0218fb9f8b19d6dd88607225927668f9
ReactCommon: 149906e01aa51142707a10665185db879898e966
RNFBAnalytics: d52a31e8683fd1b6c5667580481676a751d52484
RNFBApp: 884c958fe3256d2cb99cc92f54f00a319cc0aed6
RNFBAppCheck: f315f2d159cc72657d0742d196c48ca490e4da17
RNFBAppDistribution: e2b4697101f15b28dfcec36c6d89c41fe4ce39f4
RNFBAuth: b2ce9c35a5d86149e5aa77ef78392a4100fc676a
RNFBCrashlytics: 149a89db16522c94d62b4ff3a065e040d3f58f0a
RNFBDatabase: a172802ce1aba9219d1881126ef10687b1ed6c82
RNFBDynamicLinks: b267f48119bdd99a049ade51c97e38eafe48112a
RNFBFirestore: 2d0c6d65d3f4c9b4593f1ce2e3895c1b8b372e23
RNFBFunctions: f93c79046252938dac9086d66edba002745766a9
RNFBInAppMessaging: dd4c4348f28ea001f8b14830ffea7a3ae52f2929
RNFBInstallations: 9047285cfaa888977b644047077e1c5264e7f236
RNFBMessaging: 8957f0ee296a3e6470f2de4d9ae3cca1fb97d4f8
RNFBML: dd88f4f3ab120c48737ff3fbe07c2ba5ece1e5d9
RNFBPerf: 90568005e097974a6e37e1aeb26958539609c82b
RNFBRemoteConfig: 721a840bfa9be6a36dc2eb9171dd5a92845c23f7
RNFBStorage: 7e2c23848ae27744577581ba882eebfe352ba7f7
RNFBAnalytics: 66b04c5a140c38233988b8e00256f9a785e17873
RNFBApp: 89e2c070a5433a312e00e18d9d31f42fc2634f78
RNFBAppCheck: f940d9eff0c55ce77467f12940259209d2d174a3
RNFBAppDistribution: 00d7dbb6b8e9c398fd00bea113580a2900a6a746
RNFBAuth: d94728591b9f9a7cf1da0fedbd66a85ffba06cce
RNFBCrashlytics: 975aceb73460baabd8c399e47610204d2f3d6a64
RNFBDatabase: 6e03e1f77aa7ead14a75d0699e149534be3ddef4
RNFBDynamicLinks: b5472d7e5ac6b9971226ba5b0c5d78e42f035e39
RNFBFirestore: 1c8404a41b757195bdf3298eca559f060a2b133f
RNFBFunctions: 69b8fa54268d3a1d07735f727ac0ca301c2e05e0
RNFBInAppMessaging: 5f4b45c567b398009a866e8dc3946fb4099a548e
RNFBInstallations: 13cd2eb40595b915befa4e8bf9684fd533e30840
RNFBMessaging: 68663046575dd13f7b4aa0e278fbe2e552613e8d
RNFBML: 2eaf6180094e87f98e029279670d28455a37ac6a
RNFBPerf: fc4d5968348b1bb157ebaf044a218fbd58c2318f
RNFBRemoteConfig: 5d4d2e2d939bc6131bc7bd80633e883f51a25bac
RNFBStorage: 9f646b864b60bb57f60723ae6196156ab1e508e0
Yoga: 575c581c63e0d35c9a83f4b46d01d63abc1100ac

PODFILE CHECKSUM: c61aa64b498060e6a9470f21629e95b1ece6f524
Expand Down