diff --git a/README.md b/README.md index 6960444..4b7df47 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,19 @@ # react-native-wear-connectivity -Enstablish a two-way connection with wearOS +- Create a [Wear OS][1] app using react-native +- Connect two react-native apps (Wear OS and Android phone) +- **Both apps are written in react-native** + +[1]: https://wearos.google.com ## Installation +```sh +yarn add react-native-wear-connectivity +``` + +or + ```sh npm install react-native-wear-connectivity ``` @@ -11,13 +21,68 @@ npm install react-native-wear-connectivity ## Usage ```js -import { multiply } from 'react-native-wear-connectivity'; +import { sendMessage, watchEvents } from 'react-native-wear-connectivity'; + +function CounterScreen() { + const [count, setCount] = React.useState(0); + + // listen for messages from wearOS/phone + useEffect(() => { + const unsubscribe = watchEvents.on('message', () => { + setCount((prevCount) => prevCount + 1); + }); + + return () => { + unsubscribe(); + }; + }, []); + + // send a message from/to wearOS + const onSuccess = (result) => console.log(result); + const onError = (error) => console.log(error); + + const sendMessageToWear = () => { + const json = { text: 'hello', event: 'message' }; + sendMessage(json, onSuccess, onError); + }; + + return ( + + {count} +