<?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 Siso ngqolosi on Medium]]></title>
        <description><![CDATA[Stories by Siso ngqolosi on Medium]]></description>
        <link>https://medium.com/@sisongqolosi?source=rss-e22b12b3ecd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*_Dg9vaVxtxZNC9Dd</url>
            <title>Stories by Siso ngqolosi on Medium</title>
            <link>https://medium.com/@sisongqolosi?source=rss-e22b12b3ecd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 17:01:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sisongqolosi/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[15 Rules of Vibe Coding (React Native + Expo)]]></title>
            <link>https://medium.com/@sisongqolosi/15-rules-of-vibe-coding-react-native-expo-d89e2ea01772?source=rss-e22b12b3ecd------2</link>
            <guid isPermaLink="false">https://medium.com/p/d89e2ea01772</guid>
            <category><![CDATA[expo]]></category>
            <category><![CDATA[vibe-coding]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Siso ngqolosi]]></dc:creator>
            <pubDate>Sun, 11 May 2025 11:38:53 GMT</pubDate>
            <atom:updated>2025-05-11T11:38:53.292Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*9Z0hWsduRcbe9a299dgmcg.png" /></figure><ol><li><strong>Start from a template:</strong> Begin your project with an Expo Router starter like npx create-expo-app -e with-router. Use community templates or GitHub starters that include essentials like navigation, authentication, and themes to save time and avoid boilerplate.</li><li><strong>Use agent mode (or your AI assistant):</strong> Use AI tools (like Cursor, Windsurf or GitHub Copilot) in “agent mode” to generate components, screens, and logic using natural language. Don’t code alone — collaborate with your AI agent.</li><li><strong>Use Perplexity for mobile inspiration:</strong> Use tools like Perplexity or GitHub search to find examples of mobile UI/UX, libraries for push notifications, camera access, and advanced navigation. Ask it to show how to build specific features like “QR scanner in Expo.”</li><li><strong>Create new chats or tasks for each feature:</strong> Whether using AI or issue tracking, split your work: “Build Login Screen,” “Set Up Firebase Auth,” etc. Keep the focus tight and tasks short to reduce overwhelm.</li><li><strong>Run on device/emulator often:</strong> Use npx expo start and test regularly on your phone or emulator. Catch bugs early by running the app after each small change.</li><li><strong>Iterate and refine UI:</strong> Don’t wait for perfect design — vibe with react-native-paper, nativewind, or tailwindcss-react-native to prototype fast. Get feedback from real devices early.</li><li><strong>Use voice-to-text coding:</strong> Pair AI agents with tools like Whisper or mobile dictation to describe features and convert to code. This is perfect for brainstorming screens or logic on the go.</li><li><strong>Clone &amp; fork smartly:</strong> Use GitHub to fork existing mobile projects that use Expo or React Native Web. Remix them with your own UI and data layer.</li><li><strong>Paste errors directly to AI tools:</strong> When Metro throws red screens or TypeScript fails, copy the errors into your AI assistant and let it debug. Include relevant parts of the file or navigation stack to help it help you.</li><li><strong>Restore previous agent sessions or code checkpoints:</strong> Keep snapshots via GitHub commits or use VSCode Timeline / Cursor chat history to go back if needed.</li><li><strong>Secure your secrets:</strong> Store Firebase keys, Supabase URLs, and API keys in .env files using expo-constants or libraries like react-native-dotenv. Never hardcode keys in your components.</li><li><strong>Commit often with Git:</strong> Use GitHub or GitLab for version control. Commit with messages like “add product detail screen” or “fix Expo router dynamic routes.” Let Cursor or your CLI guide you.</li><li><strong>Deploy early via EAS:</strong> Use eas build and eas submit to test your app on real devices and deploy beta versions. Fix deployment issues early — not on launch day.</li><li><strong>Keep reusable prompts &amp; code snippets:</strong> Save working prompts (e.g., “build Expo router tab navigator with icons”) and create a snippet library for custom buttons, cards, modals, etc.</li><li><strong>Enjoy the process — just vibe:</strong> Building mobile apps should feel like fun. Explore animations with moti, try AI chat features, test on friends’ phones, and ship something dope. Vibe first, polish later.</li></ol><p>If you want a detailed walk through on these principle go to</p><p><a href="https://www.sisodev.com/codelabs/15-rules-of-vibe-coding-(react-native-+-expo)">https://www.sisodev.com/codelabs/15-rules-of-vibe-coding-(react-native-+-expo)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d89e2ea01772" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Simple Llama Index Node.js server]]></title>
            <link>https://medium.com/@sisongqolosi/creating-a-simple-llama-index-node-js-server-19295cfa6c2d?source=rss-e22b12b3ecd------2</link>
            <guid isPermaLink="false">https://medium.com/p/19295cfa6c2d</guid>
            <category><![CDATA[llama-2]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[llamaindex]]></category>
            <dc:creator><![CDATA[Siso ngqolosi]]></dc:creator>
            <pubDate>Sat, 30 Mar 2024 23:21:35 GMT</pubDate>
            <atom:updated>2024-03-31T12:20:09.229Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jMgxgS6AVUP2XgIgbpSLqw.png" /></figure><p>Creating a Node.js server to handle text queries the llamaindex tslibrary. This step-by-step tutorial will guide you through setting up an Express server that utilizes this library along with CORS (Cross-Origin Resource Sharing) support. The server will respond to POST requests with text queries and utilize a set of documents to return a relevant response.</p><h3>Prerequisites</h3><ul><li>Ensure you have Node.js installed on your system. You can download it from <a href="https://nodejs.org/">nodejs.org</a>.</li><li>Basic knowledge of JavaScript and Node.js.</li><li>An IDE or text editor of your choice (e.g., VSCode, Sublime Text).</li></ul><h3>Step 1: Initialize Your Project</h3><p>Open your terminal or command prompt.</p><p>Create a new directory for your project and navigate into it:</p><ul><li>mkdir my-query-server cd my-query-server</li></ul><p>Initialize a new Node.js project:</p><ul><li>npm init -y</li></ul><p>Add “type”: “module” to the package.json so we can use ES6 Import statements</p><p>Install the required dependencies:</p><p>npm install express cors dotenv <em>llamaindex</em></p><h3>Step 2: Create Your Server File</h3><ol><li>In your project directory, create a file named server.js.</li><li>Open server.js in your IDE or text editor.</li></ol><h3>Step 3: Set Up Your Server</h3><p>Copy the following code into your server.js file. This is your starting point, including importing necessary modules and setting up a basic server structure.</p><pre>import &quot;dotenv/config&quot;;<br>import express from &quot;express&quot;;<br>import cors from &quot;cors&quot;;<br>import { Document, VectorStoreIndex, SimpleDirectoryReader } from &quot;llamaindex&quot;;<br><br>const app = express();<br>const port = process.env.PORT || 3000;<br>app.use(cors());<br>// Middleware to use JSON body parsing<br>app.use(express.json());</pre><p>Remember to create an openAI account.</p><ul><li>Log into OpenAI to get our keys.</li><li>Enter or create your account, and then go to the <a href="https://platform.openai.com/account/api-keys">OpenAI key creation page</a> and create a key.</li><li>Copy the key</li><li>Create a file in the main folder of the project called “.env” (note the dot at the beginning of the file name) and insert the text there:</li></ul><pre>OPENAI_API_KEY=your_key</pre><p>Instead of “your_key,” enter the key you copied from OpenAI and save the file. Then add the following code</p><pre>...<br>const keys = process.env.OPENAI_API_KEY;<br>if (!keys) {<br>  throw new Error(&quot;No OpenAI API key provided&quot;);<br>}<br>...</pre><h3>Step 4: Initialize the Index</h3><p>Add the asynchronous function initializeIndex to load and index your documents. This assumes you have a directory ./data with your documents.</p><pre>async function initializeIndex() {<br>  const documents = await new SimpleDirectoryReader().loadData({<br>    directoryPath: &quot;./data&quot;,<br>  });<br>  return await VectorStoreIndex.fromDocuments(documents);<br>}</pre><h3>Step 5: Create a Route to Handle Queries</h3><p>Extend your server.js by adding a POST route that will process the queries.</p><pre>app.post(&quot;/query&quot;, async (req, res) =&gt; {<br>  try {<br>    const index = await initializeIndex();<br>    const queryEngine = index.asQueryEngine();<br>    const query = req.body.query; // Expecting a query in the JSON body<br>if (!query) {<br>      return res.status(400).send({ error: &quot;Query not provided&quot; });<br>    }<br>    const response = await queryEngine.query({ query });<br>    res.send({ response: response.toString() });<br>  } catch (error) {<br>    console.error(error);<br>    res.status(500).send({ error: &quot;An error occurred while processing the query.&quot; });<br>  }<br>});</pre><h3>Step 6: Start Your Server</h3><p>Finalize your server.js by adding the code to start the Express server.</p><pre>app.listen(port, () =&gt; {<br>  console.log(`Server running on port ${port}`);<br>});</pre><h3>Step 7: Running Your Server</h3><p>In your terminal, run the server with the following command:</p><ul><li>node server.js</li></ul><p>Your server is now running on http://localhost:3000 (or another port if you’ve configured it differently).</p><h3>Step 8: Testing Your Server</h3><p>To test your server, you can use a tool like Postman or a simple curl command in the terminal:</p><pre>curl -X POST http://localhost:3000/query -H &quot;Content-Type: application/json&quot; -d &quot;{\&quot;query\&quot;:\&quot;What did the author do in college?\&quot;}&quot;</pre><p>Postman:</p><p>URL POST: <a href="http://localhost:3000/query">http://localhost:3000/query</a>. Body: JSON { “query”: “What did the author do in college?” }</p><h3>Conclusion</h3><p>You’ve now created a basic server capable of handling text queries against a set of documents, utilizing the Express framework and handling CORS requests. This setup is quite flexible and can be adapted to various applications, such as a search engine or a FAQ bot.</p><p><a href="https://github.com/sisoalbert/node-llamaindex-server">https://github.com/sisoalbert/node-llamaindex-server</a></p><p>Application:</p><figure><a href="https://github.com/sisoalbert/Reactjs-LlamaIndex-app"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nT_9s_j0MZOWYxrf5D6TqQ.png" /></a></figure><p>Here is a simple react web app using this server to answer questions based on the doc in the server.</p><p><a href="https://github.com/sisoalbert/Reactjs-LlamaIndex-app">https://github.com/sisoalbert/Reactjs-LlamaIndex-app</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19295cfa6c2d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Step-by-Step Tutorial: Publishing a React Native App to Google Play Store]]></title>
            <link>https://medium.com/@sisongqolosi/step-by-step-tutorial-publishing-a-react-native-app-to-google-play-store-8ab3db39cd07?source=rss-e22b12b3ecd------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ab3db39cd07</guid>
            <category><![CDATA[play-store]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Siso ngqolosi]]></dc:creator>
            <pubDate>Fri, 01 Mar 2024 07:41:44 GMT</pubDate>
            <atom:updated>2024-03-01T07:41:44.031Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jaHeiVBEvWncda4HCFm4zg.png" /></figure><p><strong>Step 1: Create a Google Play Console Account</strong></p><ul><li>Go to google.com and search for “<strong>Google Play Console</strong>.”</li><li>Click on “Go to Play Console.”</li><li>Log in to your Google account.</li><li>Choose “<strong>Create for yourself.</strong>”</li><li>Provide your developer name, contact information, and address.</li><li>Agree to the terms and conditions.</li><li>Pay the $25 developer registration fee.</li></ul><p>Step 2: Generate an Upload Key Keystore</p><ul><li>Open a terminal window.</li><li>Navigate to the JDK bin folder.</li><li>Run the following command and Enter a password for the keystore and provide answers to the prompts.</li></ul><h3>Windows<a href="https://reactnative.dev/docs/signed-apk-android#windows">​</a></h3><p>On Windows keytool must be run from C:\Program Files\Java\jdkx.x.x_x\bin, as administrator.</p><pre>keytool -genkeypair -v -storetype PKCS12 -keystore my-upload-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000</pre><p>This command prompts you for passwords for the keystore and key and for the Distinguished Name fields for your key. It then generates the keystore as a file called my-upload-key.keystore.</p><p>The keystore contains a single key, valid for 10000 days. The alias is a name that you will use later when signing your app, so remember to take note of the alias.</p><h3>macOS<a href="https://reactnative.dev/docs/signed-apk-android#macos">​</a></h3><p>On macOS, if you’re not sure where your JDK bin folder is, then perform the following command to find it:</p><pre>/usr/libexec/java_home</pre><p>It will output the directory of the JDK, which will look something like this:</p><pre>/Library/Java/JavaVirtualMachines/jdkX.X.X_XXX.jdk/Contents/Home</pre><p>Navigate to that directory by using the command cd /your/jdk/path and use the keytool command with sudo permission as shown below.</p><pre>sudo keytool -genkey -v -keystore my-upload-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000</pre><p><strong>CAUTION</strong></p><p>Remember to keep the keystore file private. In case you’ve lost upload key or it’s been compromised you should <a href="https://support.google.com/googleplay/android-developer/answer/7384423#reset">follow these instructions</a>.</p><p>Step 3: Add Keystore to Android Project</p><ul><li>Drag the keystore file into the android/app folder.</li><li>Open android/app/build.gradle and add the following lines:</li></ul><pre>buildTypes {<br>    release {<br>        signingConfig signingConfigs.debug<br>    }<br>}</pre><p><strong>Step 4: Change App Name and Package Name (Optional)</strong></p><ul><li>Install react-native-rename globally: yarn global add react-native-rename</li><li>Run npx react-native rename and provide the new name and package identifier.</li></ul><p><strong>Step 5: Update Version Numbers (Optional)</strong></p><ul><li>Install react-native-version globally: yarn global add react-native-version</li><li>Run react-native version and provide the new version numbers.</li></ul><p><strong>Step 6: Generate Android Icons</strong></p><ul><li>Go to appicon.co and generate icons for Android.</li><li>Drag the generated icons into android/app/src/main/res.</li></ul><p>Step 7: Create Android App Bundle</p><ul><li>Navigate to android/app in the terminal.</li><li>Run ./gradlew bundleRelease.</li></ul><p><strong>Step 8: Create App in Google Play Console</strong></p><ul><li>Go to the Google Play Console dashboard.</li><li>Click “<strong>Create App</strong>.”</li><li>Provide app name, language, and other details.</li></ul><p><strong>Step 9: Configure App Settings</strong></p><ul><li>Go to “<strong>Setup App</strong>” and complete the following steps:</li><li>App access</li><li>Ads</li><li>Content rating</li><li>Target audience</li><li>Data safety</li></ul><p><strong>Step 10: Manage App Listing</strong></p><ul><li>Go to “<strong>Manage App Listing.</strong>”</li><li>Provide app category, description, screenshots, and other details.</li></ul><p><strong>Step 11: Release App</strong></p><ul><li>Go to “<strong>Releases</strong>” and click “Create New Release.”</li><li>Provide a release name and notes.</li><li>Upload the Android App Bundle.</li><li>Review the release and click “Start rollout to production.”</li></ul><p><strong>Step 12: Update App (Optional)</strong></p><ul><li>Increment the version numbers in package.json and android/app/build.gradle.</li><li>Build a new Android App Bundle.</li><li>Create a new release in the Google Play Console and upload the new bundle.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ab3db39cd07" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Speed Up Your React Native Development with Bun]]></title>
            <link>https://medium.com/@sisongqolosi/how-to-speed-up-your-react-native-development-with-bun-88099cc28e92?source=rss-e22b12b3ecd------2</link>
            <guid isPermaLink="false">https://medium.com/p/88099cc28e92</guid>
            <category><![CDATA[buns]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[bunjs]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Siso ngqolosi]]></dc:creator>
            <pubDate>Tue, 12 Sep 2023 09:09:48 GMT</pubDate>
            <atom:updated>2023-09-18T19:16:37.337Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-RPbfdzyHQxeUD1-6f5Q8w.png" /></figure><p>BunJS is a new JavaScript runtime that is designed to be fast and efficient. It can be used as a drop-in replacement for Node.js, and it also includes a native bundler and test runner.</p><p>In this blog post, we will show you how to use BunJS to speed up your React Native development. We will also compare the performance of BunJS to Node.js and Yarn Classic.</p><p>A GitHub pull request <a href="https://github.com/react-native-community/cli/pull/2073">linked </a>is already out for a number of new features that are being added to BunJS for React Native. These features include:</p><ul><li>Support for the React Native CLI’s init command.</li><li>Support for the React Native packager.</li><li>Support for the React Native metro bundler.</li><li>Support for the React Native test runner.</li></ul><p>These new features will make it even easier to use BunJS with React Native, and they will help to improve the performance of React Native apps.</p><p><strong>Initializing a new Expo project</strong></p><p>To initialize a new Expo project with BunJS, you can use the following command:</p><pre>bunx create-expo-app</pre><p>This command will create a new React Native project with Expo. The project will be initialized in about 1.25 seconds, which is much faster than using Node.js or Yarn Classic.</p><p><strong>Performance comparison</strong></p><p>We ran a performance comparison of BunJS, Node.js, and Yarn Classic. We initialized a new Expo project with each runtime and measured the time it took to complete the initialization.</p><p>The results of the performance comparison are shown below (Runtime: Time (seconds)):</p><p><strong>BunJS</strong>: 1.25s , <strong>Node.js</strong>: 15s , <strong>Yarn Classic</strong>: 15s</p><p>As you can see, BunJS is significantly faster than Node.js and Yarn Classic. It is about 12x faster than Node.js and 10x faster than Yarn Classic.</p><p><strong>Conclusion</strong></p><p>BunJS is a powerful tool that can help you to speed up your React Native development. It is fast, efficient, and easy to use. If you are looking for a way to improve the performance of your React Native app, then I encourage you to try BunJS.</p><p>Experimenting with Bun &amp; React Native CLI’s init command</p><p>I recently experimented with using Bun and the React Native CLI’s init command to create a new React Native project. I was surprised to see that the initialization process was much faster than when I used Node.js.</p><p>In my test, it took about 41 seconds to initialize a new React Native project with Node.js. However, it only took about 11.5 seconds to initialize the same project with Bun. That’s a significant improvement!</p><p>When using Bun for package management, it’s important to note that it excels in speed and caching efficiency. Unlike some other tools, Bun doesn’t frequently check the network for the latest package versions, which can contribute to its rapid installation times and allows for developing my React Native apps more quickly.</p><p>However, this means that if you specify version ranges like “latest” or “Canary,” Bun won’t verify if they are indeed the most recent versions. This design choice has advantages, as it allows Bun to make bold decisions without legacy constraints, but it can also lead to unexpected outcomes for users who rely on specific version management. So, while Bun’s speed is impressive, users should be mindful of its unique approach to version checking and stay informed about updates addressing these nuances.</p><p>If you’re looking for a way to speed up your React Native development, I recommend giving Bun a try. It’s a great tool that can help you save time and get your apps to market faster.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FoOBK3jOxErU&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DoOBK3jOxErU&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2FoOBK3jOxErU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/7cf041dd2258814792812cf847eda9f1/href">https://medium.com/media/7cf041dd2258814792812cf847eda9f1/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WCFMVcqCQul2-bmwoTDCTg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88099cc28e92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Convolutional Neural Networks for Image Classification in TensorFlow.js]]></title>
            <link>https://medium.com/@sisongqolosi/convolutional-neural-networks-for-image-classification-in-tensorflow-js-7f5ad5af0e9?source=rss-e22b12b3ecd------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f5ad5af0e9</guid>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[convolutional-network]]></category>
            <category><![CDATA[mnist]]></category>
            <category><![CDATA[tensorflowjs]]></category>
            <dc:creator><![CDATA[Siso ngqolosi]]></dc:creator>
            <pubDate>Thu, 13 Jul 2023 23:27:16 GMT</pubDate>
            <atom:updated>2023-07-13T23:27:16.676Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c3zZGmHpJFhXy25JkovWHg.png" /></figure><p>Convolutional neural networks (CNNs) are a type of machine learning model that are specifically designed for image classification. They are able to learn the features of images that are important for classification, such as edges, shapes, and textures.</p><p>TensorFlow.js is a JavaScript library that makes it easy to build and train CNNs in the browser. In this article, we will walk through the basics of training a CNN for image classification in TensorFlow.js.</p><p>The basics of training a conv model using tensorflow.js involves the following steps:</p><pre>model = tf.sequential(); <br>model.add(tf.layers.conv2d({inputShape: [28, 28, 1],<br> kernelSize: 3, filters: 8, activation: &#39;relu&#39;}));<br>model.add(tf.layers.maxPooling2d({poolSize: [2, 2]}));<br>model.add(tf.layers.conv2d({filters: 16,<br> kernelSize: 3, activation: &#39;relu&#39;}));<br>model.add(tf.layers.maxPooling2d({poolSize: [2, 2]}));<br>model.add(tf.layers.flatten());<br>model.add(tf.layers.dense({units: 128, activation: &#39;relu&#39;}));<br>model.add(tf.layers.dense({units: 10, activation: &#39;softmax&#39;}));<br><br>...<br>Then Compile the model and fit <br></pre><p>Let explain each line:</p><pre>model = tf.sequential()</pre><p>This line creates a new Sequential model. A Sequential model is a type of neural network that is made up of a series of layers, one after the other.</p><pre>model.add(tf.layers.conv2d({inputShape: [28, 28, 1],<br> kernelSize: 3, filters: 8, activation: &#39;relu&#39;}));</pre><p>This line adds a convolutional layer to the model. The convolutional layer takes an image as input and outputs a new image that has been filtered. The inputShape argument specifies the shape of the input image, which in this case is a 28x28x1 image. The kernelSize argument specifies the size of the kernel that is used to filter the image. The filters argument specifies the number of filters that are used in the layer. The activation argument specifies the activation function that is used after the layer. In this case, the ReLU activation function is used.</p><pre>model.add(tf.layers.maxPooling2d({poolSize: [2, 2]}));</pre><p>This line adds a max pooling layer to the model. The max pooling layer takes the output of the convolutional layer and outputs a new image that has been downsampled <em>(reduce the spatial size of the feature maps while preserving the most important features)</em>. The poolSize argument specifies the size of the pooling window that is used to downsample the image.</p><pre>model.add(tf.layers.conv2d({filters: 16,<br> kernelSize: 3, activation: &#39;relu&#39;}));</pre><p>This line adds another convolutional layer to the model. This layer has the same configuration as the first convolutional layer, except that it has 16 filters instead of 8.</p><pre>model.add(tf.layers.maxPooling2d({poolSize: [2, 2]}));</pre><p>This line adds another max pooling layer to the model. This layer has the same configuration as the first max pooling layer.</p><pre>model.add(tf.layers.flatten());</pre><p>This line flattens the output of the max pooling layer <em>(converts it from a multi-dimensional array to a one-dimensional array )</em>. This means that the output of the layer is converted from a 2D image to a 1D vector.</p><pre>model.add(tf.layers.dense({units: 128, activation: &#39;relu&#39;}));</pre><p>This line adds a dense layer to the model. A dense layer is a fully connected layer, which means that every neuron in the layer is connected to every neuron in the previous layer <em>(Dense layers are a powerful tool for learning complex relationships between input and output data)</em>. The units argument specifies the number of neurons in the layer. The activation argument specifies the activation function that is used after the layer. In this case, the ReLU activation function is used.</p><pre>model.add(tf.layers.dense({units: 10, activation: &#39;softmax&#39;}));</pre><p>This line adds the final dense layer to the model. This layer has 10 neurons, which corresponds to the 10 possible classes in the MNIST dataset. The activation argument specifies the softmax activation function, which is used to normalize the output of the layer so that the sum of all outputs is equal to 1.</p><p>In summary, the code above creates a Sequential model that consists of a series of convolutional layers, max pooling layers, and dense layers. The model is configured to classify images from the MNIST dataset.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f5ad5af0e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flower Classification with Tensorflow.js: Iris dataset]]></title>
            <link>https://medium.com/@sisongqolosi/flower-classification-with-tensorflow-js-iris-dataset-1b93abda4bd8?source=rss-e22b12b3ecd------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b93abda4bd8</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[tensorflowjs]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Siso ngqolosi]]></dc:creator>
            <pubDate>Sun, 09 Jul 2023 16:12:38 GMT</pubDate>
            <atom:updated>2023-07-09T17:14:19.174Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*uGXrNr_KL--DtUJq.png" /></figure><h4>Introduction:</h4><p>Flower classification has long been a fascinating subject in the field of pattern recognition and classification methodologies. Among the earliest datasets utilized for this purpose, the Iris dataset donated on June 30, 1988, by Fisher, remains a classic and widely employed resource for evaluating various classification techniques. In this article, we delve into the world of flower classification using TensorFlow.js, focusing on the classification of three distinct Iris flowers: Iris Setosa, Iris Versicolour, and Iris Virginica.</p><h4>Dataset Overview:</h4><p>The Iris dataset is a small, multivariate dataset that consists of 150 instances, with four attributes: sepal length, sepal width, petal length, and petal width, all measured in centimeters. The primary objective is to predict the class of the iris plant based on these features. Each class comprises 50 instances, with one class being linearly separable from the other two, while the remaining two classes are not linearly separable from each other.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/744bbe343cf3e22526c5b7214cefa09e/href">https://medium.com/media/744bbe343cf3e22526c5b7214cefa09e/href</a></iframe><p>Below is the code for the training and classification. A JavaScript script that uses TensorFlow.js to build and train a neural network model for classifying Iris flowers based on their features. The model is trained on a dataset obtained from a CSV file containing information about Iris flowers.</p><p>Here’s a breakdown of the code:</p><ol><li>Loading the required TensorFlow.js library:</li></ol><pre>&lt;script src=&quot;https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest&quot;&gt;&lt;/script&gt;</pre><p>2. Defining the main function run() that will be executed:</p><pre>async function run(){     <br>// Code for loading and preprocessing the dataset, <br>// building the model, and training it <br>}<br>run();</pre><p>3. Loading the Iris dataset from a CSV file:</p><pre>const csvUrl = &#39;/data/iris.csv&#39;;<br>const trainingData = tf.data.csv(csvUrl, {<br>     columnConfigs: {<br>         species: {<br>             isLabel: true<br>         }<br>     } });</pre><p>4. Preprocessing the data:</p><ul><li>Determining the number of features based on the column names of the dataset:</li></ul><pre>const numOfFeatures = (await trainingData.columnNames()).length - 1;</pre><ul><li>Converting the data into a suitable format for training:</li></ul><pre>const convertedData = trainingData.map(({xs, ys}) =&gt; {<br>    // Converting the species labels to one-hot encoded vectors<br>    const labels = [<br>        ys.species == &quot;setosa&quot; ? 1 : 0,<br>        ys.species == &quot;virginica&quot; ? 1 : 0,<br>        ys.species == &quot;versicolor&quot; ? 1 : 0<br>    ];<br>    return { xs: Object.values(xs), ys: Object.values(labels) };<br>}).batch(10);</pre><p><em>With one-hot encoded were are </em><strong><em>converting words</em></strong><em> to </em><strong><em>1s and 0s</em></strong><em> so the machine can understand.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*G--ToHy_GRgM_75aYCy3kg.png" /><figcaption><em>one-hot encoded</em></figcaption></figure><p>5. Building the neural network model:</p><pre>const model = tf.sequential();<br>model.add(tf.layers.dense({ inputShape: [numOfFeatures], activation: &quot;sigmoid&quot;, units: 5 }));<br>model.add(tf.layers.dense({ activation: &quot;softmax&quot;, units: 3 }));<br>// ( 3 units/classes: Iris Setosa, Iris Versicolour, and Iris Virginica)</pre><p><em>The code defines a neural network model with </em><strong><em>two dense layers</em></strong><em>. The first layer takes the </em><strong><em>input data</em></strong><em> with the specified shape and applies the sigmoid activation function. The </em><strong><em>second layer</em></strong><em> takes the </em><strong><em>output of the previous layer</em></strong><em> and applies the </em><strong><em>softmax activation function</em></strong><em>, producing probabilities for each class in a multi-class classification task.</em></p><p><em>Here, </em><em>units: 5 indicates that the dense layer will have </em><strong><em>5 neurons.</em></strong><em> Each neuron in a dense layer takes input from all the neurons in the previous layer (or the input data for the first layer) and produces an output.</em></p><p><em>The number of units in a dense layer is a </em><strong><em>design choice </em></strong><em>and can be adjusted based on the </em><strong><em>complexity of the problem</em></strong><em> and the </em><strong><em>model’s capacity to learn</em></strong><em>. Increasing the number of units allows the model to learn more complex patterns in the data but also increases the number of parameters that need to be trained, potentially leading to </em><strong><em>longer training times</em></strong><em> and </em><strong><em>overfitting</em></strong><em> if the model becomes too large relative to the available data.</em></p><p><em>In this case, the choice of </em><em>units: 5 for the first dense layer may be based on the specific problem or experimental considerations. It is common to experiment with different numbers of units and layer configurations to find the best model architecture for a given task.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-i8J3sRQ-ZQB0g40.png" /><figcaption>The sigmoid function (a.k.a. the logistic function) and its derivative</figcaption></figure><p>6. Compiling the model with a loss function and an optimizer:</p><pre>model.compile({ loss: &quot;categoricalCrossentropy&quot;, optimizer: tf.train.adam(0.06) });</pre><p><em>By using Adam as the optimizer, the model will update its parameters (weights and biases) during training, trying to minimize the specified loss function (</em><em>categoricalCrossentropy in this case) and improve its predictive performance.</em></p><p>7. Training the model using the preprocessed data:</p><pre>await model.fitDataset(convertedData, {<br>    epochs: 100,<br>    callbacks: {<br>        onEpochEnd: async (epoch, logs) =&gt; {<br>            console.log(&quot;Epoch: &quot; + epoch + &quot; Loss: &quot; + logs.loss);<br>        }<br>    }<br>});</pre><p>8. Testing the trained model:</p><ul><li>Defining a test case with input values for an Iris flower:</li></ul><pre>//We set with: sepal-length, sepal-width, petal-length, petal-width, SHAPE OF DATA<br>const testVal = tf.tensor2d([6.4, 3.2, 4.5, 1.5], [1, 4]);</pre><ul><li>Predicting the class of the test case using the trained model:</li></ul><pre>const prediction = model.predict(testVal);<br>const pIndex = tf.argMax(prediction, axis=1).dataSync();</pre><ul><li>Displaying the predicted class as an alert:</li></ul><pre>const classNames = [&quot;Setosa&quot;, &quot;Virginica&quot;, &quot;Versicolor&quot;];<br>alert(classNames[pIndex]);</pre><p>In the provided code, the test case values [6.4, 3.2, 4.5, 1.5] are used as input to the trained model to predict the class of an Iris flower. The predicted class is then displayed as an alert message. The specific output class depends on the model&#39;s training and the provided test case input.</p><p><strong>Shout out!</strong></p><p>Here is the full code:</p><pre>&lt;html&gt;<br>&lt;head&gt;&lt;/head&gt;<br>    &lt;script src=&quot;https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest&quot;&gt;&lt;/script&gt;<br>    &lt;script lang=&quot;js&quot;&gt;<br>        async function run(){<br>            const csvUrl = &#39;/data/iris.csv&#39;;<br>            const trainingData = tf.data.csv(csvUrl, {<br>                columnConfigs: {<br>                    species: {<br>                        isLabel: true<br>                    }<br>                }<br>            });<br>            <br>            const numOfFeatures = (await trainingData.columnNames()).length - 1;<br>            const numOfSamples = 150;<br>            const convertedData =<br>                  trainingData.map(({xs, ys}) =&gt; {<br>                      const labels = [<br>                            ys.species == &quot;setosa&quot; ? 1 : 0,<br>                            ys.species == &quot;virginica&quot; ? 1 : 0,<br>                            ys.species == &quot;versicolor&quot; ? 1 : 0<br>                      ] <br>                      return{ xs: Object.values(xs), ys: Object.values(labels)};<br>                  }).batch(10);<br>            <br>            //build the model<br>            <br>            const model = tf.sequential();<br>            <br>            //shape <br>            model.add(tf.layers.dense({inputShape: [numOfFeatures], activation: &quot;sigmoid&quot;, units: 5}))<br>            //three units since there are three classes<br>            model.add(tf.layers.dense({activation: &quot;softmax&quot;, units: 3}));<br>            <br>            //<br>            <br>            model.compile({loss: &quot;categoricalCrossentropy&quot;, optimizer: tf.train.adam(0.06)});<br>            <br>            //Training<br>            await model.fitDataset(convertedData, <br>                             {epochs:100,<br>                              callbacks:{<br>                                  onEpochEnd: async(epoch, logs) =&gt;{<br>                                      console.log(&quot;Epoch: &quot; + epoch + &quot; Loss: &quot; + logs.loss);<br>                                  }<br>                              }});<br>            <br>            // Test Cases:<br>            <br>            // Setosa<br>            //t testVal = tf.tensor2d([4.4, 2.9, 1.4, 0.2], [1, 4]);<br>            <br>            // Versicolor<br>            const testVal = tf.tensor2d([6.4, 3.2, 4.5, 1.5], [1, 4]);<br>            <br>            // Virginica<br>            // const testVal = tf.tensor2d([5.8,2.7,5.1,1.9], [1, 4]);<br>            <br>            const prediction = model.predict(testVal);<br>            const pIndex = tf.argMax(prediction, axis=1).dataSync();<br>            <br>            const classNames = [&quot;Setosa&quot;, &quot;Virginica&quot;, &quot;Versicolor&quot;];<br>            <br>            // alert(prediction)<br>            alert(classNames[pIndex])<br>            <br>        }<br>        run();<br>    &lt;/script&gt;<br>&lt;body&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>You will need to run a web server locally on your machine. This is because in javascript every call has to be done through and HTTP request. Therefore, even if you have your files locally, you can’t just load them directly, you have to make an HTTP request to those files.</p><p><a href="https://simplewebserver.org/">Simple Web Server</a></p><p><em>Launch Simple Web Server</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EpntHIgt9ikxzZmO" /></figure><p>Click on “CHOOSE FOLDER” and select the folder that contains the folder you want to run. For this example, we are going to run the <strong>iris_classifier.html</strong> file. On my computer, this file is located in the following folder:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yXUnAD46-EWguKOK" /></figure><p>Once you have chosen the correct folder, you can click on the Web Server URL (http://127.0.0.1:8887).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2qkEpbmcCJHTxNTB" /></figure><p>Once you click on the Web Server URL, this will open a new tab in your Chrome browser (if Chrome is your default browser). You can now click on the <strong>html</strong> file you want to run. In this case, we are going to run the <strong>iris_classifier.html</strong> file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OqLfb1fPBEm1fVK5" /></figure><ul><li><a href="https://github.com/https-deeplearning-ai/tensorflow-2-public/tree/main">GitHub - https-deeplearning-ai/tensorflow-2-public</a></li><li><a href="https://peaceadegbite1.medium.com/iris-flower-classification-60790e9718a1">Iris Flower Classification</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b93abda4bd8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Redux Persist with React Native using Redux Toolkit]]></title>
            <link>https://medium.com/@sisongqolosi/redux-persist-with-react-native-using-redux-toolkit-2908cbb9c870?source=rss-e22b12b3ecd------2</link>
            <guid isPermaLink="false">https://medium.com/p/2908cbb9c870</guid>
            <category><![CDATA[redux-toolkit]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Siso ngqolosi]]></dc:creator>
            <pubDate>Sun, 09 Jul 2023 10:39:33 GMT</pubDate>
            <atom:updated>2023-07-09T10:39:33.957Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LiwTls6tIrnznm48XCI_dw.png" /></figure><p>Redux Persist is a powerful library that enables the persistence of Redux store data across sessions in React Native applications. By integrating Redux Persist with Redux Toolkit, you can easily store and rehydrate your Redux store state, providing a seamless user experience.</p><p>Redux Toolkit is a popular library that simplifies Redux development by providing a set of utilities and conventions. It includes a reducer and action creation patterns that streamline the process of writing Redux logic. Combining Redux Persist with Redux Toolkit can significantly enhance the efficiency and reliability of state management in your React Native apps.</p><p>To get started, make sure you have a React Native project set up with Redux Toolkit. If you haven’t done this yet, you can follow the official documentation to create a new project and set up Redux Toolkit.</p><p>Once you have your Redux Toolkit store configured, you can proceed with integrating Redux Persist. Begin by installing the necessary dependencies:</p><pre>yarn add redux-persist<br>yarn add redux-redux<br>yarn add @reduxjs/toolkit<br>yarn add @react-native-async-storage/async-storage</pre><p>Redux Persist uses AsyncStorage from the @react-native-async-storage/async-storage package to persist the Redux store data. This package is specifically designed for React Native applications.</p><p>After installing the dependencies, you need to create a persistor and enhance your store with Redux Persist functionality. In your Redux store file, typically named store.js or configureStore.js, add the following code:</p><pre>import { configureStore } from &#39;@reduxjs/toolkit&#39;;<br>import { persistStore, persistReducer } from &#39;redux-persist&#39;;<br>import AsyncStorage from &#39;@react-native-async-storage/async-storage&#39;;<br>import rootReducer from &#39;./reducers&#39;;<br><br>const persistConfig = {<br>  key: &#39;root&#39;,<br>  storage: AsyncStorage,<br><br>};<br>const persistedReducer = persistReducer(persistConfig, rootReducer);<br>export const store = configureStore({<br>  reducer: persistedReducer,<br>});<br>export const persistor = persistStore(store);</pre><p>Let’s break down the code above. First, we import the necessary dependencies: configureStore from Redux Toolkit, persistStore and persistReducer from Redux Persist, AsyncStorage from @react-native-async-storage/async-storage, and your root reducer from the ./reducers file.</p><p>Next, we define the persistConfig object, which specifies the key for the persisted state and the storage mechanism (AsyncStorage in this case). You can customize the configuration based on your specific requirements.</p><p>Then, we create a new reducer using persistReducer by passing the persistConfig and the root reducer. This new reducer is the one that will be used by the store.</p><p>Finally, we export the store created with configureStore and the persistor created with persistStore.</p><p>To add whitelist and blacklist functionality to Redux Persist in Redux Toolkit, you can modify the persistConfig object as follows:</p><pre>const persistConfig = {<br>  key: &#39;root&#39;,<br>  storage: AsyncStorage,<br>  whitelist: [&#39;key1&#39;, &#39;key2&#39;],<br>  blacklist: [&#39;key3&#39;, &#39;key4&#39;],<br>};</pre><p>Here’s an explanation of how whitelist and blacklist work in Redux Persist:</p><ol><li><strong>Whitelist</strong>: By specifying an array of keys in the whitelist property, you can choose which reducers&#39; state should be persisted. Only the state of the specified reducers will be saved and restored upon app reload. In the example above, the state of key1 and key2 reducers will be persisted, while other reducers will be ignored.</li><li><strong>Blacklist</strong>: Conversely, by specifying an array of keys in the blacklist property, you can exclude specific reducers from being persisted. The state of all reducers except those specified in the blacklist will be saved and restored. In the example above, the state of all reducers except key3 and key4 will be persisted</li></ol><p>You can customize the whitelist and blacklist arrays according to your specific requirements. It&#39;s important to note that you should provide the exact keys of the reducers as they are defined in your root reducer.</p><p>Here’s an updated version of the code with the whitelist and blacklist included:</p><pre>import { configureStore } from &#39;@reduxjs/toolkit&#39;;<br>import { persistStore, persistReducer } from &#39;redux-persist&#39;;<br>import AsyncStorage from &#39;@react-native-async-storage/async-storage&#39;;<br>import rootReducer from &#39;./reducers&#39;;<br><br>const persistConfig = {<br>  key: &#39;root&#39;,<br>  storage: AsyncStorage,<br>  whitelist: [&#39;key1&#39;, &#39;key2&#39;],//Things you want to persist<br>  blacklist: [&#39;key3&#39;, &#39;key4&#39;],//Things you don&#39;t want to persist<br>};<br><br>// Middleware: Redux Persist Persisted Reducer<br>const persistedReducer = persistReducer(persistConfig, rootReducer);<br>export const store = configureStore({<br>  reducer: persistedReducer,<br>});<br>export const persistor = persistStore(store);</pre><p>By adding the whitelist and blacklist properties to the persistConfig object, you can control which parts of your Redux state are persisted and which are ignored during app reloads.</p><p>With the Redux store and persistence configured, you can now integrate Redux Persist with your React Native components. In your root component file, typically named App.js or index.js, make the following modifications:</p><pre>import React from &#39;react&#39;;<br>import { Provider } from &#39;react-redux&#39;;<br>import { PersistGate } from &#39;redux-persist/integration/react&#39;;<br>import { store, persistor } from &#39;./store&#39;;<br>import AppContainer from &#39;./AppContainer&#39;;<br><br>const App = () =&gt; {<br>  return (<br>    &lt;Provider store={store}&gt;<br>      &lt;PersistGate loading={null} persistor={persistor}&gt;<br>        &lt;AppContainer /&gt;<br>      &lt;/PersistGate&gt;<br>    &lt;/Provider&gt;<br>  );<br>};<br>export default App;</pre><p>In the code above, we import Provider from react-redux, PersistGate from redux-persist/integration/react, the store and persistor from our Redux store configuration, and the AppContainer component.</p><p>We wrap the AppContainer component with the Provider component from react-redux to provide the Redux store to our app. Then, we wrap the Provider component with the PersistGate component from redux-persist/integration/react and pass the loading prop as null (you can customize this loading behavior) and the persistor prop with our persistor.</p><p>Now, your Redux store state will persist between app sessions. You can dispatch actions and modify the state as usual, and Redux Persist will take care of storing and rehydrating the data.</p><p>By combining Redux Persist with Redux Toolkit, you can build robust React Native applications with efficient and reliable state management. Your users will appreciate the seamless experience of having their app state persist even when the app is closed or restarted.</p><h4>Redux Persist Integration</h4><p>If you’re using Redux Persist with Redux Toolkit, there are a few additional considerations to keep in mind.</p><h4>Ignoring Redux Persist Actions</h4><p>When using Redux Persist, it’s important to ignore the action types dispatched by it to prevent serialization issues. You can achieve this by configuring the serializableCheck middleware option in your Redux store setup.</p><pre>...<br><br>import { persistStore, persistReducer, FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER } from &#39;redux-persist&#39;;<br><br>...<br><br>const persistedReducer = persistReducer(persistConfig, rootReducer);<br><br>const store = configureStore({<br>  reducer: persistedReducer,<br>  middleware: (getDefaultMiddleware) =&gt;<br>    getDefaultMiddleware({<br>      serializableCheck: {<br>        ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],<br>      },<br>    }),<br>});</pre><p>By specifying the ignoredActions array with the action types [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER], Redux Toolkit will handle these actions properly during serialization, preventing any potential issues.</p><h4>Clearing Persisted State</h4><p>If you need to clear specific parts of the persisted state, such as on a logout action, you can add an extra reducer to the relevant slice. By including the PURGE action type from Redux Persist, you can clear the persisted state for that slice when calling persistor.purge().</p><pre>import { PURGE } from &#39;redux-persist&#39;;<br><br>// ...<br><br>extraReducers: (builder) =&gt; {<br>  builder.addCase(PURGE, (state) =&gt; {<br>    customEntityAdapter.removeAll(state);<br>  });<br>}</pre><p>Replace customEntityAdapter with the adapter or logic for the specific slice you want to clear.</p><p>Remember to refer to the Redux Persist and Redux Toolkit documentation for further details and customization options.</p><p>Happy coding!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FkX8VWBB_DNM%3Fstart%3D1%26feature%3Doembed%26start%3D1&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DkX8VWBB_DNM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FkX8VWBB_DNM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2aaabc8f8a346f2f20bbfd2f40216fb0/href">https://medium.com/media/2aaabc8f8a346f2f20bbfd2f40216fb0/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2908cbb9c870" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fully Typed React Navigation Drawer]]></title>
            <link>https://medium.com/@sisongqolosi/fully-typed-react-navigation-drawer-725279523054?source=rss-e22b12b3ecd------2</link>
            <guid isPermaLink="false">https://medium.com/p/725279523054</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[reactnativeappdevelopment]]></category>
            <category><![CDATA[drawer]]></category>
            <dc:creator><![CDATA[Siso ngqolosi]]></dc:creator>
            <pubDate>Sat, 08 Jul 2023 13:48:48 GMT</pubDate>
            <atom:updated>2023-07-08T13:48:48.012Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*-LwGgAJuLgLzDMbv8wpoOQ.gif" /></figure><h3>Introduction</h3><p>Drawer navigation is a popular navigation pattern that allows users to access different views in an app by swiping from the left or right side of the screen.</p><p>Creating a fully typed drawer navigation in React can greatly enhance the development experience and improve the overall quality of your app. In this blog post, we will explore how to achieve this using the latest versions of popular libraries like React Navigation.</p><p>Before we begin, make sure you have the following dependencies installed in your project:</p><pre>&quot;dependencies&quot;: {<br>  &quot;@react-navigation/drawer&quot;: &quot;^6.5.0&quot;,<br>  &quot;@react-navigation/native&quot;: &quot;^6.0.13&quot;,<br>  &quot;@react-navigation/native-stack&quot;: &quot;^6.9.1&quot;,<br>  &quot;react&quot;: &quot;18.1.0&quot;,<br>  &quot;react-native&quot;: &quot;0.70.3&quot;,<br>  &quot;react-native-gesture-handler&quot;: &quot;^2.8.0&quot;,<br>  &quot;react-native-reanimated&quot;: &quot;^2.11.0&quot;,<br>  &quot;react-native-safe-area-context&quot;: &quot;^4.4.1&quot;,<br>  &quot;react-native-screens&quot;: &quot;^3.18.2&quot;<br>}</pre><p>Once you have the necessary dependencies, follow the steps below to create a fully typed drawer navigation in React:</p><p>Step 1: Set up a basic React Native project Start by creating a new React Native project using your preferred method. You can use the React Native CLI or a tool like Expo to initialize the project.</p><p>Step 2: Install the required packages In your project directory, run the following command to install the required packages:</p><pre>npm install @react-navigation/drawer @react-navigation/native @react-navigation/native-stack react-native-gesture-handler react-native-reanimated react-native-safe-area-context react-native-screens</pre><p>Remember to add this to your <em>babel.config.js</em></p><pre>module.exports = {<br>  presets: [&quot;module:metro-react-native-babel-preset&quot;],<br>  plugins: [&quot;react-native-reanimated/plugin&quot;],<br>};</pre><p>Step 3: Set up the navigation structure Create a new file called DrawerNavigator.tsx in your project&#39;s navigation directory. Inside this file, import the necessary modules and define your navigation structure. Here&#39;s an example:</p><pre>import { createDrawerNavigator } from &#39;@react-navigation/drawer&#39;;<br>import { NavigationContainer } from &#39;@react-navigation/native&#39;;<br>import HomeScreen from &#39;../screens/HomeScreen&#39;;<br>import SettingsScreen from &#39;../screens/SettingsScreen&#39;;<br><br>type RootDrawerParamList = {<br>  Home: undefined;<br>  Settings: undefined;<br>};<br>const Drawer = createDrawerNavigator&lt;RootDrawerParamList&gt;();<br><br>const DrawerNavigator = () =&gt; {<br>  return (<br>    &lt;NavigationContainer&gt;<br>      &lt;Drawer.Navigator&gt;<br>        &lt;Drawer.Screen name=&quot;Home&quot; component={HomeScreen} /&gt;<br>        &lt;Drawer.Screen name=&quot;Settings&quot; component={SettingsScreen} /&gt;<br>      &lt;/Drawer.Navigator&gt;<br>    &lt;/NavigationContainer&gt;<br>  );<br>};<br>export default DrawerNavigator;</pre><p>In this example, we create a drawer navigator using the createDrawerNavigator function from the @react-navigation/drawer package. We define a type for our navigation parameters using TypeScript generics and specify the available screens (HomeScreen and SettingsScreen) in the RootDrawerParamList.</p><p>Step 4: Define screen components Create the HomeScreen.tsx and SettingsScreen.tsx files inside your project&#39;s screens directory. These files will contain the actual content for each screen.</p><pre>import React from &#39;react&#39;;<br>import { View, Text } from &#39;react-native&#39;;<br><br>const HomeScreen = () =&gt; {<br>  return (<br>    &lt;View&gt;<br>      &lt;Text&gt;Welcome to the Home Screen!&lt;/Text&gt;<br>    &lt;/View&gt;<br>  );<br>};<br>export default HomeScreen;</pre><pre>import React from &#39;react&#39;;<br>import { View, Text } from &#39;react-native&#39;;<br><br>const SettingsScreen = () =&gt; {<br>  return (<br>    &lt;View&gt;<br>      &lt;Text&gt;Here you can configure the app settings.&lt;/Text&gt;<br>    &lt;/View&gt;<br>  );<br>};<br>export default SettingsScreen;</pre><p>Step 5: Render the drawer navigator Finally, in your app’s entry point (usually App.tsx or index.js), import and render the DrawerNavigator component.</p><pre>import React from &#39;react&#39;;<br>import DrawerNavigator from &#39;./src/navigation/DrawerNavigator&#39;;<br>const App = () =&gt; {<br>  return &lt;DrawerNavigator /&gt;;<br>};<br>export default App;</pre><p>That’s it! You have successfully created a fully typed drawer navigation in React using React Navigation. Now you can run your app and navigate between the HomeScreen and SettingsScreen using the drawer menu.</p><p>By leveraging TypeScript generics and the type definitions provided by React Navigation, you can ensure type safety throughout your navigation code, reducing the likelihood of runtime errors and improving the overall maintainability of your app.</p><p>Arranging the files into folders</p><p>Folder Arrangement:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*Kgb0SA9PLxNhzPfcycV4kw.png" /></figure><p>Types folder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hGYgF0fanwK1PdU7d4G_ZQ.png" /></figure><h3>Conclusion</h3><p>This is just a brief overview of how to create a fully typed drawer navigation in React. For more information, please refer to the official documentation: <a href="https://reactnavigation.org/docs/drawer-navigator/">https://reactnavigation.org/docs/drawer-navigator/.</a></p><p>Link to the <a href="https://github.com/sisoalbert/TypedDrawerNavigationApp/tree/master">https://github.com/sisoalbert/TypedDrawerNavigationApp/tree/master</a></p><p><em>Known issue:iOS Warning: RCTBridge required dispatch_sync to load REAModule</em></p><p><em>Downgrade to react-native-reanimated@2.10.0 and upgrade to 2.12.0 once this issue is fixed.</em></p><p>I hope this helps!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=725279523054" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Custom theme and colours in React Native Paper]]></title>
            <link>https://medium.com/@sisongqolosi/custom-theme-and-colours-in-react-native-paper-bc3388008adf?source=rss-e22b12b3ecd------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc3388008adf</guid>
            <category><![CDATA[themes]]></category>
            <category><![CDATA[react-native-paper]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Siso ngqolosi]]></dc:creator>
            <pubDate>Wed, 28 Jun 2023 08:40:55 GMT</pubDate>
            <atom:updated>2023-06-28T08:45:25.270Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XLdbNB-mYxEK2l0bwVPQ8w.png" /></figure><p>In the vast realm of mobile app development, where user experience reigns supreme, the choice of a captivating visual theme becomes paramount.</p><p>Imagine a world where the building blocks of your app seamlessly adapt to your design aspirations, offering a harmonious blend of aesthetics and functionality. Welcome to the captivating universe of React Native Paper Theming, where the brushstrokes of creativity meet the precision of code, unlocking endless possibilities for crafting immersive user interfaces. Step into the realm where design and development converge, as we unravel the enchanting tale of React Native Paper Theming and the artistry it bestows upon your apps.</p><p>A theme is a set of values that control the appearance of React Native Paper components. It can be used to change the colors, fonts, and other styles of your app.</p><p>The DefaultTheme object is the default theme that is used by React Native Paper. It contains a set of predefined values for all of the theme properties. You can use this theme as a starting point and then customize it to match the look and feel of your app.</p><p>To create a custom theme, you can extend the DefaultTheme object and override the properties that you want to change. For example, the following code creates a custom theme that changes the primary color to red etc:</p><pre>const theme = {<br>    ...DefaultTheme,<br>    colors: {<br>      ...DefaultTheme.colors,&lt;--- Remove if you don&#39;t want any colors<br>      primary: &quot;red&quot;,<br>      secondary: &quot;yellow&quot;,<br>      background: &quot;white&quot;,<br>      surface: &quot;white&quot;,<br>    },<br>  };</pre><h3>RN paper default themes</h3><p>The following are the default colors in the library:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PGxmMyHzDgB5lKVQ5VBKGg.png" /></figure><h3>Extending the theme<a href="https://callstack.github.io/react-native-paper/docs/guides/theming#extending-the-theme">​</a></h3><p>Keeping your own properties in the theme is fully supported by our library:</p><pre>import * as React from &#39;react&#39;;<br>import {<br>  MD3LightTheme as DefaultTheme,<br>  PaperProvider,<br>} from &#39;react-native-paper&#39;;<br>import App from &#39;./src/App&#39;;<br><br>const theme = {<br>  ...DefaultTheme,<br>  // Specify custom property<br>  myOwnProperty: true,<br>  // Specify custom property in nested object<br>  colors: {<br>    myOwnColor: &#39;#BADA55&#39;,<br>  },<br>};<br><br>export default function Main() {<br>  return (<br>    &lt;PaperProvider theme={theme}&gt;<br>      &lt;App /&gt;<br>    &lt;/PaperProvider&gt;<br>  );<br>}</pre><h3>Creating dynamic theme colors<a href="https://callstack.github.io/react-native-paper/docs/guides/theming#creating-dynamic-theme-colors">​</a></h3><p>Dynamic Color Themes allows for generating two color schemes lightScheme and darkScheme, based on the provided source color. Created schemes are following the Material Design 3 color system and covering colors structure from the Paper theme. User may generate these schemes using the tool in the react native paper website:</p><p><a href="https://callstack.github.io/react-native-paper/docs/guides/theming">https://callstack.github.io/react-native-paper/docs/guides/theming</a></p><p>Here is a list of the full available customizations</p><pre>const customTheme = {<br>    ...DefaultTheme,<br>    dark: false,<br>    roundness: 4,<br>    colors: {<br>      ...DefaultTheme.colors,<br>      primary: &quot;#FF0000&quot;,<br>      primaryContainer: &quot;#7FAF73&quot;,<br>      secondary: &quot;#00FF00&quot;,<br>      secondaryContainer: &quot;#FFFF00&quot;,<br>      tertiary: &quot;#800080&quot;,<br>      tertiaryContainer: &quot;#FFA500&quot;,<br>      surface: &quot;#FFC0CB&quot;,<br>      surfaceVariant: &quot;#008080&quot;,<br>      surfaceDisabled: &quot;#808080&quot;,<br>      background: &quot;#FFFFFF&quot;,<br>      error: &quot;#A52A2A&quot;,<br>      errorContainer: &quot;#808080&quot;,<br>      onPrimary: &quot;#00FFFF&quot;,<br>      onPrimaryContainer: &quot;#FFFFFF&quot;,<br>      onSecondary: &quot;#00FF00&quot;,<br>      onSecondaryContainer: &quot;#808000&quot;,<br>      onTertiary: &quot;#800000&quot;,<br>      onTertiaryContainer: &quot;#000080&quot;,<br>      onSurface: &quot;#C0C0C0&quot;,<br>      onSurfaceVariant: &quot;#FFD700&quot;,<br>      onSurfaceDisabled: &quot;#808080&quot;,<br>      onError: &quot;#4B0082&quot;,<br>      onErrorContainer: &quot;#FF7F50&quot;,<br>      onBackground: &quot;#F5F5DC&quot;,<br>      outline: &quot;#CD853F&quot;,<br>      outlineVariant: &quot;#708090&quot;,<br>      inverseSurface: &quot;#7FFFD4&quot;,<br>      inverseOnSurface: &quot;#BDB76B&quot;,<br>      inversePrimary: &quot;#DA70D6&quot;,<br>      shadow: &quot;#E6E6FA&quot;,<br>      scrim: &quot;#D8BFD8&quot;,<br>      backdrop: &quot;#808080&quot;,<br>    },<br>  };</pre><p>The default light theme:</p><pre>{<br>  &quot;colors&quot;: {<br>    &quot;primary&quot;: &quot;rgb(53, 107, 0)&quot;,<br>    &quot;onPrimary&quot;: &quot;rgb(255, 255, 255)&quot;,<br>    &quot;primaryContainer&quot;: &quot;rgb(156, 250, 81)&quot;,<br>    &quot;onPrimaryContainer&quot;: &quot;rgb(12, 32, 0)&quot;,<br>    &quot;secondary&quot;: &quot;rgb(86, 98, 75)&quot;,<br>    &quot;onSecondary&quot;: &quot;rgb(255, 255, 255)&quot;,<br>    &quot;secondaryContainer&quot;: &quot;rgb(218, 231, 201)&quot;,<br>    &quot;onSecondaryContainer&quot;: &quot;rgb(20, 30, 12)&quot;,<br>    &quot;tertiary&quot;: &quot;rgb(56, 102, 101)&quot;,<br>    &quot;onTertiary&quot;: &quot;rgb(255, 255, 255)&quot;,<br>    &quot;tertiaryContainer&quot;: &quot;rgb(187, 236, 234)&quot;,<br>    &quot;onTertiaryContainer&quot;: &quot;rgb(0, 32, 31)&quot;,<br>    &quot;error&quot;: &quot;rgb(186, 26, 26)&quot;,<br>    &quot;onError&quot;: &quot;rgb(255, 255, 255)&quot;,<br>    &quot;errorContainer&quot;: &quot;rgb(255, 218, 214)&quot;,<br>    &quot;onErrorContainer&quot;: &quot;rgb(65, 0, 2)&quot;,<br>    &quot;background&quot;: &quot;rgb(253, 253, 245)&quot;,<br>    &quot;onBackground&quot;: &quot;rgb(26, 28, 24)&quot;,<br>    &quot;surface&quot;: &quot;rgb(253, 253, 245)&quot;,<br>    &quot;onSurface&quot;: &quot;rgb(26, 28, 24)&quot;,<br>    &quot;surfaceVariant&quot;: &quot;rgb(224, 228, 214)&quot;,<br>    &quot;onSurfaceVariant&quot;: &quot;rgb(68, 72, 62)&quot;,<br>    &quot;outline&quot;: &quot;rgb(116, 121, 109)&quot;,<br>    &quot;outlineVariant&quot;: &quot;rgb(196, 200, 186)&quot;,<br>    &quot;shadow&quot;: &quot;rgb(0, 0, 0)&quot;,<br>    &quot;scrim&quot;: &quot;rgb(0, 0, 0)&quot;,<br>    &quot;inverseSurface&quot;: &quot;rgb(47, 49, 44)&quot;,<br>    &quot;inverseOnSurface&quot;: &quot;rgb(241, 241, 234)&quot;,<br>    &quot;inversePrimary&quot;: &quot;rgb(129, 221, 54)&quot;,<br>    &quot;elevation&quot;: {<br>      &quot;level0&quot;: &quot;transparent&quot;,<br>      &quot;level1&quot;: &quot;rgb(243, 246, 233)&quot;,<br>      &quot;level2&quot;: &quot;rgb(237, 241, 225)&quot;,<br>      &quot;level3&quot;: &quot;rgb(231, 237, 218)&quot;,<br>      &quot;level4&quot;: &quot;rgb(229, 236, 216)&quot;,<br>      &quot;level5&quot;: &quot;rgb(225, 233, 211)&quot;<br>    },<br>    &quot;surfaceDisabled&quot;: &quot;rgba(26, 28, 24, 0.12)&quot;,<br>    &quot;onSurfaceDisabled&quot;: &quot;rgba(26, 28, 24, 0.38)&quot;,<br>    &quot;backdrop&quot;: &quot;rgba(45, 50, 40, 0.4)&quot;,<br>    &quot;custom0&quot;: &quot;rgb(135, 82, 0)&quot;,<br>    &quot;onCustom0&quot;: &quot;rgb(255, 255, 255)&quot;,<br>    &quot;custom0Container&quot;: &quot;rgb(255, 221, 186)&quot;,<br>    &quot;onCustom0Container&quot;: &quot;rgb(43, 23, 0)&quot;<br>  }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc3388008adf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Image Recognition React Native: Vision Camera]]></title>
            <link>https://medium.com/@sisongqolosi/image-recognition-react-native-vision-camera-8c84389a611c?source=rss-e22b12b3ecd------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c84389a611c</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[firebase-ml-kit]]></category>
            <category><![CDATA[image-classification]]></category>
            <category><![CDATA[tensorflowjs]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Siso ngqolosi]]></dc:creator>
            <pubDate>Tue, 18 Apr 2023 20:33:09 GMT</pubDate>
            <atom:updated>2023-06-20T12:49:59.678Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ONfVuHUmDXp4FaRd.jpg" /></figure><p>React Native is a powerful framework for building mobile applications that can run on both iOS and Android devices. Using firebase’s powerful ML Kit model, we are able as react native developers to get on-device Image Recognition. We are going to use the Vision Camera library and its frameprocessors.</p><h3>Installation:</h3><p>yarn add react-native-vision-camera<br>cd ios &amp;&amp; npx pod-install</p><p><a href="https://www.react-native-vision-camera.com/docs/guides">Getting Started | VisionCamera</a></p><p><em>Gradle error solution: </em><a href="https://github.com/mrousavy/react-native-vision-camera/issues/1352"><em>https://github.com/mrousavy/react-native-vision-camera/issues/1352</em></a></p><p><strong>If you are using the React Native CLI:</strong></p><p><strong>Android</strong></p><p>Open your project’s AndroidManifest.xmland add the following lines inside the &lt;manifest&gt; tag:<br>&lt;uses-permission android:name=”android.permission.CAMERA” /&gt;</p><pre>PATH:\android\app\src\main\AndroidManifest.xml</pre><p><strong>IOS</strong></p><p>Open your project’s Info.plist and add the following lines inside the outermost &lt;dict&gt; tag:<br>&lt;key&gt;NSCameraUsageDescription&lt;/key&gt;&lt;string&gt;$(PRODUCT_NAME) needs access to your Camera.&lt;/string&gt;</p><p><strong>If you are using Expo:</strong><a href="https://www.react-native-vision-camera.com/docs/guides#managed-expo"><strong>​</strong></a></p><p>Add the VisionCamera plugin to your Expo config (app.json, app.config.json or app.config.js):</p><pre>{<br>  &quot;name&quot;: &quot;my app&quot;,<br>  &quot;plugins&quot;: [<br>    [<br>      &quot;react-native-vision-camera&quot;,<br>      {<br>        &quot;cameraPermissionText&quot;: &quot;$(PRODUCT_NAME) needs access to your Camera.&quot;<br>// optionally, if you want to record audio:<br>        &quot;enableMicrophonePermission&quot;: true,<br>        &quot;microphonePermissionText&quot;: &quot;$(PRODUCT_NAME) needs access to your Microphone.&quot;<br>      }<br>    ]<br>  ]<br>}</pre><p>Finally, compile the mods:</p><pre>expo prebuild</pre><p>To apply the changes, build a new binary with EAS:</p><pre>eas build</pre><h3>Getting and Requesting Permissions:</h3><p>This ReactuseEffect hook checks the current camera permission status when the component mounts. If the permission is authorized, it sets the cameraPermission state accordingly. If not, it requests permission and sets the state to either authorized or restricted, or opens the settings if permission is still denied. This hook runs only once on mount because the dependency array is empty</p><pre>useEffect(() =&gt; {<br>    const requestCameraPermission = async () =&gt; {<br>      const status = await Camera.getCameraPermissionStatus();<br>      if (status !== &#39;authorized&#39;) {<br>        const newStatus = await Camera.requestCameraPermission();<br>        if (newStatus === &#39;denied&#39;) {<br>          openSettings();<br>        }<br>        setCameraPermission(newStatus);<br>      } else {<br>        setCameraPermission(status);<br>      }<br>    };<br>requestCameraPermission();<br>  }, []);</pre><h3>Adding the camera:</h3><p>In the Camera function, we use the <strong>useCameraDevices </strong>hook to get access to the available camera devices and set the default device to the back camera. We also create a camera reference using the <strong>useRef </strong>hook and use the <strong>useState </strong>hook to store the image path. (see <a href="https://www.react-native-vision-camera.com/docs/guides/devices">Camera Devices</a>)</p><pre>... <br> const camera = useRef(null);<br>  const devices = useCameraDevices();<br>  const device = devices.back;    <br>... <br>if (device == null) return &lt;LoadingView /&gt;<br>return (<br>&lt;&gt;<br>          &lt;Camera<br>            ref={camera}<br>            style={StyleSheet.absoluteFill}<br>            device={device}<br>            isActive={true}<br>            photo={true}<br>          /&gt;<br>&lt;/&gt;<br>       )<br>....</pre><h3>Frame processors —Image Recognition<a href="https://www.react-native-vision-camera.com/docs/guides/frame-processors#what-are-frame-processors">​</a></h3><p>Frame processors are functions that are written in JavaScript (or TypeScript) that can be used to process frames the camera “sees”. Inside those functions, you can call Frame Processor Plugins, which are high performance native functions specifically designed for certain use-cases.</p><p>Frame processors require <a href="https://github.com/software-mansion/react-native-reanimated">react-native-reanimated</a> 2.2.0 or higher.</p><pre>yarn add react-native-reanimated@2.14</pre><pre>import &#39;react-native-reanimated&#39;</pre><p>to the top of the file when using useFrameProcessor.</p><p>A <a href="https://github.com/mrousavy/react-native-vision-camera">VisionCamera</a> Frame Processor Plugin to label images using <a href="https://developers.google.com/ml-kit/vision/image-labeling">MLKit Vision Image Labeling</a>.</p><h3>Installation</h3><pre>npm install vision-camera-image-labeler<br>cd ios &amp;&amp; pod install</pre><p>Add the plugin to your babel.config.js:</p><pre>module.exports = {<br>  plugins: [<br>    [<br>      &#39;react-native-reanimated/plugin&#39;,<br>      {<br>        globals: [&#39;__labelImage&#39;],<br>      },<br>    ],</pre><blockquote><em>Note: You have to restart metro-bundler for changes in the </em><em>babel.config.js file to take effect.</em></blockquote><p>Here is the frame processor and Camera Code:</p><pre>  const frameProcessor = useFrameProcessor(<br>    frame =&gt; {<br>      &#39;worklet&#39;;<br>      const labels = labelImage(frame);<br>      console.log(&#39;Labels:&#39;, labels);<br>      const currentLabelText = labels[0]?.label;<br><br>      console.log(&#39;currentLabel:&#39;, currentLabel.value);<br>      currentLabel.value = labels[0]?.label;<br>    },<br>    [currentLabel],<br>  );<br><br>  if (device == null) return &lt;LoadingView /&gt;;<br>  return (<br>    &lt;&gt;<br>      &lt;Camera<br>        ref={camera}<br>        style={StyleSheet.absoluteFill}<br>        device={device}<br>        isActive={showCamera}<br>        photo={true}<br>        frameProcessor={frameProcessor}<br>        frameProcessorFps={3}<br>      /&gt;<br>      &lt;&gt;<br>        &lt;Label sharedValue={currentLabel} /&gt;<br>      &lt;/&gt;<br>    &lt;/&gt;<br>  );</pre><p>Walaaa!! you are done, here is the Console Log</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-sz1snS83BJAQqTO7tBObw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*TBut7KRsQfWZTKgX" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c84389a611c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>