-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(expo): add an Expo config plugin to simplify enabling Next Stora…
…ge on Android Fixes #750 Co-Authored-By: Bill Spooner <[email protected]>
- Loading branch information
1 parent
db99ba9
commit f3aa9fc
Showing
11 changed files
with
3,240 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@react-native-async-storage/async-storage-expo-plugin": minor | ||
--- | ||
|
||
Add an Expo config plugin to simplify enabling Next Storage on Android |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("./build"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("@react-native-async-storage/eslint-config"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"name": "@react-native-async-storage/async-storage-expo-plugin", | ||
"version": "1.0.0", | ||
"description": "Asynchronous, persistent, key-value storage system for React Native.", | ||
"main": "build/index.js", | ||
"types": "build/index.d.ts", | ||
"files": [ | ||
"build/", | ||
"src/", | ||
"app.plugin.js" | ||
], | ||
"author": "Two Doors Dev <[email protected]>", | ||
"contributors": [ | ||
"Hassan Khan <[email protected]> (https://github.com/hassankhan)", | ||
"Bill Spooner <[email protected]> (https://github.com/sandyklark)" | ||
], | ||
"homepage": "https://github.com/react-native-async-storage/async-storage#readme", | ||
"license": "MIT", | ||
"keywords": [ | ||
"react-native", | ||
"react native", | ||
"async storage", | ||
"asyncstorage", | ||
"storage", | ||
"expo", | ||
"expo config plugin" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/react-native-async-storage/async-storage.git", | ||
"directory": "packages/default-storage-expo-plugin" | ||
}, | ||
"scripts": { | ||
"prepack": "yarn build", | ||
"prepare": "expo-module prepare", | ||
"prepublishOnly": "expo-module prepublishOnly", | ||
"build": "CI=true expo-module build", | ||
"clean": "expo-module clean", | ||
"lint": "expo-module lint", | ||
"test:ts": "yarn build --noEmit", | ||
"test:lint": "yarn lint" | ||
}, | ||
"devDependencies": { | ||
"@expo/config-plugins": "^8.0.8", | ||
"eslint": "^8.54.0", | ||
"expo-module-scripts": "^3.5.2", | ||
"prettier": "^2.8.8" | ||
}, | ||
"peerDependencies": { | ||
"expo": "^51" | ||
}, | ||
"upstreamPackage": "@react-native-async-storage/async-storage" | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/default-storage-expo-plugin/src/android/withNextStorage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { ConfigPlugin} from "@expo/config-plugins"; | ||
import { withGradleProperties } from "@expo/config-plugins"; | ||
|
||
import type { AsyncStorageOptions } from "../types"; | ||
|
||
export const withNextStorage: ConfigPlugin<AsyncStorageOptions> = ( | ||
config, | ||
props | ||
) => { | ||
const useNextStorage = props?.android?.nextStorage?.enabled ?? false; | ||
|
||
if (!useNextStorage) { | ||
return config; | ||
} | ||
|
||
return withGradleProperties(config, (config) => { | ||
config.modResults.push({ | ||
key: "AsyncStorage_useNextStorage", | ||
value: "true", | ||
type: "property", | ||
}); | ||
|
||
return config; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { ConfigPlugin } from "@expo/config-plugins"; | ||
|
||
import { withNextStorage } from "./android/withNextStorage"; | ||
import type { AsyncStorageOptions } from "./types"; | ||
|
||
const DEFAULT_OPTS: AsyncStorageOptions = { | ||
android: { | ||
nextStorage: { | ||
enabled: false, | ||
}, | ||
}, | ||
}; | ||
|
||
const withAsyncStorage: ConfigPlugin<AsyncStorageOptions> = (config, props) => { | ||
const normalizedProps = { ...DEFAULT_OPTS, ...props }; | ||
config = withNextStorage(config, normalizedProps); | ||
return config; | ||
}; | ||
|
||
export default withAsyncStorage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export type AsyncStorageOptions = { | ||
android: { | ||
nextStorage?: { | ||
enabled: boolean; | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "expo-module-scripts/tsconfig.plugin", | ||
"compilerOptions": { | ||
"outDir": "build", | ||
"rootDir": "src" | ||
}, | ||
"include": ["./src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.