-
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 6c7a374
Showing
11 changed files
with
3,330 additions
and
83 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/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,2 @@ | ||
// @generated by expo-module-scripts | ||
module.exports = require('expo-module-scripts/eslintrc.base.js'); |
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,53 @@ | ||
{ | ||
"name": "@react-native-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.56.0", | ||
"eslint-plugin-prettier": "^5.2.1", | ||
"expo-module-scripts": "^3.5.2", | ||
"prettier": "^3.3.3" | ||
}, | ||
"peerDependencies": { | ||
"expo": "^51" | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
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,24 @@ | ||
import { ConfigPlugin, withGradleProperties } from "@expo/config-plugins"; | ||
|
||
import { 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 { 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,9 @@ | ||
{ | ||
"extends": "expo-module-scripts/tsconfig.plugin", | ||
"compilerOptions": { | ||
"outDir": "build", | ||
"rootDir": "src" | ||
}, | ||
"include": ["./src"], | ||
"exclude": ["**/__mocks__/*", "**/__tests__/*"] | ||
} |
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.