From 23e0427b2b01a1d0a4d45cda833dba45e0e42eff Mon Sep 17 00:00:00 2001 From: kesslern Date: Mon, 23 Dec 2019 20:16:08 -0500 Subject: [PATCH] Fix redux-persist on react-native Use `AsyncStorage` from `@react-native-community/async-storage` https://stackoverflow.com/a/57863264 https://stackoverflow.com/a/57082825 --- android/app/build.gradle | 1 + .../com/jellyfinclient/MainApplication.java | 2 ++ android/settings.gradle | 2 ++ ios/jellyfinclient.xcodeproj/project.pbxproj | 20 ++++++++++++++++++- package.json | 7 ++++--- src/utilities/storage/normalStorage.native.js | 6 ++---- 6 files changed, 30 insertions(+), 8 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 42edbfc..9c2c00d 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -137,6 +137,7 @@ android { } dependencies { + implementation project(':@react-native-community_async-storage') compile project(':react-native-sensitive-info') implementation fileTree(dir: "libs", include: ["*.jar"]) implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}" diff --git a/android/app/src/main/java/com/jellyfinclient/MainApplication.java b/android/app/src/main/java/com/jellyfinclient/MainApplication.java index 27775a5..6b4659a 100644 --- a/android/app/src/main/java/com/jellyfinclient/MainApplication.java +++ b/android/app/src/main/java/com/jellyfinclient/MainApplication.java @@ -3,6 +3,7 @@ import android.app.Application; import com.facebook.react.ReactApplication; +import com.reactnativecommunity.asyncstorage.AsyncStoragePackage; import br.com.classapp.RNSensitiveInfo.RNSensitiveInfoPackage; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; @@ -24,6 +25,7 @@ public boolean getUseDeveloperSupport() { protected List getPackages() { return Arrays.asList( new MainReactPackage(), + new AsyncStoragePackage(), new RNSensitiveInfoPackage() ); } diff --git a/android/settings.gradle b/android/settings.gradle index b7d3b34..81fb68c 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1,4 +1,6 @@ rootProject.name = 'jellyfinclient' +include ':@react-native-community_async-storage' +project(':@react-native-community_async-storage').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/async-storage/android') include ':react-native-sensitive-info' project(':react-native-sensitive-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sensitive-info/android') diff --git a/ios/jellyfinclient.xcodeproj/project.pbxproj b/ios/jellyfinclient.xcodeproj/project.pbxproj index 350c188..858a283 100644 --- a/ios/jellyfinclient.xcodeproj/project.pbxproj +++ b/ios/jellyfinclient.xcodeproj/project.pbxproj @@ -5,7 +5,6 @@ }; objectVersion = 46; objects = { - /* Begin PBXBuildFile section */ 00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */; }; 00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302BA1ABCB90400DB3ED1 /* libRCTGeolocation.a */; }; @@ -40,6 +39,7 @@ 5FD406900E124C86B3DE5B29 /* libRNSensitiveInfo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BC590010BF0D487F949CA09F /* libRNSensitiveInfo.a */; }; 832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; }; ADBDB9381DFEBF1600ED6528 /* libRCTBlob.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ADBDB9271DFEBF0700ED6528 /* libRCTBlob.a */; }; + A96A76A0DC544B7C8393DB34 /* libRNCAsyncStorage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A29F1E2C35C479482608D77 /* libRNCAsyncStorage.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -355,6 +355,8 @@ ADBDB91F1DFEBF0600ED6528 /* RCTBlob.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTBlob.xcodeproj; path = "../node_modules/react-native/Libraries/Blob/RCTBlob.xcodeproj"; sourceTree = ""; }; B26F2711C87340E2AD89A0C5 /* RNSensitiveInfo.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNSensitiveInfo.xcodeproj; path = "../node_modules/react-native-sensitive-info/ios/RNSensitiveInfo.xcodeproj"; sourceTree = ""; }; BC590010BF0D487F949CA09F /* libRNSensitiveInfo.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNSensitiveInfo.a; sourceTree = ""; }; + B45FABDF181745B8952AAD98 /* RNCAsyncStorage.xcodeproj */ = {isa = PBXFileReference; name = "RNCAsyncStorage.xcodeproj"; path = "../node_modules/@react-native-community/async-storage/ios/RNCAsyncStorage.xcodeproj"; sourceTree = ""; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; }; + 3A29F1E2C35C479482608D77 /* libRNCAsyncStorage.a */ = {isa = PBXFileReference; name = "libRNCAsyncStorage.a"; path = "libRNCAsyncStorage.a"; sourceTree = ""; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -384,6 +386,7 @@ 00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */, 139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */, 5FD406900E124C86B3DE5B29 /* libRNSensitiveInfo.a in Frameworks */, + A96A76A0DC544B7C8393DB34 /* libRNCAsyncStorage.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -588,6 +591,7 @@ 00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */, 139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */, B26F2711C87340E2AD89A0C5 /* RNSensitiveInfo.xcodeproj */, + B45FABDF181745B8952AAD98 /* RNCAsyncStorage.xcodeproj */, ); name = Libraries; sourceTree = ""; @@ -1219,6 +1223,7 @@ HEADER_SEARCH_PATHS = ( "$(inherited)", "$(SRCROOT)/../node_modules/react-native-sensitive-info/ios/RNSensitiveInfo", + "$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios", ); INFOPLIST_FILE = jellyfinclientTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.0; @@ -1226,6 +1231,7 @@ LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)/$(TARGET_NAME)\"", + "\"$(SRCROOT)/$(TARGET_NAME)\"", ); OTHER_LDFLAGS = ( "-ObjC", @@ -1245,6 +1251,7 @@ HEADER_SEARCH_PATHS = ( "$(inherited)", "$(SRCROOT)/../node_modules/react-native-sensitive-info/ios/RNSensitiveInfo", + "$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios", ); INFOPLIST_FILE = jellyfinclientTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.0; @@ -1252,6 +1259,7 @@ LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)/$(TARGET_NAME)\"", + "\"$(SRCROOT)/$(TARGET_NAME)\"", ); OTHER_LDFLAGS = ( "-ObjC", @@ -1272,6 +1280,7 @@ HEADER_SEARCH_PATHS = ( "$(inherited)", "$(SRCROOT)/../node_modules/react-native-sensitive-info/ios/RNSensitiveInfo", + "$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios", ); INFOPLIST_FILE = jellyfinclient/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -1294,6 +1303,7 @@ HEADER_SEARCH_PATHS = ( "$(inherited)", "$(SRCROOT)/../node_modules/react-native-sensitive-info/ios/RNSensitiveInfo", + "$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios", ); INFOPLIST_FILE = jellyfinclient/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -1323,12 +1333,14 @@ HEADER_SEARCH_PATHS = ( "$(inherited)", "$(SRCROOT)/../node_modules/react-native-sensitive-info/ios/RNSensitiveInfo", + "$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios", ); INFOPLIST_FILE = "jellyfinclient-tvOS/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)/$(TARGET_NAME)\"", + "\"$(SRCROOT)/$(TARGET_NAME)\"", ); OTHER_LDFLAGS = ( "-ObjC", @@ -1357,12 +1369,14 @@ HEADER_SEARCH_PATHS = ( "$(inherited)", "$(SRCROOT)/../node_modules/react-native-sensitive-info/ios/RNSensitiveInfo", + "$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios", ); INFOPLIST_FILE = "jellyfinclient-tvOS/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)/$(TARGET_NAME)\"", + "\"$(SRCROOT)/$(TARGET_NAME)\"", ); OTHER_LDFLAGS = ( "-ObjC", @@ -1390,12 +1404,14 @@ HEADER_SEARCH_PATHS = ( "$(inherited)", "$(SRCROOT)/../node_modules/react-native-sensitive-info/ios/RNSensitiveInfo", + "$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios", ); INFOPLIST_FILE = "jellyfinclient-tvOSTests/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)/$(TARGET_NAME)\"", + "\"$(SRCROOT)/$(TARGET_NAME)\"", ); OTHER_LDFLAGS = ( "-ObjC", @@ -1423,12 +1439,14 @@ HEADER_SEARCH_PATHS = ( "$(inherited)", "$(SRCROOT)/../node_modules/react-native-sensitive-info/ios/RNSensitiveInfo", + "$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios", ); INFOPLIST_FILE = "jellyfinclient-tvOSTests/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)/$(TARGET_NAME)\"", + "\"$(SRCROOT)/$(TARGET_NAME)\"", ); OTHER_LDFLAGS = ( "-ObjC", diff --git a/package.json b/package.json index 05cec8a..abd4cae 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "windows:release": "react-native bundle --platform=windows --entry-file index.js --assets-dest windows/jellyfinclient/ReactAssets --bundle-output windows/jellyfinclient/ReactAssets/index.windows.bundle --dev false" }, "dependencies": { + "@react-native-community/async-storage": "^1.7.1", "@reduxjs/toolkit": "^1.1.0", "electron-store": "^2.0.0", "electron-store-webpack-wrapper": "^0.0.2", @@ -95,16 +96,16 @@ "electron-packager": "^13.0.1", "eslint": "^5.16.0", "eslint-config-react-app": "^3.0.5", + "eslint-config-standard": "^14.1.0", + "eslint-config-standard-jsx": "^8.1.0", "eslint-loader": "2.1.1", "eslint-plugin-flowtype": "2.50.1", - "eslint-config-standard-jsx": "^8.1.0", - "eslint-config-standard": "^14.1.0", "eslint-plugin-import": "2.14.0", "eslint-plugin-jsx-a11y": "6.1.2", "eslint-plugin-node": "^10.0.0", "eslint-plugin-promise": "^4.2.1", - "eslint-plugin-react-hooks": "^2.3.0", "eslint-plugin-react": "^7.17.0", + "eslint-plugin-react-hooks": "^2.3.0", "eslint-plugin-standard": "^4.0.1", "file-loader": "2.0.0", "fork-ts-checker-webpack-plugin-alt": "0.4.14", diff --git a/src/utilities/storage/normalStorage.native.js b/src/utilities/storage/normalStorage.native.js index ae32def..f02f812 100644 --- a/src/utilities/storage/normalStorage.native.js +++ b/src/utilities/storage/normalStorage.native.js @@ -1,5 +1,3 @@ -import storage from "redux-persist/lib/storage"; +import AsyncStorage from '@react-native-community/async-storage'; -// This file fixes an issue with bundleing in the Metro Bundler with encountering electron-store - -export default storage; +export default AsyncStorage;