From 0349ba5d93e29f6ea10d193fd9c08118f5d49f5d Mon Sep 17 00:00:00 2001 From: Mike Hardy Date: Fri, 13 Sep 2024 12:56:38 -0500 Subject: [PATCH] fix(android): support invalidate alongside deprecated onCatalystInstanceDestroy invalidate is the new way to have a hook called when react-native instances are going away, but onCatalystInstanceDestroy is still required for compatibility with older react-native versions --- .../java/io/invertase/notifee/NotifeeApiModule.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/react-native/android/src/main/java/io/invertase/notifee/NotifeeApiModule.java b/packages/react-native/android/src/main/java/io/invertase/notifee/NotifeeApiModule.java index fe16570ba..7ed77c1d1 100644 --- a/packages/react-native/android/src/main/java/io/invertase/notifee/NotifeeApiModule.java +++ b/packages/react-native/android/src/main/java/io/invertase/notifee/NotifeeApiModule.java @@ -36,8 +36,17 @@ public static String getMainComponent(@NonNull String defaultComponent) { return Notifee.getInstance().getMainComponent(defaultComponent); } - @Override + // This method was removed upstream in react-native 0.74+, replaced with invalidate + // We will leave this stub here for older react-native versions compatibility + // ...but it will just delegate to the new invalidate method public void onCatalystInstanceDestroy() { + invalidate(); + } + + // This method was added in react-native 0.74 as a replacement for onCatalystInstanceDestroy + // It should be marked @Override but that would cause problems in apps using older react-native + // When minimum supported version is 0.74+ add @Override & remove onCatalystInstanceDestroy + public void invalidate() { NotifeeReactUtils.clearRunningHeadlessTasks(); }