-
Notifications
You must be signed in to change notification settings - Fork 9
docs: add wearable setup guides and examples #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fabOnReact
wants to merge
1
commit into
main
Choose a base branch
from
codex/add-examples-and-documentation-for-wearables
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Contributing | ||
|
||
Thanks for your interest in contributing! Please read the [root CONTRIBUTING guide](../CONTRIBUTING.md) for full details. | ||
|
||
## Development workflow | ||
|
||
1. Fork and clone the repository. | ||
2. Install dependencies with `yarn`. | ||
3. Run `yarn lint`, `yarn test`, and `yarn typecheck` before submitting. | ||
4. Open a pull request with a clear description of your changes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# watchOS setup | ||
|
||
These steps show how to link a React Native app with an Apple Watch companion using [`react-native-watch-connectivity`](https://github.com/mtford90/react-native-watch-connectivity). | ||
|
||
1. **Install the library** | ||
|
||
```sh | ||
yarn add react-native-watch-connectivity | ||
``` | ||
|
||
2. **Create a watch target** | ||
|
||
In Xcode add a watchOS app or extension to your project and enable Watch Connectivity in the capabilities tab. | ||
|
||
3. **Pair the devices** | ||
|
||
Use the iOS Simulator with a paired watch or a physical iPhone and Apple Watch. | ||
|
||
4. **Run the apps** | ||
|
||
Build the iOS app and watch extension. Use the snippet in `examples/ios-message.ts` to send a test message between the devices. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# WearOS setup | ||
|
||
Follow these steps to connect a React Native app with a WearOS companion. | ||
|
||
1. **Install the library** | ||
|
||
```sh | ||
yarn add react-native-wear-connectivity | ||
``` | ||
|
||
2. **Update `AndroidManifest.xml`** | ||
|
||
Add the required permissions and service to `android/app/src/main/AndroidManifest.xml`. | ||
|
||
```xml | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.WAKE_LOCK"/> | ||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> | ||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" /> | ||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE" /> | ||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> | ||
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" /> | ||
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" /> | ||
|
||
<service | ||
android:name="com.wearconnectivity.WearConnectivityTask" | ||
android:exported="false" | ||
android:foregroundServiceType="dataSync|connectedDevice" | ||
android:permission="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE" /> | ||
``` | ||
|
||
3. **Pair the devices** | ||
|
||
Install the Google Play Wear app on the Android phone and pair it with the WearOS emulator or device. | ||
|
||
4. **Run the apps** | ||
|
||
Start the Metro server, run the mobile app, and launch the WearOS companion. Use the snippet in `examples/android-message.ts` to verify the connection. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Troubleshooting | ||
|
||
Common issues when connecting mobile and wearable apps. | ||
|
||
## Wearable app not installed on mobile device | ||
|
||
The mobile device must have the Google Play Wear app installed to pair with the WearOS device. | ||
|
||
## WearOS device too far for Bluetooth connection | ||
|
||
Logcat may show `Device is too far for bluetooth connection` when the watch is out of range of the phone. | ||
|
||
## Failed to deliver message to AppKey | ||
|
||
Ensure the WearOS and mobile apps share the same package name, application ID, and signing key. Messages cannot be delivered if these values differ. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Platform connector examples | ||
|
||
This folder contains minimal code snippets for each supported platform. | ||
|
||
- `android-message.ts` demonstrates sending and receiving a message with the WearOS connector. | ||
- `ios-message.ts` demonstrates sending and receiving a message with the watchOS connector using [`react-native-watch-connectivity`](https://github.com/mtford90/react-native-watch-connectivity). | ||
|
||
Each snippet can be pasted into a React Native project after following the setup guides in the [`docs/`](../docs) directory. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { sendMessage, watchEvents } from 'react-native-wear-connectivity'; | ||
|
||
// Send a message to the WearOS device | ||
sendMessage({ text: 'Hello watch!' }, (reply) => { | ||
console.log('Reply from watch:', reply); | ||
}); | ||
|
||
// Listen for messages from the WearOS device | ||
const unsubscribe = watchEvents.on('message', (message) => { | ||
console.log('Received message from watch', message); | ||
}); | ||
|
||
// Call unsubscribe() when no longer needed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { sendMessage, watchEvents } from 'react-native-watch-connectivity'; | ||
|
||
// Send a message to the Apple Watch | ||
sendMessage({ text: 'Hello watch!' }, (reply) => { | ||
console.log('Reply from watch:', reply); | ||
}); | ||
|
||
// Listen for messages from the Apple Watch | ||
const unsubscribe = watchEvents.on('message', (message, reply) => { | ||
console.log('Received message from watch', message); | ||
reply({ text: 'Thanks watch!' }); | ||
}); | ||
|
||
// Call unsubscribe() when no longer needed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,5 +24,6 @@ | |
"strict": true, | ||
"target": "esnext", | ||
"verbatimModuleSyntax": true | ||
} | ||
}, | ||
"exclude": ["node_modules", "examples"] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] Exclude new examples from TypeScript build
Adding
"exclude": ["node_modules", "examples"]
here only affectstsc --noEmit
, becausetsconfig.build.json
defines its ownexclude
array and overrides this change. Whenyarn prepare
(bob build) runs, the TypeScript project referenced intsconfig.build.json
still compiles the new files inexamples/
, which fail with missing modules and unused variables, causing the build to stop. To avoid blockingyarn prepare
/publishing,tsconfig.build.json
also needs to exclude theexamples
folder.Useful? React with 👍 / 👎.