From 88801bc90194dca79ed53309057643d6e3d1da98 Mon Sep 17 00:00:00 2001 From: Dominik Czupryna Date: Thu, 28 Sep 2023 15:05:59 +0200 Subject: [PATCH 1/2] fix: package export --- docs/index.html | 38 ++++++++++++++++++++++++++++++++++++++ package.json | 6 +++--- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/docs/index.html b/docs/index.html index 16ec03d6..798ab7c3 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1968,6 +1968,44 @@

Creating BLE Manager

Note that you may experience undefined behaviour when calling a function on one BleManager and continuing with another instance. A frequently made error is to create a new instance of the manager for every re-render of a React Native Component.

+

Ask for permissions

+

Check if you requested following permissions

+ +

eg.

+
requestBluetoothPermission = async () => {
+  if (Platform.OS === 'ios') {
+    return true
+  }
+  if (Platform.OS === 'android' && PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION) {
+    const apiLevel = parseInt(Platform.Version.toString(), 10)
+
+    if (apiLevel < 31) {
+      const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION)
+      return granted === PermissionsAndroid.RESULTS.GRANTED
+    }
+    if (PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN && PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT) {
+      const result = await PermissionsAndroid.requestMultiple([
+        PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN,
+        PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT,
+        PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
+      ])
+
+      return (
+        result['android.permission.BLUETOOTH_CONNECT'] === PermissionsAndroid.RESULTS.GRANTED &&
+        result['android.permission.BLUETOOTH_SCAN'] === PermissionsAndroid.RESULTS.GRANTED &&
+        result['android.permission.ACCESS_FINE_LOCATION'] === PermissionsAndroid.RESULTS.GRANTED
+      )
+    }
+  }
+
+  this.showErrorToast('Permission have not been granted')
+
+  return false
+}

Waiting for Powered On state

When iOS application launches BLE stack is not immediately available and we need to check its status. To detect current state and following state changes we can use onStateChange() function:

diff --git a/package.json b/package.json index 03f39e9d..21764412 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,9 @@ "name": "react-native-ble-plx", "version": "3.0.0", "description": "React Native Bluetooth Low Energy library", - "main": "lib/commonjs/index", - "module": "lib/module/index", - "types": "lib/typescript/index.d.ts", + "main": "src/index", + "module": "src/index", + "types": "src/index.d.ts", "react-native": "src/index", "source": "src/index", "files": [ From a6fe5fb5ff84de9a5c8c33c00fae43b95368d16c Mon Sep 17 00:00:00 2001 From: Dominik Czupryna Date: Thu, 28 Sep 2023 15:22:12 +0200 Subject: [PATCH 2/2] fix: readme --- .eslintrc.json | 2 +- README.md | 24 ++++++++++++++---------- __tests__/BleManager.js | 1 + lefthook.yml | 2 +- scripts/copyExampleProjectFiles.js | 9 --------- tsconfig.json | 3 ++- 6 files changed, 19 insertions(+), 22 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 591771fd..f278966f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -8,7 +8,7 @@ }, "overrides": [ { - "files": ["src/**", "integration-tests/**"], + "files": ["src/**", "__tests__/**", "integration-tests/**"], "parser": "hermes-eslint", "extends": [ "plugin:react/recommended", diff --git a/README.md b/README.md index c4e6616a..e0dc4652 100644 --- a/README.md +++ b/README.md @@ -40,21 +40,27 @@ It does NOT support: ## Compatibility -This version (2.x) breaks compatibility with old RN versions. Please check [old README](./docs/README_V1.md) (1.x) +For old RN versions (<0.60) please check [old README](./docs/README_V1.md) (1.x) for the old instructions or [migration guide](./docs/MIGRATION_V1.md). -| React Native | 2.0.0 | +| React Native | 3.0.0 | | ------------ | ------------------ | -| 0.63.3 | :white_check_mark: | -| 0.62.2 | :white_check_mark: | -| 0.61.5 | :white_check_mark: | -| 0.60.6 | :white_check_mark: | +| 0.72.4 | :white_check_mark: | +| 0.71.13 | :white_check_mark: | +| 0.70.13 | :white_check_mark: | ## Recent Changes -**2.0.3** +**3.0.0** -- Updated MultiplatformBleAdapter to version 0.1.9 +- Added Example project +- Updated MultiplatformBleAdapter to version 0.2.0. +- Updated RN bridge config +- Changed CI flow +- Updated CI to RN 0.72.x +- Updated docs +- Updated dependencies +- Fixed iOS 16 bugs [Current version changes](CHANGELOG.md) [All previous changes](CHANGELOG-pre-03.md) @@ -69,8 +75,6 @@ Interested in React Native project involving Bluetooth Low Energy? [We can help Contact us at [intent](https://withintent.com/contact-us/?utm_source=github&utm_medium=github&utm_campaign=external_traffic). -Contact us at [Gitter](https://gitter.im/RxBLELibraries/react-native-ble) if you have any questions, feedback or want to help! - ## Configuration & Installation ### Expo SDK 43+ diff --git a/__tests__/BleManager.js b/__tests__/BleManager.js index 6fd050cb..8e939606 100644 --- a/__tests__/BleManager.js +++ b/__tests__/BleManager.js @@ -1,3 +1,4 @@ +/* eslint-disable no-import-assign */ import { BleManager, Device, Service, Characteristic } from '../src' import { BleErrorCode, BleErrorCodeMessage } from '../src/BleError' import * as Native from '../src/BleModule' diff --git a/lefthook.yml b/lefthook.yml index 22dff0bc..9e3c91c5 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -3,7 +3,7 @@ pre-commit: commands: lint: files: git diff --name-only @{push} - glob: "*.{js,ts,jsx,tsx}" + glob: '*.{js,ts,jsx,tsx}' run: yarn lint commit-msg: parallel: true diff --git a/scripts/copyExampleProjectFiles.js b/scripts/copyExampleProjectFiles.js index c80f3acc..d6246385 100644 --- a/scripts/copyExampleProjectFiles.js +++ b/scripts/copyExampleProjectFiles.js @@ -22,15 +22,6 @@ const copyExampleProjectJsFiles = () => { fs.cpSync(jsSourceDirectory, jsSourceDestinationDirectory, { recursive: true }) } -const androidManifestPath = path.join( - __dirname, - EXAMPLE_PROJECT_DIR_NAME, - 'android', - 'app', - 'src', - 'main', - 'AndroidManifest.xml' -) const androidManifestDestinationPath = path.join( __dirname, TEST_PROJECT_DIR_NAME, diff --git a/tsconfig.json b/tsconfig.json index 0934927f..02de3e9c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,5 +25,6 @@ "strict": true, "target": "esnext", "verbatimModuleSyntax": true - } + }, + "exclude": ["src/**", "__tests__/**", "integration-tests/**"] }