Skip to content

Commit ba5b89b

Browse files
authored
Merge pull request #8 from idpass/fix/ios-native-module
Fix issue with iOS build
2 parents 3ecfea1 + 396c8e9 commit ba5b89b

12 files changed

Lines changed: 3473 additions & 2766 deletions

File tree

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ yarn add @idpass/smartshare-react-native
1717
Import in main app:
1818

1919
```javascript
20-
import BluetoothApi from '@idpass/smartshare-react-native';
20+
import IdpassSmartshare from '@idpass/smartshare-react-native';
2121
```
2222

2323
## Development
@@ -42,9 +42,9 @@ First, a connection code or `params` needs to be communicated out-of-band and no
4242
The app that _displays the QR code_ shall generate the ephemeral connection parameters:
4343

4444
```javascript
45-
import BluetoothApi from '@idpass/smartshare-react-native';
45+
import IdpassSmartshare from '@idpass/smartshare-react-native';
4646

47-
const params = BluetoothApi.getConnectionParameters();
47+
const params = IdpassSmartshare.getConnectionParameters();
4848
console.log(params);
4949

5050
// Use any out-of-band mechanism to communicate the value of params to the peer device.
@@ -66,36 +66,36 @@ The app that _scans the QR code_ shall set its connection parameters:
6666
// Use any out-of-band mechanism to get the value of params from the peer device.
6767
// For example, you can use a QR code scanning library to get params.
6868

69-
BluetoothApi.setConnectionParameters(params);
69+
IdpassSmartshare.setConnectionParameters(params);
7070
```
7171

7272
Both apps create the connection:
7373

7474
```javascript
75-
BluetoothApi.createConnection('dual', () => {
75+
IdpassSmartshare.createConnection('dual', () => {
7676
// A secure Bluetooth connection is created
77-
// Anytime, either app may call BluetoothApi.send()
77+
// Anytime, either app may call IdpassSmartshare.send()
7878
});
7979
```
8080

8181
Once the connection is created, either app can send a string message.
8282

8383
```javascript
84-
BluetoothApi.send(message, () => {
84+
IdpassSmartshare.send(message, () => {
8585
// message sent
8686
});
8787
```
8888

8989
The app can intentionally destroy the connection.
9090

9191
```javascript
92-
BluetoothApi.destroyConnection();
92+
IdpassSmartshare.destroyConnection();
9393
```
9494

9595
The app must handle _Nearby_ events in order to receive **messages**, to monitor transfer **status** of incoming/outgoing messages, or to monitor connection related **events**:
9696

9797
```javascript
98-
BluetoothApi.handleNearbyEvents((event) => {
98+
IdpassSmartshare.handleNearbyEvents((event) => {
9999
switch (event.type) {
100100
case 'msg':
101101
console.log(event.data);
@@ -118,7 +118,7 @@ BluetoothApi.handleNearbyEvents((event) => {
118118
The React Native app can print native debug **logs** for debugging, by:
119119

120120
```javascript
121-
BluetoothApi.handleLogEvents(event => {
121+
IdpassSmartshare.handleLogEvents(event => {
122122
console.log(event.log);
123123
});
124124
```
@@ -128,18 +128,18 @@ BluetoothApi.handleLogEvents(event => {
128128
The above example snippets illustrated the use of the **dual** Bluetooth connection creation mode, wherein both devices will actively attempt to connect to each other and depending on who does it first, a connection is thereby created. The **dual** mode is a more robust mechanism to create a connection. However, an application may opt to configure one device as the `advertiser` and the other as the `discoverer`. For example, the first app that displays the QR code will advertise its presence and waits for a connection by:
129129

130130
```javascript
131-
BluetoothApi.createConnection('advertiser', () => {
131+
IdpassSmartshare.createConnection('advertiser', () => {
132132
// A secure Bluetooth connection is created
133-
// Anytime, either app may call BluetoothApi.send()
133+
// Anytime, either app may call IdpassSmartshare.send()
134134
});
135135
```
136136

137137
and the other app that scans the QR code will attempt to discover the first app by:
138138

139139
```javascript
140-
BluetoothApi.createConnection('discoverer', () => {
140+
IdpassSmartshare.createConnection('discoverer', () => {
141141
// A secure Bluetooth connection is created
142-
// Anytime, either app may call BluetoothApi.send()
142+
// Anytime, either app may call IdpassSmartshare.send()
143143
});
144144
```
145145

android/src/main/java/com/reactnativeidpasssmartshare/BluetoothApi.java renamed to android/src/main/java/com/reactnativeidpasssmartshare/IdpassSmartshare.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@
3535

3636
import java.util.Iterator;
3737

38-
public class BluetoothApi extends ReactContextBaseJavaModule {
38+
public class IdpassSmartshare extends ReactContextBaseJavaModule {
3939

40-
private static final String TAG = BluetoothApi.class.getName();
40+
private static final String TAG = IdpassSmartshare.class.getName();
4141
private BluetoothSecure bluetoothSecure;
4242

43-
public BluetoothApi(ReactApplicationContext reactContext) {
43+
public IdpassSmartshare(ReactApplicationContext reactContext) {
4444
super(reactContext);
4545
bluetoothSecure = new BluetoothSecure();
4646
}
4747

4848
@NonNull
4949
@Override
5050
public String getName() {
51-
return "BluetoothApi";
51+
return "IdpassSmartshare";
5252
}
5353

5454
private void emitEvent(String eventName, @Nullable WritableMap data) {
@@ -89,7 +89,7 @@ private void init() {
8989
}
9090

9191
///////////////////////////////////
92-
// BluetoothApi.tsx Javascript APIs
92+
// IdpassSmartshare.tsx Javascript APIs
9393
///////////////////////////////////
9494

9595
@ReactMethod(isBlockingSynchronousMethod = true)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.reactnativeidpasssmartshare;
2+
3+
import androidx.annotation.NonNull;
4+
5+
import com.facebook.react.ReactPackage;
6+
import com.facebook.react.bridge.NativeModule;
7+
import com.facebook.react.bridge.ReactApplicationContext;
8+
import com.facebook.react.uimanager.ViewManager;
9+
10+
import java.util.ArrayList;
11+
import java.util.Collections;
12+
import java.util.List;
13+
14+
public class IdpassSmartsharePackage implements ReactPackage {
15+
@NonNull
16+
@Override
17+
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
18+
List<NativeModule> modules = new ArrayList<>();
19+
modules.add(new IdpassSmartshare(reactContext));
20+
return modules;
21+
}
22+
23+
@NonNull
24+
@Override
25+
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
26+
return Collections.emptyList();
27+
}
28+
}

android/src/main/java/com/reactnativeidpasssmartshare/IdpassSmartsharePackage.kt

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)