Migrate all NativeModules to invalidate()

Summary:
This diff migrates all NativeModules away from onCatalystInstanceDestroy() to the invalidate() method.

Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D26871595

fbshipit-source-id: 132f6b75e485361835769a2b53bc742eefa47b59
This commit is contained in:
Ramanpreet Nara
2021-03-06 20:30:17 -08:00
committed by Facebook GitHub Bot
parent 18c8417290
commit 3f0df9788b
12 changed files with 20 additions and 23 deletions
@@ -893,7 +893,7 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec
}
@Override
public void onCatalystInstanceDestroy() {
public void invalidate() {
ReactApplicationContext context = getReactApplicationContextIfActiveOrWarn();
if (context != null) {
context.removeLifecycleEventListener(this);
@@ -93,7 +93,7 @@ public class LogBoxModule extends NativeLogBoxSpec {
}
@Override
public void onCatalystInstanceDestroy() {
public void invalidate() {
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
@@ -163,8 +163,8 @@ public class AccessibilityInfoModule extends NativeAccessibilityInfoSpec
}
@Override
public void onCatalystInstanceDestroy() {
super.onCatalystInstanceDestroy();
public void invalidate() {
super.invalidate();
ReactApplicationContext applicationContext = getReactApplicationContextIfActiveOrWarn();
if (applicationContext != null) {
@@ -121,8 +121,8 @@ public class AppStateModule extends NativeAppStateSpec
}
@Override
public void onCatalystInstanceDestroy() {
super.onCatalystInstanceDestroy();
public void invalidate() {
super.invalidate();
ReactApplicationContext applicationContext = getReactApplicationContextIfActiveOrWarn();
if (applicationContext != null) {
@@ -129,7 +129,7 @@ public final class TimingModule extends NativeTimingSpec
}
@Override
public void onCatalystInstanceDestroy() {
public void invalidate() {
ReactApplicationContext reactApplicationContext = getReactApplicationContext();
HeadlessJsTaskContext headlessJsTaskContext =
@@ -103,7 +103,7 @@ public class AnimationsDebugModule extends NativeAnimationsDebugModuleSpec {
}
@Override
public void onCatalystInstanceDestroy() {
public void invalidate() {
if (mFrameCallback != null) {
mFrameCallback.stop();
mFrameCallback = null;
@@ -104,11 +104,8 @@ public class DeviceInfoModule extends NativeDeviceInfoSpec implements LifecycleE
}
@Override
public void invalidate() {}
@Override
public void onCatalystInstanceDestroy() {
super.onCatalystInstanceDestroy();
public void invalidate() {
super.invalidate();
ReactApplicationContext applicationContext = getReactApplicationContextIfActiveOrWarn();
if (applicationContext != null) {
@@ -242,8 +242,8 @@ public class DialogModule extends NativeDialogManagerAndroidSpec implements Life
}
@Override
public void onCatalystInstanceDestroy() {
super.onCatalystInstanceDestroy();
public void invalidate() {
super.invalidate();
ReactApplicationContext applicationContext = getReactApplicationContextIfActiveOrWarn();
if (applicationContext != null) {
@@ -196,8 +196,8 @@ public class FrescoModule extends ReactContextBaseJavaModule
}
@Override
public void onCatalystInstanceDestroy() {
super.onCatalystInstanceDestroy();
public void invalidate() {
super.invalidate();
ReactApplicationContext applicationContext = getReactApplicationContextIfActiveOrWarn();
if (applicationContext != null) {
@@ -190,7 +190,7 @@ public final class NetworkingModule extends NativeNetworkingAndroidSpec {
}
@Override
public void onCatalystInstanceDestroy() {
public void invalidate() {
mShuttingDown = true;
cancelAllRequests();
@@ -103,7 +103,7 @@ public final class AsyncStorageModule extends NativeAsyncSQLiteDBStorageSpec
}
@Override
public void onCatalystInstanceDestroy() {
public void invalidate() {
mShuttingDown = true;
}
@@ -545,7 +545,7 @@ public class NetworkingModuleTest {
}
@Test
public void testCancelAllCallsOnCatalystInstanceDestroy() throws Exception {
public void testCancelAllCallsInvalidate() throws Exception {
PowerMockito.mockStatic(OkHttpCallUtil.class);
final int requests = 3;
final Call[] calls = new Call[requests];
@@ -578,7 +578,7 @@ public class NetworkingModuleTest {
}
verify(mHttpClient, times(3)).newCall(any(Request.class));
mNetworkingModule.onCatalystInstanceDestroy();
mNetworkingModule.invalidate();
PowerMockito.verifyStatic(OkHttpCallUtil.class, times(3));
ArgumentCaptor<OkHttpClient> clientArguments = ArgumentCaptor.forClass(OkHttpClient.class);
ArgumentCaptor<Integer> requestIdArguments = ArgumentCaptor.forClass(Integer.class);
@@ -591,7 +591,7 @@ public class NetworkingModuleTest {
}
@Test
public void testCancelSomeCallsOnCatalystInstanceDestroy() throws Exception {
public void testCancelSomeCallsInvalidate() throws Exception {
PowerMockito.mockStatic(OkHttpCallUtil.class);
final int requests = 3;
final Call[] calls = new Call[requests];
@@ -634,7 +634,7 @@ public class NetworkingModuleTest {
// verifyStatic actually does not clear all calls so far, so we have to check for all of them.
// If `cancelTag` would've been called again for the aborted call, we would have had
// `requests + 1` calls.
mNetworkingModule.onCatalystInstanceDestroy();
mNetworkingModule.invalidate();
PowerMockito.verifyStatic(OkHttpCallUtil.class, times(requests));
clientArguments = ArgumentCaptor.forClass(OkHttpClient.class);
requestIdArguments = ArgumentCaptor.forClass(Integer.class);