Skip to content

Commit 83696ea

Browse files
committed
fix(android): rn74 forward-port onCatalystInstanceDestroy -> invalidate
onCatalystInstanceDestroy is no longer calld as of rn74, so our teardown methods were not being called so we were orphaning listeners on rn 74+ this forward ports to the new invalidate API for rn74+ but leaves in place the old hook as an override for people on rn73- and just delegates to the new implementation
1 parent dd979a8 commit 83696ea

File tree

11 files changed

+39
-22
lines changed

11 files changed

+39
-22
lines changed

packages/app-check/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ private boolean isAppDebuggable() throws Exception {
100100
}
101101

102102
@Override
103-
public void onCatalystInstanceDestroy() {
104-
super.onCatalystInstanceDestroy();
103+
public void invalidate() {
104+
super.invalidate();
105105
Log.d(TAG, "instance-destroyed");
106106

107107
Iterator appCheckListenerIterator = mAppCheckListeners.entrySet().iterator();

packages/app/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseModule.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,26 @@ public final ExecutorService getTransactionalExecutor(String identifier) {
9292
return executorService.getTransactionalExecutor(identifier);
9393
}
9494

95-
@Override
96-
@CallSuper
95+
96+
// This is no longer called as of react-native 0.74 and is only here for
97+
// compatibility with older versions. It delegates to thew new `invalidate`
98+
// method, which all modules should implement now
99+
// Remove this method when minimum supported react-native is 0.74
100+
/** @noinspection removal*/
101+
@SuppressWarnings({"deprecation", "removal"})
102+
@Deprecated
97103
public void onCatalystInstanceDestroy() {
104+
// This should call the child class invalidate, which will then call super.invalidate,
105+
// and everything will work correctly up and down the inheritance hierarchy to shut down
106+
invalidate();
107+
}
108+
109+
// This should have an @Override annotation but we cannot do
110+
// that until our minimum supported react-native version is 0.74, since the
111+
// method did not exist before then
112+
@CallSuper
113+
public void invalidate() {
114+
super.invalidate();
98115
executorService.shutdown();
99116
}
100117

packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ public void initialize() {
123123
}
124124

125125
@Override
126-
public void onCatalystInstanceDestroy() {
127-
super.onCatalystInstanceDestroy();
126+
public void invalidate() {
127+
super.invalidate();
128128
Log.d(TAG, "instance-destroyed");
129129

130130
Iterator authListenerIterator = mAuthListeners.entrySet().iterator();

packages/database/android/src/reactnative/java/io/invertase/firebase/database/ReactNativeFirebaseDatabaseQueryModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public class ReactNativeFirebaseDatabaseQueryModule extends ReactNativeFirebaseM
4242
}
4343

4444
@Override
45-
public void onCatalystInstanceDestroy() {
46-
super.onCatalystInstanceDestroy();
45+
public void invalidate() {
46+
super.invalidate();
4747

4848
Iterator refIterator = queryMap.entrySet().iterator();
4949
while (refIterator.hasNext()) {

packages/dynamic-links/android/src/main/java/io/invertase/firebase/dynamiclinks/ReactNativeFirebaseDynamicLinksModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ public class ReactNativeFirebaseDynamicLinksModule extends ReactNativeFirebaseMo
7171
}
7272

7373
@Override
74-
public void onCatalystInstanceDestroy() {
74+
public void invalidate() {
7575
getReactApplicationContext().removeActivityEventListener(this);
7676
getReactApplicationContext().addLifecycleEventListener(this);
77-
super.onCatalystInstanceDestroy();
77+
super.invalidate();
7878
}
7979

8080
@ReactMethod

packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreCollectionModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public class ReactNativeFirebaseFirestoreCollectionModule extends ReactNativeFir
4242
}
4343

4444
@Override
45-
public void onCatalystInstanceDestroy() {
46-
super.onCatalystInstanceDestroy();
45+
public void invalidate() {
46+
super.invalidate();
4747

4848
for (int i = 0, size = collectionSnapshotListeners.size(); i < size; i++) {
4949
int key = collectionSnapshotListeners.keyAt(i);

packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreDocumentModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public class ReactNativeFirebaseFirestoreDocumentModule extends ReactNativeFireb
4343
}
4444

4545
@Override
46-
public void onCatalystInstanceDestroy() {
47-
super.onCatalystInstanceDestroy();
46+
public void invalidate() {
47+
super.invalidate();
4848

4949
for (int i = 0, size = documentSnapshotListeners.size(); i < size; i++) {
5050
int key = documentSnapshotListeners.keyAt(i);

packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreTransactionModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class ReactNativeFirebaseFirestoreTransactionModule extends ReactNativeFi
4545
}
4646

4747
@Override
48-
public void onCatalystInstanceDestroy() {
48+
public void invalidate() {
4949
for (int i = 0, size = transactionHandlers.size(); i < size; i++) {
5050
int key = transactionHandlers.keyAt(i);
5151
ReactNativeFirebaseFirestoreTransactionHandler transactionHandler =
@@ -57,7 +57,7 @@ public void onCatalystInstanceDestroy() {
5757
}
5858

5959
transactionHandlers.clear();
60-
super.onCatalystInstanceDestroy();
60+
super.invalidate();
6161
}
6262

6363
@ReactMethod

packages/perf/android/src/reactnative/java/io/invertase/firebase/perf/ReactNativeFirebasePerfModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public class ReactNativeFirebasePerfModule extends ReactNativeFirebaseModule {
3636
}
3737

3838
@Override
39-
public void onCatalystInstanceDestroy() {
40-
super.onCatalystInstanceDestroy();
39+
public void invalidate() {
40+
super.invalidate();
4141
module.onTearDown();
4242
}
4343

packages/remote-config/android/src/reactnative/java/io/invertase/firebase/config/ReactNativeFirebaseConfigModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public class ReactNativeFirebaseConfigModule extends ReactNativeFirebaseModule {
4545
}
4646

4747
@Override
48-
public void onCatalystInstanceDestroy() {
49-
super.onCatalystInstanceDestroy();
48+
public void invalidate() {
49+
super.invalidate();
5050

5151
Iterator<Map.Entry<String, ConfigUpdateListenerRegistration>> configRegistrationsIterator =
5252
mConfigUpdateRegistrations.entrySet().iterator();

0 commit comments

Comments
 (0)