Skip to content

Commit

Permalink
Merge pull request #1105 from dotintent/feature/add_expo_plugin
Browse files Browse the repository at this point in the history
feat: add expo config plugin
  • Loading branch information
dominik-czupryna-withintent committed Oct 17, 2023
2 parents 0e3d811 + dba51e5 commit 0e9cefe
Show file tree
Hide file tree
Showing 19 changed files with 7,633 additions and 3,876 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**/node_modules/*
node_modules/
docs/**
lib/**
plugin/build
lib/**
11 changes: 11 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@
"max-classes-per-file": "off",
"prettier/prettier": "off"
}
},
{
"files": ["plugin/**"],
"rules": {
"no-underscore-dangle": 0,
"@typescript-eslint/naming-convention": 0,
"import/no-default-export": 0,
"@typescript-eslint/no-shadow": 0,
"global-require": 0,
"@typescript-eslint/no-var-requires": 0
}
}
]
}
4 changes: 4 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ node_modules/warning/.*
!<PROJECT_ROOT>/node_modules/react-native/
<PROJECT_ROOT>/node_modules/react-native/Libraries/DevToolsSettings/DevToolsSettingsManager.d.ts

; Output files
<PROJECT_ROOT>/lib/.*
<PROJECT_ROOT>/test_project/.*

[untyped]
.*/node_modules/@react-native-community/cli/.*/.*

Expand Down
7 changes: 6 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,9 @@ Carthage
docs/

# Tests
__tests__/
__tests__/

# Expo plugin
/plugin/src
/plugin/jest.config.js
/plugin/tsconfig.json
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Outputs
plugin/build
lib
51 changes: 50 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ It does NOT support:
3. [Documentation & Support](#documentation--support)
4. [Configuration & Installation](#configuration--installation)
5. [Troubleshooting](#troubleshooting)
6. [Contributions](#contributions)

## Compatibility

Expand Down Expand Up @@ -79,7 +80,51 @@ Contact us at [intent](https://withintent.com/contact-us/?utm_source=github&utm_

### Expo SDK 43+

1. A custom expo-dev-client can now be built along with config plugins to avoid the need to eject from Expo. Learn how to integrate react-native-ble-plx with Expo [here](https://expo.canny.io/feature-requests/p/bluetooth-1). (only for expo SDK 43+)
> Tested against Expo SDK 49
> 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 [`npx expo install`](https://docs.expo.io/workflow/expo-cli/#expo-install).
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-ble-plx"]
}
}
```

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.

- `isBackgroundEnabled` (_boolean_): Enable background BLE support on Android. Adds `<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>` to the `AndroidManifest.xml`. Default `false`.
- `neverForLocation` (_boolean_): Set to true only if you can strongly assert that your app never derives physical location from Bluetooth scan results. The location permission will be still required on older Android devices. Note, that some BLE beacons are filtered from the scan results. Android SDK 31+. Default `false`. _WARNING: This parameter is experimental and BLE might not work. Make sure to test before releasing to production._
- `modes` (_string[]_): Adds iOS `UIBackgroundModes` to the `Info.plist`. Options are: `peripheral`, and `central`. Defaults to undefined.
- `bluetoothAlwaysPermission` (_string | false_): Sets the iOS `NSBluetoothAlwaysUsageDescription` permission message to the `Info.plist`. Setting `false` will skip adding the permission. Defaults to `Allow $(PRODUCT_NAME) to connect to bluetooth devices`.

> Expo SDK 48 supports iOS 13+ which means `NSBluetoothPeripheralUsageDescription` is fully deprecated. It is no longer setup in `@config-plugins/react-native-ble-plx@5.0.0` and greater.
#### Example

```json
{
"expo": {
"plugins": [
[
"@config-plugins/react-native-ble-plx",
{
"isBackgroundEnabled": true,
"modes": ["peripheral", "central"],
"bluetoothAlwaysPermission": "Allow $(PRODUCT_NAME) to connect to bluetooth devices"
}
]
]
}
}
```

### Legacy Expo (SDK < 43)

Expand Down Expand Up @@ -162,3 +207,7 @@ Contact us at [intent](https://withintent.com/contact-us/?utm_source=github&utm_
With `neverForLocation` flag active, you no longer need to ask for `ACCESS_FINE_LOCATION` in your app

## Troubleshooting

## Contributions

- Special thanks to @EvanBacon for supporting the expo config plugin.
1 change: 1 addition & 0 deletions app.plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./plugin/build/withBLE')
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
roots: ['<rootDir>/__tests__'],
preset: 'react-native'
}
Loading

0 comments on commit 0e9cefe

Please sign in to comment.