Skip to content

Commit c319205

Browse files
authoredJul 19, 2024··
fix(android)!: replace onCatalystInstanceDestroy with invalidate (#1124)

File tree

4 files changed

+13
-18
lines changed

4 files changed

+13
-18
lines changed
 

‎.changeset/quiet-snakes-count.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-native-async-storage/async-storage": major
3+
---
4+
5+
Support 0.74 (by migrating off deprecated `onCatalystInstanceDestroy`) — unfortunately, this also means that we must bump the minimum supported version to 0.65

‎packages/default-storage/android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncStorageModule.java

+6-16
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.

‎packages/default-storage/package.json

+1-1
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",

‎yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -4238,7 +4238,7 @@ __metadata:
42384238
typescript: "npm:^5.3.0"
42394239
webdriverio: "npm:^8.24.0"
42404240
peerDependencies:
4241-
react-native: ^0.0.0-0 || >=0.60 <1.0
4241+
react-native: ^0.0.0-0 || >=0.65 <1.0
42424242
languageName: unknown
42434243
linkType: soft
42444244

0 commit comments

Comments
 (0)
Please sign in to comment.