<?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 Abdullah Süha ışık on Medium]]></title>
        <description><![CDATA[Stories by Abdullah Süha ışık on Medium]]></description>
        <link>https://medium.com/@abdullahsuhaisik?source=rss-54570134045d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*DCWIdiUCQJ9RpuTddEjx6g.jpeg</url>
            <title>Stories by Abdullah Süha ışık on Medium</title>
            <link>https://medium.com/@abdullahsuhaisik?source=rss-54570134045d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 08:08:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abdullahsuhaisik/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[Robust React Native App — 4.2]]></title>
            <link>https://medium.com/sisalhubs/robust-react-native-app-4-2-8a82e5867cee?source=rss-54570134045d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a82e5867cee</guid>
            <category><![CDATA[fastlane]]></category>
            <category><![CDATA[technology-transformation]]></category>
            <category><![CDATA[we-are-sisal]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Abdullah Süha ışık]]></dc:creator>
            <pubDate>Fri, 03 Jan 2025 13:21:13 GMT</pubDate>
            <atom:updated>2025-01-03T13:21:13.880Z</atom:updated>
            <content:encoded><![CDATA[<h3>Robust React Native App — 4.2</h3><p>This section will explain how to automate the iOS app’s release and TestFlight processes.</p><h4>Before You Start</h4><p>As I mentioned before, I am writing about my hobby app. If you are wondering, you can see my production app at the <a href="https://apps.apple.com/us/app/readit-boost-your-english/id6502718898">following link</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*UchIRfbd6orknkV4FZAwTw.png" /></figure><h4>Getting Started</h4><p>Before installing Fastlane, ensure that you have the latest Xcode command-line tools installed. After confirming this, proceed with the installation of Fastlane ⬇️. Don’t forget to upgrade your Ruby version. I used 3.3.6; you can manage your Ruby with rbenv.</p><pre>brew install fastlane</pre><p>Once Fastlane is installed globally, navigate to your project directory. Before implementing Fastlane for iOS, make sure to fulfill the following prerequisites:</p><ul><li>Your iOS app must have been published at least once.</li><li>You must be signed up for the Apple Developer Program.</li></ul><pre>cd ios<br>fastlane init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*dwBGumX-O-emA33XyLr4pQ.png" /></figure><p>Fastlane will prompt you with:<br><strong>“What would you like to use Fastlane for?”</strong><br>Type 2 and press Enter. First, we will create a TestFlight lane, and later, we will set up the App Store distribution lane.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DcOSjcf37K7EjvxES2N44A.png" /></figure><blockquote>Apple ID email address</blockquote><blockquote>When you <a href="https://support.apple.com/kb/HT204316">create an Apple ID</a>, you enter an email address. This email address is your Apple ID and the username that you can use to sign in to Apple services like Apple Music and iCloud. It’s also the contact email address for your account. Be sure to check your inbox regularly. We’ll send you email notifications to help you manage your account.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-VR5MtX-sXeZ2DKPGfidyg.png" /></figure><p>Fastlane will ask for your Apple Developer account ID and password.<br>After entering your Apple ID and password, your first lane will be created successfully.<br>During the login process, Fastlane may prompt you for a 6-digit verification code. If prompted, please provide the code to proceed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MnYBBSybHWT5TDuLhFeM_w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/302/1*UGs71ci-EdkqVshen4qkLw.png" /><figcaption>It created Fastlane file</figcaption></figure><p>Here is the generated Fastlane file. Currently, it contains only the beta lane.</p><pre># This file contains the fastlane.tools configuration<br># You can find the documentation at https://docs.fastlane.tools<br>#<br># For a list of all available actions, check out<br>#<br>#     https://docs.fastlane.tools/actions<br>#<br># For a list of all available plugins, check out<br>#<br>#     https://docs.fastlane.tools/plugins/available-plugins<br>#<br><br># Uncomment the line if you want fastlane to automatically update itself<br># update_fastlane<br><br>default_platform(:ios)<br><br>platform :ios do<br>  desc &quot;Push a new beta build to TestFlight&quot;<br>  lane :beta do<br>    increment_build_number(xcodeproj: &quot;readitapp.xcodeproj&quot;)<br>    build_app(workspace: &quot;readitapp.xcworkspace&quot;, scheme: &quot;readitapp&quot;)<br>    upload_to_testflight<br>  end<br>end</pre><p>Now, let’s run the beta lane.</p><pre>fastlane beta</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i5uT_1vGlS_AtxzoJ6XM9A.png" /></figure><p>If you encounter an error, you need to create a .env file under ios/fastlane and add the following properties:</p><pre>FASTLANE_USER=&lt;Apple USER ID&gt;<br>FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD=&lt;App-Specific Password&gt;</pre><p>FASTLANE_USER should be your Apple user ID.<br>Next, you need to create FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD.</p><p>To create these properties, please follow these steps:</p><p><a href="https://appleid.apple.com/account/manage">https://appleid.apple.com/account/manage</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*89Noz-DwdxnH6ffMDk9P8Q.png" /><figcaption>Click App-Specific Passwords</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uYGhOeBskMpglvUdknSivQ.png" /><figcaption>Click Generate an app-spesicific password</figcaption></figure><p>It will ask for a key and password, then generate a password for you.<br>Add this password to the .env file as the value for FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD.<br>After that, run the command again.</p><pre>fastlane beta</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ndaNC9Op75w6SjDOxg1hVQ.png" /><figcaption>IPA file was successfully uploaded to Test flight</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kb7SQrHv_VHbYTEDgsRhzA.png" /><figcaption>Here is my latest test load</figcaption></figure><p>Let’s create another lane!<br>Now, we are going to deploy our app to the App Store.<br>To do this, simply replace upload_to_testflight with upload_to_app_store in your lane configuration.</p><pre>  desc &quot;Push a new release build to the App Store&quot;<br>  lane :release do<br>    increment_build_number(xcodeproj: &quot;readitapp.xcodeproj&quot;)<br>    build_app(workspace: &quot;readitapp.xcworkspace&quot;, scheme: &quot;readitapp&quot;)<br>    upload_to_app_store<br>  end</pre><p>run</p><pre>fastlane release</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WLHTq6idXX4BNsMSbEA8IA.png" /></figure><h4>Important Update: Xcode 15.1 and Fastlane</h4><p>Starting with Xcode 15.1, you need to modify the build_app line in your Fastfile. If you don’t update it, you might get a provisioning error. Update the build_app configuration as follows:</p><pre>  desc &quot;Push a new beta build to TestFlight&quot;<br>  lane :beta do<br>    increment_build_number(xcodeproj: &quot;readitapp.xcodeproj&quot;)<br>    build_app(xcargs: &quot;-allowProvisioningUpdates&quot;)<br>    upload_to_testflight<br>  end</pre><p>By adding this line, Fastlane will automatically fetch provisioning settings from Xcode.</p><pre>build_app(xcargs: &quot;-allowProvisioningUpdates&quot;)</pre><p>When this happens, Fastlane may prompt you for a 6-digit authentication key. Please provide the code when prompted.</p><pre>    increment_version_number(<br>      xcodeproj: &quot;readitapp.xcodeproj&quot;,<br>      bump_type: &quot;minor&quot; # or &quot;minor&quot; or &quot;major&quot; or &quot;patch&quot; depending on your versioning strategy<br>    )<br>    increment_build_number(xcodeproj: &quot;readitapp.xcodeproj&quot;)</pre><p>The increment_version_number function updates your CFBundleShortVersionString, which represents the version of your app.<br>The increment_build_number function updates your CFBundleVersion, which corresponds to the build number.<br>You should update these values each time you publish your app to the App Store.</p><p>Here are the latest beta lane codes:</p><pre>  desc &quot;Push a new beta build to TestFlight&quot;<br>  lane :beta do<br>    increment_version_number(<br>      xcodeproj: &quot;readitapp.xcodeproj&quot;,<br>      bump_type: &quot;minor&quot; # or &quot;minor&quot; or &quot;major&quot; or &quot;patch&quot; depending on your versioning strategy<br>    )<br>    increment_build_number(xcodeproj: &quot;readitapp.xcodeproj&quot;)<br>    build_app(xcargs: &quot;-allowProvisioningUpdates&quot;)<br>    upload_to_testflight<br>  end</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NPL7AxNoCrZRRlfFjepYkQ.png" /></figure><p>The latest fastfile codes below:</p><pre>require_relative &#39;utils&#39;<br><br>default_platform(:ios)<br><br>platform :ios do<br>  desc &quot;Push a new beta build to TestFlight&quot;<br>  lane :beta do<br>    increment_version_number(<br>      xcodeproj: &quot;readitapp.xcodeproj&quot;,<br>      bump_type: &quot;minor&quot; # or &quot;minor&quot; or &quot;major&quot; or &quot;patch&quot; depending on your versioning strategy<br>    )<br>    increment_build_number(xcodeproj: &quot;readitapp.xcodeproj&quot;)<br>    build_app(xcargs: &quot;-allowProvisioningUpdates&quot;)<br>    upload_to_testflight<br>  end<br><br><br>  desc &quot;Push a new release build to the App Store&quot;<br>  lane :release do<br>    increment_version_number(<br>      xcodeproj: &quot;readitapp.xcodeproj&quot;,<br>      bump_type: &quot;patch&quot; # or &quot;minor&quot; or &quot;major&quot; or &quot;patch&quot; depending on your versioning strategy<br>    )<br>    increment_build_number(xcodeproj: &quot;readitapp.xcodeproj&quot;)<br>    build_app(xcargs: &quot;-allowProvisioningUpdates&quot;)<br>    upload_to_app_store<br>  end<br>end</pre><p>In this post, I covered the iOS Fastlane processes. In my previous post, I focused on Fastlane for Android. In my next post, I will discuss Detox E2E testing. After that, I plan to write about the success of my app in the stores.</p><p>If you have any questions about iOS Fastlane, feel free to reach out to me. You can also share your thoughts, suggestions, or any issues related to React Native or native mobile development.</p><h3>Find Me 👤</h3><h4><a href="https://www.linkedin.com/in/s%C3%BCha-i%C5%9F%C4%B1k-92b251101/">LinkedIn</a>:</h4><p><a href="https://www.linkedin.com/in/s%C3%BCha-i%C5%9F%C4%B1k-92b251101/">https://www.linkedin.com/in/s%C3%BCha-i%C5%9F%C4%B1k-92b251101/</a></p><h4><a href="https://github.com/abdullahsuhaisk/">GitHub</a>:</h4><p><a href="https://github.com/abdullahsuhaisk/">https://github.com/abdullahsuhaisk/</a></p><h3>About Sisal Digital Hub Türkiye</h3><h4><a href="https://www.linkedin.com/company/sisal-digital-hub-t%C3%BCrkiye/mycompany/verification/">LinkedIn</a>:</h4><p><a href="https://www.linkedin.com/company/sisal-digital-hub-t%C3%BCrkiye/mycompany/verification/">https://www.linkedin.com/company/sisal-digital-hub-t%C3%BCrkiye/mycompany/verification/</a></p><h4><a href="https://www.linkedin.com/company/sisal-digital-hub-t%C3%BCrkiye/mycompany/verification/">Medium</a> Page:</h4><p><a href="https://www.linkedin.com/company/sisal-digital-hub-t%C3%BCrkiye/mycompany/verification/">https://www.linkedin.com/company/sisal-digital-hub-t%C3%BCrkiye/mycompany/verification/</a></p><h3>References 📚</h3><p><a href="https://docs.fastlane.tools/codesigning/xcode-project/">https://docs.fastlane.tools/codesigning/xcode-project/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a82e5867cee" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sisalhubs/robust-react-native-app-4-2-8a82e5867cee">Robust React Native App — 4.2</a> was originally published in <a href="https://medium.com/sisalhubs">Sisal Hubs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Robust React Native App — 4.1]]></title>
            <link>https://medium.com/sisalhubs/robust-react-native-app-4-1-3bac727d599d?source=rss-54570134045d------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bac727d599d</guid>
            <category><![CDATA[fastlane]]></category>
            <category><![CDATA[we-are-sisal]]></category>
            <category><![CDATA[play-store]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react-native-android]]></category>
            <dc:creator><![CDATA[Abdullah Süha ışık]]></dc:creator>
            <pubDate>Fri, 17 Nov 2023 11:11:53 GMT</pubDate>
            <atom:updated>2024-12-11T12:33:45.073Z</atom:updated>
            <content:encoded><![CDATA[<h3>Robust React Native App — 4.1</h3><p>In this section, our focus is on <strong>Fastlane</strong> — a tool facilitating the automated publication of our app on the Google Play Store. The goal is to streamline all necessary processes through <strong>Fastlane</strong>. Within this post, I’ll elaborate on automating the release and Alpha processes for an Android application.</p><h4>Before Starting Article</h4><p>Before diving into this article, I embarked on a journey after my initial piece. I transitioned from a mere concept to crafting a tangible product, leveraging the insights gained from previous articles. My app is designed to facilitate the enhancement of English reading and writing skills by enabling users to engage with English articles.</p><p>Subsequently, my articles will be closely tied to the development and progress of my app. I’ll share the challenges encountered and the solutions devised along the way. If you’re interested in trying out my app, you can download it using the <a href="https://play.google.com/store/apps/details?id=com.readit">following link.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*UchIRfbd6orknkV4FZAwTw.png" /></figure><h4>Getting Started</h4><p>Before installing Fastlane, ensure that you have the latest Xcode command line tools installed. After confirming this, proceed with the installation of Fastlane ⬇️.</p><pre>brew install fastlane</pre><p>Once you’ve installed Fastlane globally, navigate to your project directory. Before implementing Fastlane for Android, it’s crucial to gather specific prerequisites. Your Android app must have been published at least once before you can automate the process.</p><p>Gathering Your Google Credentials</p><p><a href="https://docs.fastlane.tools/getting-started/android/setup/#collect-your-google-credentials">Setup - fastlane docs</a></p><pre>cd android<br>fastlane init</pre><p>It will prompt you for the package name, which should match your package ID. If you’ve forgotten it, you can find it in <strong>yourAppfolder/Android/app/build.gradle</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1r6704BCuLHxwTiVhB24jw.png" /></figure><p>Once prompted, provide the path to the JSON secret file you downloaded (the Google Credentials). After downloading the file, place it under yourapp/android/fastlane folder.</p><p>Afterward, it will request to download existing metadata and set up metadata management (y).</p><p>Upon successful completion, it will prompt you to execute the Fastlane test.</p><p>Congratulations! Your Fastlane has been initialized, generating some necessary files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qoJJdopnGGVylYfrSn8d_w.png" /><figcaption>Success initialized fastlane</figcaption></figure><p>And Fastlane created a fastfile</p><pre># This file contains the fastlane.tools configuration<br># You can find the documentation at https://docs.fastlane.tools<br>#<br># For a list of all available actions, check out<br>#<br>#     https://docs.fastlane.tools/actions<br>#<br># For a list of all available plugins, check out<br>#<br>#     https://docs.fastlane.tools/plugins/available-plugins<br>#<br><br># Uncomment the line if you want fastlane to automatically update itself<br># update_fastlane<br><br>default_platform(:android)<br><br>platform :android do<br>  desc &quot;Runs all the tests&quot;<br>  lane :test do<br>    gradle(task: &quot;test&quot;)<br>  end<br><br>  desc &quot;Submit a new Beta Build to Crashlytics Beta&quot;<br>  lane :beta do<br>    gradle(task: &quot;clean assembleRelease&quot;)<br>    crashlytics<br>  <br>    # sh &quot;your_script.sh&quot;<br>    # You can also use other beta testing services here<br>  end<br><br>  desc &quot;Deploy a new version to the Google Play&quot;<br>  lane :deploy do<br>    gradle(task: &quot;clean assembleRelease&quot;)<br>    upload_to_play_store<br>  end<br>end</pre><p>Let’s check, is it working well?</p><p>run, make sure you are in the Android directory</p><h4>Initial run Fastlane</h4><pre>fastlane test</pre><p>If no errors occur, you have successfully initialized Fastlane. Next, remove all lines in the Fastfile and add a plugin for versioning purposes.</p><pre>fastlane add_plugin versioning_android</pre><p>then Update your fast file like below</p><h4>First lane and upload to Closed Test Alpha</h4><pre>desc &quot;Upload to Closed Test Alpha Track&quot;<br>    lane :upload_to_closed_test_alpha do<br>    # gradle(task: &#39;clean&#39;)<br>    android_set_version_code(<br>      gradle_file: &quot;app/build.gradle&quot; # optional<br>    )<br>    gradle(<br>      task: &#39;clean bundle&#39;,<br>      build_type: &#39;Release&#39;,<br>      print_command: false,<br>    )<br><br>    upload_to_play_store(<br>       track: &quot;alpha&quot;,<br>       skip_upload_apk: true,<br>       aab: lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH])<br><br> end<br></pre><p>run into the terminal</p><pre>fastlane upload_to_closed_test_alpha</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aCih1IUcSWyk44kz51GtiQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OByDPqyCiGVfr9hlKTfSXw.png" /></figure><p>Here we’ re, we accomplished a significant milestone by successfully uploading our app using Fastlane. We initiated a Closed Testing Load — an essential step in our process.</p><p>Now, let’s delve into the intricacies of what we accomplished and explain the steps taken to achieve this</p><pre>desc &quot;Upload to Closed Test Alpha Track&quot;</pre><p>Description of the lane</p><pre>lane :upload_to_closed_test_alpha do</pre><p>Fastlane operates with lanes that automate a sequence of commands. Essentially, a lane represents a predefined series of commands. These lanes can vary, including ones like release, develop, and test, each serving different purposes in the automation process.</p><pre>android_set_version_code(<br>      gradle_file: &quot;app/build.gradle&quot; # optional<br>    )</pre><p>This command is an extension within Fastlane that handles the incrementation of the Android version code. Without utilizing this extension, manually updating the version code becomes a necessity each time you deploy your app to the Play Store.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NBlQaCwxJ0_lhm4owXLYLQ.png" /></figure><pre>gradle(<br>      task: &#39;clean bundle&#39;,<br>      build_type: &#39;Release&#39;,<br>      print_command: false,<br>    )</pre><p>This is a Gradle task responsible for generating AAB (Android App Bundles) and executes a sequence of actions by first cleaning the project and then initiating the build process.</p><pre>upload_to_play_store(<br>       track: &quot;alpha&quot;,<br>       skip_upload_apk: true,<br>       aab: lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH])</pre><p>This task is designed for uploading to the Play Store. The “track” parameters determine the release track to which the app is targeted, such as alpha closed test, beta open test, or the general rollout release.</p><pre>abb: lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH])</pre><p>That line gives the location of the generated abb file.</p><p>let’s run the fastlane lane,</p><pre>fastlane upload_to_closed_test_alpha</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aCih1IUcSWyk44kz51GtiQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OByDPqyCiGVfr9hlKTfSXw.png" /></figure><h4>Second lane upload to Release</h4><p>To switch the value of the “track” parameter from “alpha” to “rollout” in the upload_to_play_store command, make the following adjustment: That&#39;s it!</p><pre>upload_to_play_store(<br>  track: &#39;rollout&#39;<br>)</pre><p>This change will target the “rollout” track for the upload process.</p><pre># Release<br>desc &quot;Upload to Release Track&quot;<br>  lane :release do<br>  # gradle(task: &#39;clean&#39;)<br>  android_set_version_code(<br>    gradle_file: &quot;app/build.gradle&quot; # optional<br>  )<br>  android_set_version_name()<br>  gradle(<br>    task: &#39;clean bundle&#39;,<br>    build_type: &#39;Release&#39;,<br>    print_command: false,<br>  )<br><br>  upload_to_play_store(<br>    track: &#39;production&#39;,<br>    skip_upload_apk: true,<br>    aab: lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH])<br>end</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/885bdaa65fdb8035202d25f5eac335be/href">https://medium.com/media/885bdaa65fdb8035202d25f5eac335be/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JD8dKXA7cOZelv7BULknYg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5n90Pbc-r2-AqJeeHB1Pyg.png" /></figure><h3>Find Me 👤</h3><h4><a href="https://www.linkedin.com/in/s%C3%BCha-i%C5%9F%C4%B1k-92b251101/">LinkedIn</a>:</h4><p><a href="https://www.linkedin.com/in/s%C3%BCha-i%C5%9F%C4%B1k-92b251101/">https://www.linkedin.com/in/s%C3%BCha-i%C5%9F%C4%B1k-92b251101/</a></p><h4><a href="https://github.com/abdullahsuhaisk/">GitHub</a>:</h4><p><a href="https://github.com/abdullahsuhaisk/">https://github.com/abdullahsuhaisk/</a></p><h3>About Sisal Digital Hub Türkiye</h3><h4><a href="https://www.linkedin.com/company/sisal-digital-hub-t%C3%BCrkiye/mycompany/verification/">LinkedIn</a>:</h4><p><a href="https://www.linkedin.com/company/sisal-digital-hub-t%C3%BCrkiye/mycompany/verification/">https://www.linkedin.com/company/sisal-digital-hub-t%C3%BCrkiye/mycompany/verification/</a></p><h4><a href="https://www.linkedin.com/company/sisal-digital-hub-t%C3%BCrkiye/mycompany/verification/">Medium</a> Page:</h4><p><a href="https://www.linkedin.com/company/sisal-digital-hub-t%C3%BCrkiye/mycompany/verification/">https://www.linkedin.com/company/sisal-digital-hub-t%C3%BCrkiye/mycompany/verification/</a></p><h3>References 📚</h3><p><a href="https://docs.fastlane.tools/codesigning/xcode-project/">https://docs.fastlane.tools/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bac727d599d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sisalhubs/robust-react-native-app-4-1-3bac727d599d">Robust React Native App — 4.1</a> was originally published in <a href="https://medium.com/sisalhubs">Sisal Hubs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Robust React Native App — 2]]></title>
            <link>https://abdullahsuhaisik.medium.com/robust-react-native-app-2-2ce01d9ea40b?source=rss-54570134045d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ce01d9ea40b</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[jest-native]]></category>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[unit-testing]]></category>
            <dc:creator><![CDATA[Abdullah Süha ışık]]></dc:creator>
            <pubDate>Sat, 15 Jul 2023 10:47:51 GMT</pubDate>
            <atom:updated>2023-07-15T10:47:51.619Z</atom:updated>
            <content:encoded><![CDATA[<h3><a href="https://medium.com/p/9610ed94ac71?source=post_stats_page-------------------------------------">Robust React Native App — </a>2</h3><p>In this section, we will be writing many unit tests. Let’s begin with what we see on the first screen. Usually, I complete writing the component before moving on to writing the unit test.</p><p>When you open the app, the onboarding screens introduce you. Therefore, we can start by writing a unit test for that component.</p><pre>import {View} from &#39;react-native&#39;;<br>import React from &#39;react&#39;;<br>import AppIntroSlider from &#39;../components/AppIntro/AppIntroSlider&#39;;<br><br>export type appIntroScreenType = {<br>    title: Array&lt;string&gt;;<br>    img: any;<br>    content: string;<br>  };<br><br>const appIntroScreensArray: Array&lt;appIntroScreenType&gt; = [<br>  ...<br>];<br><br>const Onboarding: React.FC&lt;{}&gt; = () =&gt; {<br>  return (<br>    &lt;View style={{flex: 1}}&gt;<br>      &lt;AppIntroSlider appIntroScreensArray={appIntroScreensArray} /&gt;<br>    &lt;/View&gt;<br>  );<br>};<br><br>export default Onboarding;</pre><p>The Onboarding component is a fundamental container component that creates an array of elements to be rendered in the AppIntroScreen component. This array is then passed as a prop to the AppIntroSlider component</p><blockquote>When writing <strong>unit</strong> tests, developers sometimes overthink the process. However, it is not necessary to delve too deeply into the details when writing unit tests.</blockquote><p>We can check if AppIntro <strong>renders</strong> correctly. Can I locate my components using the visual rendering mechanism in <strong>Jest</strong>? That should be <strong>sufficient</strong>. To achieve this, I need to add testId to the parent elements of my React Native components.</p><p>&lt;View style={{flex: 1}} testId = &quot;Onboarding&quot; /&gt;</p><p>Now I can check my element via <strong>getByTestId (matcher) </strong>method.</p><p>As you can see, the Onboarding component imports the AppIntroSlider component, as mentioned in the first article. For proper unit testing, it is recommended to isolate each test case within its own lifecycle. To achieve this, I can mock the AppIntroSlider component using a Jest mock function, which simplifies the testing process.</p><pre>jest.mock(&#39;../../components/AppIntro/AppIntroSlider&#39;, () =&gt; &#39;MockedAppIntroSlider&#39;);</pre><pre>import React from &#39;react&#39;;<br>import { render } from &#39;@testing-library/react-native&#39;;<br>import Onboarding from &#39;../Onboarding&#39;;<br><br><br>jest.mock(&#39;../../components/AppIntro/AppIntroSlider&#39;, () =&gt; &#39;MockedAppIntroSlider&#39;); // Mock the AppIntroSlider component<br><br>describe(&#39;Onboarding&#39;, () =&gt; {<br>  it(&#39;renders the component correctly&#39;, () =&gt; {<br>    const { getByTestId } = render(&lt;Onboarding /&gt;);<br>    const onboardingComponent = getByTestId(&#39;Onboarding&#39;)<br>    expect(onboardingComponent).toBeDefined();<br>  });<br>});<br></pre><p>That’s it, Onboarding components unit test is <strong>done</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ff_QE1ixnvhUeQMC_k1COw.png" /><figcaption>Onboarding test passes</figcaption></figure><p>We continue AppIntroSlider. Create a new file under components/AppIntro name __tests__ and create AppIntroSlider.test.tsx .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*fDnqPzJMEhzBOgW2_gO7Jw.png" /><figcaption>AppIntroSlider Components View</figcaption></figure><pre>import React, { FC, useRef, useState } from &#39;react&#39;;<br><br>import {<br>  Dimensions,<br>  NativeScrollEvent,<br>  NativeSyntheticEvent,<br>  ScrollView,<br>} from &#39;react-native&#39;;<br>import { SafeAreaView } from &#39;react-native-safe-area-context&#39;;<br>import AppIntroScreen from &#39;./AppIntroScreen&#39;;<br>import { COLORS } from &#39;../../assets&#39;;<br>import AppIntroFooter from &#39;./AppIntroFooter&#39;;<br>import { useNavigation } from &#39;@react-navigation/native&#39;;<br>import { AuthenticationNavigationProp } from &#39;../../navigations/AuthenticationNavigator/types&#39;;<br>import { appIntroScreenType } from &#39;../../screens/Onboarding&#39;;<br><br>type AppIntroSliderProps = {<br>  appIntroScreensArray: Array&lt;appIntroScreenType&gt;;<br>};<br><br>const AppIntroSlider: FC&lt;AppIntroSliderProps&gt; = ({ appIntroScreensArray }) =&gt; {<br>    ....<br>  function handleSignInButton() {<br>    ....<br>  }<br><br>  function handleScrollTo(destination: number) {<br>    ....<br>  }<br><br>  const setSliderPage = (event: NativeSyntheticEvent&lt;NativeScrollEvent&gt;) =&gt; {<br>    ....<br>  };<br><br>  return (<br>    &lt;SafeAreaView style={{ backgroundColor: COLORS.appIntroBgColor, flex: 1 }}&gt;<br>      &lt;ScrollView<br>        horizontal={true}<br>        scrollEventThrottle={16}<br>        pagingEnabled={true}<br>        showsHorizontalScrollIndicator={false}<br>        onScroll={(event: NativeSyntheticEvent&lt;NativeScrollEvent&gt;) =&gt; {<br>          setSliderPage(event);<br>        }}<br>        ref={sliderRef}<br>        testID=&quot;onBoardingContainer&quot;<br>      &gt;<br>        {appIntroScreensArray.map((screen, index) =&gt; (<br>          &lt;AppIntroScreen width={width} screen={screen} key={index} /&gt;<br>        ))}<br>      &lt;/ScrollView&gt;<br>      {/* FOOTER */}<br>      &lt;AppIntroFooter<br>        sliderState={sliderState}<br>        width={width}<br>        appIntroScreensArray={appIntroScreensArray}<br>        handleScrollTo={handleScrollTo}<br>        handleSignInButton={handleSignInButton}<br>      /&gt;<br>    &lt;/SafeAreaView&gt;<br>  );<br>};<br><br>export default AppIntroSlider;</pre><p>That component includes a custom scroll view to display each page horizontally, with each page occupying the entire screen. The component receives an array of elements as props called appIntroScreensArray. The scroll view renders these elements in the AppIntroScreen component, with an AppIntroFooter component positioned at the bottom of the screen. I will assign a testID to the other component that will be mocked.</p><p>I realized that I forgot to add the testID prop type to the components. Furthermore, I have now updated the types and included the testID prop in the first elements of the component.</p><pre>type AppIntroScreenProps = {<br>  width: number;<br>  screen: appIntroScreenType;<br>  testID?: string<br>};</pre><p>Apply the same improvements to the AppIntroFooter component.</p><pre>&lt;AppIntroScreen width={width} screen={screen} key={index} testID={&quot;appIntroScreen&quot;}  /&gt;</pre><p>Here is refactored AppIntroSlider component&#39;s return function;</p><pre><br>  return (<br>    &lt;SafeAreaView style={{ backgroundColor: COLORS.appIntroBgColor, flex: 1}} testID=&#39;appIntroSlider&#39;&gt;<br>      &lt;ScrollView<br>        horizontal={true}<br>        scrollEventThrottle={16}<br>        pagingEnabled={true}<br>        showsHorizontalScrollIndicator={false}<br>        onScroll={(event: NativeSyntheticEvent&lt;NativeScrollEvent&gt;) =&gt; {<br>          setSliderPage(event);<br>        }}<br>        ref={sliderRef}<br>        testID=&quot;onBoardingContainer&quot;<br>      &gt;<br>        {appIntroScreensArray.map((screen, index) =&gt; (<br>          &lt;AppIntroScreen width={width} screen={screen} key={index} testID={&quot;appIntroScreen&quot;} /&gt;<br>        ))}<br>      &lt;/ScrollView&gt;<br>      {/* FOOTER */}<br>      &lt;AppIntroFooter<br>        sliderState={sliderState}<br>        width={width}<br>        appIntroScreensArray={appIntroScreensArray}<br>        handleScrollTo={handleScrollTo}<br>        handleSignInButton={handleSignInButton}<br>        testID={&quot;appIntroFooter&quot;}<br>      /&gt;<br>    &lt;/SafeAreaView&gt;<br>  );<br>};<br><br>export default AppIntroSlider;</pre><p>For other test examples, I plan to refactor the components by passing them if they require only minor code changes, such as adding a testId. So don’t worry if you don’t see testID on master branch.</p><p>The first test could be to verify these components render correctly.</p><pre>  it(&#39;renders the component correctly&#39;, () =&gt; {<br><br>    const appIntroScreensArray = [<br>  {<br>    title: [&#39;Welcome to &#39;, &#39;READDIT&#39;],<br>    img: &#39;image1&#39;,<br>    content: &#39;Content 1&#39;,<br>  },<br>  {<br>    title: [&#39;Create an English &#39;, &#39;Reading HABIT&#39;],<br>    img: &#39;image2&#39;,<br>    content: &#39;Content 2&#39;,<br>  },<br><br>    const { getByTestId, getAllByTestId } = render(<br>      &lt;AppIntroSlider appIntroScreensArray={appIntroScreensArray} /&gt;<br>    );<br><br>    const appIntroSlider = getByTestId(&#39;appIntroSlider&#39;);<br>    const appIntroScreens = getAllByTestId(&#39;appIntroScreen&#39;);<br>    const appIntroFooter = getByTestId(&#39;appIntroFooter&#39;);<br><br>    expect(appIntroSlider).toBeDefined();<br>    expect(appIntroScreens.length).toBe(appIntroScreensArray.length);<br>    expect(appIntroFooter).toBeDefined();<br>  });</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Hc3CW1EtseSWumUfqjEOw.png" /><figcaption>Above tests results</figcaption></figure><p>As you see, we got an error, we need to mock our navigation components, To mock the useNavigation hook, you can include the following lines at the top of the test file.</p><pre>// Mocking the useNavigation hook<br>jest.mock(&#39;@react-navigation/native&#39;, () =&gt; ({<br>  useNavigation: jest.fn(),<br>}));</pre><p>Now it’s working. Another option is to add the above code snippets into the setup.ts file located in the test folder. I have opted for the second option.</p><p>My setup file is</p><pre>import &#39;@testing-library/jest-native/extend-expect&#39;;<br>// Mocking the useNavigation hook<br>jest.mock(&#39;@react-navigation/native&#39;, () =&gt; ({<br>    useNavigation: jest.fn(),<br>}));</pre><p>We can test the functions of the AppIntroSlider component in its children components, since AppIntroSlider passes its own functions to the children as props. This can serve as a hint when encountering difficulties in testing your functions. If you find the need to frequently perform such tests, it may indicate that a code refactor is necessary, as it could be a potential antipattern.</p><p>We can check appIntroScreen components screens count.</p><pre>  it(&#39;renders the correct number of appIntroScreens&#39;, () =&gt; {<br>    const { getAllByTestId } = render(&lt;AppIntroSlider appIntroScreensArray={appIntroScreensArray} /&gt;);<br>    const appIntroScreens = getAllByTestId(&#39;appIntroScreen&#39;);<br><br>    expect(appIntroScreens.length).toBe(appIntroScreensArray.length);<br>  });</pre><p>The last version of AppIntroSlider.test.tsx</p><pre>import React from &#39;react&#39;;<br>import { render, fireEvent } from &#39;@testing-library/react-native&#39;;<br>import AppIntroSlider from &#39;../AppIntroSlider&#39;;<br><br>// jest.mock(&#39;../AppIntroScreen&#39;, () =&gt; &#39;MockedAppIntroScreen&#39;);<br>// jest.mock(&#39;../AppIntroFooter&#39;, () =&gt; &#39;MockedAppIntroFooter&#39;);<br><br>const appIntroScreensArray = [<br>  {<br>    title: [&#39;Welcome to &#39;, &#39;READDIT&#39;],<br>    img: &#39;image1&#39;,<br>    content: &#39;Content 1&#39;,<br>  },<br>  {<br>    title: [&#39;Create an English &#39;, &#39;Reading HABIT&#39;],<br>    img: &#39;image2&#39;,<br>    content: &#39;Content 2&#39;,<br>  },<br>];<br><br>describe(&#39;AppIntroSlider&#39;, () =&gt; {<br>  it(&#39;renders the component correctly&#39;, () =&gt; {<br>    const { getByTestId, getAllByTestId } = render(<br>      &lt;AppIntroSlider appIntroScreensArray={appIntroScreensArray} /&gt;<br>    );<br><br>    const appIntroSlider = getByTestId(&#39;appIntroSlider&#39;);<br>    const appIntroScreens = getAllByTestId(&#39;appIntroScreen&#39;);<br>    const appIntroFooter = getByTestId(&#39;appIntroFooter&#39;);<br><br>    expect(appIntroSlider).toBeDefined();<br>    expect(appIntroScreens.length).toBe(appIntroScreensArray.length);<br>    expect(appIntroFooter).toBeDefined();<br>  });<br><br>  it(&#39;renders the correct number of appIntroScreens&#39;, () =&gt; {<br>    const { getAllByTestId } = render(&lt;AppIntroSlider appIntroScreensArray={appIntroScreensArray} /&gt;);<br>    const appIntroScreens = getAllByTestId(&#39;appIntroScreen&#39;);<br>    expect(appIntroScreens.length).toBe(appIntroScreensArray.length);<br>  });<br><br>});</pre><p>Instead of sending the testId prop, I suggest using a static testID by adding it to the root of the component. This approach eliminates the need for mocking components, as they have static testID values. Consequently, there is no requirement to update the AppIntroScreenProps and appIntroFooter <strong>types</strong>. This method provides greater convenience, and you only need to remove the lines:</p><pre>jest.mock(&#39;../AppIntroScreen&#39;, () =&gt; &#39;MockedAppIntroScreen&#39;);<br>jest.mock(&#39;../AppIntroFooter&#39;, () =&gt; &#39;MockedAppIntroFooter&#39;);</pre><p>That’s it.</p><pre>    &lt;View style={[styles.container, { width }]} testID={&quot;appIntroFooter&quot;}&gt;<br>     ...<br>    &lt;/View&gt;</pre><pre>const AppIntroScreen: FC&lt;AppIntroScreenProps&gt; = ({ width, screen }) =&gt; {<br>  return (<br>    &lt;View style={[styles.container, { width }]} testID={&quot;appIntroScreen&quot;}&gt;<br>      {/* HEADER */}<br>      &lt;View testID=&quot;welcomeHeader&quot; style={styles.header}&gt;<br>        &lt;Text style={styles.headerText}&gt;{screen.title[0]}&lt;/Text&gt;<br>        &lt;Text style={styles.headerText}&gt;{screen.title[1]}&lt;/Text&gt;<br>      &lt;/View&gt;<br>      {/* IMAGE */}<br>      &lt;Image source={screen.img} style={styles.imageStyle} testID=&#39;appIntroImage&#39;/&gt;<br>      {/* CONTENT */}<br>      &lt;View style={styles.wrapper}&gt;<br>        &lt;Text style={[styles.headerText, styles.content]}&gt;<br>          You can help you{&#39; &#39;}<br>          &lt;Text style={{ color: COLORS.primary }}&gt;to be a better&lt;/Text&gt; version<br>          of &lt;Text style={{ color: COLORS.primary }}&gt;yourself&lt;/Text&gt;<br>        &lt;/Text&gt;<br>      &lt;/View&gt;<br>    &lt;/View&gt;<br>  );<br>};</pre><p>Now, let’s focus on the AppIntroScreen component, which is primarily responsible for rendering the props correctly. The AppIntroScreen component takes the AppIntroScreenProps as its props, with the screen property types defined as follows:</p><pre>export type appIntroScreenType = {<br>    title: Array&lt;string&gt;;<br>    img: any;<br>    content: string;<br>  }; // exported in Onboarding.tsx</pre><pre>import React, { FC } from &#39;react&#39;;<br>import { Image, PixelRatio, StyleSheet, Text, View } from &#39;react-native&#39;;<br>import { COLORS, SIZES } from &#39;../../assets&#39;;<br>import { appIntroScreenType } from &#39;../../screens/Onboarding&#39;;<br><br>type AppIntroScreenProps = {<br>  width: number;<br>  screen: appIntroScreenType;<br>  testID?: string<br>};<br><br>/**<br> * @param props - {@link AppIntroScreenProps}<br> */<br><br>const AppIntroScreen: FC&lt;AppIntroScreenProps&gt; = ({ width, screen, testID }) =&gt; {<br>  return (<br>    &lt;View style={[styles.container, { width }]} testID={testID}&gt;<br>      {/* HEADER */}<br>      &lt;View testID=&quot;welcomeHeader&quot; style={styles.header}&gt;<br>        &lt;Text style={styles.headerText}&gt;{screen.title[0]}&lt;/Text&gt;<br>        &lt;Text style={styles.headerText}&gt;{screen.title[1]}&lt;/Text&gt;<br>      &lt;/View&gt;<br>      {/* IMAGE */}<br>      &lt;Image source={screen.img} style={styles.imageStyle} /&gt;<br>      {/* CONTENT */}<br>      &lt;View style={styles.wrapper}&gt;<br>        &lt;Text style={[styles.headerText, styles.content]}&gt;<br>          You can help you{&#39; &#39;}<br>          &lt;Text style={{ color: COLORS.primary }}&gt;to be a better&lt;/Text&gt; version<br>          of &lt;Text style={{ color: COLORS.primary }}&gt;yourself&lt;/Text&gt;<br>        &lt;/Text&gt;<br>      &lt;/View&gt;<br>    &lt;/View&gt;<br>  );<br>};<br><br>const styles = StyleSheet.create({<br>...<br>});<br><br>export default AppIntroScreen;</pre><p>We need to check props are rendering <strong>correctly</strong> ?</p><pre>import React from &#39;react&#39;;<br>import { render } from &#39;@testing-library/react-native&#39;;<br>import AppIntroScreen from &#39;../AppIntroScreen&#39;;<br><br>// Mock the image module<br>// jest.mock(&#39;../../../assets/images/AppIntro/Habits.png&#39;, () =&gt; ({<br>//     // Replace the module with a mocked value<br>//     uri: &#39;mocked-image-uri&#39;,<br>//   }));<br><br>describe(&#39;AppIntroScreen&#39;, () =&gt; {<br>  const mockScreen = {<br>    title: [&#39;Title 1&#39;, &#39;Title 2&#39;],<br>    img:  require(&#39;../../../assets/images/AppIntro/Habits.png&#39;),<br>    content: &#39;Some content&#39;<br>  };<br><br>  it(&#39;renders correctly props&#39;, () =&gt; {<br>    const { getByText, getByTestId } = render(&lt;AppIntroScreen width={320} screen={mockScreen} /&gt;);<br>    const titleElement1 = getByText(&#39;Title 1&#39;);<br>    const titleElement2 = getByText(&#39;Title 2&#39;);<br>    const imageElement = getByTestId(&#39;appIntroImage&#39;);<br><br>    expect(imageElement).toBeDefined();<br>    expect(imageElement.props.source).toEqual(mockScreen.img);<br>    expect(titleElement1).toBeDefined();<br>    expect(titleElement2).toBeDefined();<br>  });<br><br>});</pre><p>If you want, you can mock image path you can do with commented lines.</p><p>Now, let’s move on to the appIntroFooter component, which provides a more enjoyable experience due to its inclusion of logic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*8FT4MjP44Emr3K8HOgXVgg.png" /><figcaption>appIntoFooter components view when pageIndex less than appIntroScreensArray</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*z0olIOuSMZC89yKT0N52pg.png" /><figcaption>appIntoFooter components view when pageIndex more than appIntroScreensArray</figcaption></figure><p>The AppIntroFooter component demonstrates more logical behavior compared to the previously tested components. It determines which buttons to render based on the pageIndex value. When the pageIndex is greater than the length of the appIntroScreensArray minus one, indicating that we are on the last appIntro screen, it shows the login button. Conversely, it displays the Skip and Next buttons. Additionally, if the user wishes to skip the introduction screens, they can click the Skip button to directly access the last introduction screen, which features the sign-in button. Let’s proceed with testing all of these functionalities.</p><pre>type appIntroButtonType = {<br> ...<br>};<br><br>const AppIntroButton: FC&lt;appIntroButtonType&gt; = ({ title, handlePress }) =&gt; {<br>  return (<br>    ...<br>  );<br>};<br><br>type AppIntroFooterProps = {<br>  sliderState: {<br>    currentPage: number;<br>  };<br>  width: number;<br>  appIntroScreensArray: Array&lt;any&gt;;<br>  handleScrollTo: (destination: number) =&gt; void;<br>  handleSignInButton: () =&gt; void;<br>  testID: string<br>};<br><br>/**<br> * Component description<br> * @param props - {@link AppIntroFooterProps}<br> */<br><br>const AppIntroFooter: FC&lt;AppIntroFooterProps&gt; = ({<br>  sliderState,<br>  width,<br>  appIntroScreensArray,<br>  handleScrollTo,<br>  handleSignInButton,<br>  testID<br>}) =&gt; {<br>  const { currentPage: pageIndex } = sliderState;<br>  function handlePress(destination: number): void {<br>    // console.log(event);<br>    handleScrollTo(destination);<br>  }<br>  return (<br>    &lt;View style={[styles.container, { width }]} testID={testID}&gt;<br>      {pageIndex &gt;= appIntroScreensArray.length - 1 ? (<br>        &lt;View style={{ width: width - 20 }}&gt;<br>          &lt;Button<br>            title=&quot;Sign In&quot;<br>            handlePress={() =&gt; handleSignInButton()}<br>            testID=&quot;signIn&quot;<br>          /&gt;<br>        &lt;/View&gt;<br>      ) : (<br>        &lt;View style={[styles.container, { width }]}&gt;<br>          &lt;AppIntroButton<br>            handlePress={() =&gt; {<br>              handlePress(appIntroScreensArray.length - 1);<br>            }}<br>            title=&quot;Skip&quot;<br>          /&gt;<br>          &lt;View style={styles.paginationWrapper}&gt;<br>            {appIntroScreensArray.map((key, index) =&gt; (<br>              &lt;View<br>                style={[<br>                  styles.paginationDots,<br>                  { opacity: pageIndex === index ? 1 : 0.2 },<br>                ]}<br>                key={index}<br>              /&gt;<br>            ))}<br>          &lt;/View&gt;<br>          {/* handlePress(pageIndex) */}<br>          &lt;AppIntroButton<br>            handlePress={() =&gt; {<br>              handlePress(pageIndex + 1);<br>            }}<br>            title=&quot;Next&quot;<br>            handleSignInButton={handleSignInButton}<br>          /&gt;<br>        &lt;/View&gt;<br>      )}<br>    &lt;/View&gt;<br>  );<br>};<br><br>const styles = StyleSheet.create({<br>.....<br>});<br><br>export default AppIntroFooter;</pre><p>Summarize test topics,</p><ul><li>It should render the Sign In button on the last page</li><li>It should render the skip and next buttons on non-last page</li><li>it should call handleScrollTo when Skip button is pressed</li><li>it should call handleScrollTo when Next button is pressed</li><li>it should call handleSignInButton when Sign In button is pressed</li></ul><p>We found 5 test case.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d2246e6dde6077c3c2a8addc33a00289/href">https://medium.com/media/d2246e6dde6077c3c2a8addc33a00289/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*_5Mo0MrzVjnvUvlsuZDD0g.png" /></figure><h4>Button</h4><pre>type ButtonProps = {<br>  title: string;<br>  handlePress: () =&gt; void;<br>  testID: string;<br>  isLoading?: boolean;<br>};<br><br>/**<br> * @param props - {@link ButtonProps}<br> */<br><br>const Button: FC&lt;ButtonProps&gt; = ({ title, handlePress, testID, isLoading }) =&gt; {<br>  return (<br>    &lt;View style={styles.container}&gt;<br>      {isLoading ? (<br>        &lt;Spinner size={&#39;large&#39;} /&gt;<br>      ) : (<br>        &lt;TouchableOpacity<br>          style={styles.button}<br>          onPress={handlePress}<br>          testID={testID}<br>        &gt;<br>          &lt;Text style={styles.buttonTitle}&gt;{title}&lt;/Text&gt;<br>        &lt;/TouchableOpacity&gt;<br>      )}<br>    &lt;/View&gt;<br>  );<br>};</pre><p>For the button component, we can check bellows;</p><p>Firstly, mock some props</p><pre>  const mockTitle = &#39;Submit&#39;;<br>  const mockHandlePress = jest.fn();<br>  const mockTestID = &#39;submitButton&#39;;</pre><ul><li>it should display title</li></ul><pre>  it(&#39;render correctly and displays the correct title&#39;, () =&gt; {<br>    const { getByText } = render(<br>      &lt;Button title={mockTitle} handlePress={mockHandlePress} testID={mockTestID} /&gt;<br>    );<br>    const titleElement = getByText(mockTitle);<br>    expect(titleElement).toBeDefined();<br>  });</pre><ul><li>it should call when button tapped</li></ul><pre>  it(&#39;calls handlePress when button is pressed&#39;, () =&gt; {<br>    const { getByTestId } = render(<br>      &lt;Button title={mockTitle} handlePress={mockHandlePress} testID={mockTestID} /&gt;<br>    );<br>    const button = getByTestId(mockTestID);<br>    fireEvent.press(button);<br>    expect(mockHandlePress).toHaveBeenCalled();<br>  });</pre><ul><li>it should display spinner when isLoading is true</li></ul><pre> it(&#39;displays the spinner when isLoading is true&#39;, () =&gt; {<br>    const { getByTestId } = render(<br>      &lt;Button title={mockTitle} handlePress={mockHandlePress} testID={mockTestID} isLoading={true} /&gt;<br>    );<br>    const spinner = getByTestId(&#39;spinner&#39;);<br>    expect(spinner).toBeDefined();<br>  });</pre><ul><li>it should not display spinner when isLoading prop is false</li></ul><pre>  it(&#39;displays the button when isLoading is false&#39;, () =&gt; {<br>    const { getByTestId, findByTestId, queryByTestId } = render(<br>      &lt;Button title={mockTitle} handlePress={mockHandlePress} testID={mockTestID} isLoading={false} /&gt;<br>    );<br>    const spinner = getByTestId(&#39;spinner&#39;);<br>    expect(spinner).toBeNull();<br>  });</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OVkSEg_gwflpGY0KnIZQ0g.png" /><figcaption>Getting Error</figcaption></figure><p>If getByTestId does not find the element, it throws an error. In such cases, you can use queryByTestId or findByTestId instead.</p><pre>  it(&#39;displays the button when isLoading is false&#39;, () =&gt; {<br>    const { queryByTestId } = render(<br>      &lt;Button title={mockTitle} handlePress={mockHandlePress} testID={mockTestID} isLoading={false} /&gt;<br>    );<br>    const spinner = queryByTestId(&#39;spinner&#39;);<br>    expect(spinner).toBeNull();<br>  });</pre><h4>Icon</h4><p>To test the Icon components, you will need to make some changes due to the usage of the react-native-svg package, which requires additional setup. Add the following lines to the setup.ts file.</p><pre>//mock svgUri<br>jest.mock(&#39;react-native-svg&#39;, () =&gt; ({<br>  SvgUri: &#39;SvgUri&#39;,<br>}));<br><br>module.exports = &#39;SvgMock&#39;;<br>module.exports.ReactComponent = &#39;SvgMock&#39;;</pre><p>jest.config.json</p><pre>{<br>    &quot;preset&quot;: &quot;react-native&quot;,<br>    &quot;setupFilesAfterEnv&quot;: [&quot;&lt;rootDir&gt;/src/tests/setup.ts&quot;],<br>    &quot;transformIgnorePatterns&quot;: [<br>      &quot;node_modules/(?!(jest-)?@?react-native|@react-native-community|@react-navigation)&quot;<br>    ],<br>    &quot;moduleNameMapper&quot;: {<br>      &quot;\\.svg&quot;: &quot;&lt;rootDir&gt;/src/tests/setup.ts&quot;<br>    }<br>  }</pre><ul><li>it should display when get link as a prop</li></ul><pre>  it(&#39;should render as link&#39;, () =&gt; {<br>    const screen = render(&lt;Icon src=&quot;https://placehold.co/600x400&quot; /&gt;);<br>    expect(screen).toBeDefined();<br>  });</pre><ul><li>it should display when get link as a prop and width</li></ul><pre>  it(&#39;should render as link with width&#39;, () =&gt; {<br>    const { queryByTestId } = render(<br>      &lt;Icon src=&quot;https://placehold.co/600x400&quot; width={600} /&gt;,<br>    );<br>    const actual = queryByTestId(&#39;iconUri&#39;);<br>    expect(actual).not.toBeNull();<br>  });</pre><ul><li>it should display when get ID as a prop</li></ul><pre>  it(&#39;should render as id&#39;, () =&gt; {<br>    const screen = render(&lt;Icon id=&quot;user&quot; /&gt;);<br>    expect(screen).toBeDefined();<br>  });</pre><h4>TextInput</h4><pre>type TextInputProps = {<br>  placeHolder?: string;<br>  setText: Dispatch&lt;SetStateAction&lt;string&gt;&gt;;<br>  text: string;<br>  color?: string;<br>  icon?: (typeof ICON)[keyof typeof ICON];<br>  testID: string;<br>};<br><br>/**<br> * Component description<br> * Resuable TextInput Component<br> * Color option<br> * @param props - {@link TextInputProps}<br> */<br><br>const TextInput: React.FC&lt;TextInputProps&gt; = ({<br>  placeHolder,<br>  setText,<br>  text,<br>  color,<br>  icon,<br>  testID,<br>}) =&gt; {<br>  function onChangeText(text: React.SetStateAction&lt;string&gt;) {<br>    setText(text);<br>  }<br>  return (<br>    &lt;View<br>      style={[<br>        styles.container,<br>        color ? { backgroundColor: color } : { backgroundColor: COLORS.white },<br>      ]}<br>      testID={testID}<br>    &gt;<br>      {icon ? (<br>        &lt;View style={styles.iconContainer}&gt;<br>          &lt;Icon id={icon} width={&#39;20&#39;} height={&#39;20&#39;} /&gt;<br>        &lt;/View&gt;<br>      ) : null}<br>      &lt;ReactTextInput<br>        style={[styles.input]}<br>        onChangeText={(text: string) =&gt; onChangeText(text)}<br>        value={text}<br>        placeholder={placeHolder}<br>      /&gt;<br>    &lt;/View&gt;<br>  );<br>};<br><br>const styles = StyleSheet.create({<br>  ...<br>});<br><br>export default TextInput;</pre><ul><li>it should display correctly with placeHolder</li><li>it should update text value when typing</li></ul><pre>  it(&#39;render correctly with placeHolder and should update text value when typing&#39;, () =&gt; {<br>    const { getByPlaceholderText } = render(<br>      &lt;TextInput<br>        placeHolder={placeHolder}<br>        setText={setTextMock}<br>        text=&quot;&quot;<br>        color={color}<br>        testID={testID}<br>      /&gt;,<br>    );<br><br>    const inputElement = getByPlaceholderText(placeHolder);<br>    fireEvent.changeText(inputElement, testText);<br>    expect(setTextMock).toHaveBeenCalledWith(testText);<br>  });</pre><ul><li>it should render an icon if the icon prop is provided</li></ul><pre><br>  it(&#39;should render an icon if the icon prop is provided&#39;, () =&gt; {<br>    const { getByTestId } = render(<br>      &lt;TextInput<br>        placeHolder={placeHolder}<br>        setText={setTextMock}<br>        text={testText}<br>        icon={testIcon}<br>        testID={testID}<br>      /&gt;,<br>    );<br>    const iconElement = getByTestId(iconTestId);<br>    expect(iconElement).toBeTruthy();<br>  });</pre><ul><li>it should render with props bgColor if the color prop is provided</li></ul><pre>  it(&#39;should render with props bgColor if the color prop is provided&#39;, () =&gt; {<br>    const { getByTestId } = render(<br>      &lt;TextInput<br>        placeHolder={placeHolder}<br>        setText={setTextMock}<br>        text={testText}<br>        icon={testIcon}<br>        testID={testID}<br>        color={color}<br>      /&gt;,<br>    );<br>    const textInput = getByTestId(testID).parent;<br>    expect(textInput).toHaveStyle({ backgroundColor: color });<br>  });</pre><p>We have learned a lot so far, and you can continue on your own. The Login component has not been tested yet. It does not receive props directly; instead, it creates some functions and passes them as props to the ForgetPassword and SignIn components. You can test these functions by mocking them in the ForgetPassword and SignIn components. Additionally, you can check if the Login component renders correctly and displays the expected content.</p><p>I believe the examples mentioned above are sufficient for now. If you need further assistance, you can refer to the instructions provided earlier. You can find all the code changes and files at <a href="https://github.com/abdullahsuhaisk/robustReactNativeApp/tree/unitTest">https://github.com/abdullahsuhaisk/robustReactNativeApp/tree/unitTest</a>.</p><p>The next article will delve into E2E testing in React Native, focusing specifically on the DETOX testing framework.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ce01d9ea40b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Robust React Native App — 1]]></title>
            <link>https://abdullahsuhaisik.medium.com/robust-react-native-app-1-9610ed94ac71?source=rss-54570134045d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9610ed94ac71</guid>
            <category><![CDATA[react-native-unit-test]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react-native-testing]]></category>
            <category><![CDATA[test-types]]></category>
            <category><![CDATA[react-native-e2e-test]]></category>
            <dc:creator><![CDATA[Abdullah Süha ışık]]></dc:creator>
            <pubDate>Thu, 06 Jul 2023 12:21:56 GMT</pubDate>
            <atom:updated>2023-11-22T11:07:53.617Z</atom:updated>
            <content:encoded><![CDATA[<h3>Robust React Native App — 1</h3><p>Nowadays, building apps has become relatively easier, thanks to the abundance of tutorials and boilerplate code available on the internet. It has opened up opportunities for individuals to create their own apps with relative ease. However, the real challenge lies in developing a robust app with a solid structure.</p><p>In this article series, I will delve into the topic of building a robust React Native app that is fortified with unit tests for its components, as well as integration and end-to-end (E2E) tests. By implementing a comprehensive testing strategy, we can ensure that our app functions reliably and as intended, even as it grows in complexity and scale. I am going to write a series related and planning 5 articles about it. The topics are :</p><h4>1. Project Overview and the Importance of Testing</h4><p>Before we dive into the details, let’s start with a brief project overview. We’ll explore the significance of testing in the React Native app development process and why it is crucial for creating a successful and robust application.</p><h4><a href="https://abdullahsuhaisik.medium.com/robust-react-native-app-2-2ce01d9ea40b">2. Writing Unit Tests</a></h4><p>In this section, we will explore how to write effective unit tests that isolate and verify the functionality of each component. By testing individual units of code in isolation, we can catch potential issues early on and maintain the desired behavior of our app.</p><h4>3. Writing E2E Test with Detox</h4><p>In addition to unit tests, e2e tests are essential for verifying the proper interaction between various components of your React Native app. We will explore the usage of Detox, a powerful end-to-end testing framework, to write e2e tests that simulate user interactions and validate the behavior of our app as a whole. These tests will ensure that the different parts of our app work harmoniously together, providing a seamless user experience.</p><h4><a href="https://abdullahsuhaisik.medium.com/robust-react-native-app-4-1-3bac727d599d">4. Fastlane CI/CD process</a></h4><p>Continuous Integration and Continuous Deployment (CI/CD) are vital practices in modern app development workflows. In this section, we will discuss how to integrate a <strong>fastlane</strong> CI/CD process into your React Native app. By automating the build, test, and deployment processes, we can streamline development and ensure that changes are thoroughly tested and deployed efficiently.</p><h4>5. Streamlining Processes with Oclif</h4><p>Repetitive tasks can consume valuable development time and effort. In this final section, we will explore how to leverage Oclif, a command-line framework, to simplify and automate repetitive processes in your React Native app development (clean and setup process). By creating custom commands and automating tasks, you can enhance productivity and focus on building high-quality features for your app.</p><p>Here is my project. I am going to create a branch for every article. You can start investigating with the master branch. After cloning the app, you can do your own, following me.</p><ul><li><a href="https://github.com/abdullahsuhaisk/robustReactNativeApp">GitHub - abdullahsuhaisk/robustReactNativeApp: the importance of unit testing, and the inclusion of end-to-end testing. It implies that the article will provide readers with a comprehensive guide to building robust React Native applications using testing techniques.</a></li><li><a href="https://youtube.com/shorts/tDo35v2_g1U?feature=share">Robust React Native App</a></li></ul><p>If you watch a Youtube video, you could see all features and available screens. I wanted to make this article like a real-life example. The project’s structure is the small version that we used on our projects. I read lots of article-related Unit tests and E2E tests, but they focus on theory in this series I am going to touch on a real example, and we will be coding the tests together. Before diving into the tests, let me introduce my app and a little bit of talk about tests.</p><p>Let’s consider the scenario where we are creating an English reading habit app, our goal is to help clients get reading habits. We are going to make robust authentication for this app. The authentication features have already been implemented. We are <strong>not</strong> going to develop the <strong>app’s features</strong> in this article, we are going to just focus on tests. Before going to test-related topics, please take a careful look at the project’s <a href="https://github.com/abdullahsuhaisk/robustReactNativeApp">master</a> branch.</p><p>The app consists of five screens: Onboarding, Login, SignIn, ForgetPassword, and HomeScreen.</p><p>Followed libraries were used <strong>react-native-navigation, react-native-svg</strong>, and <strong>redux-saga </strong>and the app was written with typescript. In this tutorial, you can also find redux-saga, typescript usages and examples, and react-navigation typescript examples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*hiCk5joGap35bHpH_8Tcfg.png" /><figcaption>File Structure</figcaption></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fgw3IWyGkC0rsazTi%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Ftest-gw3IWyGkC0rsazTi&amp;image=https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExdHI4eHJydXhoZnNpZDdjb2tsY3h2dWFzMTk1N2Vva25penppdzFvNiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2Fgw3IWyGkC0rsazTi%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1c2cd80bc0d57859eccdff109a9909e/href">https://medium.com/media/d1c2cd80bc0d57859eccdff109a9909e/href</a></iframe><h4>What is the Unit Test, and why should I write it?</h4><p>The purpose of the unit test is <strong>validating</strong> your individual components and functions (unit) with code, is providing and checking your code to ensure it is working as <strong>expected</strong>. Unit testing is the <strong>simplest</strong> and <strong>least expensive</strong> testing option. Unit testing helps the React component conform to standards. I’ve noticed that most of the time when I’m writing a unit test, I’m increasing the quality of the component.</p><p>Another benefit of unit testing is to help to <strong>understand the code</strong> that is written by <strong>another developer</strong>. Indeed, if your component doesn’t follow some of the unwritten rules and standards you <strong>can’t test reliablely the components</strong>, and you have<strong> to refactor </strong>your components.</p><h4>What is the Integration Test?</h4><p>Integration test is just more complex unit test. If you want to test your component&#39;s interaction with others. For example, if your component makes async operations, and you want to test it with the result of the async operation, it calls an integration test, however, you have to mock this async operation. Another example is when you manage state using Redux and want to test a component that uses Redux; this is called integration testing.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3o85xChv5muUGOhyWk%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fmashable-funny-pope-tinder-3o85xChv5muUGOhyWk&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExZWFyNzZrdjR3YXRueWcwbTl4b2N1cnU2c2xqcTFnbmR2a2h3NGU2aiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2F3o85xChv5muUGOhyWk%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="564" frameborder="0" scrolling="no"><a href="https://medium.com/media/eec15d75a0bafd0afa18f1a1a04d1fbb/href">https://medium.com/media/eec15d75a0bafd0afa18f1a1a04d1fbb/href</a></iframe><h4>What is the E2E test?</h4><p>E2E testing, also known as Gray Box Testing, allows you to test your entire system from a user’s perspective. The focus is on whether the application works, rather than how it works. I highly recommend E2E testing as it helps avoid time wastage. You may wonder how it helps to <strong>avoids wasting time</strong>, considering that writing E2E tests can be time-consuming. We will delve into this topic in the related article, but I can assure you that during development, developers often perform numerous manual tests. When adding a new feature, we test it multiple times, potentially breaking things, and wasting time on manual tests. By automating these tests, we can save valuable time.</p><h4>Summary:</h4><p>Unit tests focus on testing <strong>individual</strong> components or functions in <strong>isolation</strong>, whereas E2E (end-to-end) tests verify the <strong>integrated behavior</strong> of the application as a whole. Unit tests provide quick feedback and help identify bugs within specific code units, while E2E tests validate the end-to-end functionality of the system. Both types of tests are valuable and serve complementary purposes in ensuring the <strong>quality</strong> and <strong>reliability</strong> of a software application. Unit tests help ensure that individual units of code work correctly, while E2E tests ensure that all the different parts of the application work together seamlessly. By combining both types of tests, developers can have <strong>confidence</strong> in the <strong>stability</strong> and <strong>correctness</strong> of their software.</p><p>Before diving into the unit test topic, let’s familiarize ourselves with some terms.</p><figure><img alt="Jest is the most popular JS test framework." src="https://cdn-images-1.medium.com/max/796/1*yRX97DiEyDcMMvsYYeg3OQ.png" /></figure><h4>What is the Test Runner?</h4><p>A test runner is responsible for executing tests. It locates test files, provides an execution environment, and delivers results. We will be using Jest, which is a widely used and popular <strong>test runner</strong>. Other JavaScript test runners include <strong>Enzyme</strong>, <strong>Jasmine</strong>, and more.</p><h4><strong>What are Assertions?</strong></h4><p>When writing tests, assertions are used to compare the actual value with the expected value. Jest provides a range of <strong>matchers</strong> for this purpose. These <strong>matchers</strong> allow us to validate different values using different comparison techniques and modifiers.</p><p>Here are several <strong>matchers’</strong> documents by JEST;</p><ul><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tobevalue">.toBe(value)</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tohavebeencalled">.toHaveBeenCalled()</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tohavebeencalledtimesnumber">.toHaveBeenCalledTimes(number)</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tohavebeencalledwitharg1-arg2-">.toHaveBeenCalledWith(arg1, arg2, …)</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tohavebeenlastcalledwitharg1-arg2-">.toHaveBeenLastCalledWith(arg1, arg2, …)</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tobeclosetonumber-numdigits">.toBeCloseTo(number, numDigits)</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tobedefined">.toBeDefined()</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tobefalsy">.toBeFalsy()</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tobegreaterthannumber">.toBeGreaterThan(number)</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tobegreaterthanorequalnumber">.toBeGreaterThanOrEqual(number)</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tobelessthannumber">.toBeLessThan(number)</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tobelessthanorequalnumber">.toBeLessThanOrEqual(number)</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tobeinstanceofclass">.toBeInstanceOf(Class)</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tobenull">.toBeNull()</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tobetruthy">.toBeTruthy()</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tobeundefined">.toBeUndefined()</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tocontainitem">.toContain(item)</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tocontainequalitem">.toContainEqual(item)</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#toequalvalue">.toEqual(value)</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tohavelengthnumber">.toHaveLength(number)</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tomatchregexporstring">.toMatch(regexpOrString)</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tomatchobjectobject">.toMatchObject(object)</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tomatchsnapshotoptionalstring">.toMatchSnapshot(optionalString)</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tothrowerror">.toThrow(error)</a></li><li><a href="https://jest-bot.github.io/jest/docs/expect.html#tothrowerrormatchingsnapshot">.toThrowErrorMatchingSnapshot()</a></li></ul><blockquote>React-Native initially relies on the react-test-renderer library, which is built upon Jest, for testing purposes. However, we have decided to utilize alternative packages instead of the react-test-renderer library for our testing needs. They are <strong>@testing-library/jest-native</strong> and<strong> @testing-library/react-native</strong></blockquote><h4>@testing-library/jest-native</h4><p>That library provides custom element matchers for jest. These matchers are;</p><ul><li><a href="https://github.com/testing-library/jest-native#tobedisabled">toBeDisabled</a></li><li><a href="https://github.com/testing-library/jest-native#tobedisabled">toBeEnabled</a></li><li><a href="https://github.com/testing-library/jest-native#tobeemptyelement">toBeEmptyElement</a></li><li><a href="https://github.com/testing-library/jest-native#tocontainelement">toContainElement</a></li><li><a href="https://github.com/testing-library/jest-native#tobeonthescreen">toBeOnTheScreen</a></li><li><a href="https://github.com/testing-library/jest-native#tohaveprop">toHaveProp</a></li><li><a href="https://github.com/testing-library/jest-native#tohavetextcontent">toHaveTextContent</a></li><li><a href="https://github.com/testing-library/jest-native#tohavestyle">toHaveStyle</a></li><li><a href="https://github.com/testing-library/jest-native#tobevisible">toBeVisible</a></li><li><a href="https://github.com/testing-library/jest-native#tohaveaccessibilitystate">toHaveAccessibilityState</a></li><li><a href="https://github.com/testing-library/jest-native#tohaveaccessibilityvalue">toHaveAccessibilityValue</a></li></ul><p>They provide enhanced testing capabilities specifically tailored for React Native elements.</p><h4>@testing-library/react-native</h4><p>Basically, this library provides rendering components and grap rendered elements more easily and elegant way than react-test-render.</p><pre>import { render, screen, fireEvent } from &#39;@testing-library/react-native&#39;;</pre><h4>Let’s start coding</h4><p>First, clone the app and install the dependencies</p><p>git clone git@github.com:abdullahsuhaisk/robustReactNative.git</p><p>npm install (install node_modules dependencies)</p><p>npx pod-install (install iOS dependencies)</p><p>If everything succeeds, you will be able to run iOS and android</p><p>npm run ios</p><p>If you see the onboarding screen, everything is working as expected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HE4MhERnwXxABEfPttElsQ.png" /></figure><p>Let’s run npm run test</p><p>If you encounter an error, don’t worry. Jest found our test files in the __test__ folder and executed them. Let&#39;s remove the /root/__test__ folder as we won&#39;t be needing it.</p><h4><strong>Adding Test Library</strong></h4><p>npm install @testing-library/jest-native @testing-library/react-native --save-dev</p><p>After adding the dependencies, we need to make some configurations. Update your package.json file as follows:</p><pre>{<br>  &quot;name&quot;: &quot;buildingRobustReactNativeApp&quot;,<br>  &quot;version&quot;: &quot;0.0.1&quot;,<br>  &quot;private&quot;: true,<br>  &quot;scripts&quot;: {<br>    &quot;android&quot;: &quot;react-native run-android&quot;,<br>    &quot;ios&quot;: &quot;react-native run-ios&quot;,<br>    &quot;lint&quot;: &quot;eslint .&quot;,<br>    &quot;start&quot;: &quot;react-native start&quot;,<br>    &quot;test&quot;: &quot;jest&quot;<br>  },<br>  &quot;dependencies&quot;: {<br>    &quot;@react-native-community/checkbox&quot;: &quot;^0.5.15&quot;,<br>    &quot;@react-navigation/bottom-tabs&quot;: &quot;^6.5.7&quot;,<br>    &quot;@react-navigation/native&quot;: &quot;^6.1.6&quot;,<br>    &quot;@react-navigation/native-stack&quot;: &quot;^6.9.12&quot;,<br>    &quot;@redux-devtools/extension&quot;: &quot;^3.2.5&quot;,<br>    &quot;axios&quot;: &quot;^1.4.0&quot;,<br>    &quot;react&quot;: &quot;18.2.0&quot;,<br>    &quot;react-native&quot;: &quot;0.71.11&quot;,<br>    &quot;react-native-safe-area-context&quot;: &quot;^4.6.3&quot;,<br>    &quot;react-native-screens&quot;: &quot;^3.21.1&quot;,<br>    &quot;react-native-svg&quot;: &quot;^13.9.0&quot;,<br>    &quot;react-native-svg-transformer&quot;: &quot;^1.0.0&quot;,<br>    &quot;react-redux&quot;: &quot;^8.1.0&quot;,<br>    &quot;redux&quot;: &quot;^4.2.1&quot;,<br>    &quot;redux-logger&quot;: &quot;^3.0.6&quot;,<br>    &quot;redux-saga&quot;: &quot;^1.2.3&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;@babel/core&quot;: &quot;^7.20.0&quot;,<br>    &quot;@babel/preset-env&quot;: &quot;^7.20.0&quot;,<br>    &quot;@babel/runtime&quot;: &quot;^7.20.0&quot;,<br>    &quot;@react-native-community/eslint-config&quot;: &quot;^3.2.0&quot;,<br>    &quot;@testing-library/jest-native&quot;: &quot;^5.4.2&quot;,<br>    &quot;@testing-library/react-native&quot;: &quot;^12.1.2&quot;,<br>    &quot;@tsconfig/react-native&quot;: &quot;^2.0.2&quot;,<br>    &quot;@types/jest&quot;: &quot;^29.2.1&quot;,<br>    &quot;@types/react&quot;: &quot;^18.0.24&quot;,<br>    &quot;@types/react-test-renderer&quot;: &quot;^18.0.0&quot;,<br>    &quot;@types/redux-logger&quot;: &quot;^3.0.9&quot;,<br>    &quot;babel-jest&quot;: &quot;^29.2.1&quot;,<br>    &quot;eslint&quot;: &quot;^8.19.0&quot;,<br>    &quot;jest&quot;: &quot;^29.2.1&quot;,<br>    &quot;metro-react-native-babel-preset&quot;: &quot;0.73.10&quot;,<br>    &quot;prettier&quot;: &quot;^2.4.1&quot;,<br>    &quot;react-test-renderer&quot;: &quot;18.2.0&quot;,<br>    &quot;typescript&quot;: &quot;4.8.4&quot;<br>  },<br>  &quot;jest&quot;: {<br>    &quot;preset&quot;: &quot;react-native&quot;<br>  }<br>}</pre><p>Remove the &quot;jest&quot; key from the package.json file and create a new file called jest.config.json in the root directory with the following content:</p><pre>{<br>    &quot;preset&quot;: &quot;react-native&quot;,<br>    &quot;setupFilesAfterEnv&quot;: [&quot;&lt;rootDir&gt;/src/tests/setup.ts&quot;],<br>    &quot;transformIgnorePatterns&quot;: [<br>      &quot;node_modules/(?!(jest-)?@?react-native|@react-native-community|@react-navigation)&quot;<br>    ]<br>  }</pre><p>Navigate to the src directory and create a tests folder inside it. Inside the tests folder, create a file named setup.ts. For now, you can add the following line at the top of the file to enable the extended expected functionality:</p><pre>import &#39;@testing-library/jest-native/extend-expect&#39;</pre><p>After we are going to add global mock functions into the setup.ts</p><p>Let’s check our new test environments work correctly.</p><p>Create a new file named jest-native.test.tsx under the src/tests. Because we want to check new matchers, and renderer work correctly.</p><pre>import * as React from &#39;react&#39;;<br>import { StyleSheet, View, Button, Text, TextInput } from &#39;react-native&#39;;<br>import { render } from &#39;@testing-library/react-native&#39;;<br><br>// import &#39;@testing-library/jest-native/extend-expect&#39;;<br><br>const style = StyleSheet.create({<br>  style1: {<br>    color: &#39;red&#39;,<br>    backgroundColor: &#39;green&#39;,<br>  },<br>});<br><br>test(&#39;jest-native matchers work correctly&#39;, () =&gt; {<br>  const { getByText, getByA11yHint } = render(<br>    &lt;View&gt;<br>      &lt;Button title=&quot;Enabled Button&quot; onPress={jest.fn()} /&gt;<br>      &lt;Button title=&quot;Disabled Button&quot; disabled={true} onPress={jest.fn()} /&gt;<br>      &lt;Text accessibilityHint=&quot;Empty Text&quot; style={style.style1} /&gt;<br>      &lt;Text accessibilityHint=&quot;Not Empty Text&quot;&gt;Not empty&lt;/Text&gt;<br>      &lt;View accessibilityHint=&quot;Empty View&quot; /&gt;<br>      &lt;View accessibilityHint=&quot;Not Empty View&quot;&gt;<br>        &lt;Text /&gt;<br>      &lt;/View&gt;<br>      &lt;View accessibilityHint=&quot;Container View&quot;&gt;<br>        &lt;View accessibilityHint=&quot;First-Level Child&quot;&gt;<br>          &lt;Text&gt;Second-Level Child&lt;/Text&gt;<br>        &lt;/View&gt;<br>      &lt;/View&gt;<br>      &lt;TextInput<br>        accessibilityHint=&quot;Text Input&quot;<br>        allowFontScaling={false}<br>        secureTextEntry={true}<br>        defaultValue=&quot;111&quot;<br>      /&gt;<br>    &lt;/View&gt;,<br>  );<br><br>  expect(getByText(&#39;Enabled Button&#39;)).toBeEnabled();<br>  expect(getByText(&#39;Disabled Button&#39;)).not.toBeEnabled();<br>  expect(getByText(&#39;Disabled Button&#39;)).toBeDisabled();<br>  expect(getByText(&#39;Enabled Button&#39;)).not.toBeDisabled();<br><br>  expect(getByA11yHint(&#39;Empty Text&#39;)).toBeEmptyElement();<br>  expect(getByA11yHint(&#39;Empty View&#39;)).toBeEmptyElement();<br>  expect(getByA11yHint(&#39;Not Empty Text&#39;)).not.toBeEmptyElement();<br>  expect(getByA11yHint(&#39;Not Empty View&#39;)).not.toBeEmptyElement();<br><br>  expect(getByA11yHint(&#39;Container View&#39;)).toContainElement(<br>    getByA11yHint(&#39;First-Level Child&#39;),<br>  );<br>  expect(getByA11yHint(&#39;Container View&#39;)).toContainElement(<br>    getByText(&#39;Second-Level Child&#39;),<br>  );<br>  expect(getByA11yHint(&#39;Container View&#39;)).not.toContainElement(<br>    getByText(&#39;Enabled Button&#39;),<br>  );<br><br>  expect(getByA11yHint(&#39;Not Empty Text&#39;)).toHaveTextContent(&#39;Not empty&#39;);<br>  expect(getByA11yHint(&#39;Not Empty Text&#39;)).toHaveTextContent(/Not empty/);<br>  expect(getByA11yHint(&#39;Not Empty Text&#39;)).not.toHaveTextContent(&#39;Is empty&#39;);<br><br>  expect(getByA11yHint(&#39;Empty Text&#39;)).toHaveStyle({ color: &#39;red&#39; });<br>  expect(getByA11yHint(&#39;Empty Text&#39;)).toHaveStyle({<br>    color: &#39;red&#39;,<br>    backgroundColor: &#39;green&#39;,<br>  });<br>  expect(getByA11yHint(&#39;Empty Text&#39;)).not.toHaveStyle({ color: &#39;green&#39; });<br>  expect(getByA11yHint(&#39;Empty Text&#39;)).not.toHaveStyle({<br>    color: &#39;green&#39;,<br>    backgroundColor: &#39;green&#39;,<br>  });<br><br>  const textInput = getByA11yHint(&#39;Text Input&#39;);<br>  expect(textInput).toBeTruthy();<br>  expect(textInput).toHaveProp(&#39;allowFontScaling&#39;);<br>  expect(textInput).toHaveProp(&#39;allowFontScaling&#39;, false);<br>  expect(textInput).toHaveProp(&#39;secureTextEntry&#39;);<br>  expect(textInput).toHaveProp(&#39;secureTextEntry&#39;, true);<br>  expect(textInput).toHaveProp(&#39;defaultValue&#39;);<br>  expect(textInput).toHaveProp(&#39;defaultValue&#39;, &#39;111&#39;);<br>});</pre><p>Then run npm run test</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*4W6ZoMnyucWfSOWEJTLCHQ.png" /></figure><p>Voilà, everything works correctly.</p><p>If you are stuck, you can get help at <a href="https://github.com/abdullahsuhaisk/robustReactNativeApp/commit/d30dcf4b88f71a6629f92c9d3740faa7183f8059">https://github.com/abdullahsuhaisk/robustReactNativeApp/commit/d30dcf4b88f71a6629f92c9d3740faa7183f8059</a> and unitTest branch is related unit Test, also you can inspect that.</p><h4>Code Coverage</h4><p>Coverage is defined asthe reporting of a particular important event or subject on Cambridge Dictionary.</p><p>Coverage helps me to visualise what did I tested, what should I test.</p><p>npm test -- --coverage</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5TT1JQeWG3Rfx1VnVgNHIA.png" /></figure><p>It only worked on one test file. We need to introduce our components to coverage actions.</p><p>npm run test -- --coverage --watchAll --collectCoverageFrom=&#39;src/components/**/*{ts,tsx}&#39;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3xtpyz6BwIGi349hlkYmqA.png" /></figure><p>We introduced which folder it should cover. It generates a folder in root, that calls coverage.</p><p>Most time Uncovered Line will help you to target what didn’t I test.</p><p>Open coverage/Icov-report/index.html</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PcCyRrLRxBzXRgdsB2YDAg.png" /></figure><p>The coverage command also creates reports HTML page through jest. Add coverage command into packages JSON.</p><pre> &quot;scripts&quot;: {<br>    &quot;android&quot;: &quot;react-native run-android&quot;,<br>    &quot;ios&quot;: &quot;react-native run-ios&quot;,<br>    &quot;lint&quot;: &quot;eslint .&quot;,<br>    &quot;start&quot;: &quot;react-native start&quot;,<br>    &quot;test&quot;: &quot;jest&quot;,<br>    &quot;debug&quot;: &quot;open &#39;rndebugger://set-debugger-loc?host=localhost&amp;port=8081&#39;&quot;,<br>    &quot;coverage&quot;: &quot;npm run test -- --coverage --watchAll --collectCoverageFrom=&#39;src/components/**/*.{ts,tsx}&#39; --collectCoverageFrom=&#39;!src/**/*.{types, stories, constants, test, spec}.{ts,tsx}&#39;&quot;<br>  },</pre><p>Now you can only run npm run coverage</p><p><em>Next article, I am going to write each component&#39;s unit test.</em></p><p>For more detail<a href="https://www.npmjs.com/package/@testing-library/react-native"><br>https://www.npmjs.com/package/@testing-library/react-native</a><br><a href="https://testing-library.com/docs/ecosystem-jest-native/">https://testing-library.com/docs/ecosystem-jest-native/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9610ed94ac71" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular JS Parent-Child Controller Communication and Best Practice for usage]]></title>
            <link>https://medium.com/orion-innovation-techclub/angular-js-parent-child-controller-communication-and-best-practice-for-usage-29b7bf0d0643?source=rss-54570134045d------2</link>
            <guid isPermaLink="false">https://medium.com/p/29b7bf0d0643</guid>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[techclub-tr]]></category>
            <dc:creator><![CDATA[Abdullah Süha ışık]]></dc:creator>
            <pubDate>Fri, 21 Jan 2022 06:42:13 GMT</pubDate>
            <atom:updated>2022-01-21T06:42:13.675Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/768/0*vgXY2EzwZuq2n3yi.png" /></figure><p>In this article, we will talk about parent-child controller relations in <strong>AngularJS</strong>. So you should be familiar with it. We are just focusing on a specific topic, on the <strong>first version of AngularJS(1.3.16)</strong> before <strong>Google </strong>implemented a new version(<strong>Angular 2+</strong>).<br>Dividing your controller in the little pieces has a lot of <strong>benefits</strong>. Especially, when your controller is too expanded and managing becomes hard. But the passing of data from parent to child or vice versa can be trouble when they both render the same $scope variable in their own HTML.</p><p>Using the parent and child controller approach or regular approach (more service) depends on your choice. I support both of them. I am here as a benefit to <strong>prevent/avoid</strong> issues and to <strong>identify</strong> how it has assisted you. If you follow the article, you will discover the parent and child controller approach at which scenario that we used.</p><p>In our scenario, we have different login pages for different customers into the same app which works for multiple customers, through the config. We didn’t divide it into login controllers before, because of just HTML appearance difference and little logic difference. Some new <strong>requests</strong> pushed us to divide our login controller into the 2 children components and parent login controller. Indeed, we had 3 login controllers, (loginController.js, aCompanyLoginController.js, and otherCompaniesLoginController.js)</p><p>At this point, I want to talk about best practices and our use case for parent-child controller communication in <strong>AngularJS</strong>. We kept common things on<em>loginController</em>, translate data, error logic, loading spinner, some<em>$scope</em> variable (if they are going to use both of controllers), etc. <em>aCompanyController</em> had to be very different from the past because new request requirements are different but <em>otherCompaniesLoginController</em> can use old codes.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F11h471O9Q1baKY%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fstickers%2Ferror-11h471O9Q1baKY&amp;image=https%3A%2F%2Fmedia4.giphy.com%2Fmedia%2F11h471O9Q1baKY%2F200.gif%3Fcid%3D790b7611fcdedd1faddfc8fcae3f64e57e267e94cd572381%26rid%3D200.gif%26ct%3Ds&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a21635d45e484b2027e6ecae79c0dc8/href">https://medium.com/media/7a21635d45e484b2027e6ecae79c0dc8/href</a></iframe><p>The error logic would be an issue. Because it is common, so we defined in the parent controller, and all controllers will use it in their own special login method. The errorLogic can be updated to parent and child controllers, if they update directly on <em>$scope.error</em> value, an issue occurs. AngularJS creates a new <em>$scope.error </em>value for every controller. We defined <em>$scope.error</em> on the parent controller, we can access it on the child controller through <em>$scope.error</em>. When we update `$scope.error` on child controller, that creates a new one, and the child controller’s HTML uses it. Indeed, AngularJS starts confused because <em>$scope.error</em> shows several references. We should prevent directly updating common parent <em>$scope .</em></p><p>After some research on Google, there were numerous suggestions that have been made with `$emit `. That was not very cool, and we’ve needed more basic and logical things, and they just focused on one-way communication.(We need two-way communication) Our solution is, when you need to update `$scope` variable, you do it with the encapsulated set method, and it is defined on the parent controller. Any controller can’t directly set <em>$scope</em> variable. They should use the same encapsulated set method, and every HTML content should use the same <em>$scope</em> variable that has the same reference.</p><p>I think above is enough for theory, so let me show you a code. I know that was a boring part :)</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F26tn33aiTi1jkl6H6%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fscreen-monitor-closeup-26tn33aiTi1jkl6H6&amp;image=https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExYWJibWplbzdyaXg3dDY1bWhwN2EzcGZ1OXNlZTJ6ZG84bzJqNmM4ZyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2F26tn33aiTi1jkl6H6%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/efc66ae16a0424fe51283afd60b88947/href">https://medium.com/media/efc66ae16a0424fe51283afd60b88947/href</a></iframe><p>Define all common things on loginController.js and start some initial processes if you require them. In our case, we need to fetch translation files.</p><p>In the Below code snippets, I will not show all code, just important pieces, so focus on error and spinner logic because these values need to handle. Logics are the same, but two examples are better than one. They can be updated in both controllers and aCompanyController needs to process again for more special things.</p><p>Parent loginController.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4916f7ac81890e9c520057947fc72a3b/href">https://medium.com/media/4916f7ac81890e9c520057947fc72a3b/href</a></iframe><p>I created the <em>$setLoadingIcon</em> method on the parent controller. Because my child controllers want to update the same <em>$scope.showLoadingIcon</em>, and they will render on HTML. My main purpose is to handle <em>$scope.showLoadingIcon</em> in a function, guarantee to use the same reference when updating everywhere. Considering this, we will prevent the same variable from creating double references. All controllers are going to use the same <em>$scope.showLoadingIcon.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e83ce88c81fecf72a3969905063af98/href">https://medium.com/media/8e83ce88c81fecf72a3969905063af98/href</a></iframe><p>loginErrorHandler function uses <strong>setLoadingIcon </strong>to update <strong>$scope.showLoadingIcon </strong>in parent controller.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce7ce2f35fa8ab752d9e5cce572ddc9c/href">https://medium.com/media/ce7ce2f35fa8ab752d9e5cce572ddc9c/href</a></iframe><p>Child-controller uses parent’s <em>setLoadingIcon</em>methods, and it updates parent’s <em>$scope.showLoadingIcon</em> through parent-controller’s method. In this way, they both use the same <em>$scope.showLoadingIcon .</em></p><p>We don’t need any specific getter(get method) for this. We can directly access <strong>$scope.showLoadingIcon</strong> on controller and HTML</p><p>Consequently, If you need to handle the common <em>$scope</em> variable both of parent and child controller, wrap it a function. It’s like a kinda <strong>setter</strong> method on the parent controller. My last word is “ <em>Use Redux guys</em> “ :) I just tried to keep my app’s state well.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29b7bf0d0643" width="1" height="1" alt=""><hr><p><a href="https://medium.com/orion-innovation-techclub/angular-js-parent-child-controller-communication-and-best-practice-for-usage-29b7bf0d0643">Angular JS Parent-Child Controller Communication and Best Practice for usage</a> was originally published in <a href="https://medium.com/orion-innovation-techclub">Orion Innovation techClub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My first meeting Swift-UI as a FrontEnd Developer]]></title>
            <link>https://abdullahsuhaisik.medium.com/my-first-meeting-swift-ui-as-a-frontend-developer-ae9a349e9223?source=rss-54570134045d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae9a349e9223</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[react-swift-comp]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Abdullah Süha ışık]]></dc:creator>
            <pubDate>Sat, 23 Jan 2021 15:14:14 GMT</pubDate>
            <atom:updated>2021-09-14T18:11:37.548Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>My first meeting Swift-UI as a FrontEnd Developer.</strong><br>Today I’m gonna write about SwiftUI and talk about my first app developed by Swift UI.</p><p>I am trying to move to mobile development with Swift from a front-end developer. If you don’t know me, I am a front-end developer, developing communication apps with Web RTC, Angular js, and Cordova in a Turkish communication company.</p><p>I am going to compare Swift with React Js. For this blog, React knowledge good for you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Veu1v90NGKHUlKaYG_ODBA.png" /><figcaption>The application “Business Card”</figcaption></figure><p>We are going to make a business card app step by step and discuss by comparing the React component structure and the new Swift UI.<br>For my first impression about Swift UI, I really like it and it is easier than the Storyboard. Developing with StoryBoard was really hard for me. I used to CSS. The storyboard was complicated for me. Some property just changing with code some of other with pannel. That was hard.<br>But Swift UI is like an Atomic design which is made with Components.</p><p>Before than start the application, I need to say I’m a newbie on Swift.<br>Let’s create a business app.</p><figure><img alt="Select Single View App" src="https://cdn-images-1.medium.com/max/1024/1*cHUIFIMmm7J8Hb3OzD6B_g.png" /><figcaption>Select Single View App</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fqV1_jcFFOgPlSET-w_PUQ.png" /><figcaption>Give a name of your project and chose the location after this step press the create button</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5D_Vr08YVUydfF3eZZDLnA.png" /></figure><p>I think it is a wonderful feature that comes with Swift UI because the screen is dynamic when you change something the screen will update, awesome.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fl2Sqir5ZxfoS27EvS%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fl2Sqir5ZxfoS27EvS%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fl2Sqir5ZxfoS27EvS%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a24c4a85ab77a12f3424facaea82b18/href">https://medium.com/media/9a24c4a85ab77a12f3424facaea82b18/href</a></iframe><p>Delete the Text(“Hello, World!”). We need to set the background color. It’s really easy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ip_vXxvtTeO3vwLT0bnvyw.png" /><figcaption>Press Right Top Corner Plus Button</figcaption></figure><p>When you click the right corner plus button you will see a bunch of Control Views which is like Component in React or React Native. If I confused about it please guess about it, I can mix Component and Control Views. Typing color and drag and drop on the editor inside the <br><strong>var</strong> body: <strong>some</strong> View {</p><p>}</p><p>For the color pick, I prefer this web site <a href="https://flatuicolors.com/">https://flatuicolors.com/</a> but we can’t use given hex code in Swift. (like #2ecc71 ) For the converting, you can use <a href="https://www.uicolor.io/">https://www.uicolor.io/</a><br>Color Control View needs parameter. Mine is <strong>UIColor(red: 0.09, green: 0.63, blue: 0.52, alpha: 1.00). </strong>When you applied the above steps you should see the Safe area. <strong>.edgesIgnoringSafeArea(.all) </strong>This code snippet will ignore safe area. And this point like React component’s props. If Color View Controller would be React component it’s like <br><strong>&lt;Color&gt; &lt;/Color&gt;</strong> High Order Component and if I want to ignore Safe Area probably I neet to send props like<br><strong>&lt;Color edgesIgnoringSafeArea={true}&gt; &lt;/Color&gt;</strong></p><p>In Swift UI we are adding modifiers for this, there is more way. I think modifiers like React Components Props. I am thinking like there are a lot of components developed by Apple and Swift UI uses these components with modifiers and these modifiers like props.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wfA2p7-O2nCGrQDBiPxghQ.png" /><figcaption>Select Edges Ignoring Safe are drag to the next to do Color and drop it</figcaption></figure><p>My background Color is done, Now I need to add İmage. Again going to the right corner plus and type Image. Uppss , there was a problem, I can’t add the Image component without any Stack view.<br>We need to use <strong>ZStack, VStack, or HStack </strong>in the parent when we want to add multiple elements in one body.</p><p>ZStack means, This parent view stacks can make the child views on top of each other. Hence it creates overlapping content.</p><p>For the image adding, first, you need to add an image into your <strong>Assets.xcassets </strong>folder. After that, you can call directly with its name.</p><blockquote>ZStack {</blockquote><blockquote>Color(UIColor(red: 0.09, green: 0.63, blue: 0.52, alpha: 1.00)).edgesIgnoringSafeArea(.all/)</blockquote><blockquote>Image(“myImageName”)</blockquote><blockquote>}</blockquote><p>We need to add some modifiers to our image, you can find these things in the right corner plus the button in the modifiers tab, or If you know these modifiers you can directly write.</p><p>First <strong>resizable()</strong>, Second <strong>.aspectRatio(contentMode: .fit)</strong>, Third one is <strong>clipShape(Circle())</strong> it’s like <strong>borderRadius(%50), </strong>fourth<strong> </strong>.<strong>frame(width:150, height:150) </strong>and last one is<strong> .overlay(Circle().stroke(Color.white,lineWidth: 5)) </strong>it’s like padding in web.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7h2y70aIltYOYl2Nr6o6mQ.png" /><figcaption>Description will be here</figcaption></figure><p>Now I am going to add a new component <strong>InfoView.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*ZhBqJuCRKUoaUjjrL7Nk-Q.png" /><figcaption>InfoView in Swift, InfoComponent in React.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*3-xluhcllVwLaaa8IQ-xzg.png" /><figcaption>These all view (components) should be in VStack</figcaption></figure><p>Before creating InfoView, create Vertical Stack and add Image inside it.</p><p>The easiest way select all about Image and click command and left-click choose the <strong>Embed in VStack.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3X6LLrbUXBbvcVaX5BrdXQ.png" /></figure><p>I am going to add my name and my title section before the infoView. For this, add Text(“My Name”) modifiers are<strong>.font</strong>, <strong>.bold</strong>, and .<strong>foregroundColor.</strong></p><p>InfoView needs RoundedRectangle. It takes cornerRadios parameter, this parameter likes borderRadious in Web and we should set the frame again. For color .forgroundColor, for putting something inside rectangle we need to use .overlay and two item should in overlay into HStack because we need horizantel aligment.For the margin we can use .padding(.all) there is weird I know We have to use margin but their a sticky difference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wWlDl995uDNBVvDaxsnS5w.png" /><figcaption>Info view is done</figcaption></figure><p>I need one more InfoView, for this coming swift UI beautify. If I want to create another of this view, I don’t have to retype all of these codes or copy-paste. Just I need to select code which is I want to reuse, command-click, and select Extract Subview.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0PYV_qbtvxe4uX7Bl0eY-g.png" /><figcaption>Extract Subview</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ubJ2xsuxsLywqwWb3T_eBg.png" /><figcaption>Created new View(Component)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Me1GOiecnm2om6y76X8WNg.png" /><figcaption>Reusable components</figcaption></figure><p>Now my reusable components need props in React language, so I can use everywhere what I want to use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zY-2nKkYmrI1dku20thCBQ.png" /><figcaption>New Reusable View Ready</figcaption></figure><p>As you can see I added some properties to my new struct InfoView.</p><p>Indeed, If I want to move my new struct to a new file. Right, Click to the app folder and select New File after that step, select SwiftUI View.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*78Z0bz2-R7RylZRa3LSIuQ.png" /><figcaption>New view</figcaption></figure><p>We are done thanks for reading.</p><p><a href="https://media.giphy.com/media/26u4lOMA8JKSnL9Uk/giphy.gif">https://media.giphy.com/media/26u4lOMA8JKSnL9Uk/giphy.gif</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae9a349e9223" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build your own personal web site]]></title>
            <link>https://abdullahsuhaisik.medium.com/build-your-own-personal-web-site-8fe91fcddf7a?source=rss-54570134045d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8fe91fcddf7a</guid>
            <category><![CDATA[material-ui]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Abdullah Süha ışık]]></dc:creator>
            <pubDate>Sun, 13 Dec 2020 12:52:07 GMT</pubDate>
            <atom:updated>2020-12-13T12:52:07.464Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello, firstly I need to say, it’s my first English blog post so before the start sorry for this.</p><p>I decided to make my own personnel web site. I think it should be more professional for me. And these days I haven’t any alive project. My all project came from my employer so sometimes I learn something and I want to implement somewhere and there is no resource for this and I am moving to mobile development which is Ios. Therefore I need to learn some last things which are Material UI and making something my self with out design. Indeed, my first goal of making a personal website and add some technological things in the future. For example, I will add my own online code editor to my website, and the pdf generator quite excited for me. In this series, I am going to write about React, Material Uı, share my experience and source which is I thought is helpful. For these series, you need knowledge about React.</p><p>Let me introduce myself a little bit, I am 3 years old front-end developer after university I started my career with react-native, I need to develop a CRM app for the middle company. It was a one-time job and after this, I’ve met React and I started my first real full-time job in Bursa at a small startup, I’ve worked for one year at this company. I developed an Interactive video-player with React, VideoJs, Grapql, and styled-component. That was a great experience for me because of these things pretty new techs. After then, I started to Netaş and moved to Istanbul. Now I am part of a huge team and we’re developing a communication app for a big enterprise business. That was quite interesting for me because our tech stack is Web-Rtc, web socket, angularJs(it’s bloody old ), and Cordova.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fb2oMd0AKFQQlAzRVTM%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fb2oMd0AKFQQlAzRVTM%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fb2oMd0AKFQQlAzRVTM%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/7864a40025d0b732e7fd030230556492/href">https://medium.com/media/7864a40025d0b732e7fd030230556492/href</a></iframe><p>Anyways, that information is enough :)</p><p>Let’s back the personal web site.</p><p>Firstly, I started with Jira. Because I already started a lot of interested and super project but I couldn’t continue and finish. I think I have not planned this a reason why I couldn’t finish my project. My Jira has a just simple Kanban board. But I will use it effectively, and I will learn how can I program myself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zc-7JsbRWzuR_kG4txsMCA.png" /></figure><p>It’s just simple. When I have a new idea I will add it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nteBM9dNAJ3qS00WAdtoKw.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FPbFp1FmxteXsc%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FPbFp1FmxteXsc%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FPbFp1FmxteXsc%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="773" frameborder="0" scrolling="no"><a href="https://medium.com/media/51740a5065cbc1f67e1f5bf7ff1bad85/href">https://medium.com/media/51740a5065cbc1f67e1f5bf7ff1bad85/href</a></iframe><p>My other Todo was got Material Course because I haven’t any experience with Material UI. For the first impression, it is awesome and every javascript developer should know one CSS Framework.<br>For learning Material Uı, I don’t like long tutorial series and also I hate long documents. My way is simple, just watch the shortest video about the topic and continue with documents, but I find a very helpful series I am going to share both of them.<br>I&#39;ve watched this video<br> <a href="https://www.youtube.com/watch?v=DJ1_CKs_LPI&amp;ab_channel=JasonRivera">https://www.youtube.com/watch?v=DJ1_CKs_LPI&amp;ab_channel=JasonRivera</a><br>other <br><a href="https://www.youtube.com/watch?v=pHclLuRolzE&amp;list=PLQg6GaokU5CwiVmsZ0d_9Zsg_DnIP_xwr&amp;ab_channel=AnthonySistilli">https://www.youtube.com/watch?v=pHclLuRolzE&amp;list=PLQg6GaokU5CwiVmsZ0d_9Zsg_DnIP_xwr&amp;ab_channel=AnthonySistilli</a></p><p><a href="https://material-ui.com/getting-started/installation/">https://material-ui.com/getting-started/installation/</a></p><p>Let&#39;s start<br>npx create-react-app mypersonelapp</p><p>cd mypersonelapp</p><p>npm install @material-ui/core</p><p>npm install @material-ui/icons</p><h4>Theming</h4><p><a href="https://material-ui.com/customization/theming/">https://material-ui.com/customization/theming/</a></p><p>It looks like a high-order component, we need to wrap our app which is we would be created the Themening component. I am creating a utils folder and I was adding it inside.</p><p>For now, I am just creating a simple theme property.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9bad42a4e1ae04ce8e80bd3e88c1684a/href">https://medium.com/media/9bad42a4e1ae04ce8e80bd3e88c1684a/href</a></iframe><p>Don’t forget to “export default theme” now we will add ThemeProvider with this theme property to “index.js”</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00b7ab479693fa46a6c83efb44f14b6b/href">https://medium.com/media/00b7ab479693fa46a6c83efb44f14b6b/href</a></iframe><p>I wrapped the App component in the index component so every component will be rendered inside ThemeProvider.</p><p>Now let’s create the Appbar component.<br>You can follow this <a href="https://material-ui.com/api/app-bar/">https://material-ui.com/api/app-bar/</a></p><p>I added a new folder as Components and adding AppBar inside it. I just copied on the material document, I will specifical it, I wanna dived 2 section my appbar, the first side will be about routing and the right side will be about my social media account so right side be icons place.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a696a019780505dc0c9f19fa9f865779/href">https://medium.com/media/a696a019780505dc0c9f19fa9f865779/href</a></iframe><p>I calling my new component on AppJs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7ca943065b773ea387a04481a984505/href">https://medium.com/media/f7ca943065b773ea387a04481a984505/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*raTgnENnfUDLvSltebrfKA.png" /><figcaption>My appbar</figcaption></figure><blockquote>Let’s customize my appbar. For the right side, I just added below codes. Left side need some job. I’ve opened own job on my kanban board.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b-sgdH0HSBS3VK3DT4lZXg.png" /><figcaption>I thought you, I have to work regular, so everything needs to be on board because after some time I forget</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cVP-kwv65Qexe_b3vyIcUg.png" /><figcaption>Topbar</figcaption></figure><blockquote>import LinkedInIcon from &#39;@material-ui/icons/LinkedIn&#39;;<br> &lt;IconButton aria-label=”show 4 new mails” color=”inherit” href=”link&quot;&gt;</blockquote><blockquote>&lt;LinkedInIcon /&gt;</blockquote><blockquote>&lt;/IconButton&gt;</blockquote><p>I think it’s enough for now. Next episode I am going to make the left side which has a router with my pages and has a little state management on the parent state.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8fe91fcddf7a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Higher-Order Components]]></title>
            <link>https://abdullahsuhaisik.medium.com/higher-order-components-d68a22f5f39?source=rss-54570134045d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d68a22f5f39</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[high-order-component]]></category>
            <category><![CDATA[react-hook]]></category>
            <dc:creator><![CDATA[Abdullah Süha ışık]]></dc:creator>
            <pubDate>Sun, 08 Sep 2019 23:12:58 GMT</pubDate>
            <atom:updated>2019-09-08T23:12:58.133Z</atom:updated>
            <content:encoded><![CDATA[<p>Nedir Bu HighOrder Component ?<br>Bir komposizyonu türetilen diğer componentler dede kullanmak. Polimorfizm ‘e oldjukça benzeri bir yapı aslında bu , aynı zamanda da bir pattern olarak da geçiyor. Şimdi şöyle birden fazla yerde aynı stateleri kullanmamız gerekiyor. Ama şöyle bir fark var , her aynı durumu her bir componentin kendi stateti gibi görmesi gerekiyor. Burada parent componentin child componentlere state göndermesinden farklı bir kullanım var. Parent component gönderdiği stateler diğer componentlerin propsu olur. Bu state de bir işlem yaptığında aslında propsunda yani parent componentin statetine işlem yapmış olur.Uygun bir örnek olarak;</p><blockquote>const [counter,setCounter]= React.useState(0)</blockquote><p>Yukarıda ki Statemiz olduğunu düşünün parent componentden child componentime gönderdiğimde , child componentte setCounter yaparsam parent componentimin state ti olan counter güncellenir. Ve parent componentim tekrardan render edilir.</p><p>Peki nasıl Hoc kullanacağız ? İki tane count işlemi yapan componentim olduğunu düşünelim, bu componentleri görevi sadece sayaclarını artırmak. Bu sayaç işlemleri aslında ortaktır. Burada hoc yaklaşımını kullanabilirim.</p><p>Hoc yakalaşım kullanmadan ;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d553fbaa1d8100050c64bb6171cbb3f/href">https://medium.com/media/8d553fbaa1d8100050c64bb6171cbb3f/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/09a85205853b618e6f42b39007e1f901/href">https://medium.com/media/09a85205853b618e6f42b39007e1f901/href</a></iframe><p>Görüldüğü gibi her iki componentde aynı işleri yapıyor. Dolayısı ile bunları counter componenti yapıp sarmalayabiliriz.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/771c3f8d3cdc59f38f4c875e202ae1e2/href">https://medium.com/media/771c3f8d3cdc59f38f4c875e202ae1e2/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19665722bfe7257f0a875dd35c19b186/href">https://medium.com/media/19665722bfe7257f0a875dd35c19b186/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd7b56c8dc5ac6d5313d2bff6d95e349/href">https://medium.com/media/fd7b56c8dc5ac6d5313d2bff6d95e349/href</a></iframe><p>Bu high ordered component , aslında parametre olarak fonksiyon alan bir fonksiyondan başkabirşey değil. Parametre olarak fonksiyon alır ve bu fonksiyona kendi iç statelerini set eder. Aynı zamanda componentin çağrıldığı yerde props atanmış isede bu propslar …props olarak iletir.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ddc12d2838c5f88e0661e2392db01e8/href">https://medium.com/media/2ddc12d2838c5f88e0661e2392db01e8/href</a></iframe><p>name propertisini …props sayesinde iletebildim. High order componentin nerede kullanılacağı aslında tamamen sizde. Bir yerde codun bir kaç kez tekrar ettiğini hissediyorsanız kullanabilirsiniz.</p><p>Yukarıdaki kodların çalışan adresi : <a href="https://codesandbox.io/s/highordercomponent-2zj6z">https://codesandbox.io/s/highordercomponent-2zj6z</a></p><p>Bir sonraki Hoc yazımda apollo client den gelen Query componentini özelleştirmeyi düşünüyorum. Query zaten hoc derseniz, Her seferinde loading ve error durumları olan bir component diyebilirim.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d68a22f5f39" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hoc yaklaşım {children} Elemetin e Props Göndermek]]></title>
            <link>https://abdullahsuhaisik.medium.com/hoc-yakla%C5%9F%C4%B1m-children-elemetin-e-props-g%C3%B6ndermek-d0886b1392b2?source=rss-54570134045d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0886b1392b2</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Abdullah Süha ışık]]></dc:creator>
            <pubDate>Fri, 30 Aug 2019 17:54:23 GMT</pubDate>
            <atom:updated>2019-08-30T17:54:23.270Z</atom:updated>
            <content:encoded><![CDATA[<h3>Sorun ?</h3><p>Bir hoc yazdığımızı düşünelim basit bir hoc mesela layout gibi. Arka plan rengini render ettiği çocuklarına ilettiğini düşünelim. Peki props da iletmek istersek bu işlem nasıl olmalı ? Bu komposizyonda baba componentimiz çocuklarını bilemez ve tanımaz. Dolayısı ile props da gönderemeyiz. Ama göndermemiz lazım. Şimdi adım adım sorunu inceleyelim.Ardından <strong>reactClone </strong>element ile sorunumuzu çözelim.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0599b56e174d037cae993b32caec45a/href">https://medium.com/media/e0599b56e174d037cae993b32caec45a/href</a></iframe><p>Çokça basit bir layout wrapper i olarak bunu düşünün. Arka planı mavi yapıp içine gelecek componentleri ortalayan bir hoc component yaptık. Mesela isteklerimizden birisi hoc içindeki componente (child) method tanımlayıp parent componentimin rengini değiştirmek istediğimi var sayalım.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f79d681245a3297ef26da227b6d6c7c/href">https://medium.com/media/8f79d681245a3297ef26da227b6d6c7c/href</a></iframe><blockquote>&lt;props.children setColor={setColor}&gt; {children} &lt;/props.children&gt;</blockquote><p>return’nun içindeki yapı tamamiyle yanlış.Bize böyle bir yapı lazım sadece. Burada kurtarıcımız. React.cloneElement gelecek. Şimdi şöyleki ;</p><blockquote>React.cloneElement(<br> element,<br> [props],<br> […children]<br>)</blockquote><p>İlk parametre olarak component alıyor. Diğer parametre ise obje olarak propslarım, bir state yada method olabilir.</p><p>Hoc componentimde bütün çocuklarında render edilebilmesi için React.Children.map methodunu kullanacağım. Buradaki map Javascript map ı değil. React Children dan gelen map;İçine component objesi alıyor ve onu dönüyor. Uzun lafın kısası ;</p><blockquote>const children = React.Children.map(props.children, (child, index) =&gt; {</blockquote><blockquote>return React.cloneElement(child, {</blockquote><blockquote>index,</blockquote><blockquote>setColor</blockquote><blockquote>});</blockquote><blockquote>});</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a94137dc10a1426d662619d13e34c041/href">https://medium.com/media/a94137dc10a1426d662619d13e34c041/href</a></iframe><p>Layout umun son versiyonu içinde bazı data bilgilerinide adını bilmediğim çocuk componentime göndere biliyorum.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64e595eef0b9d571539a14e9ad6f5db1/href">https://medium.com/media/64e595eef0b9d571539a14e9ad6f5db1/href</a></iframe><p>Peki gerçek bir projede bu ihtiyac nerden çıktı ? Şimdi şöyle ki daha önceki yazılarımı okuyanlar bilir. Interaktif bir video player geliştiriyorum ve bu video player componentlerini Json ile dışarıdan alıyor. Aslında componentlerim içeride tanımlı, yanlızca hangi componentlerin render edileceği hangilerinin render edilmeyeceğine akış şekline Jsondan gelen veri karar veriyor. İhticımız video playerin alt tarafında kalan controlbardan geldi, her bir müşteri control barını özelliştirebilir. Controlbar daki bu componentlerin grapql ile client tarafta ilişki kurması gerekiyor, Çünkü tetiklemeleri var. Aslında bu bundan dolayı gelişti. Client object ini child ları bilmeden iletebilmem gerekiyordu. En altaki yazıda olayın çıkış noktası, ben sadece kendi yaklaşımı yazmış ve biraz Türkçeleştirmiş oldum. Teşekkürler…</p><p>Çalışan örnek : <a href="https://codesandbox.io/s/restless-fog-r715j">https://codesandbox.io/s/restless-fog-r715j</a></p><p>GitHub: <a href="https://github.com/abdullahsuhaisk">https://github.com/abdullahsuhaisk</a></p><blockquote><a href="https://codepen.io/Yuschick/post/react-passing-state-to-props-children-in-jsx">https://codepen.io/Yuschick/post/react-passing-state-to-props-children-in-jsx</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0886b1392b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Widget Renderer 3 (CustomHook)]]></title>
            <link>https://abdullahsuhaisik.medium.com/react-widget-renderer-3-customhook-9c853c8809f4?source=rss-54570134045d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c853c8809f4</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Abdullah Süha ışık]]></dc:creator>
            <pubDate>Sun, 25 Aug 2019 21:48:30 GMT</pubDate>
            <atom:updated>2019-08-25T21:48:30.730Z</atom:updated>
            <content:encoded><![CDATA[<ul><li><a href="https://medium.com/@abdullahsuhaisik/react-widget-render-1-67896c5f4b49">React Widget Render 1</a></li><li><a href="https://medium.com/@abdullahsuhaisik/react-widget-renderer-2-35759ae55cb1">React Widget Renderer 2</a></li></ul><p>Önceki yazılarda bir tab componenti yapmıştık. Bu tab compentine diğer componentleri tanımlamıştık, dışarıdan aldığı Json objesine göre bu tabı seçili elementini render ediyor ve ya etmiyordu. Aynı zamanda seçili componenti state inde tutuyordu. Bu tutma işlemi özellikle active class gibi css özelliklerinin verilmesinde kullanabiliriz.</p><p>Şimdi kullanıcılarımızın kendi temalarını kendi css lerini oluşturduğunu ve bunuda uygulamamıza run time da eklenmesi gerektiğini kurgulayalım. Bunuda custom hooks ile yapalım. React 16 dan sonra gelen en güzel özellik hookslar.</p><p>Çok kısaca hookslardan bahsedelim.Bana göre hooksların iki tane olayı var bizi class component yazmaktan kurtarıyor. this. keyword lerinden bizi kurtarıyor gerci es 6 ile bind etmeler daha kolay ama. Hooks lar ile herşeyi fonsiyonlara dökdük. Artık o kadar class component yazmıyorum ki nasıl yazıldığına bakmam gerekti.</p><p>Class component ile state tanımlarken , this.state { … } gibi bir tanımlama yapıyorduk ve update methodunu yapıyorduk ama şimdi.</p><pre>const [state,updateState] = React.useState(&#39;ilk deger&#39;);</pre><p>Yukarıda hooks ile bir state tanımladık. <strong>state dizimin 0. elamanı ile </strong>stateme ulaşıyorum. dizimin <strong>1.elamanı updateState ilede</strong> state min güncelleme methodu ve bunların hepsi useState methodunda geldi.</p><p>Bir diğer hooks ise lifecycle methodlarının yerine geçen useEffect. Bütün önceki lifecycle methodlarının yerine geçen harika birşey.</p><pre>React.useEffect( ()=&gt; {</pre><pre>// get işlemi event işlemleri burada yapılır</pre><pre>// Eğer unmount yapmak istersek return ile geri döneriz</pre><pre>// Burada bir state güncellenebilir. Bir state değiştiğinde tekrardan useEffecti çalışıtmak istersek<br>},[HangiDurumDeğişirseUseEffectTekrardanÇalışacak])</pre><p>Daha birkaç tane daha yeni gelen özellikler var ama onları başka zaman işleriz.Özellikle useCallback baya güzel ve performanslı.</p><p>Peki customHook nedir ? Aşağıdaki örneği inceleyelim. Aynı zamanda bu hooks app mizde kullanacağımız hook.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/510e1b89a80bbdcf8ac7618250203bc7/href">https://medium.com/media/510e1b89a80bbdcf8ac7618250203bc7/href</a></iframe><p>Aslında global bir yere fonksiyon yazmak gibi ben bu fonksiyonumu daha başka yerlerde de kullanacağım ve bu fonksiyonu kullandığım yerler fonksiyonumda değişikliğim olursa tekrar render edilsin gibi. Hook yazarken de reactın useState ve useEffect methodlarını kullanabiliyorum. Beni kod tekrarında kurtarıyor. Hoc ile de yazabilirdim…</p><pre>export function useCss() {</pre><pre>useEffect(() =&gt; {</pre><pre>addCustomCss(&#39;/style/styles.css&#39;);</pre><pre>}, []);</pre><pre>}</pre><p>Dışarı çıkardığımız useCss() fonksiyonu useCss çağrıldığı anda useEffect cağırılıyor oda tek bir sefer addCustomCss() methodunu ‘/style/styles.css’ parametresiyle çağırıyor.</p><pre>function addCustomCss(url) {</pre><pre>const link = document.createElement(&#39;link&#39;);</pre><pre>link.setAttribute(&#39;rel&#39;, &#39;stylesheet&#39;);</pre><pre>link.setAttribute(&#39;type&#39;, &#39;text/css&#39;);</pre><pre>link.setAttribute(&#39;href&#39;, url);</pre><pre>document.getElementsByTagName(&#39;head&#39;)[0].appendChild(link);</pre><pre>}</pre><p>addCustomCss() methodu ise parametre olarak gelen css dosyasını uygulamamıza inject ediyor. Bu methodlar yardımı ile run time da uygulamanızın css ini dışarıdan gelecek şekilde değiştirebilirsiniz. Peki bu react için çok doğru bir yöntem midir ? Aslında kullanım şeklinize bağlı olarak değil kullanılacak yada kullanılmayacak bütün css file larını uygulamama ekliyorum ve performans açısından kayıp. Yanlış kullanım kök componentte bütün css filelarını yüklemek. Doğru kullanım hook’s kullanarak secilen componentte componentin css lerini inject ederek kullanmak. Ama yapımız doğru kullanıma çok yaklaşık.</p><p>Buraya kadar tamam isek şimdi hookslarımızı app.js de çağıralım. Önce bir Json template objesi oluşturalım ardından ise küçük bir css yazalım.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/58a49f9584a8ec5a5cdb0fb11be10579/href">https://medium.com/media/58a49f9584a8ec5a5cdb0fb11be10579/href</a></iframe><pre>useCss(&#39;/style/styles.css&#39;);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VSQ3q0ZHsqXAWljAgUWDzg.jpeg" /></figure><p>Evet css imizi import ettik. Şimdi sırada tab componentim için Json objesini eklemek kaldı.</p><pre>function App() {</pre><pre>useCss(&quot;/style/styles.css&quot;);</pre><pre>const tema = useTemplate();</pre><pre>const [tab, setTab] = useState(&quot;login&quot;);</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51e6fe3e24fa55547ff141c913d58ccd/href">https://medium.com/media/51e6fe3e24fa55547ff141c913d58ccd/href</a></iframe><p>App.js de yukarıdaki güncellemeleri yapıyorum. Artık Componentim tamamen dışarıdan css ve componentler ile çalışıyor.</p><p><a href="https://github.com/abdullahsuhaisk/ReactWidgetsRender">https://github.com/abdullahsuhaisk/ReactWidgetsRender</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c853c8809f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>