├── .circleci └── config.yml ├── .flowconfig ├── .gitattributes ├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── android ├── .project ├── .settings │ └── org.eclipse.buildship.core.prefs ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── solinor │ └── bluetoothstatus │ ├── RNBluetoothManagerModule.java │ └── RNBluetoothManagerPackage.java ├── examples ├── BTStatusTest │ ├── .buckconfig │ ├── .eslintrc.js │ ├── .flowconfig │ ├── .gitattributes │ ├── .gitignore │ ├── .prettierrc.js │ ├── .watchmanconfig │ ├── App.js │ ├── AppClass.js │ ├── __tests__ │ │ └── App-test.js │ ├── android │ │ ├── .project │ │ ├── .settings │ │ │ └── org.eclipse.buildship.core.prefs │ │ ├── app │ │ │ ├── _BUCK │ │ │ ├── build.gradle │ │ │ ├── build_defs.bzl │ │ │ ├── debug.keystore │ │ │ ├── proguard-rules.pro │ │ │ └── src │ │ │ │ ├── debug │ │ │ │ └── AndroidManifest.xml │ │ │ │ └── main │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── btstatustest │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ └── MainApplication.java │ │ │ │ └── res │ │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ └── values │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ ├── build.gradle │ │ ├── gradle.properties │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ └── settings.gradle │ ├── app.json │ ├── babel.config.js │ ├── index.js │ ├── ios │ │ ├── BTStatusTest-tvOS │ │ │ └── Info.plist │ │ ├── BTStatusTest-tvOSTests │ │ │ └── Info.plist │ │ ├── BTStatusTest.xcodeproj │ │ │ ├── project.pbxproj │ │ │ └── xcshareddata │ │ │ │ └── xcschemes │ │ │ │ ├── BTStatusTest-tvOS.xcscheme │ │ │ │ └── BTStatusTest.xcscheme │ │ ├── BTStatusTest.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ ├── BTStatusTest │ │ │ ├── AppDelegate.h │ │ │ ├── AppDelegate.m │ │ │ ├── Base.lproj │ │ │ │ └── LaunchScreen.xib │ │ │ ├── Images.xcassets │ │ │ │ ├── AppIcon.appiconset │ │ │ │ │ └── Contents.json │ │ │ │ └── Contents.json │ │ │ ├── Info.plist │ │ │ └── main.m │ │ ├── BTStatusTestTests │ │ │ ├── BTStatusTestTests.m │ │ │ └── Info.plist │ │ ├── Podfile │ │ └── Podfile.lock │ ├── metro.config.js │ ├── package-lock.json │ ├── package.json │ └── yarn.lock └── ManagerTest │ └── android │ └── .project ├── index.d.ts ├── index.js ├── ios ├── RNBluetoothManager.h ├── RNBluetoothManager.m ├── RNBluetoothManager.podspec └── RNBluetoothManager.xcodeproj │ └── project.pbxproj ├── jest.config.js ├── package-lock.json ├── package.json ├── react-native-bluetooth-status.podspec └── yarn.lock /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | defaults: &defaults 2 | docker: 3 | # Choose the version of Node you want here 4 | - image: circleci/node:10.11 5 | working_directory: ~/repo 6 | 7 | version: 2 8 | jobs: 9 | setup: 10 | <<: *defaults 11 | steps: 12 | - checkout 13 | - restore_cache: 14 | name: Restore node modules 15 | keys: 16 | - v1-dependencies-{{ checksum "package.json" }} 17 | # fallback to using the latest cache if no exact match is found 18 | - v1-dependencies- 19 | - run: 20 | name: Install dependencies 21 | command: yarn install 22 | - save_cache: 23 | name: Save node modules 24 | paths: 25 | - node_modules 26 | key: v1-dependencies-{{ checksum "package.json" }} 27 | 28 | tests: 29 | <<: *defaults 30 | steps: 31 | - checkout 32 | - restore_cache: 33 | name: Restore node modules 34 | keys: 35 | - v1-dependencies-{{ checksum "package.json" }} 36 | # fallback to using the latest cache if no exact match is found 37 | - v1-dependencies- 38 | - run: 39 | name: Change Permissions 40 | command: sudo chown -R $(whoami) /usr/local 41 | - run: 42 | name: Run tests 43 | command: yarn ci:test # this command will be added to/found in your package.json scripts 44 | 45 | publish: 46 | <<: *defaults 47 | steps: 48 | - checkout 49 | - run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc 50 | - restore_cache: 51 | name: Restore node modules 52 | keys: 53 | - v1-dependencies-{{ checksum "package.json" }} 54 | # fallback to using the latest cache if no exact match is found 55 | - v1-dependencies- 56 | # Run semantic-release after all the above is set. 57 | - run: 58 | name: Publish to NPM 59 | command: yarn ci:publish 60 | 61 | workflows: 62 | version: 2 63 | test_and_release: 64 | jobs: 65 | - setup 66 | - tests: 67 | requires: 68 | - setup 69 | - publish: 70 | requires: 71 | - tests 72 | filters: 73 | branches: 74 | only: master 75 | -------------------------------------------------------------------------------- /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | .*/examples/ManagerTest/node_modules/.* 3 | ; We fork some components by platform 4 | .*/node_modules/react-native/.*[.]android.js 5 | 6 | .*/Libraries/.*/__flowtests__/.* 7 | 8 | ; Ignore "BUCK" generated dirs 9 | /\.buckd/ 10 | 11 | ; Ignore unexpected extra "@providesModule" 12 | .*/node_modules/.*/node_modules/fbjs/.* 13 | 14 | ; Ignore duplicate module providers 15 | ; For RN Apps installed via npm, "Libraries" folder is inside 16 | ; "node_modules/react-native" but in the source repo it is in the root 17 | .*/Libraries/react-native/React.js 18 | .*/Libraries/react-native/ReactNative.js 19 | 20 | [include] 21 | 22 | [libs] 23 | node_modules/react-native/Libraries/react-native/react-native-interface.js 24 | node_modules/react-native/flow 25 | flow/ 26 | 27 | [options] 28 | emoji=true 29 | 30 | module.system=haste 31 | 32 | munge_underscores=true 33 | 34 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' 35 | 36 | suppress_type=$FlowIssue 37 | suppress_type=$FlowFixMe 38 | suppress_type=$FixMe 39 | 40 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-0]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) 41 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-0]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ 42 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 43 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError 44 | 45 | [version] 46 | ^0.114.0 47 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # OSX 3 | # 4 | .DS_Store 5 | 6 | # node.js 7 | # 8 | node_modules/ 9 | npm-debug.log 10 | yarn-error.log 11 | 12 | 13 | # Xcode 14 | # 15 | build/ 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | xcuserdata 25 | *.xccheckout 26 | *.moved-aside 27 | DerivedData 28 | *.hmap 29 | *.ipa 30 | *.xcuserstate 31 | project.xcworkspace 32 | .vscode/ 33 | 34 | 35 | # Android/IntelliJ 36 | # 37 | build/ 38 | .idea 39 | .gradle 40 | local.properties 41 | *.iml 42 | 43 | # BUCK 44 | buck-out/ 45 | \.buckd/ 46 | *.keystore 47 | 48 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /examples 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017-2019 Juha Linnanen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-bluetooth-status 2 | 3 | React Native library to monitor and manage bluetooth state. Monitoring the bluetooth state works cross-plaform (iOS & Android). 4 | In addition, Android can directly enable / disable bluetooth. 5 | **V2 introduced new Hooks API!** 6 | 7 | ## Installation 8 | 9 | `$ npm install react-native-bluetooth-status --save` 10 | 11 | On RN 0.60+ with autolinking run `pod install` in your `ios/` folder. 12 | 13 | ##### RN < 0.60 14 | 15 | `$ react-native link react-native-bluetooth-status` 16 | 17 |
18 | Manual installation on older RN versions 19 | 20 | #### iOS 21 | 22 | 1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]` 23 | 2. Go to `node_modules` ➜ `react-native-bluetooth-status` and add `RNBluetoothManager.xcodeproj` 24 | 3. In XCode, in the project navigator, select your project. Add `libRNBluetoothManager.a` to your project's `Build Phases` ➜ `Link Binary With Libraries` 25 | 4. Run your project (`Cmd+R`)< 26 | 27 | #### Android 28 | 29 | 1. Open up `android/app/src/main/java/[...]/MainApplication.java` 30 | 31 | 1.1 Add `import com.solinor.bluetoothstatus.RNBluetoothManagerPackage;` to the imports at the top of the file 32 | 33 | 1.2 Add `new RNBluetoothManagerPackage()` to the list returned by the `getPackages()` method in that file 34 | Note: If you add it to the end of the list it should look something like this: 35 | 36 | ``` 37 | @Override 38 | protected List getPackages() { 39 | return Arrays.asList( 40 | new MainReactPackage(), // Note the addtional comma needed for the original last item in the list 41 | new RNBluetoothManagerPackage() // For https://github.com/solinor/react-native-bluetooth-status 42 | ); 43 | } 44 | ``` 45 | 46 | 2. Append the following lines to `android/settings.gradle`: 47 | ``` 48 | include ':react-native-bluetooth-status' 49 | project(':react-native-bluetooth-status').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-bluetooth-status/android') 50 | ``` 51 | 3. Insert the following lines inside the dependencies block in `android/app/build.gradle`: 52 | ``` 53 | compile project(':react-native-bluetooth-status') 54 | ``` 55 | 56 |
57 | ## Usage 58 | 59 | ### Hooks API: 60 | 61 | ```javascript 62 | import { useBluetoothStatus } from 'react-native-bluetooth-status'; 63 | 64 | ... 65 | 66 | const [btStatus, isPending, setBluetooth] = useBluetoothStatus(); 67 | return ( 68 | {!isPending && {btStatus ? 'On' : 'Off'}} 69 |