Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ Add the following entry to your `android/app/src/main/AndroidManifest.xml` (full
</manifest>
```

### Garmin setup

To enable Garmin devices, install the Garmin connector and include the Garmin
SDK binaries in your project:

```sh
yarn add react-native-garmin-connect
```

Download the Garmin SDK from the Garmin developer portal and copy the provided
`ConnectIQ.jar` (or latest `.aar`) into your `android/app/libs` directory. Add
the dependency inside `android/app/build.gradle`:

```gradle
dependencies {
implementation files('libs/ConnectIQ.jar')
}
```

Rebuild the Android project after adding the SDK files to ensure the Garmin
library is linked correctly.

## React Native API Documentation

The example of implementation available in the [CounterScreen](example/src/CounterScreen/index.android.tsx).
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
"url": "https://github.com/fabOnReact/react-native-wear-connectivity/issues"
},
"homepage": "https://github.com/fabOnReact/react-native-wear-connectivity#readme",
"dependencies": {
"react-native-garmin-connect": "^0.1.0"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
Expand Down
44 changes: 44 additions & 0 deletions src/garmin/GarminConnector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { NativeEventEmitter } from 'react-native';
import GarminConnect from 'react-native-garmin-connect';

/**
* Provides a small wrapper around the Garmin Connect SDK.
* The connector exposes a simple API used by the library to
* communicate with Garmin wearables.
*/
class GarminConnector {
private emitter: NativeEventEmitter;

constructor() {
// GarminConnect is a native module; wrap it with an event emitter so we
// can subscribe to SDK events from JavaScript.
this.emitter = new NativeEventEmitter(GarminConnect as any);
}

/**
* Initializes the Garmin SDK.
*/
initialize(): Promise<void> {
// The SDK exposes an initialize call which prepares the connection layer.
return GarminConnect.initialize();
}

/**
* Sends a payload to a paired Garmin device.
*/
sendMessage(message: Record<string, unknown>): Promise<void> {
Comment on lines +21 to +29

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Guard Garmin connector when native module is unavailable

The new wrapper calls GarminConnect.initialize() and GarminConnect.sendMessage() directly. On iOS (and on Android projects that haven’t copied Garmin’s native SDK yet), react-native-garmin-connect resolves to undefined, so invoking either method will throw a runtime exception as soon as the connector is used. Other APIs in this package (sendMessage, watchEvents) already gate native calls behind platform checks to avoid crashing on unsupported platforms. The Garmin connector should similarly no-op or warn when the native module is missing so that importing the package in cross‑platform code doesn’t crash apps that aren’t set up for Garmin yet.

Useful? React with 👍 / 👎.

return GarminConnect.sendMessage(message);
}

/**
* Adds a listener for incoming messages from the Garmin device.
* Returns an unsubscribe function to remove the listener.
*/
onMessage(callback: (message: any) => void): () => void {
const subscription = this.emitter.addListener('message', callback);
return () => subscription.remove();
}
}

export default new GarminConnector();

1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const startFileTransfer: SendFile = (file, _metadata) => {
};

export { startFileTransfer, sendMessage, watchEvents, WearConnectivity };
export { default as GarminConnector } from './garmin/GarminConnector';
export type { ReplyCallback, ErrorCallback };

type WearParameters = {
Expand Down