Skip to content

Commit

Permalink
fix(android): rn74 forward-port onCatalystInstanceDestroy -> invalidate
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mikehardy committed Nov 16, 2024
1 parent dd979a8 commit 83696ea
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ private boolean isAppDebuggable() throws Exception {
}

@Override
public void onCatalystInstanceDestroy() {
super.onCatalystInstanceDestroy();
public void invalidate() {
super.invalidate();
Log.d(TAG, "instance-destroyed");

Iterator appCheckListenerIterator = mAppCheckListeners.entrySet().iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,26 @@ public final ExecutorService getTransactionalExecutor(String identifier) {
return executorService.getTransactionalExecutor(identifier);
}

@Override
@CallSuper

// This is no longer called as of react-native 0.74 and is only here for
// compatibility with older versions. It delegates to thew new `invalidate`
// method, which all modules should implement now
// Remove this method when minimum supported react-native is 0.74
/** @noinspection removal*/
@SuppressWarnings({"deprecation", "removal"})
@Deprecated
public void onCatalystInstanceDestroy() {
// This should call the child class invalidate, which will then call super.invalidate,
// and everything will work correctly up and down the inheritance hierarchy to shut down
invalidate();
}

// This should have an @Override annotation but we cannot do
// that until our minimum supported react-native version is 0.74, since the
// method did not exist before then
@CallSuper
public void invalidate() {
super.invalidate();
executorService.shutdown();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public void initialize() {
}

@Override
public void onCatalystInstanceDestroy() {
super.onCatalystInstanceDestroy();
public void invalidate() {
super.invalidate();
Log.d(TAG, "instance-destroyed");

Iterator authListenerIterator = mAuthListeners.entrySet().iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public class ReactNativeFirebaseDatabaseQueryModule extends ReactNativeFirebaseM
}

@Override
public void onCatalystInstanceDestroy() {
super.onCatalystInstanceDestroy();
public void invalidate() {
super.invalidate();

Iterator refIterator = queryMap.entrySet().iterator();
while (refIterator.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ public class ReactNativeFirebaseDynamicLinksModule extends ReactNativeFirebaseMo
}

@Override
public void onCatalystInstanceDestroy() {
public void invalidate() {
getReactApplicationContext().removeActivityEventListener(this);
getReactApplicationContext().addLifecycleEventListener(this);
super.onCatalystInstanceDestroy();
super.invalidate();
}

@ReactMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public class ReactNativeFirebaseFirestoreCollectionModule extends ReactNativeFir
}

@Override
public void onCatalystInstanceDestroy() {
super.onCatalystInstanceDestroy();
public void invalidate() {
super.invalidate();

for (int i = 0, size = collectionSnapshotListeners.size(); i < size; i++) {
int key = collectionSnapshotListeners.keyAt(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public class ReactNativeFirebaseFirestoreDocumentModule extends ReactNativeFireb
}

@Override
public void onCatalystInstanceDestroy() {
super.onCatalystInstanceDestroy();
public void invalidate() {
super.invalidate();

for (int i = 0, size = documentSnapshotListeners.size(); i < size; i++) {
int key = documentSnapshotListeners.keyAt(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ReactNativeFirebaseFirestoreTransactionModule extends ReactNativeFi
}

@Override
public void onCatalystInstanceDestroy() {
public void invalidate() {
for (int i = 0, size = transactionHandlers.size(); i < size; i++) {
int key = transactionHandlers.keyAt(i);
ReactNativeFirebaseFirestoreTransactionHandler transactionHandler =
Expand All @@ -57,7 +57,7 @@ public void onCatalystInstanceDestroy() {
}

transactionHandlers.clear();
super.onCatalystInstanceDestroy();
super.invalidate();
}

@ReactMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public class ReactNativeFirebasePerfModule extends ReactNativeFirebaseModule {
}

@Override
public void onCatalystInstanceDestroy() {
super.onCatalystInstanceDestroy();
public void invalidate() {
super.invalidate();
module.onTearDown();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public class ReactNativeFirebaseConfigModule extends ReactNativeFirebaseModule {
}

@Override
public void onCatalystInstanceDestroy() {
super.onCatalystInstanceDestroy();
public void invalidate() {
super.invalidate();

Iterator<Map.Entry<String, ConfigUpdateListenerRegistration>> configRegistrationsIterator =
mConfigUpdateRegistrations.entrySet().iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public class ReactNativeFirebaseStorageModule extends ReactNativeFirebaseModule
}

@Override
public void onCatalystInstanceDestroy() {
public void invalidate() {
ReactNativeFirebaseStorageTask.destroyAllTasks();
super.onCatalystInstanceDestroy();
super.invalidate();
}

/**
Expand Down

0 comments on commit 83696ea

Please sign in to comment.