Skip to content

Commit

Permalink
Docs improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosinigaglia committed Dec 30, 2023
1 parent 05e9bab commit 703fe9c
Show file tree
Hide file tree
Showing 12 changed files with 1,035 additions and 899 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# documentation.

# Sample workflow for building and deploying a Jekyll site to GitHub Pages
name: Deploy Jekyll site to Pages
name: Deploy docs to Pages

on:
push:
Expand Down
896 changes: 2 additions & 894 deletions README.md

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ url: "https://innoveit.github.io"

theme: just-the-docs

color_scheme: dark

aux_links:
"Project on GitHub":
- "//github.com/innoveit/react-native-ble-manager"
- "//github.com/innoveit/react-native-ble-manager"

nav_external_links:
- title: Project on GitHub
url: https://github.com/innoveit/react-native-ble-manager
hide_icon: false
opens_in_new_tab: false
20 changes: 20 additions & 0 deletions docs/_includes/nav_footer_custom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div class="mb-5 pl-5 switch-container">
<label class="switch">
<input type="checkbox" id="theme-switch" />
<span class="slider round">
<span class="icon sun">☀️</span>
<span class="icon moon">🌙</span>
</span>
</label>
</div>
<script>
document
.getElementById("theme-switch")
.addEventListener("change", function (event) {
if (event.target.checked) {
jtd.setTheme("light");
} else {
jtd.setTheme("dark");
}
});
</script>
113 changes: 112 additions & 1 deletion docs/_sass/custom/custom.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,120 @@

.site-title {
@include mq(md) {
font-size: 0.9rem !important;
}

@include mq(lg) {
font-size: 1rem !important;
}
}

.switch-container {
display: none;

@include mq(md) {
display: block;
width: $nav-width-md;
}

@include mq(lg) {
display: block;
width: $nav-width;
}
}

.switch {
position: relative;
display: inline-block;
width: 50px;
height: 25px;
}

.switch input {
opacity: 0;
width: 0;
height: 0;
}

.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}

.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}

input:checked+.slider {
background-color: #2196F3;
}

input:focus+.slider {
box-shadow: 0 0 1px #2196F3;
}

input:checked+.slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}

/* Forma rotonda dello slider */
.slider.round {
border-radius: 34px;
}

.slider.round:before {
border-radius: 50%;
}

.slider:before {
height: 21px;
width: 21px;
left: 2px;
bottom: 2px;
}

.slider {
.icon {
display: none;
position: absolute;
top: 50%;
transform: translateY(-50%);
color: #FFF;
}

/* Icona del sole */
.sun {
left: 4px;
}

/* Icona della luna */
.moon {
right: 4px;
}
}


/* Mostra l'icona appropriata in base allo stato dello switch */
input:checked+.slider .sun {
display: block;
}

input:not(:checked)+.slider .moon {
display: block;
}
15 changes: 15 additions & 0 deletions docs/changelog.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
layout: page
title: Changelog
permalink: /changelog/
nav_order: 100
---

# Changelog

To read all the details go to the [Github Releases section](https://github.com/innoveit/react-native-ble-manager/releases).

## Release v11.0.X

- The iOS module has been completely rewritten in Swift.
- The manufacturerData field has been made consistent between Android and iOS.
163 changes: 163 additions & 0 deletions docs/events.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
---
layout: page
title: Events
permalink: /events/
nav_order: 2
parent: Usage
---

# Events

### BleManagerStopScan

The scanning for peripherals is ended.

**Arguments**

- `status` - `Number` - [iOS] the reason for stopping the scan. Error code 10 is used for timeouts, 0 covers everything else. [Android] the reason for stopping the scan (<https://developer.android.com/reference/android/bluetooth/le/ScanCallback#constants_1>). Error code 10 is used for timeouts

**Examples**

```js
bleManagerEmitter.addListener("BleManagerStopScan", (args) => {
// Scanning is stopped
});
```

### BleManagerDidUpdateState

The BLE change state.

**Arguments**

- `state` - `String` - the new BLE state. can be one of `unknown` (iOS only), `resetting` (iOS only), `unsupported`, `unauthorized` (iOS only), `on`, `off`, `turning_on` (android only), `turning_off` (android only).

**Examples**

```js
bleManagerEmitter.addListener("BleManagerDidUpdateState", (args) => {
// The new state: args.state
});
```

### BleManagerDiscoverPeripheral

The scanning find a new peripheral.

**Arguments**

- `id` - `String` - the id of the peripheral
- `name` - `String` - the name of the peripheral
- `rssi` - `Number` - the RSSI value
- `advertising` - `JSON` - the advertising payload, here are some examples:
- `isConnectable` - `Boolean`
- `serviceUUIDs` - `Array of String`
- `manufacturerData` - `JSON` - contains a json with the company id as field and the custom value as raw `bytes` and `data` (Base64 encoded string)
- `serviceData` - `JSON` - contains the raw `bytes` and `data` (Base64 encoded string)
- `txPowerLevel` - `Int`
- `rawData` - [Android only] `JSON` - contains the raw `bytes` and `data` (Base64 encoded string) of the all advertising data

**Examples**

```js
bleManagerEmitter.addListener("BleManagerDiscoverPeripheral", (args) => {
// The id: args.id
// The name: args.name
});
```

### BleManagerDidUpdateValueForCharacteristic

A characteristic notify a new value.

**Arguments**

- `value``Array` — the read value
- `peripheral``String` — the id of the peripheral
- `characteristic``String` — the UUID of the characteristic
- `service``String` — the UUID of the characteristic

> Event will only be emitted after successful `startNotification`.
**Example**

```js
import { bytesToString } from "convert-string";
import { NativeModules, NativeEventEmitter } from "react-native";

const BleManagerModule = NativeModules.BleManager;
const bleManagerEmitter = new NativeEventEmitter(BleManagerModule);

async function connectAndPrepare(peripheral, service, characteristic) {
// Connect to device
await BleManager.connect(peripheral);
// Before startNotification you need to call retrieveServices
await BleManager.retrieveServices(peripheral);
// To enable BleManagerDidUpdateValueForCharacteristic listener
await BleManager.startNotification(peripheral, service, characteristic);
// Add event listener
bleManagerEmitter.addListener(
"BleManagerDidUpdateValueForCharacteristic",
({ value, peripheral, characteristic, service }) => {
// Convert bytes array to string
const data = bytesToString(value);
console.log(`Received ${data} for characteristic ${characteristic}`);
}
);
// Actions triggereng BleManagerDidUpdateValueForCharacteristic event
}
```

### BleManagerConnectPeripheral

A peripheral was connected.

**Arguments**

- `peripheral` - `String` - the id of the peripheral
- `status` - `Number` - [Android only] connect [`reasons`](<https://developer.android.com/reference/android/bluetooth/BluetoothGattCallback.html#onConnectionStateChange(android.bluetooth.BluetoothGatt,%20int,%20int)>)

### BleManagerDisconnectPeripheral

A peripheral was disconnected.

**Arguments**

- `peripheral` - `String` - the id of the peripheral
- `status` - `Number` - [Android only] disconnect [`reasons`](<https://developer.android.com/reference/android/bluetooth/BluetoothGattCallback.html#onConnectionStateChange(android.bluetooth.BluetoothGatt,%20int,%20int)>)
- `domain` - `String` - [iOS only] disconnect error domain
- `code` - `Number` - [iOS only] disconnect error code (<https://developer.apple.com/documentation/corebluetooth/cberror/code>)

### BleManagerPeripheralDidBond

A bond with a peripheral was established

**Arguments**

Object with information about the device

### BleManagerCentralManagerWillRestoreState [iOS only]

This is fired when [`centralManager:WillRestoreState:`](https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerdelegate/1518819-centralmanager) is called (app relaunched in the background to handle a bluetooth event).

**Arguments**

- `peripherals` - `Array` - an array of previously connected peripherals.

_For more on performing long-term bluetooth actions in the background:_

[iOS Bluetooth State Preservation and Restoration](https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html#//apple_ref/doc/uid/TP40013257-CH7-SW10)

[iOS Relaunch Conditions](https://developer.apple.com/library/archive/qa/qa1962/_index.html)

### BleManagerDidUpdateNotificationStateFor [iOS only]

The peripheral received a request to start or stop providing notifications for a specified characteristic's value.

**Arguments**

- `peripheral` - `String` - the id of the peripheral
- `characteristic` - `String` - the UUID of the characteristic
- `isNotifying` - `Boolean` - Is the characteristic notifying or not
- `domain` - `String` - [iOS only] error domain
- `code` - `Number` - [iOS only] error code
3 changes: 2 additions & 1 deletion docs/index.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

layout: home
title: Home
nav_order: 1
---

## A React Native Bluetooth Low Energy library.
# A React Native Bluetooth Low Energy library.

## Introduction

Expand Down
3 changes: 2 additions & 1 deletion docs/install.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
layout: page
title: Install
permalink: /install/
nav_order: 2
---

# Install
Expand Down Expand Up @@ -79,4 +80,4 @@ In iOS >= 13 you need to add the `NSBluetoothAlwaysUsageDescription` string key.

If the deployment target is earlier than iOS 13, you also need to add the `NSBluetoothPeripheralUsageDescription` string key.

For background use you nedd to add `bluetooth-peripheral` in `UIBackgroundModes` key. Refer to the [documentation](https://developer.apple.com/documentation/xcode/configuring-background-execution-modes/).
For background use you nedd to add `central-peripheral` in `UIBackgroundModes` key. Refer to the [documentation](https://developer.apple.com/documentation/xcode/configuring-background-execution-modes/).
Loading

0 comments on commit 703fe9c

Please sign in to comment.