You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+85-50Lines changed: 85 additions & 50 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,56 +4,109 @@ Contributions are always welcome, no matter how large or small!
4
4
5
5
We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. Before contributing, please read the [code of conduct](./CODE_OF_CONDUCT.md).
The first step is building the react-native Android mobile app.
30
+
2) Open the project with android studio, build and run it on an [Android WearOS emulator](https://github-production-user-asset-6210df.s3.amazonaws.com/24992535/303911079-f6cb9f84-dc50-492b-963d-6d9e9396f451.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVCODYLSA53PQK4ZA%2F20250125%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20250125T110158Z&X-Amz-Expires=300&X-Amz-Signature=4bd2be95943124fe34fb13e6a54e9a2fe8a9c06d1eb8afdf005ce02cf43c90d1&X-Amz-SignedHeaders=host).
29
31
30
-
```bash
31
-
cd example
32
-
yarn install
33
-
yarn start
34
-
# Now build android
35
-
yarn android
32
+
3) Now you can pair the WearOS emulator with the Android Mobile Emulator as explained in these [instructions](https://developer.android.com/training/wearables/get-started/connect-phone).
33
+
34
+
### Detailed explanation on how WearOS (Jetpack Compose) communicates with React Native (Android Mobile)
35
+
36
+
**Sending messages from Jetpack Compose WearOS to React Native Mobile Device**
37
+
38
+
[sendMessageToClient](https://github.com/fabOnReact/wearos-communication-with-rn/blob/371e6c5862d49ccbff08ab951a26284a216daf97/app/src/main/java/com/wearconnectivityexample/presentation/MainActivity.kt#L75-L87) is implemented on Jetpack Compose WearOS to send messages to the React Native Mobile App. `sendMessageToClient` is triggered on WearOS when [clicking](https://github.com/fabOnReact/wearos-communication-with-rn/blob/371e6c5862d49ccbff08ab951a26284a216daf97/app/src/main/java/com/wearconnectivityexample/presentation/WearApp.kt#L31) on the watch Button Component.
39
+
40
+
```kotlin
41
+
funsendMessageToClient(node:Node) {
42
+
val jsonObject =JSONObject().apply {
43
+
put("event", "message")
44
+
put("text", "hello")
45
+
}
46
+
try {
47
+
val sendTask =Wearable.getMessageClient(applicationContext).sendMessage(
48
+
node.getId(), jsonObject.toString(), null
49
+
)
50
+
} catch (e:Exception) {
51
+
Log.w("WearOS: ", "e $e")
52
+
}
53
+
}
36
54
```
37
55
38
-
### Build the WearOS App
56
+
The WearOS `sendMessageToClient` function retrieves the devices connected via bluetooth to the WearOS device, and sends a JSON payload to those devices.
57
+
58
+
The payload is:
39
59
40
-
```bash
41
-
cd watch-example
42
-
yarn install
43
-
yarn start --port=8082
60
+
```javascript
61
+
{
62
+
event:"message",
63
+
text:"this is the message parameter",
64
+
}
44
65
```
45
66
46
-
Build the project with `yarn android`, open the [react native dev menu][23] and change the bundle location to `your-ip:8082` (for ex. `192.168.18.2:8082`).
47
-
Now you can build the WearOS app with the command:
67
+
The React Native Mobile App uses `watchEvents.on(eventName, callback)` to listen to the `message` event and to increase the number displayed in the React Native Mobile App. The implementation in the React Native Mobile example is in [CounterScreen/index.android.tsx](https://github.com/fabOnReact/react-native-wear-connectivity/blob/2f936622422e197c22bef228b44eb24b46c878ae/example/src/CounterScreen/index.android.tsx#L14-L16).
**Sending messages from React Native Mobile Device to Jetpack Compose WearOS**
83
+
84
+
The React Native Mobile App Example sends messages to the WearOS Jetpack Compose example with [sendMessage](https://github.com/fabOnReact/react-native-wear-connectivity/blob/2f936622422e197c22bef228b44eb24b46c878ae/example/src/CounterScreen/index.android.tsx#L29-L33).
[22]: https://gist.github.com/assets/24992535/f6cb9f84-dc50-492b-963d-6d9e9396f451'wear os large round'
56
-
[23]: https://reactnative.dev/docs/debugging
94
+
The Jetpack Compose WearOS app implements [onMessageReceived](https://github.com/fabOnReact/wearos-communication-with-rn/blob/371e6c5862d49ccbff08ab951a26284a216daf97/app/src/main/java/com/wearconnectivityexample/presentation/MainActivity.kt#L89-L95) and updates the Counter number on the screen when the message is received:
onMessageReceived modifies the [count state variable](https://github.com/fabOnReact/wearos-communication-with-rn/blob/371e6c5862d49ccbff08ab951a26284a216daf97/app/src/main/java/com/wearconnectivityexample/presentation/MainActivity.kt#L31) and re-renders the Counter component with a new [text](https://github.com/fabOnReact/wearos-communication-with-rn/blob/371e6c5862d49ccbff08ab951a26284a216daf97/app/src/main/java/com/wearconnectivityexample/presentation/WearApp.kt#L46).
107
+
108
+
You can copy the [implementation](https://github.com/fabOnReact/wearos-communication-with-rn/tree/main/app/src/main/java/com/wearconnectivityexample/presentation) from the example, or follow the instructions above to rename package name, application id and change the signing key to pair that example with your React Native App.
109
+
57
110
58
111
### Sending a pull request
59
112
@@ -62,19 +115,10 @@ yarn android
62
115
When you're sending a pull request:
63
116
64
117
- Prefer small pull requests focused on one change.
65
-
- Verify that linters and tests are passing.
66
118
- Review the documentation to make sure it looks good.
67
119
- Follow the pull request template when opening a pull request.
68
120
- For pull requests that change the API or implementation, discuss with maintainers first by opening an issue.
We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing.
75
-
76
-
Our pre-commit hooks verify that the linter and tests pass when committing.
77
-
78
122
### Publishing to npm
79
123
80
124
We use [release-it](https://github.com/release-it/release-it) to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc.
@@ -84,12 +128,3 @@ To publish new versions, run the following:
84
128
```sh
85
129
yarn release
86
130
```
87
-
88
-
### Scripts
89
-
90
-
The `package.json` file contains various scripts for common tasks:
91
-
92
-
-`yarn`: setup project by installing dependencies.
93
-
-`yarn typecheck`: type-check files with TypeScript.
0 commit comments