<?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 Ahmed Sbai on Medium]]></title>
        <description><![CDATA[Stories by Ahmed Sbai on Medium]]></description>
        <link>https://medium.com/@sbaiahmed1?source=rss-113ef063808e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*DXdRRh0pzaH_CGzpHZTiBQ.jpeg</url>
            <title>Stories by Ahmed Sbai on Medium</title>
            <link>https://medium.com/@sbaiahmed1?source=rss-113ef063808e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 04:13:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sbaiahmed1/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[Mobile Security: A Deep Dive into React Native Biometrics]]></title>
            <link>https://javascript.plainenglish.io/mobile-security-a-deep-dive-into-react-native-biometrics-9f19645320d9?source=rss-113ef063808e------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f19645320d9</guid>
            <category><![CDATA[biometrics]]></category>
            <category><![CDATA[new-architecture]]></category>
            <category><![CDATA[react-native-biometrics]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[mobile-app-security]]></category>
            <dc:creator><![CDATA[Ahmed Sbai]]></dc:creator>
            <pubDate>Sun, 29 Jun 2025 16:39:20 GMT</pubDate>
            <atom:updated>2025-06-30T00:01:31.096Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qtyudSQwD4WAWPvVM27Wmg.png" /></figure><blockquote>How a modern library is revolutionising biometric authentication in React Native apps</blockquote><p>In an era where mobile security has become paramount, biometric authentication has emerged as the gold standard for protecting user data. Today, we’re exploring `<a href="https://github.com/sbaiahmed1/react-native-biometrics">@sbaiahmed1/react-native-biometrics</a>` , a cutting-edge React Native library that’s setting new standards for biometric authentication across iOS and Android platforms.</p><h4><strong><em>The Problem: Fragmented Biometric Authentication</em></strong></h4><p>Before diving into the solution, let’s understand the challenge. Mobile developers have long struggled with implementing biometric authentication due to:</p><ul><li>Platform Inconsistencies : iOS uses Face ID and Touch ID, while Android supports various fingerprint sensors and face recognition systems</li><li>Complex Native Integration : Each platform requires different native code implementations</li><li>Security Vulnerabilities : Many existing solutions use hardcoded key aliases, creating potential security risks</li><li>Limited Debugging Tools : Troubleshooting biometric issues across devices has been notoriously difficult</li></ul><h3>Enter React Native Biometrics: A Unified Solution</h3><p>The `<a href="http://twitter.com/sbaiahmed1/react-native-biometrics">@sbaiahmed1/react-native-biometrics</a>` library addresses these challenges with a comprehensive, security-first approach. Built with modern Swift for iOS and Kotlin for Android, this library offers:</p><p><strong>🔒 Unified API Across Platforms<br></strong>The library provides a single JavaScript interface that works seamlessly across both iOS and Android:</p><pre>import { isSensorAvailable, simplePrompt } from &#39;@sbaiahmed1/react-native-biometrics&#39;;<br><br>// Check availability across all platforms<br>const sensorInfo = await isSensorAvailable();<br>if (sensorInfo.available) {<br>  const result = await simplePrompt(&#39;Please authenticate to continue&#39;);<br>}</pre><p><strong>🛡️ Advanced Security Features<br></strong>What sets this library apart is its comprehensive security architecture:<br> App-Specific Key Aliases<br>Unlike previous solutions that used hardcoded aliases (creating security vulnerabilities), this library implements app-specific key generation:</p><pre>// Automatic app-specific alias generation<br>const defaultAlias = await getDefaultKeyAlias();<br>// Returns: &quot;com.myapp.ReactNativeBiometrics&quot;<br><br>// Or configure custom aliases for different contexts<br>await configureKeyAlias(&#39;com.myapp.biometric.payment&#39;);</pre><p>this enhancement eliminates cross-app key access vulnerabilities that plagued earlier implementations.</p><p><strong>Cryptographic Key Integrity Validation<br></strong>The library includes sophisticated key validation mechanisms:</p><pre>// Comprehensive integrity checking<br>const integrityResult = await validateKeyIntegrity(&#39;my-secure-key&#39;);<br>console.log(&#39;Hardware-backed:&#39;, integrityResult.integrityChecks.hardwareBacked);<br>console.log(&#39;Key accessible:&#39;, integrityResult.integrityChecks.keyAccessible);<br>console.log(&#39;Signature test passed:&#39;, integrityResult.integrityChecks.signatureTestPassed);</pre><p><strong>Digital Signature Operations<br></strong>For applications requiring data integrity verification:</p><pre>// Generate cryptographic signatures<br>const signatureResult = await verifyKeySignature(&#39;my-key&#39;, &#39;sensitive data&#39;);<br><br>// Later, validate data integrity<br>const validationResult = await validateSignature(<br>  &#39;my-key&#39;, <br>  &#39;sensitive data&#39;, <br>  signatureResult.signature<br>);</pre><p><strong>🔧 Enhanced Authentication Options<br></strong>The library supports both simple and advanced authentication scenarios:</p><pre>// Enhanced authentication with customizable UI<br>const result = await authenticateWithOptions({<br>  title: &#39;🔐 Secure Login&#39;,<br>  subtitle: &#39;Verify your identity&#39;,<br>  description: &#39;Use your biometric to access your account securely&#39;,<br>  allowDeviceCredentials: true,    // Allow PIN/password fallback<br>  disableDeviceFallback: false,    // Enable fallback options<br>});</pre><p><strong>📝 Comprehensive Logging System<br></strong>One of the library’s standout features is its advanced logging system, as detailed in this file (<a href="https://github.com/sbaiahmed1/react-native-biometrics/blob/main/docs/LOGGING.md">LOGGING</a>).</p><pre>// Configure centralized logging<br>configureLogger({<br>  enabled: true,<br>  level: LogLevel.INFO,<br>  prefix: &#39;[MyApp-Biometrics]&#39;,<br>  includeTimestamp: true,<br>  includeContext: true<br>});<br><br>// All operations are automatically logged<br>const logs = getLogs();</pre><p>The library includes comprehensive diagnostic utilities, as demonstrated in this <a href="https://github.com/sbaiahmed1/react-native-biometrics/blob/93af827b8c7c920ee9184cc42af75ca3a01662a6/example/src/DebuggingExample.tsx">Debugging Example</a></p><pre>// Get detailed device information<br>const diagnostics = await getDiagnosticInfo();<br>console.log(&#39;Platform:&#39;, diagnostics.platform);<br>console.log(&#39;Biometric capabilities:&#39;, diagnostics.biometricCapabilities);<br>console.log(&#39;Security level:&#39;, diagnostics.securityLevel);<br><br>// Run comprehensive functionality tests<br>const testResults = await runBiometricTest();<br>if (!testResults.success) {<br>  console.log(&#39;Issues found:&#39;, testResults.errors);<br>}</pre><h3>Real-World Implementation: The Example App</h3><p>The library includes a comprehensive example application showcasing all features. The <a href="https://github.com/sbaiahmed1/react-native-biometrics/blob/93af827b8c7c920ee9184cc42af75ca3a01662a6/example/src/CombinedBiometricsDemo.tsx">CombinedBiometricsDemo</a> component demonstrates:</p><p><strong>Key Management Interface</strong></p><pre>// Create keys with custom aliases<br>const handleCreateKeys = async (alias?: string) =&gt; {<br>  const result = await createKeys(alias);<br>  // Update UI with new key information<br>};<br><br>// Comprehensive testing suite<br>const runComprehensiveTest = async () =&gt; {<br>  const tests = [<br>    { name: &#39;Create Keys&#39;, fn: () =&gt; handleCreateKeys(alias) },<br>    { name: &#39;Validate Key Integrity&#39;, fn: () =&gt; handleValidateKeyIntegrity() },<br>    { name: &#39;Generate Signature&#39;, fn: () =&gt; handleGenerateSignature() },<br>    { name: &#39;Validate Signature&#39;, fn: () =&gt; handleValidateSignature() },<br>  ];<br>  <br>  for (const test of tests) {<br>    await test.fn();<br>  }<br>};</pre><p><strong>Security Testing Dashboard</strong></p><p>The example app provides a complete testing interface where developers can:</p><ul><li>Configure custom key aliases</li><li>Test key integrity validation</li><li>Generate and verify digital signatures</li><li>Monitor all operations in real-time</li><li>View comprehensive test results</li></ul><h3>Architecture and Performance</h3><p><strong>Modern Native Implementation</strong></p><ul><li>Swift for iOS implementation (replacing older Objective-C approaches)</li><li>Kotlin for Android implementation (modern, type-safe)</li><li>Hardware-backed security when available</li><li>Minimal dependencies for optimal performance</li></ul><p><strong>TypeScript-First Design</strong></p><p>Every aspect of the library is built with TypeScript, providing:</p><ul><li>Complete type safety</li><li>Excellent IDE support</li><li>Self-documenting APIs</li><li>Reduced runtime errors</li></ul><p><strong>New Architecture Compatibility</strong></p><p>The library supports both React Native’s old and new architectures, ensuring future-proofing for applications.</p><h3>Security Best Practices</h3><p>The library implements several security measures that developers should understand:</p><p><strong>Hardware-Backed Keys</strong></p><pre>// Check if keys are hardware-backed<br>const attributes = await getKeyAttributes(&#39;my-key&#39;);<br>if (attributes.attributes?.hardwareBacked) {<br>  console.log(&#39;Keys are stored in secure hardware&#39;);<br>}</pre><p><strong>Key Rotation Strategy</strong></p><pre>// Implement secure key rotation<br>const rotateKeys = async () =&gt; {<br>  const newAlias = &#39;com.myapp.biometric.v2&#39;;<br>  <br>  // Create new keys<br>  await createKeys(newAlias);<br>  <br>  // Validate integrity<br>  const integrity = await validateKeyIntegrity(newAlias);<br>  if (!integrity.valid) {<br>    throw new Error(&#39;New key integrity validation failed&#39;);<br>  }<br>  <br>  // Update configuration<br>  await configureKeyAlias(newAlias);<br>  <br>  // Clean up old keys<br>  await deleteKeys(&#39;com.myapp.biometric.v1&#39;);<br>};</pre><p><strong>Multi-Context Security</strong></p><p>The library supports different security contexts within the same app:</p><pre>// Different keys for different purposes<br>const LOGIN_KEY = &#39;com.myapp.biometric.login&#39;;<br>const PAYMENT_KEY = &#39;com.myapp.biometric.payment&#39;;<br>const ADMIN_KEY = &#39;com.myapp.biometric.admin&#39;;<br><br>// Each context has isolated security<br>await createKeys(LOGIN_KEY);<br>await createKeys(PAYMENT_KEY);</pre><h3>Production Considerations</h3><h4>Error Handling</h4><p>The library provides comprehensive error codes and handling:</p><pre>try {<br>  const result = await authenticateWithOptions(options);<br>  if (!result.success) {<br>    switch (result.errorCode) {<br>      case &#39;USER_CANCEL&#39;:<br>        // Handle user cancellation<br>        break;<br>      case &#39;BIOMETRY_LOCKOUT&#39;:<br>        // Handle too many failed attempts<br>        break;<br>      default:<br>        // Handle other errors<br>    }<br>  }<br>} catch (error) {<br>  // Handle system-level errors<br>}</pre><p><strong>Performance Monitoring</strong></p><pre>// Production logging configuration<br>configureLogger({<br>  enabled: true,<br>  level: LogLevel.WARN, // Only warnings and errors<br>  useColors: false,     // Disable colors in production<br>  maxStoredLogs: 1000   // Limit memory usage<br>});<br><br>// Monitor for issues<br>const analyzePerformance = () =&gt; {<br>  const logs = getLogs();<br>  const errorLogs = logs.filter(log =&gt; log.level === LogLevel.ERROR);<br>  <br>  if (errorLogs.length &gt; 5) {<br>    // Alert: High error rate detected<br>    reportToAnalytics(&#39;high_biometric_error_rate&#39;, errorLogs.length);<br>  }<br>};</pre><h3>The Developer Experience</h3><p>What makes this library exceptional is its focus on developer experience:</p><p><strong>Comprehensive Documentation<br></strong>Every feature is thoroughly documented with:</p><ul><li>Clear examples for common use cases</li><li>Advanced scenarios for complex implementations</li><li>Security guidelines for production apps</li><li>Troubleshooting guides for common issues</li></ul><p><strong>Rich Example Application<br></strong>The included example app serves as:</p><ul><li>Reference implementation for best practices</li><li>Testing playground for new features</li><li>Debugging tool for development</li><li>Learning resource for developers</li></ul><p><strong>Active Development<br></strong>The library is actively maintained with:</p><ul><li>Regular updates for new React Native versions</li><li>Security patches and improvements</li><li>Community feedback integration</li><li>Comprehensive testing across devices</li></ul><h3>Future Roadmap</h3><p>The library’s roadmap includes exciting enhancements:</p><ol><li>Automatic Key Rotation : Scheduled rotation policies with integrity validation</li><li>Remote Security Policies : Support for server-side security configuration</li><li>Advanced Audit Logging : Tamper-detection and compliance reporting</li><li>Multi-Factor Validation : Combining multiple authentication methods</li><li>Real-time Monitoring : Live integrity and usage pattern monitoring</li></ol><h3>Conclusion: A New Standard for Mobile Security</h3><p>The <a href="https://github.com/sbaiahmed1/react-native-biometrics">`@sbaiahmed1/react-native-biometrics`</a> library represents a significant leap forward in mobile biometric authentication. By addressing the security vulnerabilities of previous solutions while providing a comprehensive, developer-friendly API, it sets a new standard for what biometric libraries should offer.</p><p><strong>Key Takeaways:<br>- </strong>Security-First Design : App-specific key aliases and hardware-backed encryption<br>- Comprehensive Feature Set : From simple authentication to advanced cryptographic operations<br>- Developer-Friendly : Excellent TypeScript support and debugging tools<br>- Production-Ready : Robust error handling and performance monitoring<br>- Future-Proof : Compatible with React Native’s evolving architecture</p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/@InPlainEnglish"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a> | <a href="https://twitch.tv/inplainenglish"><strong>Twitch</strong></a></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f19645320d9" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/mobile-security-a-deep-dive-into-react-native-biometrics-9f19645320d9">Mobile Security: A Deep Dive into React Native Biometrics</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</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’s New Architecture: A Comprehensive Guide]]></title>
            <link>https://javascript.plainenglish.io/react-natives-new-architecture-a-comprehensive-guide-d1e2ce8f126e?source=rss-113ef063808e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1e2ce8f126e</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react-native-development]]></category>
            <category><![CDATA[new-architecture]]></category>
            <dc:creator><![CDATA[Ahmed Sbai]]></dc:creator>
            <pubDate>Tue, 29 Oct 2024 10:17:13 GMT</pubDate>
            <atom:updated>2024-10-31T14:22:05.713Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fblog.xmartlabs.com%2Fblog%2Fi-tested-react-native-new-architecture-improvements%2F&amp;psig=AOvVaw3JJSzysUfXmrhgZ11gfAd7&amp;ust=1730282729282000&amp;source=images&amp;cd=vfe&amp;opi=89978449&amp;ved=0CBQQjRxqFwoTCKi7ic2rs4kDFQAAAAAdAAAAABAI" src="https://cdn-images-1.medium.com/max/1024/0*gh2bTLx9HHDqV_lY.png" /><figcaption><a href="https://blog.xmartlabs.com/images/i-tested-react-native-new-architecture-improvements/featured.png">copyright: </a><a href="https://blog.xmartlabs.com/images/i-tested-react-native-new-architecture-improvements/featured.png">https://blog.xmartlabs.com/images/i-tested-react-native-new-architecture-improvements/featured.png</a></figcaption></figure><h3>Introduction</h3><p>Since Facebook launched React Native in 2015 it has completely changed the process of creating mobile apps. It introduced mobile development to the learn once write anywhere concept by enabling developers to create native apps with React.</p><p>But as applications became more sophisticated and performance requirements rose some of the original architectures shortcomings were revealed. Since the new architecture is enabled by default in React-Native’s most recent release version 0. 76 I decided to take a chance. We have been seeing teasers of it since 2018 when they decided we needed to opt in for a new arch and it arrived with everything we had been waiting for.</p><p>We’ll examine React Natives new architecture in this in-depth guide learning about its essential elements why it was required and how it revolutionizes the way we create mobile apps</p><h3>Why a New Architecture?</h3><h3>The Old Architecture’s Limitations</h3><p>The original React Native architecture, while groundbreaking, had several inherent limitations that became more pronounced as applications grew in complexity:</p><ol><li><strong>Performance Bottlenecks</strong></li></ol><ul><li>The JavaScript bridge became a significant bottleneck for data-intensive applications</li><li>Achieving consistent 60 FPS animations was challenging</li><li>Large amounts of data had to be serialized and deserialized when passing between JavaScript and native code</li></ul><p><strong>2. Asynchronous Layout</strong></p><ul><li>Layout calculations were asynchronous, leading to layout thrashing</li><li>Visual inconsistencies were common in complex UIs</li><li>The async nature made it difficult to integrate smoothly with native UI components</li></ul><p><strong>3. Bridge-Based Communication</strong></p><ul><li>All communication between JavaScript and native code had to go through the bridge</li><li>Serialisation/deserialisation overhead impacted performance</li><li>No way to share typed objects between JavaScript and native code</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zZkfJugXQ0grI20O" /><figcaption>copyrights: <a href="https://res.cloudinary.com/formidablelabs/image/upload/f_auto,q_auto/v1675121564/dotcom/uploads-old-diagram-full">https://res.cloudinary.com/formidablelabs/image/upload/f_auto,q_auto/v1675121564/dotcom/uploads-old-diagram-full</a></figcaption></figure><h3>Goals of the New Architecture</h3><p>The new architecture was designed with several ambitious goals in mind:</p><ol><li><strong>Performance Improvements</strong></li></ol><ul><li>Achieve consistent 120 FPS animations</li><li>Reduce application startup time</li><li>Minimise memory usage</li><li>Enable direct communication between JavaScript and native code</li></ul><p><strong>2. Better Native Integration</strong></p><ul><li>Seamless interoperability with existing native code</li><li>Simplified process for wrapping native modules</li><li>Direct manipulation of native views from JavaScript</li></ul><p><strong>3. Enhanced Developer Experience</strong></p><ul><li>Improved type safety across the JavaScript-native boundary</li><li>Better error checking and debugging capabilities</li><li>More intuitive APIs for native module development</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ag7lcuTbrjeDyi37.png" /></figure><h3>Key Components of the New Architecture</h3><p>The new architecture consists of four main components working together to provide a more robust and performant framework:</p><h3>1. JavaScript Interface (JSI)</h3><p>JSI is the cornerstone of the new architecture, fundamentally changing how JavaScript and native code interact:</p><p><strong>Direct Communication</strong></p><ul><li>Eliminates the need for JSON serialisation/deserialisation</li><li>Allows JavaScript to hold and manipulate C++ objects directly</li><li>Enables synchronous method calls between JavaScript and native code</li></ul><p><strong>Performance Benefits</strong></p><ul><li>No more bridge traversal overhead</li><li>Immediate method invocations</li><li>Ability to hold references to native objects</li><li>Platform-agnostic design for easier platform support</li></ul><h3>2. Fabric</h3><p>Fabric is the new rendering system, bringing significant improvements to how React Native renders UI:</p><p><strong>Synchronous Layout</strong></p><ul><li>Eliminates layout thrashing</li><li>Provides consistency with native UI frameworks</li><li>Enables more predictable rendering behavior</li></ul><p><strong>Native Integration</strong></p><ul><li>Better integration with existing native views</li><li>Improved support for native-driven animations</li><li>More efficient reconciliation and commit phases</li></ul><p><strong>Performance Optimisations</strong></p><ul><li>Reduced memory footprint</li><li>More efficient view updates</li><li>Better support for complex animations and gestures</li></ul><h3>3. TurboModules</h3><p>TurboModules revolutionise how native modules work in React Native:</p><p><strong>Lazy Loading</strong></p><ul><li>Modules are loaded on-demand</li><li>Unused modules don’t impact performance</li><li>Significant reduction in app startup time</li></ul><p><strong>Type Safety</strong></p><ul><li>Complete type safety between JavaScript and native code</li><li>Compile-time error catching</li><li>Generated type-safe bindings</li></ul><p><strong>Performance Improvements</strong></p><ul><li>Reduced memory usage</li><li>Faster method invocations through JSI</li><li>More efficient resource utilization</li></ul><h3>4. Codegen</h3><p>Codegen automates the creation of native code bindings:</p><p><strong>Automatic Code Generation</strong></p><ul><li>Generates C++ headers and Objective-C interfaces from JavaScript</li><li>Supports Flow and TypeScript type definitions</li><li>Ensures consistency between JavaScript and native interfaces</li></ul><p><strong>Developer Benefits</strong></p><ul><li>Reduced manual coding requirements</li><li>Fewer opportunities for errors</li><li>Simplified native module creation process</li></ul><h3>Migration and Adoption</h3><p>If you are working with simple react native components, you have nothing to do, just follow the guide to enable the new architecture in your project <a href="https://reactnative.dev/architecture/landing-page#should-i-use-the-new-architecture-today">here</a>.</p><p>But if you are a react native library maintainer, transitioning to the new architecture has been designed to be as smooth as possible:</p><h4>Gradual Adoption Strategy</h4><ul><li>Components can be migrated incrementally</li><li>Old and new architectures can coexist</li><li>No need for a complete rewrite of existing applications</li></ul><h4>Migration Tools and Resources</h4><ol><li><strong>Available Tools</strong></li></ol><ul><li>Migration scripts for automating parts of the process</li><li>Compatibility layers for bridging old and new architectures</li><li>Extensive documentation and guides</li></ul><p><strong>2. Best Practices</strong></p><ul><li>Start with smaller, isolated components</li><li>Thoroughly test each migrated component</li><li>Plan for incremental releases</li><li>Maintain backwards compatibility</li></ul><h3>Benefits and Real-World Impact</h3><p>The new architecture delivers substantial improvements across several areas:</p><h4>Performance Improvements</h4><ul><li>Up to 50% reduction in app startup time</li><li>Consistent 120 FPS animations</li><li>Reduced latency in user interactions</li><li>Better memory utilisation</li></ul><h4>Developer Experience</h4><ul><li>More intuitive APIs</li><li>Better debugging capabilities</li><li>Improved error messages</li><li>Simplified native module creation</li></ul><h4>Enhanced Capabilities</h4><ul><li>Better support for large-scale applications</li><li>Improved performance in data-intensive scenarios</li><li>More seamless integration with native features</li><li>Future-proof architecture for emerging technologies</li></ul><h3>Future outlook</h3><p>The new architecture positions React Native for continued growth and innovation:</p><h4>Emerging Possibilities</h4><ul><li>Better integration with ARKit and ML frameworks</li><li>Continuous performance optimisations</li><li>More seamless cross-platform development</li><li>Increased adoption in enterprise applications</li></ul><h4>Community and Resources</h4><ul><li>Active community development</li><li>Regular updates and improvements</li><li>Extensive documentation and tutorials</li><li>Growing ecosystem of compatible libraries</li></ul><h3>Conclusion</h3><p>In conclusion, With the new architecture of React Native cross-platform mobile development has advanced significantly. Through the resolution of long-standing issues and the introduction of potent new features it offers a stronger basis for creating mobile applications with high performance.</p><p>Codegen TurboModules Fabric and JSI work together to produce a more developer-friendly type-safe and effective framework that can better meet the needs of contemporary mobile applications.</p><p>Understanding and implementing these new architectural elements will be essential for maintaining your competitiveness in the mobile development market whether youre creating a brand-new application or updating an old one.</p><h3>Further Learning Resources</h3><ul><li>Official React Native Documentation: https://<a href="https://reactnative.dev/">reactnative.dev</a></li><li>React Native Community: <a href="https://github.com/react-native-community/discussions-and-proposals">GitHub Discussions</a></li><li>React Native Blog: <a href="https://reactnative.dev/blog">react-native.dev/blog</a></li><li>Major Conferences: React Native EU, Chain React</li></ul><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a></li><li><a href="https://differ.blog/"><strong>Create a free AI-powered blog on Differ.</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1e2ce8f126e" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/react-natives-new-architecture-a-comprehensive-guide-d1e2ce8f126e">React Native’s New Architecture: A Comprehensive Guide</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easy and Custom Code Input with 0 dependencies in React Native]]></title>
            <link>https://javascript.plainenglish.io/easy-and-custom-code-input-with-0-dependencies-in-react-native-9e89826277f9?source=rss-113ef063808e------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e89826277f9</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[otp-verification]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Ahmed Sbai]]></dc:creator>
            <pubDate>Fri, 09 Jun 2023 00:03:22 GMT</pubDate>
            <atom:updated>2023-06-11T02:06:45.143Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wH-MAlx9FrOajWjf.jpg" /><figcaption><a href="https://i.ytimg.com/vi/naVaJDYpptY/maxresdefault.jpg">https://i.ytimg.com/vi/naVaJDYpptY/maxresdefault.jpg</a></figcaption></figure><p>Having an OTP (One-Time Password) text input in your app can provide several benefits and enhance the overall user experience. It can be useful when having to enable two-factor authentication, verify user accounts, facilitate password resets, authorize transactions, improve user convenience, and meet compliance standards. It is a valuable feature for applications that prioritize user security and require reliable user authentication methods.</p><p>Nowadays, mostly all the apps are using it and of course, you’re thinking about adding this component to the React Native app you’re building</p><p>In general, most people tend to add a new dependency but that’s actually a bunch of code that you’re not totally using and gonna be bundled into your app.</p><p>Here is the final outcome of the component</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*tUv_unakVityTdhtC9Q-lg.gif" /><figcaption>Final Component</figcaption></figure><p>The concept of this is so simple, we create a text input that is hidden, we control it with REF, and use the value to render the digits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*hTaj6XpP2Eo060Mh" /><figcaption>source ( <a href="https://codepen.io/retyui/pen/WNGdNdJ">https://codepen.io/retyui/pen/WNGdNdJ</a> )</figcaption></figure><p>Okay, let&#39;s dig into the code</p><pre>// Cell count <br>const CELL_COUNT = 5;<br><br>const ConfirmationCde: React.FC = () =&gt; {<br>  const ref = useRef&lt;TextInput&gt;(null);<br>// State <br>  const [code, setCode] = useState&lt;string&gt;(&#39;&#39;);<br>// To create an array according to Cell Count <br>const codeDigitsArray = new Array(CELL_COUNT).fill(0);<br><br>return (<br>    &lt;View style={styles.container}&gt;<br>      &lt;Pressable<br>        onLongPress={handleLongPress}<br>        style={styles.inputsContainer}<br>        onPress={handleOnPress}<br>      &gt;<br>        {codeDigitsArray.map(toDigitInput)}<br>      &lt;/Pressable&gt;<br>      &lt;TextInput<br>              ref={ref}<br>              value={code}<br>              onChangeText={setCode}<br>              keyboardType=&quot;number-pad&quot;<br>              returnKeyType=&quot;done&quot;<br>              textContentType=&quot;oneTimeCode&quot;<br>              maxLength={CELL_COUNT}<br>              style={styles.hiddenCodeInput}<br>       /&gt;<br>    &lt;/View&gt;)<br>  }<br><br>const styles = StyleSheet.create({<br>  container: {<br>    flex: 1,<br>    alignItems: &#39;center&#39;,<br>    width: &#39;100%&#39;,<br>  },<br>  inputsContainer: {<br>    width: &#39;100%&#39;,<br>    flexDirection: &#39;row&#39;,<br>    justifyContent: &#39;space-between&#39;,<br>  },<br>  inputContainerFocused: {<br>    borderColor: &#39;red&#39;,<br>  },<br>  hiddenCodeInput: {<br>    position: &#39;absolute&#39;,<br>    height: 0,<br>    width: 0,<br>    opacity: 0,<br>  },<br>});</pre><p>We need to create toDigitInput function that will help us to create our code-like output</p><pre>// Methods<br>const toDigitInput = (_value: number, idx: number) =&gt; {<br>    const emptyInputChar = &#39; &#39;;<br>    const digit = code?.[idx] || emptyInputChar;<br>    const [containerIsFocused, setContainerIsFocused] = useState&lt;boolean&gt;(false);<br><br>    const isCurrentDigit = idx === code?.length;<br>    const isLastDigit = idx === CELL_COUNT - 1;<br>    const isCodeFull = code?.length === CELL_COUNT;<br><br>    const isFocused = isCurrentDigit || (isLastDigit &amp;&amp; isCodeFull);<br>    const containerStyle =<br>      containerIsFocused &amp;&amp; isFocused<br>        ? {<br>            ...{ borderColor: &#39;blue&#39;, borderWidth: 2 },<br>          }<br>        : {};<br>    return (<br>      &lt;View key={idx} style={containerStyle}&gt;<br>        &lt;Text style={{}}&gt;{digit}&lt;/Text&gt;<br>      &lt;/View&gt;<br>    );<br>  };</pre><p>Next, we need to add a method to focus the hidden input and indicate the active cell</p><pre>  const handleOnPress = () =&gt; {<br>    setContainerIsFocused(true);<br>    ref?.current?.focus();<br>  };</pre><p>We’ll be losing focus when we blur the input</p><pre>  const handleOnBlur = () =&gt; {<br>    setContainerIsFocused(false);<br>  };</pre><p>Also if you want to focus input on the component mount, I would really recommend adding this code</p><pre>  // Side Effects<br><br>  useEffect(() =&gt; {<br>    InteractionManager.runAfterInteractions(() =&gt; {<br>      setContainerIsFocused(true);<br>      ref?.current?.focus();<br>    });<br>  }, []);</pre><p>I’ve added the InteractionManager to avoid any lagging/glitching caused by navigation or other animations</p><p>This is the final code, you can find it at this expo snack <a href="https://snack.expo.dev/PzXz-FItRG">https://snack.expo.dev/PzXz-FItRG</a></p><pre>import {<br>  InteractionManager,<br>  Pressable,<br>  TextInput,<br>  View,<br>  Text,<br>  StyleSheet,<br>} from &#39;react-native&#39;;<br>import React, { useEffect, useRef, useState } from &#39;react&#39;;<br><br>const CELL_COUNT = 5;<br><br>const App: React.FC = () =&gt; {<br>  const [code, setCode] = useState(&#39;&#39;);<br>  const [containerIsFocused, setContainerIsFocused] = useState(false);<br><br>  const codeDigitsArray = new Array(CELL_COUNT).fill(0);<br>  const ref = useRef(null);<br><br>  const toDigitInput = (_value: number, idx: number) =&gt; {<br>    const emptyInputChar = &#39; &#39;;<br>    const digit = code?.[idx] || emptyInputChar;<br><br>    const isCurrentDigit = idx === code?.length;<br>    const isLastDigit = idx === CELL_COUNT - 1;<br>    const isCodeFull = code?.length === CELL_COUNT;<br><br>    const isFocused = isCurrentDigit || (isLastDigit &amp;&amp; isCodeFull);<br>    const containerStyle =<br>      containerIsFocused &amp;&amp; isFocused<br>        ? [<br>            styles.codeInputCellContainer,<br>            styles.inputContainerFocused,<br>        ]<br>        : styles.codeInputCellContainer;<br>    return (<br>      &lt;View key={idx} style={containerStyle}&gt;<br>        &lt;Text style={{}}&gt;{digit}&lt;/Text&gt;<br>      &lt;/View&gt;<br>    );<br>  };<br><br>  const handleOnPress = () =&gt; {<br>    setContainerIsFocused(true);<br>    ref?.current?.focus();<br>  };<br><br>  const handleLongPress = () =&gt; {<br>    console.log(&#39;long pressed&#39;);<br>    setCode(&#39;12345&#39;);<br>  };<br><br>  const handleOnBlur = () =&gt; {<br>    setContainerIsFocused(false);<br>  };<br><br>  // Effects<br><br>  useEffect(() =&gt; {<br>    InteractionManager.runAfterInteractions(() =&gt; {<br>      setContainerIsFocused(true);<br>      ref?.current?.focus();<br>    });<br>  }, []);<br><br>  return (<br>    &lt;View style={styles.container}&gt;<br>      &lt;Pressable<br>        onLongPress={handleLongPress}<br>        style={styles.inputsContainer}<br>        onPress={handleOnPress}&gt;<br>        {codeDigitsArray.map(toDigitInput)}<br>      &lt;/Pressable&gt;<br>      &lt;TextInput<br>        ref={ref}<br>        value={code}<br>        onChangeText={setCode}<br>        onEndEditing={handleOnBlur}<br>        keyboardType=&quot;number-pad&quot;<br>        returnKeyType=&quot;done&quot;<br>        textContentType=&quot;oneTimeCode&quot;<br>        maxLength={CELL_COUNT}<br>        style={styles.hiddenCodeInput}<br>      /&gt;<br>    &lt;/View&gt;<br>  );<br>};<br><br>export default App;<br><br>const styles = StyleSheet.create({<br>  container: {<br>    flex: 1,<br>    alignItems: &#39;center&#39;,<br>    width: &#39;100%&#39;,<br>    paddingHorizontal: 10<br>  },<br>  inputsContainer: {<br>    width: &#39;100%&#39;,<br>    flexDirection: &#39;row&#39;,<br>    justifyContent: &#39;space-between&#39;,<br>  },<br>  inputContainerFocused: {<br>    borderColor: &#39;blue&#39;,<br>  },<br>  hiddenCodeInput: {<br>    position: &#39;absolute&#39;,<br>    height: 0,<br>    width: 0,<br>    opacity: 0,<br>  },<br>  codeInputCellContainer: {<br>    height: 50,<br>    width: 50,<br>    borderRadius: 15,<br>    justifyContent: &#39;center&#39;,<br>    alignItems: &#39;center&#39;,<br>    borderColor: &#39;black&#39;,<br>    borderWidth:2<br>  },<br>});</pre><p>That’s it. Easy, Fast, and 0 dependencies</p><p>Thanks 🙏 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e89826277f9" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/easy-and-custom-code-input-with-0-dependencies-in-react-native-9e89826277f9">Easy and Custom Code Input with 0 dependencies in React Native</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lazy loading and code splitting in React Native? Is that even possible?]]></title>
            <link>https://javascript.plainenglish.io/lazy-loading-and-code-splitting-in-react-native-is-that-even-possible-2f6d23d75b81?source=rss-113ef063808e------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f6d23d75b81</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[code-splitting]]></category>
            <category><![CDATA[lazy-loading]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[performance]]></category>
            <dc:creator><![CDATA[Ahmed Sbai]]></dc:creator>
            <pubDate>Thu, 11 May 2023 09:11:05 GMT</pubDate>
            <atom:updated>2024-09-09T05:35:05.754Z</atom:updated>
            <content:encoded><![CDATA[<h3>Lazy Loading and Code Splitting in React Native — Is That Even Possible?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w4VeLNDOTgubT85dHdPddw.jpeg" /></figure><p>Lazy loading is the practice of loading components of your software only when they are needed, rather than loading everything at once. It’s like having a butler that gives you what you need when you need it!</p><p>Simply put, lazy loading is a design pattern. You can load parts of your application as needed to reduce initial load time. For example, components and modules related to user login and registration can be loaded first. Then you can load the rest of the components based on the user’s navigation.</p><p>For sluggish loading components, utilize <strong><em>React.lazy()</em></strong> method in React Native.</p><p>React 18 is now enabled by default when you enable the New Architecture in React Native 0.69.</p><p>This implies that as soon as we move, we may start using the new capabilities in React 18. For Devs that migrate to the New Architecture or develop a new app with the New Architecture enabled, The React team anticipates that React 18 will function out-of-the-box with few adjustments because the new concurrent functionalities are opt-in by utilizing features like <strong><em>startTransition</em></strong> or <strong><em>Suspense</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eWogCDMHPNY2skejf2PLfA.png" /></figure><blockquote><em>💡</em> <strong>Learn more about the power of server-driven UI in React Native:</strong></blockquote><p><a href="https://differ.blog/p/exploring-the-power-of-server-driven-ui-in-react-native-b21249">Exploring the Power of Server-Driven UI in React Native</a></p><blockquote><em>👉</em> To read more such acrticles, <a href="https://differ.blog/"><strong>sign up for free on Differ</strong></a>.</blockquote><h4><strong>Lazy Loading of a Normal Component</strong></h4><p>Here in this example, we will see a simple implementation of the Lazy Loading into our App</p><pre>import React from &#39;react&#39;;<br>import { View } from &#39;react-native&#39;;<br>import { styles } from &#39;./styles&#39;;<br>import ComplexComponent from &#39;./ComplexComponent&#39;<br><br>function App() {<br>  return (<br>    &lt;View style={styles.container}&gt;<br>      &lt;ComplexComponent/&gt;<br>    &lt;/View&gt;<br>  );<br>}</pre><p>Here in the first snippet, our component will be loaded directly into our app, no matter how much time it takes to render, we will have a blank space until its time.</p><pre>import React, {lazy, Suspense} from &#39;react&#39;;<br>import { Text, View } from &#39;react-native&#39;;<br>import { styles } from &#39;./styles&#39;;<br><br>const ComplexComponent = lazy(()=&gt; import(&quot;./ComplexComponent&quot;))<br><br>function App() {<br>  return (<br>    &lt;View style={styles.container}&gt;<br>    &lt;Suspense fallback={()=&gt; &lt;Text&gt;Loading ....&lt;/Text&gt;}&gt;<br>      &lt;ComplexComponent/&gt;<br>    &lt;/Suspense&gt;<br>    &lt;/View&gt;<br>  );<br>}<br><br>export default App;</pre><p>In the second code snippet, As you can see, we need to use both React.lazy() and React.Suspense features to build a lazy-loading component in React. This will help us to have a text shown saying loading until the component finishes its render phase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ogpvzHpHpDTumGul06nTEw.png" /></figure><h4>Lazy Loading of a Router Screen Component</h4><p>We all know that Routers can be exhausting to our app, especially if we have a lot of expensive components loaded on our app start</p><pre>import ComplexComponent from &#39;./ComplexComponent&#39;;<br><br>&lt;NavigationContainer&gt;<br>      &lt;Stack.Navigator initialRouteName=&quot;Home&quot;&gt;<br>        &lt;Stack.Screen name=&quot;Home&quot; component={HomeScreen} /&gt;<br>        &lt;Stack.Screen name=&quot;complex&quot; component={ComplexComponent} /&gt;<br>      &lt;/Stack.Navigator&gt;<br>&lt;/NavigationContainer&gt;</pre><p>Let&#39;s try and apply the lazy loading on that complex component</p><pre>import React, {lazy, Suspense} from &#39;react&#39;;<br><br>const ComplexComponent = lazy(() =&gt; import(&#39;./ComplexComponent&#39;));<br><br>&lt;NavigationContainer&gt;<br>      &lt;Stack.Navigator initialRouteName=&quot;Home&quot;&gt;<br>        &lt;Stack.Screen name=&quot;Home&quot; component={HomeScreen} /&gt;<br>        &lt;Stack.Screen name=&quot;complex&quot; component={(props)=&gt; {<br>            &lt;Suspense fallback={&lt;ActivityIndicator /&gt;}&gt;<br>              &lt;ComplexComponent {...props} /&gt;<br>            &lt;/Suspense&gt;<br>          }} <br>        /&gt;<br>      &lt;/Stack.Navigator&gt;<br>&lt;/NavigationContainer&gt;</pre><p>Here we are going to load chunks of data when the user navigates to that specific component so which will reduce our application&#39;s initial loading time by reducing the bundle size and Improving user experience at initial loading.</p><p>Long story short, Lazy loading is cool!! It works and it’s more suitable for large-scale applications because it helps to optimize them in a lot of aspects, but we should not overuse it, especially for small applications because splitting small bundles will have no effect but adding more configurations. also, fallback placeholders can slow down quick scrolling if we are lazy loading lists or stuff like that for example</p><p>This post covered what lazy loading is, how to implement it in React Native, and the positives and some downsides we should be aware of before utilizing it. I hope this post has helped you.</p><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://twitter.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a></li><li>Visit our other platforms: <a href="https://cofeed.app/"><strong>CoFeed</strong></a> | <a href="https://differ.blog/"><strong>Differ</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f6d23d75b81" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/lazy-loading-and-code-splitting-in-react-native-is-that-even-possible-2f6d23d75b81">Lazy loading and code splitting in React Native? Is that even possible?</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Amazing Features Introduced in Reanimated 3]]></title>
            <link>https://javascript.plainenglish.io/amazing-features-introduced-in-reanimated-3-2ad5320ab9e3?source=rss-113ef063808e------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ad5320ab9e3</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[reanimated]]></category>
            <category><![CDATA[react-native-animation]]></category>
            <dc:creator><![CDATA[Ahmed Sbai]]></dc:creator>
            <pubDate>Thu, 06 Apr 2023 00:08:34 GMT</pubDate>
            <atom:updated>2023-04-10T00:43:02.567Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*18iSi79riGjY0b7f6H85qA.png" /><figcaption>Reanimated by <a href="https://medium.com/u/23d9a033fed2">Software Mansion</a></figcaption></figure><p>React Native is a popular open-source framework that enables developers to build high-performance mobile applications using JavaScript and React. One of the key libraries that have been widely adopted by React Native developers is React Native Reanimated. This library provides a set of APIs that allow developers to create complex, high-performance animations and user interfaces that are smooth and responsive. Recently, the React Native Reanimated library has been updated to version 3, introducing several new features and improvements.</p><h4>Shared Element Transitions</h4><p>Shared element transitions refer to the animation effects that occur when a user interface element is moved or transformed from one screen to another. These transitions create a visual connection between the two screens and provide a smooth and seamless experience for the user. Shared element transitions are often used in mobile app development, particularly in e-commerce and photo-sharing apps, where users need to view a product or image on one screen and then seamlessly transition to another screen to view more details or related content. By animating shared elements, developers can create a more immersive and engaging user experience that keeps users engaged and increases overall user satisfaction.</p><p>In React Native that was quite challenging behavior and it was the most waited feature in reanimated with react-navigation</p><p>Here is a little demonstration of the output when using this feature. Note that it is still in its early stages and it will be enhanced hopefully soon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*kHryWVsWwDQ5U3J7_8nxgw.gif" /><figcaption>Demonstration of what the output may look like</figcaption></figure><p>As you can see, you can notice that it works absolutely fine with a combination of Layout Animations provided by Reanimated and all other animations. This smooth animation occurs when the code has the same sharedTransitionTag attribute on animated views that live on two different screens. As the user navigates, the transition between views will be seamless and smooth.</p><h4>Inline styles API</h4><p>this new addition allows you to avoid useAnimatedStyle ‘s hook when shared values can be directly mapped to one of the components’ styles or properties thus reducing a lot of boilerplates. Check out below how an example component can be refactored to use this new API. Of course, this feature is completely optional and you can continue using useAnimatedStyle or even mix animated styles with the new inline syntax. You can read more details about this feature<a href="https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/animations#animations-in-inline-styles"> reanimated documentation website</a>.</p><p>Here’s an example provided by the Reanimated team</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*R-z464MA_AxAYJDW.png" /><figcaption>Inline animated styles</figcaption></figure><p>This will allow us to create reusable style codes with multiple variables that can be passed/manipulated on the go. It is now developer friendly and makes our experience with reanimated easier and easier.</p><h4>Faster, faster, Faster</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*vQTyyXMgxzfn-cie.gif" /></figure><p>Well, if you take a general look at the library, you won’t notice big changes. But if you dive a little deep into it, you’ll find tons of optimizations and rewritten code going all around from worklets/shared values engine as well as the layout animations engine.</p><p>With all these changes at the very core of Reanimated, I think we should expect more fun updates to come as a consequence and more and more cool features upcoming.</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>.</em></p><p><em>Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p><p><strong><em>Interested in scaling your software startup</em></strong><em>? Check out </em><a href="https://circuit.ooo/?utm=publication-post-cta"><strong><em>Circuit</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ad5320ab9e3" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/amazing-features-introduced-in-reanimated-3-2ad5320ab9e3">Amazing Features Introduced in Reanimated 3</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React: MVVM example with MobX and Hooks]]></title>
            <link>https://javascript.plainenglish.io/react-mvvm-with-mobx-89b2444b1f64?source=rss-113ef063808e------2</link>
            <guid isPermaLink="false">https://medium.com/p/89b2444b1f64</guid>
            <category><![CDATA[mobx-react]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[mvvm]]></category>
            <category><![CDATA[mobx]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Ahmed Sbai]]></dc:creator>
            <pubDate>Wed, 21 Dec 2022 00:03:56 GMT</pubDate>
            <atom:updated>2022-12-22T02:40:54.267Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1IZjh74vgRP_wrKDwb1yOQ.png" /></figure><p>You have experience developing React applications, but you have never used the Model-View-ViewModel (MVVM) architectural pattern in your projects. Not to worry! In this post, I’ll give you a basic overview of how MVVM, which uses MobX to create highly testable code, can be implemented in your next React app.</p><h4>MVVM? What the hell is that?</h4><p>MVVM is the separation of the code that drives the UI (e.g., changing colors on a button or text on a label) from the business logic that drives it (e.g., producing the string “Hello, John” or “Hello, Guest” depending on whether John is authorized) by transferring that logic outside of the component and into a standalone object. The behaviors for presenting information or carrying out tasks at the user’s request will vary for each screen or component in an app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*XNFgx3mN1Vrk-IjO.png" /><figcaption>MVVM explained</figcaption></figure><h4>Why use MVVM?</h4><p>MVVM maintains view-specific logic connected to the view in the sense that it is not maintained in a more global setting (like Redux may), but it also separates/decouples it from the view because it is a fully different object defined entirely by the developer. That is, there is no mystery as to how it works, and it can be tested at a relevant high code coverage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*EzrhF55FpOWO9W46" /></figure><p>Testing, MVVM makes it much easier to do unit tests on that object’s logic rather than blurring the boundary into UI testing. We don’t need to render any components or rely on any UI-specific lifecycle or other dependencies. Instead, we can simply create some pure business logic, inject any of our own dependencies, and ensure that it produces whatever the UI expects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*CdUxhCcvsEhWNJGj" /></figure><p>Decoupling it from the UI also allows us to construct a “dumb” UI, which means that our UI does nothing but show data without changing it and transfers interactions to something else (the view model). This simplifies ( makes it easier to read) the UI code, allowing it to be more reusable because no logic is required — and making it incredibly easy to show UI components in Storybook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/0*ovWXbZMmEQUQCccS" /></figure><h4><strong>What is MobX? is it worth it?</strong></h4><p>MobX (according to their website) is a battle-tested library that makes state management simple and scalable by transparently applying functional reactive programming.</p><p>it is a library that notifies the view when the state of its view model changes, resulting in a fresh rendering (this is called the observer pattern).</p><h4>The example</h4><p>If you’ve ever read the Redux Toolkit documentation, you’ve probably encountered their counter-example. We’ll build the same thing using an MVVM approach to see how it looks different and how to test it.</p><p>To transform this into an MVVM design, we’ll need one object called the View Model that houses our logic, one object called the View that takes the View Model as a prop and returns the completely rendered view, and one more object to connect them all together.</p><p>Starting with the View Model, we can move all of the functionality to this object and expose only what the View will need to interact with:</p><pre>// ViewModel.js<br>import {action, computed, observable} from &quot;mobx&quot;;<br><br>class ViewModel {<br>  // Initial value for the count variable that is marked as observable<br>  @observable private count = 0;<br>  <br>  constructor(/*here we can accept any dependency*/){<br>    // here we use our dependency and manipulate it<br>   }<br><br>  @action onClick = (): void =&gt; {<br>    this.count += 1;<br>  };<br><br>  @computed get countLabel(): string {<br>    return `clicked ${this.count} times`;<br>  }<br>}<br><br>export default ViewModel;</pre><p>In a View Model, we can mock them out in our tests using Jest. But, before we get to the testing, here is our View:</p><pre>// View.jsx<br><br>import {observer} from &quot;mobx-react&quot;;<br>import ViewModel from &quot;./ViewModel&quot;;<br><br>const ViewComponent = ({viewModel}: Props) =&gt; (<br>  &lt;div&gt;<br>    &lt;p&gt;{viewModel.countLabel}&lt;/p&gt;<br>    &lt;button onClick={viewModel.onClick}&gt;Click me&lt;/button&gt;<br>  &lt;/div&gt;<br>);<br><br>export default observer(ViewComponent);</pre><p>Our View is no longer regarded to be anything more than UI code. The View does not execute any logic; everything, from the information displayed to the user interactions, is routed through the View Model.</p><p>Finally, there is the “glue” that holds them together. This is the component we’ve mentioned in our ‘Root’ or other components (rather than ‘ViewModel.js’ or ‘View.jsx’ explicitly).</p><pre>// App.jsx <br>const App = () =&gt; {<br>  const viewModel = new ViewModel(/*here we can inject dependenicies to retrieve them as i said above*/);<br>  return &lt;ViewComponent viewModel={viewModel} /&gt;;<br>};<br><br>export default App;</pre><p>For each MVVM component, this file will look precisely the same (except for the dependencies injected into the View Model if they exist ). Its primary goal is to inject dependencies into the View Model and return the View, removing the need for boilerplate code in our UI components that use this View.</p><h4><strong>Testing!</strong></h4><p>Now for the major reason for using MVVM: testing! In essence, you must construct a standard component test in which the component is displayed before interacting with it.</p><p>Our View Model test will end up looking like this.</p><pre>// ViewModel.test.js<br>import ViewModel from &quot;./ViewModel&quot;;<br><br>beforeEach(() =&gt; {<br>  viewModel = new ViewModel(/*we mock our dependency*/);<br>});<br><br>it(&quot;has appropriate initial label&quot;, () =&gt; {<br>  expect(viewModel.countLabel).toEqual(&quot;clicked 0 times&quot;);<br>});<br><br>describe(&quot;when clicked&quot;, () =&gt; {<br>  beforeEach(() =&gt; {<br>    viewModel.onClick();<br>  });<br><br>  it(&quot;updates the counter label&quot;, () =&gt; {<br>    expect(viewModel.countLabel).toEqual(&quot;clicked 1 times&quot;);<br>  });<br>});</pre><p>When developing unit tests, we usually want to test one thing at a time. This is a View Model test that is analogous to their sample component tests. Without going through the UI, we can test only the logic that drives the counter.</p><h4>In a nutshell</h4><p>The use case I’ve described is really simple, which may leave you wondering “what’s the point?” — which is reasonable given the simplicity of the counter-example. It’s far more probable that we’ll have networking calls, asynchronous activities, and a global state to keep track of, which is where MVVM can truly shine. We can simply inject this kind of dependencies and verify our UI’s behaviors using MVVM without having to develop UI tests to ensure our UI is operating as intended.</p><p>With MVVM, you may establish a clear separation of concerns, and testing will be as easy as breathing.</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p><p><strong><em>Interested in scaling your software startup</em></strong><em>? Check out </em><a href="https://circuit.ooo/?utm=publication-post-cta"><strong><em>Circuit</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89b2444b1f64" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/react-mvvm-with-mobx-89b2444b1f64">React: MVVM example with MobX and Hooks</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Parallax Effect to Scroll View Items in React Native]]></title>
            <link>https://javascript.plainenglish.io/parallax-effect-to-scroll-view-items-in-react-native-a2265ce81cba?source=rss-113ef063808e------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2265ce81cba</guid>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[parallax-scrolling]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Ahmed Sbai]]></dc:creator>
            <pubDate>Sun, 02 Jan 2022 10:21:54 GMT</pubDate>
            <atom:updated>2022-01-03T05:19:38.152Z</atom:updated>
            <content:encoded><![CDATA[<h4>Create a parallax scrolling effect in React Native.</h4><p>Animations nowadays are a very important part of the user experience, they allow you to convey physically believable motion in your interface and drastically increase the quality of the delivered UI.</p><p>For the last few days, I was searching for a package to create this parallax scrolling effect in React Native, (here’s an example done with flutter <a href="https://docs.flutter.dev/assets/images/docs/cookbook/effects/ParallaxScrolling.gif">https://docs.flutter.dev/assets/images/docs/cookbook/effects/ParallaxScrolling.gif</a>), but I got no good lib there to help me out so I decided to go on my own and create it from scratch using Reanimated 2 provided to us from <a href="https://medium.com/u/23d9a033fed2">Software Mansion</a>.</p><p>As for today, here’s what are we going to get as an outcome:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wRk9WoFrn4PCWrYLSyvs-Q.gif" /><figcaption>Final Outcome</figcaption></figure><p>Let’s dig right into it. first, we have to create our project:</p><pre>npx react-native init parallaxAnimation</pre><p>After initializing our project we need to use our Reanimated Library.</p><pre>yarn add react-native-reanimated</pre><p>then we have to follow the installation guide, it is all listed here: <a href="https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation">https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation</a></p><p>As we know, Reanimated is a React Native library that allows for creating smooth animations and interactions that runs on the UI thread and helps us to do magic 🪄</p><p>Same things as react-native Animated API, it provides Animated. View, ScrollView, and more … It also provides Layout animations.</p><p>Let&#39;s get our hands doing some code.</p><p>Here we have our basic code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1405ca41e6f78a82a092eee372927471/href">https://medium.com/media/1405ca41e6f78a82a092eee372927471/href</a></iframe><p>At first, we have to transform our View, ScrollView, etc… into some animated components.</p><p>So, we’re going to transform our scroll view into an animated one:</p><pre>import Animated from &#39;react-native-reanimated&#39;</pre><pre>&lt;FlatList&gt;&lt;/FlatList&gt; =&gt; &lt;Animated.FlatList&gt;&lt;/Animated.FlatList&gt;</pre><p>Note: If flat-List doesn’t show in your suggestion list, we can simply create it by doing:</p><pre>const AnimatedFlatList = Animated.createAnimatedComponent(FlatList)</pre><pre>then we use it as :</pre><pre>&lt;AnimatedFlatList&gt;&lt;/AnimatedFlatList&gt;</pre><p>After having our FlatList transformed into an animated component, we have to retrieve our scroll position as long as we scroll, here we’re going to use useSharedValue to store the scrollY, and useAnimatedScrollHandler to handle Scrolling events (Scroll, Momentum, etc.):</p><pre>const scrollPosition = useSharedValue(0);</pre><p>Then,</p><pre>const handleScroll = useAnimatedScrollHandler(<br>    {<br>      onScroll: event =&gt; {<br>        scrollPosition.value = event.contentOffset.y;<br>      }<br>    }<br>);</pre><p>After that, we bind it to our FlatList and we set scrollEventThrottle to 16 to capture all of the scrolling events:</p><pre>&lt;AnimatedFlatList<br>    onScroll={handleScroll} <br>    scrollEventThrottle={16}<br>   ...<br>/&gt;</pre><p>Now that we got our scroll position saved, we need to pass it down to our component as a prop.</p><p>Now we have to set our input range for the animation, so we can Interpolate the values within this range.</p><p>At first, we have to transform our Item component into an animated component, we’re animating the image only (we’re going to make it translate on Y-axis so the image will be an animated component:</p><pre>const Item=({index, scrollPosition})=&gt;{<br>  return (<br>      &lt;View key={index} style={styles.scrollContent}&gt;<br>        &lt;Animated.Image<br>          style={[{<br>           height: <strong><em>Dimensions</em></strong>.get(&#39;screen&#39;).height*2,<br>           width: <strong><em>Dimensions</em></strong>.get(&#39;window&#39;).width,<br>           resizeMode:&#39;cover&#39;,<br>        }]} <br>          source={{uri:&#39;https://random.imagecdn.app/1920/1080&#39;}}/&gt;<br>      &lt;Text <br>        style={[<br>          {color: &#39;white&#39;, position: &#39;absolute&#39;,zIndex:99, <br>          fontSize: 50, bottom: 10}]}<br>        &gt;<br>         hehehehhehe<br>        &lt;/Text&gt;<br>      &lt;/View&gt;<br>  )<br>}</pre><p>Now, we have to add our animated styles, and it can be done with a hand from useAnimatedStyle hook, our component should be looking like this:</p><pre>const Item=({index, scrollPosition})=&gt;{</pre><pre><br>const {height, width} = useWindowDimensions()  </pre><pre>const imageAnimatedStyle = useAnimatedStyle(() =&gt; {<br>    const translateY = interpolate(<br>        scrollPosition.value,<br>        [(index-1)* height/2, index*height/2, (index+1)*height/2],<br>        [-100, 0, 100],<br>    );<br>    return {<br>      transform: [{translateY}],<br>    };<br>  }, []);</pre><pre>  return (<br>      &lt;View key={index} style={styles.scrollContent}&gt;<br>        &lt;Animated.Image<br>          style={[{<br>           height: <strong><em>height</em></strong>*1.5,<br>           width: <strong><em>width</em></strong>,<br>           resizeMode:&#39;cover&#39;,<br>         },<br>         <strong><em>imageAnimatedStyle</em></strong>             <br>        ]} <br>          source={{uri:&#39;https://random.imagecdn.app/1920/1080&#39;}}/&gt;<br>      &lt;Text <br>        style={[<br>          {color: &#39;white&#39;, position: &#39;absolute&#39;,zIndex:99, <br>          fontSize: 50, bottom: 10}]}<br>        &gt;<br>         hehehehhehe<br>        &lt;/Text&gt;<br>      &lt;/View&gt;<br>  )<br>}</pre><p>Now let’s explain the code step by step :</p><p>At first, we retrieved our scroll position from props, then we interpolated through the scroll position so that our range would be our item, the previous, and the next one, so we could figure out if we’re scrolling up or down, then we did append the animated style to the rest of the image style.</p><p>now we would be like playing with the position of the image on the Y-axis and we’re going to move it a little bit up or down to have this nice parallax effect.</p><p>Here’s the final code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3e6cbeea3e80b13502186af9aa930c8/href">https://medium.com/media/b3e6cbeea3e80b13502186af9aa930c8/href</a></iframe><p>Happy Coding!</p><p><em>More content at </em><a href="http://plainenglish.io/"><em>plainenglish.io</em></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><em>free weekly newsletter</em></a><em>. Get exclusive access to writing opportunities and advice in our </em><a href="https://discord.gg/GtDtUAvyhW"><em>community Discord</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2265ce81cba" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/parallax-effect-to-scroll-view-items-in-react-native-a2265ce81cba">Parallax Effect to Scroll View Items in React Native</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple Collapsing Header Animation using React Native]]></title>
            <link>https://javascript.plainenglish.io/simple-collapsing-header-animation-using-react-native-21f4c26b2222?source=rss-113ef063808e------2</link>
            <guid isPermaLink="false">https://medium.com/p/21f4c26b2222</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[animation]]></category>
            <dc:creator><![CDATA[Ahmed Sbai]]></dc:creator>
            <pubDate>Thu, 14 Jan 2021 19:09:42 GMT</pubDate>
            <atom:updated>2021-01-15T18:55:25.346Z</atom:updated>
            <content:encoded><![CDATA[<p>Animations are very important to create a great user experience, they allow you to convey physically believable motion in your interface.</p><p>The Animated library is designed to make animations fluid, powerful, and painless to build and maintain. Animated focuses on declarative relationships between inputs and outputs, configurable transformations in between, and start/stop methods to control time-based animation execution.</p><p>As for today, we’re focusing on animating our header component to finally achieve the following result :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*w_hkJ9c82dAJj9Ag-DDznQ.gif" /><figcaption>Final result</figcaption></figure><p>Let&#39;s dig right into it. first, we have to create our project</p><pre>$ react-native init animation</pre><p>After initializing our project we need to use our Animated API , provided by React Native.</p><p>At first, we create our view :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/39fec7f9a95f4a4b4ac75451eba59f1f/href">https://medium.com/media/39fec7f9a95f4a4b4ac75451eba59f1f/href</a></iframe><p>After defining our views, we need to import Animated from react-native. The Animated module provides us with the necessary tools to animate our views :</p><ul><li>Animated.View</li><li>Animated.ScrollView</li><li>Animated.Image</li><li>Animated.Text</li><li>…</li></ul><p>After we’ve known the basic components of the animated library, we can go straight into animating.</p><p>At first, we have to transform our View, ScrollView, etc… into some animated components.</p><pre>&lt;ScrollView&gt;...&lt;/ScrollView&gt; =&gt; &lt;Animated.ScrollView&gt;...&lt;/Animated.ScrollView&gt;</pre><p>Then, we need to hold our scroll position into something that doesn&#39;t seem to be affected by the re-renders of our components, our best option here is the “ref”.</p><pre>import React, {useRef} from &#39;react&#39;</pre><pre>const scrollPosition = useRef(new <strong><em>Animated</em></strong>.<em>Value</em>(0)).current;</pre><p>After setting our ‘scrollPosition ’ now we should change it programmatically as we scroll. We should be writing the following code to access the native scroll position :</p><pre>&lt;Animated.ScrollView<br>  onScroll={<strong><em>Animated</em></strong>.event(<br>    [{nativeEvent: {contentOffset: {y: scrollPosition}}}],<br>    {useNativeDriver: false},<br>  )}<br>  contentInsetAdjustmentBehavior=&quot;automatic&quot;<br>  style={[styles.scrollView]}&gt;<br>...<br>&lt;/Animated.ScrollView&gt;</pre><p>As we can see scrolling through, we have our scroll offset logged into our terminal :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PPlBA-wotu8ffpZS97sP8A.png" /><figcaption>Scroll position output</figcaption></figure><p>Now, we’ve got the basics done. Moving into animating our header’s height. First, we have to define a minimum height so our header view wouldn&#39;t collapse over 0 height …</p><pre>const minHeaderHeight = 70<br>const maxHeaderHeight = 200</pre><p>Now we should be defining our header’s height that we’re animating :</p><pre>const headerHeight = scrollPosition.interpolate({<br>  inputRange: [0, 500],<br>  outputRange: [maxHeaderHeight, minHeaderHeight],<br>  extrapolate: &#39;clamp&#39;,<br>});</pre><p>The input range here is what we are providing as a scroll position and the output range is what we expect as an output. Please note that the input range and output range arrays must have the same length.</p><p>We should have this output :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*bStoDgJMDecaAdtEYhEL2g.gif" /></figure><p>We can do the same to animate font size, image height, text opacity, and image position.</p><p>Note that we can use the Dimensions API from react-native to get dynamic sizes.</p><pre>const opacity = scrollPosition.interpolate({<br>  inputRange: [0, 100, 200],<br>  outputRange: [1, 0.5, 0],<br>  extrapolate: &#39;clamp&#39;,<br>});<br>const size = scrollPosition.interpolate({<br>  inputRange: [0, 100, 200, 300, 400],<br>  outputRange: [20, 17, 15, 13, 11],<br>  extrapolate: &#39;clamp&#39;,<br>});<br>const imageHeight = scrollPosition.interpolate({<br>  inputRange: [0, 400],<br>  outputRange: [100, 50],<br>  extrapolateLeft: &#39;identity&#39;,<br>  extrapolateRight: &#39;clamp&#39;,<br>});<br>const imagePosition = scrollPosition.interpolate({<br>  inputRange: [0, 400],<br>  outputRange: [(37 * <strong><em>Dimensions</em></strong>.get(&#39;window&#39;).width) / 100, 0],<br>  extrapolateLeft: &#39;identity&#39;,<br>  extrapolateRight: &#39;clamp&#39;,<br>});</pre><p>The final code should be looking like this. This is the most basic example that we can have to dig into animations using react-native.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa7b2e63657075717cb2b6bca8a82bcc/href">https://medium.com/media/fa7b2e63657075717cb2b6bca8a82bcc/href</a></iframe><p>Happy Coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21f4c26b2222" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/simple-collapsing-header-animation-using-react-native-21f4c26b2222">Simple Collapsing Header Animation using React Native</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>