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
I suggest you to try to run the example before doing your own implementation. You can try to modify the WearOS example and connect it to your mobile app following this instructions.
55
101
56
-
### How to run the React Native Mobile App example
102
+
**How to run the React Native Mobile App example**
57
103
58
104
You need to clone the `react-native-wear-connectivity` project, build and run the mobile app example.
59
105
@@ -66,7 +112,7 @@ yarn
66
112
yarn android
67
113
```
68
114
69
-
### How to run the Jetpack Compose WearOS example
115
+
**How to run the Jetpack Compose WearOS example**
70
116
71
117
1) Clone the WearOS Jetpack Compose [example](https://github.com/fabOnReact/wearos-communication-with-rn)
72
118
```
@@ -94,8 +140,7 @@ In our example, the gradle configs set the singingConfigs to use the same file d
94
140
**Android Mobile React Native app**
95
141
- Make sure both apps are using the same key, in our example the singingConfigs for the React Native Mobile App are configured [here](https://github.com/fabOnReact/react-native-wear-connectivity/blob/2f936622422e197c22bef228b44eb24b46c878ae/example/android/app/build.gradle#L78-L104) and the [debug.keystore](https://github.com/fabOnReact/wearos-communication-with-rn/blob/371e6c5862d49ccbff08ab951a26284a216daf97/app/debug.keystore) is the same from the WearOS app.
96
142
97
-
### How to implement the Jetpack Compose WearOS app
98
-
143
+
### Detailed explanation of the Implementation
99
144
**Sending messages from Jetpack Compose WearOS to React Native Mobile Device**
100
145
101
146
[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.
@@ -142,6 +187,34 @@ useEffect(() => {
142
187
}, []);
143
188
```
144
189
190
+
**Sending messages from React Native Mobile Device to Jetpack Compose WearOS**
191
+
192
+
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).
193
+
194
+
```javascript
195
+
constsendMessageToWear= () => {
196
+
setDisabled(true);
197
+
constjson= { text:'hello' };
198
+
sendMessage(json, onSuccess, onError);
199
+
};
200
+
```
201
+
202
+
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).
215
+
216
+
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](https://github.com/fabOnReact/wearos-communication-with-rn?tab=readme-ov-file#both-apps-share-the-same-package-name-and-applicationid) to rename package name, application id and change the signing key to pair that example with your React Native App.
217
+
145
218
## FAQ on Troubleshooting Errors
146
219
147
220
While some error messages are displayed on the metro server for the mobile or wearOS device (port 8082), other warnings are only available through logcat.
0 commit comments