<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kunjal Soni on Medium]]></title>
        <description><![CDATA[Stories by Kunjal Soni on Medium]]></description>
        <link>https://medium.com/@sonikunjal?source=rss-a1511503d6f8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*k0Tsvk-Bcny1mYPa2dwRxw.jpeg</url>
            <title>Stories by Kunjal Soni on Medium</title>
            <link>https://medium.com/@sonikunjal?source=rss-a1511503d6f8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 03:43:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sonikunjal/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[React Native That You Can Feel: Custom Haptic Feedback]]></title>
            <link>https://medium.com/simform-engineering/react-native-that-you-can-feel-custom-haptic-feedback-f0f96d51d4bc?source=rss-a1511503d6f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0f96d51d4bc</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[haptic-feedback]]></category>
            <category><![CDATA[vibration]]></category>
            <category><![CDATA[react-native-haptic]]></category>
            <category><![CDATA[custom-haptic]]></category>
            <dc:creator><![CDATA[Kunjal Soni]]></dc:creator>
            <pubDate>Thu, 06 Nov 2025 11:34:51 GMT</pubDate>
            <atom:updated>2025-11-06T11:34:51.037Z</atom:updated>
            <content:encoded><![CDATA[<h4>Bring your app to life with vibration patterns and feedback that users can literally feel</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XRKEFaqoOngZqFgnR28JlQ.png" /></figure><p>Haptic feedback is how your device communicates through touch- those subtle vibrations when you receive a call or message. Beyond adding a sense of responsiveness, haptics make interactions more intuitive and assist users with visual impairments by providing tactile cues.</p><p>In React Native, you can define custom vibration patterns — sequences of vibrations with specific durations and pauses to create unique tactile feedback for different app interactions.</p><p>In a React Native app, there are mainly 2 ways to create haptic feedback patterns:</p><h3><strong>1. Using the vibration API provided by React Native</strong></h3><p>The Vibration API in React Native lets your app trigger device vibrations easily. It is useful for giving feedback to users during interactions like alerts, notifications, or button presses.</p><p>The following code snippets show how we can use the Vibration API provided by React Native to perform vibrations on the device.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67535024677c214369d941416c54d975/href">https://medium.com/media/67535024677c214369d941416c54d975/href</a></iframe><ul><li>The Vibration API enables vibration patterns on both Android and iOS devices with a simple API call</li><li>The number passed as a parameter in the vibrate function is the duration of vibration in milliseconds.</li></ul><blockquote>In Android devices, this custom duration works as expected. However, it <strong>does not properly work in iOS</strong> devices (It always <strong>defaults to 400ms</strong>).</blockquote><p>In order to maintain this consistency in both platforms, we require a 3rd party library to achieve it.</p><h3>2.<strong> Using a custom 3rd party library, react-native-haptic-patterns</strong></h3><p>The <a href="https://github.com/SimformSolutionsPvtLtd/react-native-haptic-patterns">react-native-haptic-patterns</a> library leverages native APIs to play customized haptic patterns with different durations and intensities.</p><p>This library efficiently solves the problem mentioned above and helps integrate consistent behaviour for both Android &amp; iOS platforms.</p><p>Moreover, it also enables performing custom vibration patterns very easily.</p><h4>Implement Custom Haptic Pattern:</h4><p>Installing the library:</p><pre>npm install react-native-haptic-patterns<br><br>OR<br><br>yarn add react-native-haptic-patterns</pre><p>For <strong>iOS</strong>, Cocoapods requires this extra step:</p><pre>npx pod-install</pre><p>For <strong>Android</strong>, you may need to add below permission to <strong>AndroidManifest.xml </strong>file:</p><pre>&lt;uses-permission android:name=&quot;android.permission.VIBRATE&quot; /&gt;</pre><h4>Play Custom Haptic Patterns:</h4><p>With <a href="https://github.com/SimformSolutionsPvtLtd/react-native-haptic-patterns/tree/develop">react-native-haptic-patterns</a>, playing custom haptic patterns in your React Native app is easier than ever. Just create an array of patterns and pass it into a function.</p><p>The following code snippets show a very simple example to achieve it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/168e5bcd2d9b506adf26d881047d3579/href">https://medium.com/media/168e5bcd2d9b506adf26d881047d3579/href</a></iframe><p>In the haptic config array (customHapticPatterns):</p><p><strong>startTime</strong> – The start point (in milliseconds) of this segment in the overall haptic timeline.</p><p><strong>endTime</strong> – The end point (in milliseconds) marking when this segment stops.</p><p><strong>isPause</strong> – A boolean flag that tells whether this segment is a pause (no vibration) or an active haptic pulse.</p><ul><li>true → pause (no vibration)</li><li>false → play haptic feedback during this duration</li></ul><p><strong>Example:</strong><br> { startTime: 0, endTime: 100, isPause: false } → vibrate from 0 ms to 100 ms.<br> { startTime: 100, endTime: 200, isPause: true } → stay silent (no vibration) for 100 ms.</p><h4>Record custom haptic patterns:</h4><p>If you wish to record<strong> </strong>custom patterns in your React Native app, the library has showcased a really nice example. <a href="https://github.com/SimformSolutionsPvtLtd/react-native-haptic-patterns/blob/develop/example/src/App.tsx"><strong>Click here to view it</strong></a><strong>.</strong></p><h3><strong>Best practices &amp; points to consider while employing haptic feedback in your app</strong></h3><p><strong>Use sparingly</strong>: Avoid overwhelming users with excessive haptic feedback; it should complement the experience, not distract from it.</p><p><strong>Customise feedback types:</strong> Utilise different haptic patterns for various actions to convey distinct meanings (e.g., success vs. error).</p><p><strong>User control:</strong> Provide options for users to enable or disable haptic feedback according to their preferences.</p><p><strong>Consistency: </strong>Maintain consistent use of haptic feedback across similar actions to create a cohesive user experience.</p><p><strong>Accessibility considerations</strong>: When adding haptic feedback, consider accessibility. Some users with sensory sensitivities may find vibrations uncomfortable, so offering options to adjust or disable them makes your app more inclusive. Thoughtful design ensures everyone can enjoy a comfortable and engaging experience.</p><h3>Real-world Use Cases and Examples</h3><p><strong>Buttons and interactions: </strong>Using haptic feedback on button presses and other interactive elements improves user experience by providing a physical sense of confirmation, making the interface feel more responsive and engaging.</p><p><strong><em>Example</em></strong><em>: When a user taps a “Like” button, a subtle vibration confirms the action without needing visual changes.</em></p><p><strong>Form validations and error alerts: </strong>Implementing haptic cues to signal form validation results or errors helps users quickly recognise mistakes or successful inputs, reducing confusion and improving form usability.</p><p><strong><em>Example</em></strong><em>: If a user submits a form with a missing required field, a short vibration alerts them to the error.</em></p><p><strong>Gaming and Immersive experiences: </strong>Haptic feedback in games adds a layer of realism by simulating physical sensations tied to actions or events, such as collisions, explosions, or item pickups, creating a more immersive and enjoyable experience.</p><p><strong><em>Example</em></strong><em>: When a character takes damage in a game, the device vibrates to simulate impact and increase immersion.</em></p><h3>Additional Resources and References</h3><ul><li><a href="https://github.com/SimformSolutionsPvtLtd/react-native-haptic-patterns/blob/develop/README.md">https://github.com/SimformSolutionsPvtLtd/react-native-haptic-patterns/blob/develop/README.md</a></li><li><a href="https://docs.expo.dev/versions/latest/sdk/haptics/">https://docs.expo.dev/versions/latest/sdk/haptics/</a></li><li><a href="https://reactnative.dev/docs/vibration">https://reactnative.dev/docs/vibration</a></li></ul><blockquote><strong><em>For more updates on the latest tools and technologies, follow the </em></strong><a href="https://medium.com/simform-engineering"><strong><em>Simform Engineering</em></strong></a><strong><em> blog.</em></strong></blockquote><blockquote><strong><em>Follow Us: </em></strong><a href="https://twitter.com/simform"><strong><em>X</em></strong></a><strong><em> | </em></strong><a href="https://www.linkedin.com/company/simform/"><strong><em>LinkedIn</em></strong></a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0f96d51d4bc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/simform-engineering/react-native-that-you-can-feel-custom-haptic-feedback-f0f96d51d4bc">React Native That You Can Feel: Custom Haptic Feedback</a> was originally published in <a href="https://medium.com/simform-engineering">Simform Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Native App with Apple Watch & Widget Support]]></title>
            <link>https://medium.com/simform-engineering/react-native-app-with-apple-watch-widget-support-9daef5e131d7?source=rss-a1511503d6f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/9daef5e131d7</guid>
            <category><![CDATA[widget]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[apple-watch]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Kunjal Soni]]></dc:creator>
            <pubDate>Thu, 27 Jun 2024 04:00:53 GMT</pubDate>
            <atom:updated>2024-06-27T04:00:53.092Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>Extending your app’s reachability to your users’ wrists</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I9arFpW6WbVftid8urPmfQ.gif" /></figure><p>We all love developing mobile apps using React Native because it provides cross-platform integration which is widely used for iOS as well as Android applications. But do you know what is more exciting?</p><p>You guessed it right! It is a React Native application which also supports smart watch devices.</p><p>In this article, we will learn how to integrate an Apple watchOS application with our React Native application. Moreover, we will also create a widget which can be set as a complication in watch faces.</p><h3><strong>Prerequisites</strong></h3><ul><li>Basic knowledge of React Native, Xcode, and SwiftUI</li><li>Xcode with watchOS-supported device simulator</li></ul><h3><strong>Setting up your development environment</strong></h3><p>To build a watchOS app for our React Native app, we will use Xcode, which is an IDE provided by Apple.</p><p>Moreover, we will use <strong>WatchKit</strong>, which is a framework provided by Apple to build watchOS apps. With WatchKit, we can create watchOS apps and program them to connect and work with apps on other Apple devices.</p><h4><strong>Installing necessary dependencies for watchOS and widgets</strong></h4><p>To implement communication between iOS and watchOS apps, we will use a library named <strong>react-native-watch-connectivity</strong>.</p><ul><li>To install this package, you may use yarn or npm based on your project:</li></ul><pre>npm install react-native-watch-connectivity - save</pre><pre>yarn add react-native-watch-connectivity</pre><p>Don’t forget to install cocoapods!</p><pre>cd ios &amp;&amp; pod install &amp;&amp; cd ..</pre><p>Next up, we will create a very basic React Native screen which will have a count variable with plus and minus buttons.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7259c749d0a89a76d77c6a8c6bf8b59/href">https://medium.com/media/a7259c749d0a89a76d77c6a8c6bf8b59/href</a></iframe><h3>Adding support for watchOS app</h3><p>Now that you have set up your iOS app, let’s move forward and start developing our watchOS app.</p><p>Open your iOS project using Xcode. From the toolbar, select File -&gt; New -&gt; Target.</p><p>You will see the following window: From the top tabs, select <strong>watchOS</strong>, and under that tab, select <strong>App</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zXz81dioz7J7msumGG71oQ.png" /><figcaption>Adding watchOS app to your project</figcaption></figure><p>Next up, you will see another window to provide more details about the watchOS app.</p><p>Provide an app name and bundle identifier for the watchOS app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A_KDcTnjjZRfJeDksJTTKA.png" /><figcaption>Provide additional information for the watchOS app</figcaption></figure><p>From the window shown above, you can select whether you already have an existing iOS app or not. In our case, we have an iOS app project setup. So we will select <strong>Watch App for Existing iOS App</strong>, and from the drop-down below, select our iOS app’s target.</p><p>After clicking the <strong>Finish</strong> button, you will notice that a new folder has been added to our Xcode project. That folder contains our watchOS project files.</p><h4><strong>Designing the watchOS app’s UI</strong></h4><p>Now, we will start designing the UI for our watchOS application. To begin, open the <strong>ContentView.swift</strong> file, which contains SwiftUI code.</p><p>In our SwiftUI code, we will display a simple text element that will show the value of the counter.</p><p>Our ContentView should look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d9134b8583640a78823a16d83587f70/href">https://medium.com/media/4d9134b8583640a78823a16d83587f70/href</a></iframe><h3>Implementing functionality</h3><p>Now, let’s set up a mechanism for two-way communication between the iOS and the watchOS apps.</p><h4><strong>Sending messages from the iOS app to the watchOS app</strong></h4><ul><li><strong>iOS app as sender</strong></li></ul><p>To send messages to the watchOS app, we will need to use the package we have installed in the React Native app.</p><p>Let’s import <strong>sendMessage</strong> and <strong>getReachability</strong> function from the <strong>react-native-watch-connectivity</strong> and use them to determine the watch’s reachability to send the count variable to the watchOS app.</p><p>We will modify our button actions as shown below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/267ec274a34b70fb33b1072aaf9567df/href">https://medium.com/media/267ec274a34b70fb33b1072aaf9567df/href</a></iframe><ul><li><strong>watchOS app as receiver</strong></li></ul><p>To set up the watchOS app to receive messages sent from the iOS app, let’s create a new Swift file and name it <strong>ConnectionHelper.swift</strong>. We will use this class to capture messages and events sent from the iOS app.</p><p>To begin, let’s create a class named <strong>ConnectionHelper</strong> and inside that, we will set up our watch session and events.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19fa0fc4955e201850112713c57b2794/href">https://medium.com/media/19fa0fc4955e201850112713c57b2794/href</a></iframe><p>This code will give you an error, which forces us to implement the required methods in our class for the watch session delegate.</p><p>To keep the code clean, create an extension of our class ConnectionHelper and implement <strong>WCSessionDelegate</strong> into it. The extension must also implement the method shown below, as it is a required method.</p><blockquote><strong>Info:</strong> An extension in Swift allows you to add new functionality to an existing class.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52dac57b6f6563e31830ff19c2d5189a/href">https://medium.com/media/52dac57b6f6563e31830ff19c2d5189a/href</a></iframe><p>This method is useful for indicating when there are any changes in the activation state of WCSession. It means we can see that communication between your iOS app and the paired Apple watch is now active. If not, it sends an error.</p><p>The next step is getting events and messages that are sent from our iOS app into our watchOS app, for which we will implement the <strong>didReceiveMessage</strong> method in the extension. Our <strong>ConnectionHelper</strong> extension should look like this now:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2a660914ee0abc564de8c0448fe274c/href">https://medium.com/media/c2a660914ee0abc564de8c0448fe274c/href</a></iframe><p>Using the above-declared method, we will update the value of our counter. Let’s first declare it inside our <strong>ConnectionHelper</strong> class. Our class should now look as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9014d2e1d9c90729c36d944ccdfe96b7/href">https://medium.com/media/9014d2e1d9c90729c36d944ccdfe96b7/href</a></iframe><p>We declared a variable count, annotated it as <strong>Published</strong> and implemented <strong>ObservableObject</strong> protocol in our class because we want to track whenever this count variable is changed.</p><p>Now, we need to implement a logic that updates the count value whenever we receive an event from the iOS app. To achieve this, we will use the <strong>didReceiveMessage</strong> method defined in our ConnectionHelper extension.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3870f146bf564dfa11d332b8cbaf931/href">https://medium.com/media/c3870f146bf564dfa11d332b8cbaf931/href</a></iframe><blockquote><strong>Info:</strong> Whenever you get a message into the watchOS app from iOS app, you can send a reply by using the replyHandler callback.</blockquote><p>Now that we have created our counter variable, it’s time to use it inside our watchOS app’s UI. Let’s instantiate the <strong>ConnectionHelper</strong> class in our <strong>ContentView</strong> and use the <strong>count</strong> property to display it under the text element.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/802524aa92d68441bb83c2f021a70cbf/href">https://medium.com/media/802524aa92d68441bb83c2f021a70cbf/href</a></iframe><p>Now, our one-way communication from the iOS app to the watchOS app is complete.</p><h4><strong>Sending messages from the watchOS app to the iOS app</strong></h4><ul><li><strong>watchOS app as sender</strong></li></ul><p>To implement sending messages from the watchOS app to the iOS app, we will first create a helper function inside the ConnectionHelper class that will send the count variable as a message from the watchOS to our iOS app using the watch session that we previously created.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac7d9f4ddaf0eea8cf456f5c4b99dd97/href">https://medium.com/media/ac7d9f4ddaf0eea8cf456f5c4b99dd97/href</a></iframe><p>In the next step, we will modify our ContentView file to add buttons with text <strong>+</strong> and <strong>-</strong> followed by adding actions to them. As shown in the code snippet below, we will modify the count variable and use the <strong>sendNewCount</strong> function to send it to the iOS app.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1bac5ab0219368c76ba8e843b54aa4cd/href">https://medium.com/media/1bac5ab0219368c76ba8e843b54aa4cd/href</a></iframe><p>But wait! We still need to set up our iOS app to listen to the messages sent from the watchOS app.</p><ul><li><strong>iOS app as receiver</strong></li></ul><p>To handle these incoming messages, we first need to use <strong>watchEvents</strong> to listen to the messages, which are imported from the <strong>react-native-watch-connectivity </strong>package.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b191190cc369357124766c6b39e9688/href">https://medium.com/media/1b191190cc369357124766c6b39e9688/href</a></iframe><p>Voila! That’s it. Let’s run both apps and give them a try.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*PqaAgPuCgE1W_RGKEC9r7Q.gif" /><figcaption>Communication between iOS and watchOS apps</figcaption></figure><h3><strong>Adding widgets to the watchOS application</strong></h3><h4><strong>Setting up the Widget Extension target</strong></h4><p>To introduce widget support for our watchOS app, we will need to create a new target in the same Xcode project.</p><p>We will add a new target named <strong>Widget Extension</strong> to our project, similar to the watchOS target.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ua1cRCizT8wjMPYuByRZgg.png" /><figcaption>Adding Widget Extension target</figcaption></figure><p>After clicking <strong>Next</strong>, provide the product name for your widget target.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cJlBQpsPuKPastlXZWLZaQ.png" /><figcaption>Providing details of Widget Extension target</figcaption></figure><p>Once you have set up your Widget Extension target, you will see a new folder in your project, named <strong>CounterWidget</strong> in this case. This folder will initially contain two Swift files, <strong>AppIntent</strong> and <strong>CounterWidget.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*qB5OBr8F1L2rs7FdSIA1Sg.png" /></figure><h4><strong>Designing and implementing the widget UI and its functionality</strong></h4><p>Before modifying the UI, let’s first set up our count variable in the Widget Extension.</p><p>To accomplish this, open the <strong>AppIntent</strong> file, declare a variable named <strong>currentCount</strong>, and set up the constructors as shown in the code snippet below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/476178920e9c1e3e62ae9ed3cb6cbf3a/href">https://medium.com/media/476178920e9c1e3e62ae9ed3cb6cbf3a/href</a></iframe><p>To start designing our widget’s UI, let’s open the <strong>CounterWidget</strong> file. Scroll down to the <strong>EntryView</strong>, which was automatically generated by Xcode when we created the Widget Extension. We will create a very simple text component and, inside it, show our current count variable as shown below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c411d89ac1af2be54f5a74ff0e21f03b/href">https://medium.com/media/c411d89ac1af2be54f5a74ff0e21f03b/href</a></iframe><h4><strong>Communicate and share data between the watchOS app and the Widget Extension</strong></h4><p>Now, we want to show our current count variable, declared in the watchOS app, in our widget’s UI. But Apple does not provide a direct way to exchange data between the watchOS app and a widget. So, we will store our count variable in <strong>UserDefaults</strong>, which is local storage provided by Apple.</p><blockquote><strong>More info on UserDefaults</strong>: <a href="https://developer.apple.com/documentation/foundation/userdefaults">https://developer.apple.com/documentation/foundation/userdefaults</a></blockquote><p>To share a single property across our watchOS app and Widget Extension, we have to add a new capability called App Groups for both watchOS and Widget Extension.</p><p>To do so, open Project Settings -&gt; select your target, and then select the tab <strong>Signing &amp; Capabilities</strong>. Click the <strong>+ Capability</strong> button to your target in that window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*GtSXYwEQNDN_0kSSAioqOQ.png" /><figcaption>Adding capability</figcaption></figure><p>After adding App Groups as capabilities, you will see this section inside that window. Now, tap the <strong>+</strong> button and add an identifier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Oi6UowBHUXse79d2aOoyw.png" /><figcaption>Adding App Groups</figcaption></figure><p>Now, provide a valid identifier for the container (which will also be used as a suite name for UserDefaults) where our data will be stored and used by multiple targets in our project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*LOkU3Gn6qm190trhJG8Xxw.png" /><figcaption>Provide app group container name</figcaption></figure><blockquote><strong>Note:</strong> Make sure to do this step for both the watchOS app and the Widget Extension.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yl_up2dM4x0VvJUOZQaGvQ.png" /><figcaption>Adding App Groups capability to the watchOS and Widget Extension targets</figcaption></figure><p>The <strong>CounterWidget</strong> file will contain all the logic that manages the user interface (UI) and its functionality. However, the main function is the <strong>timeline</strong> function, which is responsible for refreshing the widget’s UI at specified intervals.</p><blockquote><strong>For more info about it, read:</strong> <a href="https://developer.apple.com/documentation/widgetkit/appintenttimelineprovider">https://developer.apple.com/documentation/widgetkit/appintenttimelineprovider</a></blockquote><p>Moving forward, now that we have our app groups ready, let’s set up the mechanism for sharing our data between the watchOS app and the Widget Extension.</p><p>We will declare a new variable called appCount inside our ConnectionHelper class, which is declared in the watchOS target’s folder, and it will be annotated with <strong>AppStorage</strong> using <strong>UserDefaults</strong>, as shown below:</p><p>In addition to that, to make the <strong>appCount</strong> variable functional, we will assign a new value to it whenever the <strong>count</strong> is changed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1db2d5febad4d219b396ed4ebf3b95fd/href">https://medium.com/media/1db2d5febad4d219b396ed4ebf3b95fd/href</a></iframe><p>In the next step, to display it inside the widget’s UI, we want to modify the Timeline Provider of the widget. For that, navigate to the pre-generated Provider structure inside the CounterWidget file.</p><p>First, we want to declare the appCount variable in that structure’s scope and modify the provider functions so that they look as shown below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75f75aa0d166ca272859ec0ce911ee76/href">https://medium.com/media/75f75aa0d166ca272859ec0ce911ee76/href</a></iframe><p>Hallelujah! We have successfully set up our watchOS app’s Widget Extension to show the count value. Now let’s run and give it a shot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/277/1*4W6YaN1I5FIM0FKJHUZ2BA.gif" /><figcaption>Updating Widget’s UI when count is changed from the watchOS app</figcaption></figure><p>Let’s try modifying the count from the iOS application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*u8y-X3CelS4YDm0JLFuIdg.gif" /><figcaption>Updating Widget’s UI when count is changed from the iOS or watchOS app</figcaption></figure><blockquote>The full project is available on this <a href="https://github.com/kunjalsoni-simformsolutions/RNWatchWidgetApp"><strong>GitHub repo</strong></a><strong>. 🚀</strong></blockquote><h3><strong>Conclusion</strong></h3><p>We successfully integrated the React Native app with watchOS, as well as widget support for the watch faces.</p><p>Now, it’s your turn to create awesome apps using WatchKit and WidgetKit. Share your ideas and projects in the comments below.</p><p>Happy coding! 😉</p><blockquote><strong>For more updates on the latest tools and technologies, follow the </strong><a href="https://medium.com/simform-engineering"><strong>Simform Engineering</strong></a><strong> blog.</strong></blockquote><blockquote><strong>Follow us: </strong><a href="https://twitter.com/simform"><strong>Twitter</strong></a><strong> | </strong><a href="https://www.linkedin.com/company/simform/"><strong>LinkedIn</strong></a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9daef5e131d7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/simform-engineering/react-native-app-with-apple-watch-widget-support-9daef5e131d7">React Native App with Apple Watch &amp; Widget Support</a> was originally published in <a href="https://medium.com/simform-engineering">Simform Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>