Skip to content

Commit 04873b8

Browse files
authored
fix(android)!: replace onCatalystInstanceDestroy with invalidate (react-native-async-storage#1124)
1 parent 692ec74 commit 04873b8

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncStorageModule.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import com.facebook.react.bridge.Arguments;
1616
import com.facebook.react.bridge.Callback;
1717
import com.facebook.react.bridge.GuardedAsyncTask;
18-
import com.facebook.react.bridge.LifecycleEventListener;
1918
import com.facebook.react.bridge.ReactApplicationContext;
2019
import com.facebook.react.bridge.ReactContextBaseJavaModule;
2120
import com.facebook.react.bridge.ReactMethod;
@@ -34,7 +33,7 @@
3433

3534
@ReactModule(name = AsyncStorageModule.NAME)
3635
public final class AsyncStorageModule
37-
extends NativeAsyncStorageModuleSpec implements ModuleDataCleaner.Cleanable, LifecycleEventListener {
36+
extends NativeAsyncStorageModuleSpec implements ModuleDataCleaner.Cleanable {
3837

3938
// changed name to not conflict with AsyncStorage from RN repo
4039
public static final String NAME = "RNCAsyncStorage";
@@ -60,11 +59,12 @@ public AsyncStorageModule(ReactApplicationContext reactContext) {
6059
@VisibleForTesting
6160
AsyncStorageModule(ReactApplicationContext reactContext, Executor executor) {
6261
super(reactContext);
62+
6363
// The migration MUST run before the AsyncStorage database is created for the first time.
6464
AsyncStorageExpoMigration.migrate(reactContext);
6565

6666
this.executor = new SerialExecutor(executor);
67-
reactContext.addLifecycleEventListener(this);
67+
6868
// Creating the database MUST happen after the migration.
6969
mReactDatabaseSupplier = ReactDatabaseSupplier.getInstance(reactContext);
7070
}
@@ -81,8 +81,10 @@ public void initialize() {
8181
}
8282

8383
@Override
84-
public void onCatalystInstanceDestroy() {
84+
public void invalidate() {
8585
mShuttingDown = true;
86+
// ensure we close database when activity is destroyed
87+
mReactDatabaseSupplier.closeDatabase();
8688
}
8789

8890
@Override
@@ -93,18 +95,6 @@ public void clearSensitiveData() {
9395
mReactDatabaseSupplier.clearAndCloseDatabase();
9496
}
9597

96-
@Override
97-
public void onHostResume() {}
98-
99-
@Override
100-
public void onHostPause() {}
101-
102-
@Override
103-
public void onHostDestroy() {
104-
// ensure we close database when activity is destroyed
105-
mReactDatabaseSupplier.closeDatabase();
106-
}
107-
10898
/**
10999
* Given an array of keys, this returns a map of (key, value) pairs for the keys found, and
110100
* (key, null) for the keys that haven't been found.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"merge-options": "^3.0.4"
6767
},
6868
"peerDependencies": {
69-
"react-native": "^0.0.0-0 || >=0.60 <1.0"
69+
"react-native": "^0.0.0-0 || >=0.65 <1.0"
7070
},
7171
"devDependencies": {
7272
"@babel/core": "^7.20.0",

0 commit comments

Comments
 (0)