react-nativewear-osapple-watchwearables

Creating a smart watch supporting app using React-Native


We are doing and R & D on smart watch support using React Native. R & D scope is like connect to a smart watch through phone then trigger/vibrate the watch when event comes from socket in phone. So at that time we will be sending some particular message from phone to smart watch to initiate the vibration.

When searching for the same we came across this SO Question which says RN doesn't support smart watch(remember the post is from 2016)

In the same post it mention about ReactNative Vanilla which I totally don't understand

  1. Is react-native vanila a npm package or is it a new domain like react-native

Then I came across this GitHub but this involves native side coding.

If anybody can give any insight into the same it would be helpful Thanks in advance

Tried searching for the same and couldn't find anything useful


Solution

    1. create a React Native wearOS app https://github.com/fabOnReact/react-native-wear-connectivity?tab=readme-ov-file#how-to-create-a-wearos-app-using-react-native
    2. sendMessage from Mobile App to WearOS app https://github.com/fabOnReact/react-native-wear-connectivity?tab=readme-ov-file#api-documentation

    Mobile device sends the message

    import { sendMessage } from 'react-native-wear-connectivity';
    
    sendMessage({ text: 'Hello watch!' });
    

    WearOS device receives the message

    import { watchEvents } from 'react-native-wear-connectivity';
    
    const unsubscribe = watchEvents.on('message', (message) => {
      console.log('received message from watch', message);
    });
    
    1. When you receive the message, use Vibration.vibrate() React Native API to vibrate the wearOS device:

    https://reactnative.dev/docs/vibration

    Vibration.vibrate()
    

    This is the RN Implementation of the Vibration Module https://github.com/facebook/react-native/blob/aff06a4f8542f13ea2ea18fde0ec73a99fef577b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/vibration/VibrationModule.java#L14