-
Notifications
You must be signed in to change notification settings - Fork 467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(expo): add an Expo config plugin to simplify enabling Next Storage implementation #1145
Open
hassankhan
wants to merge
1
commit into
react-native-async-storage:main
Choose a base branch
from
twodoorsdev:hassankhan/add-expo-config-plugin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "EXPO_NONINTERACTIVE=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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, I think this can be removed, as it'll be released with version specified in package.json