-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from EvanBacon/@evanbacon/config-plugin
Created Expo config plugin
- Loading branch information
Showing
4 changed files
with
113 additions
and
0 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
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,49 @@ | ||
const { withEntitlementsPlist, withInfoPlist } = require('@expo/config-plugins') | ||
|
||
const HEALTH_SHARE = 'Allow $(PRODUCT_NAME) to check health info' | ||
const HEALTH_UPDATE = 'Allow $(PRODUCT_NAME) to update health info' | ||
|
||
const withHealthKit = ( | ||
config, | ||
{ healthSharePermission, healthUpdatePermission, isClinicalDataEnabled } = {}, | ||
) => { | ||
// Add permissions | ||
config = withInfoPlist(config, (config) => { | ||
config.modResults.NSHealthShareUsageDescription = | ||
healthSharePermission || | ||
config.modResults.NSHealthShareUsageDescription || | ||
HEALTH_SHARE | ||
config.modResults.NSHealthUpdateUsageDescription = | ||
healthUpdatePermission || | ||
config.modResults.NSHealthUpdateUsageDescription || | ||
HEALTH_UPDATE | ||
|
||
return config | ||
}) | ||
|
||
// Add entitlements. These are automatically synced when using EAS build for production apps. | ||
config = withEntitlementsPlist(config, (config) => { | ||
config.modResults['com.apple.developer.healthkit'] = true | ||
if ( | ||
!Array.isArray(config.modResults['com.apple.developer.healthkit.access']) | ||
) { | ||
config.modResults['com.apple.developer.healthkit.access'] = [] | ||
} | ||
|
||
if (isClinicalDataEnabled) { | ||
config.modResults['com.apple.developer.healthkit.access'].push( | ||
'health-records', | ||
) | ||
|
||
// Remove duplicates | ||
config.modResults['com.apple.developer.healthkit.access'] = [ | ||
...new Set(config.modResults['com.apple.developer.healthkit.access']), | ||
] | ||
} | ||
|
||
return config | ||
}) | ||
|
||
return config | ||
} | ||
module.exports = withHealthKit |
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,59 @@ | ||
# Expo installation | ||
|
||
> This package cannot be used in the "Expo Go" app because [it requires custom native code](https://docs.expo.io/workflow/customizing/). | ||
First install the package with yarn, npm, or [`expo install`](https://docs.expo.io/workflow/expo-cli/#expo-install). | ||
|
||
```sh | ||
expo install react-native-health | ||
``` | ||
|
||
After installing this npm package, add the [config plugin](https://docs.expo.io/guides/config-plugins/) to the [`plugins`](https://docs.expo.io/versions/latest/config/app/#plugins) array of your `app.json` or `app.config.js`: | ||
|
||
```json | ||
{ | ||
"expo": { | ||
"plugins": ["react-native-health"] | ||
} | ||
} | ||
``` | ||
|
||
Next, rebuild your app as described in the ["Adding custom native code"](https://docs.expo.io/workflow/customizing/) guide. | ||
|
||
## API | ||
|
||
The plugin provides props for extra customization. Every time you change the props or plugins, you'll need to rebuild (and `prebuild`) the native app. If no extra properties are added, defaults will be used. | ||
|
||
- `healthSharePermission` (_string_): Sets the iOS `NSHealthShareUsageDescription` permission message to the `Info.plist`. Defaults to `Allow $(PRODUCT_NAME) to check health info`. | ||
- `healthUpdatePermission` (_string_): Sets the iOS `NSHealthUpdateUsageDescription` permission message to the `Info.plist`. Defaults to `Allow $(PRODUCT_NAME) to update health info`. | ||
- `isClinicalDataEnabled` (_boolean_): Adds `health-records` to the `com.apple.developer.healthkit.access` entitlement in the iOS project. Defaults to false. | ||
|
||
`app.config.js` | ||
|
||
```json | ||
{ | ||
"expo": { | ||
"plugins": [ | ||
[ | ||
"react-native-health", | ||
{ | ||
"isClinicalDataEnabled": true, | ||
"healthSharePermission": "Custom health share permission", | ||
"healthUpdatePermission": "Custom health update permission" | ||
} | ||
] | ||
] | ||
} | ||
} | ||
``` | ||
|
||
## Background Processing | ||
|
||
Background processing is not currently supported by this plugin. | ||
|
||
## Capabilities | ||
|
||
This plugin will enable the iOS `com.apple.developer.healthkit` entitlement, but in order to sync this with the bundle identifier' production capabilities you'll need to do one of two things: | ||
|
||
- Automatic: Build the app with [EAS build](https://docs.expo.io/build/introduction/) | ||
- Manual: Visit [Apple developer portal](https://developer.apple.com/account/resources/identifiers/list) and enable the HealthKit capability for your bundle identifier before building for production. This can also be done via Xcode. |
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 |
---|---|---|
|
@@ -26,5 +26,8 @@ | |
}, | ||
"peerDependencies": { | ||
"react-native": ">=0.40.0" | ||
}, | ||
"dependencies": { | ||
"@expo/config-plugins": "^2.0.0" | ||
} | ||
} |