<?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 takahirom on Medium]]></title>
        <description><![CDATA[Stories by takahirom on Medium]]></description>
        <link>https://medium.com/@takahirom?source=rss-c781a202ce0a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1WR73u9Ugb40-dM8wqGcCA.png</url>
            <title>Stories by takahirom on Medium</title>
            <link>https://medium.com/@takahirom?source=rss-c781a202ce0a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 18:40:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@takahirom/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[GitHub’s New Stacked PRs Quietly Break Your Diff CI — Here’s Why and How to Fix It]]></title>
            <link>https://medium.com/@takahirom/githubs-new-stacked-prs-quietly-break-your-diff-ci-here-s-why-and-how-to-fix-it-f36c8ffb91a9?source=rss-c781a202ce0a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f36c8ffb91a9</guid>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[takahirom]]></dc:creator>
            <pubDate>Fri, 07 Aug 2026 09:18:32 GMT</pubDate>
            <atom:updated>2026-08-07T09:18:32.553Z</atom:updated>
            <content:encoded><![CDATA[<p><em>I maintain </em><a href="https://github.com/takahirom/roborazzi"><em>Roborazzi</em></a><em>, a screenshot testing library for Android, and I recently spent days chasing “screenshot regressions” that nobody had made. The culprit was not the tests. It was how GitHub builds the commit your CI checks out.</em></p><p>GitHub recently shipped <a href="https://docs.github.com/en/pull-requests/get-started/about-stacked-prs">native stacked pull requests</a> in <a href="https://github.blog/changelog/2026-07-30-stacked-pull-requests-are-now-in-public-preview/">public preview</a> (July 2026), with a <a href="https://github.com/github/gh-stack">gh-stack CLI extension</a> alongside the web UI. If your repository has any CI job that posts a &quot;diff&quot; — dependency changes, screenshot comparisons, APK size — read on before your team adopts stacks.</p><h3>The symptom</h3><p>You open a stacked PR (a PR whose base is another PR’s branch). Your CI posts:</p><ul><li>A dependency diff comment: “dagger 2.58 → 2.60.1” — you never touched dependencies</li><li>A screenshot diff report: screens you never modified, shown in red</li></ul><p>The PR’s “Files changed” tab looks perfectly clean. Only the diff-type CI jobs are screaming.</p><h3>The cause: newer main leaks into the merge ref</h3><p>You probably know that pull_request CI checks out github.sha — a temporary merge commit (the <a href="https://docs.github.com/en/rest/pulls/pulls">&quot;test commit&quot;</a>), not your branch. Classically that meant merge(your base branch&#39;s tip, your head): harmless for diff jobs, because the baseline comes from that same base branch.</p><p>For stacked PRs, the merge target changed. GitHub builds your test commit on top of the base PR’s test commit — which already contains the latest main. This part isn&#39;t documented (the <a href="https://docs.github.com/en/pull-requests/reference/stacked-pull-requests">reference</a> says only that workflows &quot;trigger as if each pull request in the stack targets the base of the stack ... so no workflow changes are required&quot; — true for build and test jobs, not for diffs); you can verify it in your own runs with git rev-parse HEAD^1.</p><p>Here is the whole problem in one picture. A1 is the base PR, B1 is your PR, M2·M3landed on main after the stack was cut, and T1·T2 are the test commits GitHub chains together:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PGISp58QjXoqljWbB6gglw.png" /><figcaption>Today: the baseline (A1) is compared against GitHub’s test commit (T2), which contains M2·M3 via T1. The drift shows up as “your” diff.</figcaption></figure><p>A renovate bump, a layout fix, a moved file — anything that landed on main after your stack was cut is now reported as a change you made. This is harmless for builds and tests (you <em>want</em> to test the merged future) and poison for anything that compares two trees.</p><p>One more trap: a stacked PR has two things you could call “the base”. Say your stack is main ← feature-1 ← feature-2. From feature-2&#39;s point of view, its base branch is feature-1 (one level below), while the stack base — the branch the whole stack finally lands on — is main. The event hands these out inconsistently:</p><ul><li>github.base_ref → rewritten to the stack base, main (measured in my experiment)</li><li>github.event.pull_request.base.ref → still the branch one level below</li><li>github.event.pull_request.stack.base.ref → the stack base by definition: <em>&quot;The branch the entire stack ultimately targets, such as </em><em>main&quot;</em> (<a href="https://docs.github.com/en/pull-requests/how-tos/merge-and-close-pull-requests/optimizing-ci-for-stacked-pull-requests">docs</a>)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_wJJ2jgs2E4aiYr7P96Tpw.png" /></figure><p>So a workflow that fetches baselines “from github.base_ref&quot; silently switches to main the moment the PR joins a stack — and main is the wrong diff base anyway, since comparing against it gives the whole stack&#39;s diff. Resolve the base you actually mean, explicitly.</p><h3>The fix: derive both sides from the same commit</h3><p>The invariant that kills this whole class of false positives:</p><blockquote><em>In a two-sided comparison, both sides must be derived from the same commit.</em></blockquote><p>Three patterns, depending on how expensive your baseline is to produce. The figures below all show the same graph — only the compared pair changes.</p><p>1. Compare the merge ref against its own first parent (HEAD^1).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gVX83DO-phk5QLtaI5jQMA.png" /><figcaption>Fix 1: T1 vs T2. Whatever main T1 contains, T2 contains too, so it cancels.</figcaption></figure><p>Works when the baseline is cheap to recompute in-run (e.g. gradle dependenciesoutput): compute it once from HEAD^1, once from HEAD, diff the two. Two prerequisites: the default shallow checkout has no parent commits, so set fetch-depth: 2; and this only works when HEAD really is the merge ref, so guard with git rev-parse -q --verify HEAD^2 (if your workflow checks out head.sha instead, HEAD^1 silently diffs just your last commit).</p><p>2. Build the merge yourself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Ochdg9L-8sA0USbbiCVJQ.png" /><figcaption>Fix 2: A1 vs S, a merge your workflow builds from the base tip. S’s first parent <em>is</em> the baseline.</figcaption></figure><p>Works when baselines are prebuilt artifacts (e.g. screenshot images recorded per branch). Don’t check out github.sha. Instead:</p><pre># prerequisite: fetch-depth: 0 (or fetch $base_ref and $HEAD_SHA explicitly)<br># resolve the branch one level below via the REST API — don&#39;t assume base_ref<br>base_ref=$(gh api &quot;repos/$REPO/pulls/$PR&quot; --jq &#39;.base.ref&#39;)<br>git checkout --detach &quot;origin/$base_ref&quot;<br>git -c user.name=&quot;ci&quot; -c user.email=&quot;ci@example.com&quot; \<br>  merge --no-edit &quot;$HEAD_SHA&quot;   # conflict? fail and ask for a rebase</pre><p>Cost: one git merge. The tradeoff: you render &quot;base + your PR,&quot; not &quot;latest main + everything.&quot; That merged-future fidelity is still covered by your build and test jobs, which keep using GitHub&#39;s test commit — for a diff job, the fidelity surplus is exactly the noise.</p><p>3. Compare two real commits: head vs fork point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JWJ4xjr0_AxvojWqNHJwdg.png" /><figcaption>Fix 3: A1 vs B1. Two commits someone actually pushed; no synthetic merge involved at all.</figcaption></figure><p>Works if your CI already builds an artifact for every pushed commit (an APK per commit, for example): diff the artifact of your head against the artifact of the fork point (git merge-base &quot;$base_ref&quot; HEAD, with base_ref resolved as in pattern 2). Two rules keep the fork-point math honest: feed merge-base the branch one level below, not the stack base (that would give you the whole stack&#39;s diff), and update stacked branches by merging the branch one level below — merging main directly into a stacked branch makes the fork point ambiguous, and drift leaks back in. Pattern 2 needs neither rule.</p><h3>Takeaways</h3><ul><li>On pull_request, CI checks out a synthetic merge. For stacked PRs, the docs say workflows trigger <em>as if every PR targets the stack base</em>; that the merge ref chains on the base PR&#39;s merge ref is what I measured, not something documented.</li><li>Build/test jobs benefit from this; diff jobs are structurally broken by it.</li><li>Fix: derive both sides of the comparison from the same commit — merge-ref-vs-parent, self-made merge, or two real commits at the fork point.</li><li>A stacked PR has two “bases”: the branch one level below (GET /pulls/{number}→ base.ref) and the stack base (github.event.pull_request.stack.base.ref). Resolve the one you mean explicitly — don&#39;t assume what base_ref points to.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f36c8ffb91a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing Arbigent — An AI Agent Testing Framework for Modern Applications]]></title>
            <link>https://medium.com/@takahirom/introducing-arbigent-an-ai-agent-testing-framework-for-modern-applications-f43a2e01d342?source=rss-c781a202ce0a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f43a2e01d342</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[agents]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[takahirom]]></dc:creator>
            <pubDate>Sun, 19 Jan 2025 09:56:58 GMT</pubDate>
            <atom:updated>2025-01-20T13:08:48.754Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introducing Arbigent — An AI Agent Testing Framework for Modern Applications</h3><p>Are you struggling with flaky UI tests? Ever experienced tests breaking due to minor UI changes? Modern applications are dynamic and complex, making traditional UI testing brittle and prone to failure. While AI agents offer a promising alternative, they need structure to be effective. Arbigent is a new open-source framework that provides this structure, enabling robust, scenario-based AI agent testing for today’s evolving applications.</p><p><a href="https://github.com/takahirom/arbigent">GitHub - takahirom/arbigent: Zero to AI agent testing in minutes for Android, iOS, and Web apps. Arbigent&#39;s intuitive UI and powerful code interface make it accessible to everyone, while its scenario breakdown feature ensures scalability for even the most complex tasks.</a></p><p><strong>The Problem with Traditional UI Testing</strong></p><p>Traditional UI testing often relies on brittle methods that are easily broken by even minor UI changes. A/B tests, updated tutorials, unexpected dialogs, dynamic advertising, or ever-changing user-generated content can bring your test suite to a grinding halt. This fragility leads to constant maintenance and frustration, making testing a bottleneck rather than a safeguard.</p><p><strong>AI Agents to the Rescue? Not Quite.</strong></p><p>AI agents, with their ability to understand and interact with applications more like a human, seemed like the perfect solution. However, simply unleashing an AI agent on your app without a structured approach can be chaotic. Agents might get sidetracked, open other apps, or click the wrong buttons due to the sheer complexity of modern applications.</p><p><strong>Arbigent: A Practical Solution for AI Agent Testing</strong></p><p>I hope that Arbigent, by providing a robust framework for AI agent testing, can help bridge the gap between the limitations of traditional testing and the potential of AI agents. It aims to address the challenges of both approaches, offering a practical and scalable solution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nQPHXFvIqad3_QWvoYJgiQ.png" /></figure><p>Here’s how:</p><p><strong>1. Scenario Decomposition: Taming Complexity</strong></p><p>Arbigent allows the decomposition of complex tasks into smaller, dependent scenarios. Think of it like this: instead of telling the AI agent “Test the entire checkout flow,” you can define scenarios like “Login,” “Add item to cart,” and “Complete purchase.” Each scenario builds upon the previous one, creating a clear and manageable testing path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*_ilCI6ONzfKobDz1DVkgow.png" /></figure><p><strong>2. Customizable to Your Needs</strong></p><p>Arbigent offers flexibility by supporting various AI providers, operating systems, and form factors. Inspired by <a href="https://square.github.io/okhttp/features/interceptors/">OkHttp’s interceptor</a> pattern, Arbigent offers interfaces that allow you to:</p><ul><li><strong>Use your preferred AI:</strong> Integrate with popular AI providers like OpenAI, Gemini, or even your internal models.</li><li><strong>Support various platforms:</strong> Test on Android, iOS, web, and even TV interfaces with D-pad navigation.</li><li><strong>Adapt to different form factors:</strong> Arbigent’s architecture allows for extending support to devices beyond phones and tablets.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jwpOvg1tV17SMaYeSNM4EQ.png" /></figure><p><strong>3. Designed for Technical and Non-Technical Users</strong></p><p>Arbigent caters to both technical and non-technical team members.</p><ul><li><strong>Intuitive UI:</strong> QA engineers can create and manage test scenarios using a user-friendly visual interface. Define goals, set up dependencies, and even add image-based assertions, all without writing a single line of code.</li><li><strong>Developer-Friendly Tools:</strong> Arbigent currently offers a command-line interface (CLI) for executing scenarios and integrating with CI/CD pipelines. We are actively working on expanding these capabilities with a more comprehensive code interface in the future.</li></ul><p><strong>Key Features in a Nutshell</strong></p><ul><li><strong>Scenario Dependencies:</strong> Break down complex tasks into smaller, linked scenarios.</li><li><strong>Hybrid Workflow:</strong> Create scenarios in the UI, execute them via code or command line interface.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GYjCBPOtNGZD05h72YNNKg.png" /></figure><ul><li><strong>Multi-Platform Support:</strong> Test on iOS, Android, Web, and TV.</li><li><strong>AI Optimization:</strong> Streamline UI trees and annotated screenshots for better AI understanding.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IV1guP60yPqUo15LJfbl_w.png" /></figure><ul><li><strong>Cost-Effective:</strong> Open-source and compatible with efficient AI models.</li><li><strong>Robustness Features:</strong> AI-powered image assertion and stuck screen detection.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_9dLJZLKhQSn1Y0CLSbFmg.png" /></figure><ul><li><strong>Open Source and Community-Driven:</strong> Free to use, modify, and contribute to.</li></ul><p><strong>Arbigent and the SMURF Framework</strong></p><p>The Google Testing Blog introduced the <a href="https://testing.googleblog.com/2024/10/smurf-beyond-test-pyramid.html">SMURF framework</a> for categorizing automated testing frameworks. Here’s how Arbigent stacks up <strong>(</strong>based on my, the author’s, assessment<strong>)</strong>:</p><ul><li><strong>Speed (1/5):</strong> Currently limited by the speed of the underlying AI technology.</li><li><strong>Maintainability (4/5):</strong> Arbigent promotes maintainability through natural language test definitions and task decomposition. More significantly, the underlying AI model can adapt to minor UI changes, minimizing the need to rewrite tests for every small update, thus reducing maintenance effort.</li><li><strong>Utilization (1/5):</strong> Requires device and AI resources. The AI cost is relatively low; for instance, using GPT-4o, it’s estimated to be around $0.005 per step and $0.02 per task.</li><li><strong>Reliability (3/5):</strong> Features like auto-wait, dialog handling, and self-correction contribute to reliable test execution. Arbigent also incorporates a retry mechanism, allowing scenarios to be re-executed from the start in case of failure. The flexibility of the underlying AI further enhances reliability. However, external factors like emulator flakiness can still affect test stability.</li><li><strong>Fidelity (5/5):</strong> Tests are performed on real or emulated devices running the actual application, ensuring high fidelity to real-world usage.</li></ul><p>As AI technology advances, Arbigent’s limitations in speed, utilization, and reliability are expected to improve significantly.</p><p><strong>Getting Started</strong></p><p>Ready to explore a new approach to testing with Arbigent? Getting started is simple. You can download the Arbigent UI from <a href="https://github.com/takahirom/arbigent/releases">the Releases page</a> on GitHub, connect your device, and begin creating test scenarios in minutes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nd7oFRm-Mlc7vXrdte3LKw.png" /></figure><p>For detailed installation instructions, head over to the <a href="https://github.com/takahirom/arbigent">guide in the Arbigent README</a>. The README also covers using the Arbigent Command Line Interface (CLI) via Homebrew for advanced users and integration with CI/CD pipelines like GitHub Actions.</p><p>Whether you prefer a visual approach with the UI or command-line based control with the CLI, Arbigent offers different options to fit your team’s needs. Start exploring the power of AI agent testing today! Download Arbigent and try creating your first scenario!</p><p><a href="https://github.com/takahirom/arbigent">GitHub - takahirom/arbigent: Zero to AI agent testing in minutes for Android, iOS, and Web apps. Arbigent&#39;s intuitive UI and powerful code interface make it accessible to everyone, while its scenario breakdown feature ensures scalability for even the most complex tasks.</a></p><p><strong>Learn More</strong></p><p>Dive deeper into Arbigent’s architecture, execution flow, class diagram, and CLI usage details by visiting the <a href="https://github.com/takahirom/arbigent">GitHub repository</a>. If you find this interesting, please star it!</p><p><strong>The Future of AI Agent Testing</strong></p><p>I hope that Arbigent, by combining a user-friendly interface with a powerful and customizable code interface, can empower teams to build robust and maintainable tests for modern applications. As AI technology continues to evolve, it is my hope that Arbigent will become a valuable tool for ensuring the quality and reliability of software in the years to come. I invite you to join the community, contribute to the project, and help shape the future of AI agent testing!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f43a2e01d342" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Solve Flaky Robolectric and Roborazzi Tests]]></title>
            <link>https://medium.com/@takahirom/how-to-solve-flaky-robolectric-and-roborazzi-tests-5731e55581cd?source=rss-c781a202ce0a------2</link>
            <guid isPermaLink="false">https://medium.com/p/5731e55581cd</guid>
            <category><![CDATA[robolectric]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[takahirom]]></dc:creator>
            <pubDate>Mon, 22 Jan 2024 09:18:02 GMT</pubDate>
            <atom:updated>2024-07-17T03:44:59.354Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*K8MONe7rUdTczaut" /></figure><p>I’ve been using <a href="https://github.com/takahirom/roborazzi">Roborazzi</a> and <a href="https://robolectric.org/">Robolectric</a> and encountered some minor issues during the test installation process.<br>I believe Robolectric tests are generally less flaky than device tests. However, even Robolectric tests can sometimes be flaky.<br>I believe sharing our experiences about what caused the tests to be flaky and how we addressed these issues will be beneficial.</p><p>It is advisable to create a custom Test Rule to solve these problems.</p><blockquote>If you would like to understand why we use Robolectric and Roborazzi, please refer to this slide:</blockquote><blockquote><a href="https://speakerdeck.com/takahirom/robolectric-native-graphics-and-roborazzi">https://speakerdeck.com/takahirom/robolectric-native-graphics-and-roborazz</a>i</blockquote><h3>The Basics</h3><p>To ensure test consistency, we need to keep all threads under control. This is the main reason the tests become flaky.</p><h4>Android Official Libraries</h4><p><strong>Utilize </strong><a href="https://developer.android.com/reference/androidx/arch/core/executor/testing/InstantTaskExecutorRule">InstantTaskExecutorRule</a><strong>()</strong></p><p>Android Architecture Components, such as Lifecycle and LiveData, utilize task executors from Architecture Components. We need to control these threads.</p><p><strong>Utilize </strong><strong>supportFragmentManager.executePendingTransactions() Before Verification</strong></p><p>We use this method to commit Fragments in tests.</p><p><strong>Utilize </strong><strong>composeTestRule.waitForIdle() Before Verification</strong></p><p>I noticed an issue where LazyColumn does not layout properly without this method.</p><p><strong>Utilize ShadowLooper.runUiThreadTasksIncludingDelayedTasks() Before Verification</strong></p><p>We need to ensure the Looper is empty.</p><h4><strong>Kotlin Coroutines:</strong></h4><p><strong>Injecting Coroutine Dispatchers:<br></strong>I replace the Default and IO dispatchers with StandardTestDispatcher using Dagger Hilt. StandardTestDispatcher does not run automatically; therefore, we need to manually execute testScheduler.advanceTimeBy() or a similar function in tests.</p><p>I am using Dagger Hilt, but please feel free to use your preferred method of Dependency Injection to replace dependencies in tests.</p><p><strong>Utilizing </strong><strong>Dispatchers.setMain():</strong><br>The setMain() method is part of the Kotlin Coroutines&#39; coroutines-test library.<br>I frequently opt for UnconfinedTestDispatcher() in setMain(), as it closely mimics the behavior of Dispatchers.Main.immediate.</p><h4>RxJava:</h4><p>We need to call RxJavaPlugins.setComputationSchedulerHandler{} and some threads before tests.</p><h3>Task Management Mixing Problem</h3><p>We can run Android Looper tasks(messages), coroutine tasks, and others before verification. However, after running coroutine tasks, additional Android Looper tasks might be added, leading to inconsistent results. We have two options to resolve this issue:</p><ol><li>Immediate Execution of Tasks: We can execute tasks immediately, for example, by using UnconfinedTestDispatcher. This approach is straightforward but does not accurately reflect real-world conditions.</li><li>Loop to Ensure Task Queue is Empty: We can loop, say, five times to empty the task queue. This approach more closely simulates real threading behavior.</li></ol><h3>Case study</h3><p><strong>Issue with Glide Images Sometimes Not Loading</strong><br>Cause: Related to the Glide image library, likely involves internal threading.<br>Solution: Use local Drawable in tests.</p><p><strong>Issue with Glide Images Sometimes Having Different Alpha</strong><br>Cause: Unmanaged animations are present.<br>Solution: Turn off transitions using transition(DrawableTransitionOptions().dontTransition()).</p><p><strong>Issue with Coil Images Sometimes Not Loading</strong><br>Cause: Related to the Coil image library, likely involves internal threading.<br>Solution: Address using mechanisms provided within Coil.</p><p><a href="https://github.com/coil-kt/coil/tree/main/coil-test#testing">https://github.com/coil-kt/coil/tree/main/coil-test#testing</a></p><p><strong>Initial Display of MotionLayout</strong><br>Cause: MotionLayout has its own timing within it, which is challenging to control. <a href="https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/motion/widget/MotionLayout.java;l=1173;drc=d941e7b3a88c5e14b088a1ad9c548576268d6219">https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/motion/widget/MotionLayout.java;l=1173;drc=d941e7b3a88c5e14b088a1ad9c548576268d6219</a><br>Solution: Managed by advancing the animation progress.</p><p><strong>Occasional Font Misalignment with Calligraphy</strong><br>Cause: The application of fonts was asynchronous.<br>Solution: Apply fonts before testing. You can use ViewPump.init(…) before tests.</p><p><strong>RecyclerView Sometimes Fails to Display Lists Correctly</strong><br>Cause: An Executor within the ListAdapter was uncontrolled.</p><p><a href="https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:recyclerview/recyclerview/src/main/java/androidx/recyclerview/widget/AsyncDifferConfig.java;l=131;drc=187e9a2088c3f281cfb617b9bedd94b9a3546d8b">https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:recyclerview/recyclerview/src/main/java/androidx/recyclerview/widget/AsyncDifferConfig.java;l=131;drc=187e9a2088c3f281cfb617b9bedd94b9a3546d8b</a><br>Solution: Specify a Test Executor on our end using DI.</p><p><strong>Fragment’s onStop Method Not Called Without ActivityScenario.close</strong></p><p>Cause: The Fragment’s onStop method is not invoked when ActivityScenario.close() is not used, leading to the CoroutineScope being retained across different tests.</p><p>Solution: To ensure that the Fragment’s onStop method is called and to prevent the CoroutineScope from being carried over between tests, always use ActivityScenario.close(). This practice helps in maintaining test stability.</p><p><strong>Issue with Time Discrepancies in ThreeTenAbp (Not Flaky but Consistent)</strong><br>Cause: The issue was due to the use of the current time.<br>Solution: Use a fixed time for testing.</p><p><strong>Failing Due to Time Limit Constraints in test.runTest</strong><br>Cause: Robolectric is slow when starting due to its use of ByteBuddy.<br>Solution: Extend the time limit to accommodate this delay.</p><p><strong>I’m using Compose, and the tests are running slowly</strong></p><p>You can try this new workaround:</p><p><a href="https://github.com/robolectric/robolectric/issues/9043#issuecomment-2217319164">https://github.com/robolectric/robolectric/issues/9043#issuecomment-2217319164</a></p><h3>Summary</h3><p>Solving these issues can sometimes be challenging, but they become clearer as we investigate. Essentially, we should focus on managing the unmanaged aspects. Additionally, by sharing knowledge like this, we can make it easier to find solutions within the community.</p><p>If you find any mistakes, errors, or have a better approach, please let me know.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5731e55581cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Roborazzi: Elevating Android Visual Testing to the Next Level]]></title>
            <link>https://medium.com/@takahirom/roborazzi-elevating-android-visual-testing-to-the-next-level-46ec56b24055?source=rss-c781a202ce0a------2</link>
            <guid isPermaLink="false">https://medium.com/p/46ec56b24055</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[roborazzi]]></category>
            <dc:creator><![CDATA[takahirom]]></dc:creator>
            <pubDate>Mon, 23 Oct 2023 06:01:36 GMT</pubDate>
            <atom:updated>2023-12-07T01:58:33.047Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mfh6ZUkaTU060zmR" /></figure><p>As an Android developer, I’ve always valued efficient testing. <a href="https://dagger.dev/hilt/testing-philosophy.html">Dagger Hilt’s testing philosophy</a>, which emphasizes the use of real code over mocks, was a revelation for me. However, when integrating Hilt with Robolectric for JVM tests, a noticeable gap appeared: the absence of UI visualization. This challenge led to the birth of Roborazzi. Built on Robolectric, Roborazzi incorporates the new Robolectric Native Graphics feature, allowing developers to capture screenshots during tests. In this article, we’ll explore the significance of screenshot testing, differentiate between JVM and Android device tests, and unveil Roborazzi’s groundbreaking approach.</p><h4>Why Screenshot Testing is Important</h4><p>Screenshot testing is key to validate your app’s appearance and functionality. It efficiently detects visual issues and <strong>tests the app as users would use it</strong>, making it easier to spot problems. Additionally, screenshot testing is not tied directly to the underlying code. This means that even if the production code changes, <strong>as long as the behavior and appearance remain consistent, the test will not need modifications</strong>. It ensures that tests remain valid and reliable even after refactoring.</p><h4>JVM Tests vs Android Device Tests</h4><p>Testing is an important part of the development cycle, making sure the app works right. Testing on real devices or emulators gives a true check of your app because that’s how users use it. But, testing on these can take a lot of time and can have errors or “flakiness”. This “flakiness” may arise because devices or emulators work with many things in the system and we can’t handle all of them, making tests not stable. With Robolectric, <strong>we can test on a local JVM environment. This lets us do tests fast and in a trusted way.</strong></p><h4>Introduction to Roborazzi</h4><p>The need for an enhanced testing tool led to the development of Roborazzi. Roborazzi incorporates Robolectric. The newly-released feature, <a href="https://github.com/robolectric/robolectric/releases/tag/robolectric-4.10"><strong>Robolectric Native Graphics</strong></a>, <strong>allows developers to capture screenshots</strong>. This tool enhances Android JVM Integration tests by integrating with Robolectric, providing visual feedback through screenshots and view tree dumps.</p><p>You can set up Roborazzi by <a href="https://github.com/takahirom/roborazzi#try-it-out">this document</a></p><p>Here’s how the test configuration should appear. In the tests, all you need to do for standard UI tests is add <strong>@GraphicsMode(GraphicsMode.Mode.NATIVE)</strong> and invoke Roborazzi&#39;s <strong>.captureRoboImage()</strong> method. This approach is consistent with regular <a href="https://developer.android.com/jetpack/compose/testing">Compose Tests</a> or <a href="https://developer.android.com/training/testing/espresso">Espresso Tests</a>. You can fully leverage Roborazzi and <strong>effortlessly integrate it into any UI-related tests</strong>.</p><pre>@RunWith(RobolectricTestRunner::class)<br>// This flag is to enable Robolectric Native Graphics<br>// and needed to take screenshot. <br>@GraphicsMode(GraphicsMode.Mode.NATIVE)<br>class RoborazziTest {<br>  // From official Compose Test Library<br>  @get:Rule<br>  val composeTestRule = createAndroidComposeRule&lt;MainActivity&gt;()<br>  @Test<br>  fun captureRoboImageSample() {<br>    composeTestRule.onRoot()<br>      // This will save `build/outputs/Roborazzi/RoborazziTest.captureRoboImageSample.png`<br>      .captureRoboImage()</pre><h4>Continuous Integration Workflow</h4><p>Continuous Integration (CI) promotes frequent code integrations to detect conflicts early. One of its applications is image management in development. Here are two methods:</p><p><strong>Approach of Committing Images on the Branch</strong></p><p>This approach is used in the <a href="https://github.com/android/nowinandroid">Now in Android App</a></p><ul><li>In this approach, <strong>images are directly committed on the feature branch</strong>.</li><li>Changes are detected and new images are committed via CI like GitHub Actions.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PG7HRg_nQlev_MFHNVR22w.png" /></figure><p><em>Pros</em>:</p><ul><li><strong>Simplicity</strong>: Directly committing images to the feature branch keeps things straightforward and avoids additional branching complexities.</li><li><strong>UI Image Comparison</strong>: Using GitHub’s UI, collaborators can easily compare and spot differences in images.</li></ul><p><em>Cons</em>:</p><ul><li><strong>Persisting Old Images</strong>: Since images are directly committed to the branch, old images will remain in the Git repository’s history, potentially bloating the repository size over time. You can utilize a <strong>blobless clone</strong>, allowing you to fetch the repository without the blob history. This option might mitigate the issue. However, it could be challenging to revert from this approach. For more information, visit GitHub’s blog on <a href="https://github.blog/2020-12-21-get-up-to-speed-with-partial-clone-and-shallow-clone/">partial and shallow clones</a>.</li></ul><p><strong>The Companion Branch Approach</strong></p><p>This approach is used in <a href="https://github.com/DroidKaigi/conference-app-2023">DroidKaigi 2023 App</a> . It’s a method I’ve been adopting.</p><ul><li>This approach <strong>commits images to a separate ‘companion’ branch</strong>, distinct from the main branch.</li><li>Using GitHub Actions, reference images are uploaded as an artifact.</li><li>Images are committed in the ‘companion’ branch corresponding to a specific feature branch and a comment is posted to the Pull Request.</li><li>A process is indicated for cleaning up (deleting) outdated branches a month later.</li><li>You can refer to <a href="https://github.com/takahirom/roborazzi-compare-on-github-comment-sample">the workflow sample</a>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-2sf7-ueja7QsxhtClzOTQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*XZ36BUM_ZHqQdW8e.png" /><figcaption>The comment on GitHub pull request</figcaption></figure><p>You can check <a href="https://github.com/DroidKaigi/conference-app-2023/pull/911#issuecomment-1689919188">an example comment here</a>.</p><p><em>Pros</em>:</p><ul><li><strong>Repository Size Reduction</strong>: By using a separate companion branch and cleaning it up periodically, it can help in keeping the main repository size in check.</li><li><strong>Intuitive Feedback on PR</strong>: Posting images as comments on the Pull Request provides a direct and visual feedback mechanism, which can be easily understood by collaborators.</li></ul><p><em>Cons</em>:</p><ul><li><strong>Complexity</strong>: Managing multiple branches, especially companion branches for each feature, can add complexity to the Git workflow.</li><li><strong>Dependency on CI</strong>: While not impossible, verifying changes locally becomes challenging because this approach heavily relies on Continuous Integration.</li></ul><p>There are other options available, such as using Git LFS or GCS servers. However, displaying comparison images on GitHub with these methods can be challenging, so they are not covered here.</p><h3>The Core Value Proposition</h3><h4>Paparazzi and Roborazzi: A Comparison</h4><p>Paparazzi is an effective tool for checking View and Compose UI, given its foundation on Android Studio’s LayoutLib. Yet, it lacks support for Robolectric tests. <strong>This limitation affects the use of Espresso and Dagger Hilt, narrowing down testing possibilities</strong>. Consequently, capturing scrolled screen screenshots becomes challenging, and achieving higher test coverage is more difficult.</p><h4>Key Features of Roborazzi</h4><p>Here’s a breakdown of the unique advantages Roborazzi brings to the table:</p><p><strong>Roborazzi-specific Advantages:</strong></p><ul><li><strong>Screenshot Testing</strong>: Delivers a visual overview of how UI elements appear during tests, aiding in the <strong>easier identification of bugs</strong>. It also enables comparison of screenshots and the use of provided Gradle tasks.</li><li><strong>Ease of Debugging</strong>: With visual feedback and the Roborazzi <strong>Debug dump feature</strong>, the debugging process becomes more streamlined, saving developers valuable time.</li></ul><p><strong>Benefits of Integrating Roborazzi with Robolectric:</strong></p><ul><li><strong>Rapid Feedback Loop</strong>: <strong>With accelerated test execution, developers receive immediate feedback, promoting swift iterations</strong>.</li><li><strong>Espresso Compatibility</strong>: By utilizing Espresso, you can interact with the app as needed, <strong>enabling you to capture scrolled screenshots and conduct navigation tests in Compose</strong>.</li><li><strong>Compatibility with Dagger Hilt</strong>: Dagger Hilt is a dependency injection library for Android, simplifying the management of app-wide dependencies and improving the reusability and testability of code. When used in conjunction with Roborazzi, Hilt enhances test coverage, fortifying the code’s adaptability during refactoring.</li></ul><p><strong>Benefits of Collaborating with Roborazzi and Dagger Hilt:</strong></p><ul><li><strong>Protection against regressions</strong>: With the assistance of Dagger Hilt, <strong>you can effortlessly safeguard your code by achieving high test coverage</strong>. This is made possible by <a href="https://dagger.dev/hilt/testing.html"><strong>easily replacing dependencies like API clients with test doubles</strong></a>. Here is an example of how we create a fake API. <a href="https://github.com/DroidKaigi/conference-app-2023#fake-api-server">https://github.com/DroidKaigi/conference-app-2023#fake-api-server</a></li><li><strong>Refactoring Resilience</strong>: Since taking screenshots isn’t directly tied to the code, and with the use of Dagger Hilt negating the need to change internal app code, <strong>you won’t have to adjust tests when making code modifications</strong>.</li></ul><h3>Recommended Practices</h3><h4>The patterns suggested for using Roborazzi</h4><p>I believe that employing Roborazzi for testing could be effectively executed through the following three patterns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QoxxFzye3LSLDwKxHsRtGg.png" /></figure><p>1. <strong>Define several representative patterns and perform full-screen rendering tests for each to ensure the majority of functionalities are verified.</strong></p><ul><li>For instance, <strong>how paid content appears to free users</strong>.</li><li>This can be easily achieved by substituting server responses with test doubles, such as with Dagger Hilt.</li><li><strong>Why</strong>: There is a tradeoff that larger range tests are more likely to be false positive because they are more likely to detect changes, but they are also more likely to provide protection against regression. <strong>In my opinion, there should be both assertions for fine objects and assertions for large objects.</strong> This test will be a test for large unit assertions.</li></ul><p>Example:</p><pre>@HiltAndroidTest<br>@RunWith(RobolectricTestRunner::class)<br>...<br>class ArticleDetailScreenTest {<br>  @Test<br>  fun checkPaidContentsForPaidUserRendering {<br>    articleScreenRobot {<br>      setupPaidUser()<br>      setupPaidContentServer()<br><br>      launchActivity()<br>  <br>      recordOrCompareCapture()<br>    }<br>  }<br>  @Test<br>  fun checkPaidContentsForFreeUserRendering {<br>    articleScreenRobot {<br>      setupPaidContentServer()<br>  <br>      launchActivity()<br><br>      // The main thing being tested here is a screenshot, <br>      // but since what I am trying to make sure of is <br>      // the rendering as a screen, <br>      // I think it is safe to have an assertion as well.<br>      assertSubscribeButtonExists()<br>      recordOrCompareCapture()<br>    }<br>  }<br>...<br>}<br>class ArticleScreenRobot {<br>  // Please refer to &quot;Using the Robot testing pattern&quot; section.<br>  fun setupPaidContentServer() {<br>  ...<br>  }<br>  <br>  fun launchActivity() {<br>  ...<br>  }<br>    <br>  fun recordOrCompareCapture() {<br>  ...<br>  }<br>}</pre><p>2. <strong>Use screenshots as a tool to confirm UI presentation during UI testing, resolving the inability to view UI in Robolectric tests and aiding in debugging when tests fail.</strong></p><ul><li>This is not to be considered a test in itself.</li><li><strong>The diffs from screenshots taken in this manner should be used as supplemental information</strong>, accessible upon expansion, rather than being a part of the developers’ regular view. This is because they tend to generate a significant number of false positives, which, if commonly displayed, could lead developers to disregard the tests entirely.</li><li><strong>Why</strong>: For example, <strong>while testing whether a button is displayed, changes like the rounding of button corners might be caught in the screenshot, leading to false positives</strong>. Therefore, it is prudent to use screenshots solely as a debugging tool, to visually verify elements when necessary, and to avoid relying on them as definitive proof of test success or failure.</li></ul><pre>@HiltAndroidTest<br>@RunWith(RobolectricTestRunner::class)<br>...<br>class ArticleDetailScreenTest {<br>  @Test<br>  fun shouldShowSubscribeButtonWhenPaidContentsAndFreeUser {<br>    articleScreenRobot {<br>      setupPaidContentServer()<br>  <br>      launchActivity()<br>  <br>      // This won&#39;t cause the test to fail <br>      // in order to prevent false positives. <br>      // However, if you wish to view the screenshots, <br>      // they are available for debugging purposes.<br>      recordOrCompareCaptureJustForDebug()<br>      checkSubscribeButtonShown()<br>    }<br>  }<br>...<br>}<br>class ArticleScreenRobot {<br>  // Please refer to the &quot;Using the Robot testing pattern&quot; section<br>  fun setupPaidContentServer() {<br>  ...<br>  }<br>  <br>  fun launchActivity() {<br>  ...<br>  }<br>    <br>  fun recordOrCompareCaptureJustForDebug() {<br>  ...<br>  }<br>}</pre><p>3. <strong>Perform screenshot tests of UI components</strong></p><ul><li>Screenshots testing truly excels when evaluating design system components. You have the option to manually capture screenshots, or utilize tools like <a href="https://github.com/takahirom/roborazzi/issues/19#issuecomment-1732854042">Showkase</a> or <a href="https://proandroiddev.com/automate-screenshot-testing-for-compose-previews-via-reflection-e6eb0f8fd977">Reflection</a>. Additionally, you can take screenshots with various configurations, such as dark mode or different font scales.</li><li>Component testing can include user interactions such as expanding and scrolling, but these are <strong>strictly part of the setup process for verifying the display, not to test the functionality of the interactions themselves</strong>. Each interaction requires its own test. For instance, a test for the expand action would need to verify, separately, that the detailed text is displayed, as confirmed by assertions like ‘isDisplayed’ in Espresso.</li></ul><pre>@RunWith(RobolectricTestRunner::class)<br>...<br>class DesignSystemComponentsPreviewTest {<br>  @Test<br>  fun checkAwesomeButtonComponent {<br>    captureRoboImage {<br>       AwesomeButton()<br>    }<br>  }<br>...</pre><h4>Best Practices for Employing Roborazzi</h4><ul><li>Utilizing Roborazzi’s dump feature for effective debugging.<br><strong>Roborazzi provides a dumping view tree feature. It helps you to debug the view state when the screenshots don’t show as expected</strong>. <a href="https://github.com/takahirom/roborazzi#dump-mode">Roborazzi’s documentation on dump mode</a></li></ul><pre>onView(ViewMatchers.isRoot())<br>      .captureRoboImage(<br>        roborazziOptions = RoborazziOptions(<br>          // Use CaptureType.Dump to capture the dump image<br>          captureType = RoborazziOptions.CaptureType.Dump()<br>        )<br>      )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0HGiDuSdGOAU5jcl.png" /></figure><ul><li>Configuring the default behavior of Roborazzi:<br>When you execute `captureRoboImage()` in tests, Roborazzi determines its behavior. By default, `captureRoboImage()` doesn’t perform any actions. However, when you execute tests with Roborazzi tasks such as `recordRoborazziDebug` or `verifyRoborazziDebug`, Roborazzi captures images using `captureRoboImage()`. Therefore, if you execute tests via the Android Studio run button or similar methods, images won’t be generated. Nonetheless, <strong>you can modify Roborazzi’s default behavior to capture images even when simply running tests. This allows you to debug tests using Android Studio and encourages your colleagues to utilize Roborazzi, as they can easily view the captured images</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*ngTSt-c3G_bZGpnRpzVWqw.png" /></figure><pre># gradle.properties<br>roborazzi.test.record=true</pre><p><a href="https://github.com/takahirom/roborazzi#roborazzi-gradleproperties-options">https://github.com/takahirom/roborazzi#roborazzi-gradleproperties-options</a></p><h4>Integration Test Practices with Roborazzi</h4><ul><li><strong>Adopting a Test-First approach for visual differences<br>Using Roborazzi for screenshot testing encourages a test-first approach</strong>. By writing tests initially, you can easily view the visual differences with Roborazzi. Observing these differences between the ‘before’ and ‘after’ states ensures test accuracy. Additionally, this approach optimizes your workflow.</li><li>Using the <strong>Robot testing pattern ensures structured and readable tests<br></strong>Creating maintainable tests can be challenging. I believe <strong>we should structure tests as we do with production code</strong>. You can refer to Jake’s presentation for more insights. <a href="https://jakewharton.com/testing-robots/">https://jakewharton.com/testing-robots/</a></li></ul><pre>@RunWith(AndroidJUnit4::class)<br>@GraphicsMode(GraphicsMode.Mode.NATIVE)<br>@HiltAndroidTest<br>@Config(<br>    qualifiers = RobolectricDeviceQualifiers.NexusOne<br>)<br>class TimetableScreenTest {<br>    @get:Rule<br>    @BindValue val robotTestRule: RobotTestRule = RobotTestRule&lt;MainActivity&gt;(this)    // Make our Robot<br>    @Inject lateinit var timetableScreenRobot: TimetableScreenRobot<br>    @Test<br>    fun checkLaunchShot() {<br>        timetableScreenRobot {<br>            // setupTimetableScreenContent() and checkScreenCapture() are<br>            // Robot&#39;s method<br>            setupTimetableScreenContent()<br>            checkScreenCapture()<br>        }<br>    }<br>...<br>class TimeTableRobot @Inject constructor() {<br>...<br>    // Sets up the content for the Timetable screen<br>    fun setupTimetableScreenContent() {<br>        composeTestRule.setContent {<br>            KaigiTheme {<br>                TimetableScreen(<br>                    onSearchClick = { },<br>                    onTimetableItemClick = { },<br>                    onBookmarkIconClick = { },<br>                )<br>            }<br>        }<br>    }<br>...<br>}</pre><ul><li>Protection against regressions with leveraging the <strong>high coverage tests in conjunction with Hilt</strong>.<br>We can make a test just for UI with Roborazzi. But Roborazzi is too good just to make tests for UI components. <strong>Roborazzi works with whole application code leveraging Hilt</strong>. This is made possible by <a href="https://dagger.dev/hilt/testing.html"><strong>easily replacing dependencies like API clients with test doubles</strong></a>.</li><li>Using Android Studio’s “Run Tests with Coverage” for Debugging<br>Integration tests can be challenging due to the extensive code they run on. However, using the “Run Tests with Coverage” feature in Android Studio can aid in debugging. While coverage isn’t explicitly for debugging, it’s useful for this purpose. Instead of adding logs everywhere, <strong>you can understand the test flow through this feature</strong>. However, note that using it with Robolectric can cause a VerifyError. A workaround is available here: <a href="https://github.com/robolectric/robolectric-gradle-plugin/issues/144#issuecomment-129283404">link</a>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5OaW_qL7bEcjS0-vgqcX0g.png" /></figure><ul><li><strong>Begin by writing a blank screen test </strong>when adding a new screen to the app<strong> </strong><br>Starting with a blank screen makes it simpler to incorporate screenshot tests. <strong>This ensures that the screenshot test functions correctly and helps structure your development process</strong>. Thanks to Roborazzi’s tests being independent of the code, modifications to the code become simpler and more feasible.</li><li><strong>The Trade-offs of Screenshot Testing<br></strong>Screenshot testing simplifies test creation and provides valuable visual feedback, yet it requires manual validation when appearances change. This presents a <strong>risk of oversight</strong>, which could allow bugs to slip through if not meticulously reviewed. To mitigate these risks, please refer to the patterns suggested for using Roborazzi.</li></ul><h4>Real-World Use Case: DroidKaigi 2023 App</h4><p>The implementation of Roborazzi in <a href="https://github.com/DroidKaigi/conference-app-2023#screenshot-testing-with-robolectric-native-graphics-rng-and-roborazzi">DroidKaigi 2023</a> app serves as a testament to its efficacy. The app, developed with contributions from over 150 developers, employs Roborazzi for screenshot testing, achieving an impressive 80% test coverage. This real-world use case underscores Roborazzi’s potential in enhancing the quality and efficiency of the testing process in a collaborative development environment.</p><h3>Community Impact and Future Directions</h3><h4>Community Reception</h4><p>The positive reception and widespread adoption of Roborazzi within the developer community reflect its impact. Its mention in <strong>Google’s </strong><a href="https://github.com/android/nowinandroid#screenshot-tests"><strong>Now In Android</strong></a> and utilization by <a href="https://twitter.com/tsmith/status/1695095257044852823"><strong>developers at Uber</strong></a> are just a few instances of its growing popularity. The feedback from the community has been invaluable, aiding in the continuous improvement of Roborazzi.</p><h4>What’s Next for Roborazzi</h4><p>Roborazzi is set to expand its capabilities with experimental support for Jetpack Compose Desktop, leveraging Skia for screenshot testing. This advancement aims to further streamline the testing process, enhancing its efficiency and efficacy.</p><p>Additionally, <strong>I plan to release </strong><a href="https://github.com/takahirom/roborazzi/issues/176"><strong>a simple Emulator that utilizes Robolectric Native Graphics</strong></a>, which I believe will greatly assist developers in debugging both apps and tests.</p><p>For future developments, we’re also considering enhancements in documentation and the implementation of image hash storage.</p><h3>Conclusion</h3><p>Roborazzi emerges as a powerful tool that addresses the inherent challenges in Android testing. By offering faster, more reliable, and visually verifiable tests, it not only enhances the efficiency of the testing process but also contributes to fostering a culture of quality assurance in Android development. As it continues to evolve with community feedback and technological advancements, Roborazzi holds promise for setting new standards in Android testing practices.</p><p><strong>We welcome feedback</strong> from the community to further enhance Roborazzi’s capabilities. If you’re using Roborazzi, <strong>please</strong> <strong>share your experiences</strong>. Your insights not only help improve the tool but also motivate and guide others in the community.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46ec56b24055" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DroidKaigi 2021アプリをDroidKaigiの情報配信のアプリとして活用していきます]]></title>
            <link>https://medium.com/droidkaigi/droidkaigi-2021%E3%82%A2%E3%83%97%E3%83%AA%E3%82%92droidkaigi%E3%81%AE%E6%83%85%E5%A0%B1%E9%85%8D%E4%BF%A1%E3%81%AE%E3%82%A2%E3%83%97%E3%83%AA%E3%81%A8%E3%81%97%E3%81%A6%E6%B4%BB%E7%94%A8%E3%81%97%E3%81%A6%E3%81%84%E3%81%8D%E3%81%BE%E3%81%99-c0c7ced6a564?source=rss-c781a202ce0a------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0c7ced6a564</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[droidkaigi]]></category>
            <category><![CDATA[conference]]></category>
            <dc:creator><![CDATA[takahirom]]></dc:creator>
            <pubDate>Mon, 23 May 2022 06:09:10 GMT</pubDate>
            <atom:updated>2022-05-23T06:09:10.018Z</atom:updated>
            <content:encoded><![CDATA[<p>DroidKaigi co-organizer の @<a href="https://medium.com/u/c781a202ce0a">takahirom</a> です。</p><p>今年もDroidKaigi公式アプリの開発を始めています。DroidKaigiでは毎年開催している大きなイベントだけでなく、LT会やポッドキャスト配信などさまざまなコンテンツを配信しています。今年の公式アプリでは、みなさんにそのようなイベントの情報を届けていくアプリとして去年開発したアプリを活用した開発を採用しています。</p><p>現状のDroidKaigi公式アプリの開発状況は、DroidKaigi 2021のアプリをforkしたリポジトリを作成し、様々な通知とその通知内容を表示できる機能を追加しています。これをもとに各種情報の配信をできるようにしていこうとしています。</p><p><a href="https://github.com/DroidKaigi/droidkaigi-feed-reader-app">DroidKaigi/droidkaigi-feed-reader-app</a></p><p>DroidKaigi公式アプリの各種機能はDroidKaigiスタッフの <a href="https://github.com/yurihondo">@yurihondo</a> さんと <a href="https://github.com/matsujun">@matsujun</a> さんがメインのアプリの開発を担当し、<a href="https://github.com/RyuNen344">@RyuNen344</a> さんがサーバーサイ ドの開発を担当しています。iOSのアプリも開発を進めており、 <a href="https://github.com/ry-itto">@ry-itto</a> さんが中心となって開発しています。DroidKaigiやAndroidの情報を配信することに貢献していただいています。</p><p>これに伴い、2021のアプリはメンテナンスされなくなりますが、<a href="https://github.com/DroidKaigi/droidkaigi-feed-reader-app">DroidKaigi/droidkaigi-feed-reader-app</a>にてコントリビュートを受け付けています！</p><p><a href="https://github.com/DroidKaigi/droidkaigi-feed-reader-app">DroidKaigi/droidkaigi-feed-reader-app</a></p><p>現在は最初のリリースにむけて準備中になります。今後も順次追加機能を開発していきますので、アプリをインストールしてお待ち下さい。</p><p><a href="https://play.google.com/store/apps/details?id=io.github.droidkaigi.feeder">https://play.google.com/store/apps/details?id=io.github.droidkaigi.feeder</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0c7ced6a564" width="1" height="1" alt=""><hr><p><a href="https://medium.com/droidkaigi/droidkaigi-2021%E3%82%A2%E3%83%97%E3%83%AA%E3%82%92droidkaigi%E3%81%AE%E6%83%85%E5%A0%B1%E9%85%8D%E4%BF%A1%E3%81%AE%E3%82%A2%E3%83%97%E3%83%AA%E3%81%A8%E3%81%97%E3%81%A6%E6%B4%BB%E7%94%A8%E3%81%97%E3%81%A6%E3%81%84%E3%81%8D%E3%81%BE%E3%81%99-c0c7ced6a564">DroidKaigi 2021アプリをDroidKaigiの情報配信のアプリとして活用していきます</a> was originally published in <a href="https://medium.com/droidkaigi">DroidKaigi</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cautions for using classes of other modules as arguments of Composable functions in Jetpack Compose]]></title>
            <link>https://medium.com/@takahirom/cautions-for-using-classes-of-other-modules-as-arguments-of-composable-functions-in-jetpack-compose-b26f1e1dfc9d?source=rss-c781a202ce0a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b26f1e1dfc9d</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[takahirom]]></dc:creator>
            <pubDate>Sun, 27 Mar 2022 08:07:55 GMT</pubDate>
            <atom:updated>2022-03-27T22:26:12.550Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oELYtgVo5b_yMLixmIUW1Q.jpeg" /><figcaption><a href="https://unsplash.com/@ros160?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a>-<a href="https://unsplash.com/s/photos/hole?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">rosarionuñez</a></figcaption></figure><p>Compose skips the Composable function in a nice way when the same object is passed as an argument.<br>However, there is a condition for this.</p><p>Suppose you have an app module and a model module.<br>The app module has Compose applied and has Composable functions.<br>The model module has a simple Article class.</p><p>Of these, only Composable2 skips over the same object when it is properly passed. 😵</p><pre>app module ------------&gt; model module<br>fun Composable1()        class Articles<br>fun Composable2()        class Article<br>fun Composable3()</pre><p>app module</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/971efe70fb985b4c9e850a5f926e4b64/href">https://medium.com/media/971efe70fb985b4c9e850a5f926e4b64/href</a></iframe><p>model module</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1dcf3a6a81d16c36033cb08b2171e759/href">https://medium.com/media/1dcf3a6a81d16c36033cb08b2171e759/href</a></iframe><p>This can be verified by using <a href="https://github.com/androidx/androidx/blob/androidx-main/compose/compiler/design/compiler-metrics.md">Compose Compiler Metrics</a>. If it is restartable and not skippable, it will not be skipped even if the arguments are the same.</p><p>app_release-composables.txt</p><pre>restartable fun Composable1(<br>  unstable articles: Articles<br>)<br>restartable skippable fun Composable2(<br>  stable uiModel: UiModel<br>)<br>restartable fun Composable3(<br>  unstable article: Article<br>)</pre><h3>What should we do?</h3><p>Three solutions are possible.</p><h4>Solution 1: Wrap in a class that is @Stable.</h4><p>The first is to wrap it in a UiModel class like a Composable2 function. This works well by informing Compose that this object will not be modified. In this case, you should always be aware of wrapping in a Stable class while developing.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f829b3d080a5b45090da3123aa01ef8d/href">https://medium.com/media/f829b3d080a5b45090da3123aa01ef8d/href</a></iframe><h4>Solution 2: Run the Compose compiler even on modules with models.</h4><p>The way to do this is to run the Compose compiler also in the model module where these Articles, etc. are located.<br>This allows Compose to know about this Article and other classes, so it works well.<br>However, this also requires dependency of the Compose runtime, so if you treat Jetpack Compose as a UI framework, it may be a bit confusing in terms of separation from the UI. (If you consider the Composable mechanism as a mechanism to manage whether this change is possible or not, it may be considered acceptable to include it.)</p><p><a href="https://github.com/takahirom/compose-multi-module-stability/commit/a4a1a34ec769a8524309a2205f43b8f28ce6e633#diff-1fcd54ff839a5ae2ba602b56b215fe6c8202961396253435a3d6995814aa5d35R23">Apply compose compiler and runtime dependency · takahirom/compose-multi-module-stability@a4a1a34</a></p><p>However, even in this case, fun Composable1(articles: Articles) will not prevent Recompose. This is because List can be an instance of MutableList(ArrayList) and not Stable. However, this is the same problem no matter which solution is used.</p><pre>unstable class Articles {<br>  unstable val articles: List&lt;Article&gt;<br>  &lt;runtime stability&gt; = Unstable<br>}</pre><p><a href="https://github.com/takahirom/compose-multi-module-stability/commit/197ebe042cf2b55df7c164d23367b021464f117b#diff-7f18668c77db7822092fe2dd092247c3b68961fe7cd67db3cdd83b5efb828409R1-R4">Add model metrics · takahirom/compose-multi-module-stability@197ebe0</a></p><h4>Solution 3: Convert to a UI model.</h4><p>Of course, doing this and using a class in the UI solves the problem. This allows for the separation of concerns.<br>But, of course, it is not only a benefit, but also a cost, as this means implementing, testing, reviewing, and maintaining the mapping in every development.</p><p>(This is also mentioned in the Guide to app architecture. <a href="https://developer.android.com/jetpack/guide/data-layer?hl=en#business-models">https://developer.android.com/jetpack/guide/data-layer?hl=en#business-models</a> )</p><h3>Summary</h3><p>Each of these solutions has its own merits and demerits, so I think it is a good idea to take the method you think you can take from this list.</p><p>Morisan noticed it in the product and told me about the problem, and I looked into it<br>Original story (the one I asked about)</p><p><a href="https://app.slack.com/client/T09229ZC6/CJLTWPH7S">Slack</a></p><p>Source code for this example</p><p><a href="https://github.com/takahirom/compose-multi-module-stability">GitHub - takahirom/compose-multi-module-stability</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b26f1e1dfc9d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use Kotlin OptIn annotation for safe release in trunk-based development]]></title>
            <link>https://medium.com/@takahirom/use-kotlin-optin-annotation-for-safe-release-in-trunk-based-development-72b2d8923538?source=rss-c781a202ce0a------2</link>
            <guid isPermaLink="false">https://medium.com/p/72b2d8923538</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[trunk-based-development]]></category>
            <dc:creator><![CDATA[takahirom]]></dc:creator>
            <pubDate>Tue, 01 Mar 2022 00:50:37 GMT</pubDate>
            <atom:updated>2022-03-01T02:41:43.612Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*t-dFkxpK1frfSKk-.jpg" /></figure><p>It is common to use Feature Flag to control the features under development and put them into the master branch when you are developing.</p><p>In large-scale feature development, you may end up creating bugs by calling features without checking them, which you may only want to use after checking them with flags.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4002c3a163db715220f40c93088b969f/href">https://medium.com/media/4002c3a163db715220f40c93088b969f/href</a></iframe><p>Ideally, these functions should be encapsulated in classes so that they are not visible, but that can be difficult for large features.</p><h3>Proposal</h3><p>Here’s what I came up with, using Kotlin’s OptIn. This allows you to check if you are calling the wrong thing at compile time.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbf5a73767f7b7df65d1d0e48cafb89c/href">https://medium.com/media/fbf5a73767f7b7df65d1d0e48cafb89c/href</a></iframe><p>You then use the feature with the OptIn annotation to check that it is enabled for handling.<br>In this way, you can introduce new features while checking them at compile time.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97ec0280bcf483224bdb78173e6917a0/href">https://medium.com/media/97ec0280bcf483224bdb78173e6917a0/href</a></iframe><p>This usage is just my own idea, but it works well in my project. I’d like to hear any feedback on it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72b2d8923538" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jetpack Compose State Guideline]]></title>
            <link>https://medium.com/@takahirom/jetpack-compose-state-guideline-494d467b6e76?source=rss-c781a202ce0a------2</link>
            <guid isPermaLink="false">https://medium.com/p/494d467b6e76</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android-jetpack]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[takahirom]]></dc:creator>
            <pubDate>Sat, 04 Dec 2021 10:25:05 GMT</pubDate>
            <atom:updated>2021-12-10T01:05:29.029Z</atom:updated>
            <content:encoded><![CDATA[<h4>This article presents the information provided on the official website of Jetpack Compose in the form of guidelines</h4><p>There are a lot of guidelines in the official documentation, but it is not a DO DON’T format guideline. Therefore, I would like to summarize them to facilitate the development of Compose.</p><p>If you have any feedback, please let me know. I would like to revise the article.</p><p>References</p><p>Android Developers <a href="https://developer.android.com/jetpack/compose/state#managing-state">https://developer.android.com/jetpack/compose/state</a></p><p>A Compose state of mind: Using Jetpack Compose’s automatic state observation <a href="https://www.youtube.com/watch?v=rmv2ug-wW4U">https://www.youtube.com/watch?v=rmv2ug-wW4U</a></p><p>Codelab <a href="https://developer.android.com/codelabs/jetpack-compose-state#0">https://developer.android.com/codelabs/jetpack-compose-state#0</a></p><h3>Compose Basics</h3><p>This section is not a Compose Guideline, but rather an explanation of the basic usage of Compose, which is required when implementing an application using Compose.</p><h3>1: Changes in the state of the UI must be observable by Compose.</h3><p><strong>What is State in the first place?</strong></p><blockquote>State in an app is any value that can change over time. This is a very broad definition and encompasses everything from a Room database to a variable on a class.</blockquote><p><a href="https://developer.android.com/jetpack/compose/state?hl=en">https://developer.android.com/jetpack/compose/state?hl=en</a></p><p>If the app is a news app, the article is the state. If the app has a switch, the state is whether the switch is on or not. <strong>Basically, most of the apps use “State”</strong>.</p><p>To make State changes observed by Compose,<strong> it is necessary to use MutableState or collectAsState() to use Compose’s State instead of Kotlin’s var variables.</strong></p><p>Declaring a variable in Compose using Kotlin’s var does not work well because the change is not observed by Compose.</p><p>❌ DON’T</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17092eb4421acd347a034d37f05aceaf/href">https://medium.com/media/17092eb4421acd347a034d37f05aceaf/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/145/1*Y5sB_rvAiXgSm-N7u8r89g.gif" /><figcaption>Changes are not reflected. Does not work as a switch 😭</figcaption></figure><p>⭕️ DO</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05eb0f8bfea00ee8158d5481e1da3c1f/href">https://medium.com/media/05eb0f8bfea00ee8158d5481e1da3c1f/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/145/1*HDfnjpfau0k3hoCXzCXN6A.gif" /></figure><p><strong>Why</strong></p><p>Because state changes are not reflected and do not work.</p><h3>Why does the DO example work so well?</h3><p>Actually, the <strong>`DO` function of MySwitch is recomposed(re-executed)</strong> when the state is changed. However, the `DON’T` function is not recomposed.<br>Let’s put `println()` and see if the DO example really works again.</p><p>DO Example</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf35f2bca7d021566089c28308969aa3/href">https://medium.com/media/bf35f2bca7d021566089c28308969aa3/href</a></iframe><p>You can see that MySwitch() is re-run as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*pZ7ngva6Hm7znne7Bf_eNg.gif" /></figure><h3>Why does MySwitch() get rerun?</h3><p>The next question you may be wondering is how it is re-executed, right?</p><p>If you go to the MutableState implementation, you will see the following implementation: In Jetpack Compose, <strong>State value is set to custom setter or custom getter, which means it is not just a variable, but it is processed</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F_wgX3UYHjZz-Min" /><figcaption>From SnapshotMutableStateImpl</figcaption></figure><p>In other words, Jetpack Compose monitors the read of the State value, and <strong>Jetpack Compose keeps the function that reads the value for the MutableState</strong>, so it can call the function that reads the State when the MutableState is changed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/0*bEFXWFhwDakd3D1U" /><figcaption>Figure showing that Compose runtime knows that `MySwitch()` got MutableState.value.</figcaption></figure><h3>2 States created in Composable must be remembered</h3><p>You need to use `remember{}` for states created in Composable function.<br>Using `remember{}` allows you to keep the data in Compose.</p><p>❌DON’T</p><p>The changes are not reflected as in the previous example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45b6c5d828123f12f8424375e14a197e/href">https://medium.com/media/45b6c5d828123f12f8424375e14a197e/href</a></iframe><p>⭕️ DO</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb092de819692184c224448e002a7cca/href">https://medium.com/media/bb092de819692184c224448e002a7cca/href</a></iframe><p><strong>Why</strong></p><p>Again, let’s see if `MySwitch()` is working properly in the DON’T example by putting `println()` in `MySwitch()`.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b73f0ab4d5a5bd14e96fba0bdd2d60ed/href">https://medium.com/media/b73f0ab4d5a5bd14e96fba0bdd2d60ed/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*F80IXVFwDYYk3x0s4z6uyA.gif" /></figure><p>It seems that `MySwitch()` is being recomposed. However, <strong>the value of MutableState is not changed.</strong></p><p>The MutableState is used and the change is detected and the function is recomposed, but the state created in the Composable is not retained without using remember, so a new MutableState(false) is created and the state is not retained.<br>You can see that each time the HashCode of the instance changes, <strong>the MutableState is recreated each time.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9xHayN7JU25foney" /></figure><h3>Where is it stored when I do remember{}?</h3><p>To understand this, you need to understand <strong>Composition</strong> first.<br>Compose composes a Composition by executing a Composable function at runtime.<br>Composition is a tree structure, for example, the following Composable function will compose a Composition as shown in the figure below.</p><pre><a href="http://twitter.com/Composable">@Composable</a><br>fun MyComposable() {<br>   ​Column {<br>       ​Text(&quot;Hello&quot;)<br>       ​Text(&quot;World&quot;)<br>   ​}<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MTRFmCGqQVHEoxaM" /></figure><p>This Composition can hold not only UI elements but also data, which is saved by `remember{}`.</p><p>Let’s go back to our example, what would this Composition look like if it were not remembered?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45b6c5d828123f12f8424375e14a197e/href">https://medium.com/media/45b6c5d828123f12f8424375e14a197e/href</a></iframe><p>In the following example, there is a Switch() as a child of MySwitch().<br>The MutableState is not stored in Composition.</p><pre>MySwitch<br>└── Switch</pre><p>So what happens if you use `remember{}`?</p><pre>MySwitch<br>├── **MutableState (var checked)**<br>└── Switch</pre><p>If you use `remember{}` in this way, the MutableState is saved in this Composition. Since `remember{}` holds the value at the time MySwitch enters the Composition and uses it in the next and subsequent calls, it is saved and used.</p><p><a href="https://developer.android.com/jetpack/compose/state#state-in-composables">https://developer.android.com/jetpack/compose/state#state-in-composables</a></p><blockquote>Composable functions can store a single object in memory by using the remember composable. <strong>A value computed by remember is stored in the Composition during initial composition, and the stored value is returned during recomposition.</strong> remember can be used to store both mutable and immutable objects.</blockquote><h3>3: Let’s use Kotlin’s Delegated Property to access the State.</h3><p>❌DON’T</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f74cc57910a28030034eccfd433bfa53/href">https://medium.com/media/f74cc57910a28030034eccfd433bfa53/href</a></iframe><p>⭕️DO</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32f55375eb330428f622b424330a67a5/href">https://medium.com/media/32f55375eb330428f622b424330a67a5/href</a></iframe><p><strong>Why</strong></p><p>In Kotlin, there is a feature called Delegated Property, which simply eliminates the need to access the value property every time. So, let’s use it for easy writing.</p><h3>4: State changes must not be made in the scope of a Composable function.</h3><p>❌DON’T</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/584c50c8a773f86c3763ac74f4ac4fd0/href">https://medium.com/media/584c50c8a773f86c3763ac74f4ac4fd0/href</a></iframe><p>⭕️DO</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e327b6e1fca35b3622433ffe7ec0cd23/href">https://medium.com/media/e327b6e1fca35b3622433ffe7ec0cd23/href</a></iframe><p><strong>Why</strong></p><p>In this example, `MySwitch()` will be called again infinitely as checked is changed, and the switch will keep blinking. This is to prevent such an accident.<br> The lambda we are passing to `onCheckedChange` is not a Composable function, so it is safe to change it in that lambda.<br>If you want to handle changing the State when `MySwitch()` enters or exits a Composition, you should consider using the SideEffect function.</p><p><a href="https://developer.android.com/jetpack/compose/side-effects?hl=ja">https://developer.android.com/jetpack/compose/side-effects</a></p><h3>Guidelines for State Management in Compose</h3><h4><strong>Practices related to state hoisting</strong></h4><p>State hoisting is a pattern that makes a component stateless by moving the state up, and when adapted to a composable function, it usually means introducing the following two arguments</p><pre>value: T Data to display<br>onValueChange: (T) -&gt; Unit Event to request a change in the value</pre><h3>5: Make Composable functions reusable and testable with State hoisting</h3><p>⭕️DO</p><p>Screen() flows the data to MySwitch(), and Screen() receives the events of MySwitch().</p><p>checked: Boolean<br>onCheckChanged: (Boolean) -&gt; Unit</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e416e01b234732c604fa8eed83f50f98/href">https://medium.com/media/e416e01b234732c604fa8eed83f50f98/href</a></iframe><p>❌DON’T</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/39b88ad296ed044db610cbda141b9b6d/href">https://medium.com/media/39b88ad296ed044db610cbda141b9b6d/href</a></iframe><p><strong>Why</strong></p><p>As the title says, to make it reusable and testable.<br>For example, let’s say you want to start this Switch state from ON first from a saved state. But you can’t do that with this, so you can’t use it with other buttons. Also, since it only has an internal state, it is difficult to check it by adding values in tests.</p><h3>6: Use state hosting to change to single source of truth. State should be hoisted to at least the lowest common parent of all composables that use the state.</h3><p>This time, I lined up the text on the side to show whether it was “ON” or “OFF”.</p><p>⭕️DO</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed53b6eefddee98319b22885b229fda8/href">https://medium.com/media/ed53b6eefddee98319b22885b229fda8/href</a></iframe><p>❌DON’T</p><p>I’m using initialChecked and other methods to manage the data in MySwitch(). This is reusable, and maybe we can write a test for it? What do you think will happen with this code?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba3ca2486c5531c5260ef5822995a9a0/href">https://medium.com/media/ba3ca2486c5531c5260ef5822995a9a0/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/145/1*XUawilXYjj2NLYHnx2ZL2w.gif" /></figure><p><strong>Pressing the text does not update</strong> <strong>the checkbox</strong> and is buggy.😇</p><p><strong>Why State hoisting?</strong></p><p>As mentioned in the title, this is because it is possible to have a single source of truth. <br>In order to prevent bugs like this one, it is important to prevent duplication of states, reduce the number of state changes to a single point, and keep the unchangeable states flowing. This is a method of structuring called single source of truth. State hoisting makes this possible.</p><p><strong>Why should State be hoisted to at least the lowest common parent of all composables that use the state</strong></p><p>The common parent here will be the Composite function of Screen(), and the DO example has State here.<br>In the DO example, we have State here because it is difficult to make it a single source of truth if it is not the common parent.</p><h3>7: Pass only the necessary arguments to the Composable function</h3><p>By separating the Stateless and Stateful functions, we can pass only the arguments we need.</p><p>⭕️ DO</p><p>Separate the Stateless and Stateful ViewModel, and pass only the necessary data to the stateless Composable function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4694363233f93e3cbe2beebd624a0df1/href">https://medium.com/media/4694363233f93e3cbe2beebd624a0df1/href</a></iframe><p>❌DON’T</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa94ace935cd1e4adfa0785326ae55a7/href">https://medium.com/media/fa94ace935cd1e4adfa0785326ae55a7/href</a></iframe><p><strong>Why</strong></p><ul><li>Stateless Composable can be easily previewed and tested. (In this case, we only have one button, so we can just preview MySwitch(), but if we have a lot of items on the screen, it will be a lot of work🤔)</li><li>The Composable function can be reused when it needs to be reused.</li></ul><h3>8: Try not to pass the state held in Composition to the ViewModel of Architecture Component</h3><p>❌DON’T</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4797a1014c743bd735f2b93d7076e1d6/href">https://medium.com/media/4797a1014c743bd735f2b93d7076e1d6/href</a></iframe><p><strong>Why</strong></p><p>This is because the lifecycle of ViewModel and Composition is different, and ViewModel lives longer, so if you have scaffoldState in ViewModel, ViewModel will continue to have the old scaffoldState and leak.</p><h3>9: Try to prevent logic from being written in Composable functions.</h3><p>This guideline is not necessary in this example because it is not complicated at all, but if the Composable becomes more complex, it will need to be split.<br>Let’s say we change the Snackbar to display when the check is changed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/1*epYe6N31BUIvc6s6lBmegA.gif" /></figure><p>❌DON’T</p><p>It’s still quite simple, but various processes are coming into the Composable function of SettingScreen() 😭</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/330194fe115f044610f8f0829ef1b867/href">https://medium.com/media/330194fe115f044610f8f0829ef1b867/href</a></iframe><p>⭕️DO</p><p>Using the State holder, I was able to separate the logic quite a bit, and the Composable function became quite simple.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee9a9c43e740a96d618e3bd13d15146e/href">https://medium.com/media/ee9a9c43e740a96d618e3bd13d15146e/href</a></iframe><p><strong>Why</strong></p><p>This is for separation of concerns.</p><p>A famous Android developer also said that when designing Compose UI, you need to be careful because Compose tends to mix business logic with UI.</p><p><a href="https://youtu.be/nVTSyLnv_4w?t=1387">https://youtu.be/nVTSyLnv_4w?t=1387</a></p><p>The Android Developers provided the following guidelines on how to separate the logic.</p><pre>* Composables for simple UI element state management.<br>* State holders for complex UI element state management. They own UI elements&#39; state and UI logic.<br>* Architecture Components ViewModels as a special type of state holder in charge of providing access to the business logic and the screen or UI state.</pre><p>You can also have dependencies as follows</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*EK4PnlMZ64sCe2ak" /></figure><p><a href="https://developer.android.com/jetpack/compose/state#managing-state">https://developer.android.com/jetpack/compose/state#managing-state</a></p><p>State holders are used to manage the states of complex UI elements, and in this case, they are needed because the role of Snackbar management has become more complex with the addition of Composable.<br>As you can see, the more complex the UI, the more you need a state holder.</p><h3>Summary</h3><ul><li>What is State? “All values that may change over time”.</li><li>I introduced 9 guidelines to manage State in Jetpack Compose.</li><li>How to use Jetpack Compose to manage State. <br>You need to understand Jetpack Compose to run it properly.</li><li>The basic idea is Single source of truth and separation of concerns. It may be useful to know them even outside of Compose.</li></ul><p>If you have any feedback, please let me know. I would like to revise the article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=494d467b6e76" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding the Jetpack Compose layout with diagrams]]></title>
            <link>https://medium.com/@takahirom/understanding-the-jetpack-compose-layout-with-diagrams-1b7311765841?source=rss-c781a202ce0a------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b7311765841</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[takahirom]]></dc:creator>
            <pubDate>Wed, 10 Nov 2021 01:31:11 GMT</pubDate>
            <atom:updated>2021-11-10T01:31:11.552Z</atom:updated>
            <content:encoded><![CDATA[<p>I would like to s use this diagram to remind me of how it works when using custom layouts.</p><p>Here’s a simple example to illustrate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WhwCIS_T5oCLOL-vg6r8sQ.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd8450b479580d0bcedb21aa04213227/href">https://medium.com/media/bd8450b479580d0bcedb21aa04213227/href</a></iframe><p>The layout consists of three parts.</p><ul><li>Measure children</li><li>Decide own size</li><li>Place children</li></ul><p>This is also mentioned in Deep dive into Jetpack Compose layouts.<a href="https://youtu.be/zMKMwh9gZuI?t=344"> https://youtu.be/zMKMwh9gZuI?t=344</a></p><p>The following diagram shows how this works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RwHyXQWIESL9saJd31AhxQ.png" /></figure><p>At first, MeasureScope.mesure() will be called, which is passed as the Layout argument.</p><p>Then, “Measure children” is done first. For Box 1, this is done in (1), (3), (4), and (9).</p><p>This function calls measure() on the measurables passed as arguments. At this time, constraints is passed, which contains the minimum height, maximum height, minimum width, and maximum width.</p><p>Example of constraints</p><pre>Constraints(minWidth = 1080, maxWidth = 1080, minHeight = 275, maxHeight = 275)</pre><p>Example of measure children</p><pre>Layout(<br>    content = <strong>{ </strong>content() <strong>}</strong>,<br>    modifier = modifier<br>) <strong>{ </strong>measurables: List&lt;Measurable&gt;,<br>    constraints: Constraints <strong>-&gt;<br>    </strong><em>// ① Measure children<br>    </em>val placeables = measurables.<em>mapIndexed </em><strong>{ </strong>index, measurable <strong>-&gt;<br>        </strong>measurable.measure(constraints)<br>    <strong>}</strong></pre><p>The next step is to “Decide own size”. For Box1, this is done in (10)</p><p>Since we know the size of the child’s layout in Step 1, we can use that size to determine the size of our own layout.</p><p>It then calls layout{} with the calculated size.</p><pre>// ② Decide own size(simplified)<br>val height = placeables.sumOf { it.height }<br>val width = placeables.maxOf { it.width }<br>val layout = layout(width, height) {<br>...<br>}<br>return layout</pre><p>The last step is to “Place children”. For Box1, this is done in (13) ,(14)</p><p>In the layout{} block, we use Placable, which is the return value of the measure() call in Step 1, and determine the position of the child layout by calling place() on Placable.</p><pre>val layout = layout(width, height) {<br>    // ③ Place children<br>    var y = 0<br>    placeables.forEach { placable: Placeable -&gt;<br>        placable.placeRelative(x = 0, y = y)<br>        y += placable.height<br>    }<br>}</pre><p>This diagram will help you understand how they are all connected.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b7311765841" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Inside Jetpack Compose]]></title>
            <link>https://medium.com/@takahirom/inside-jetpack-compose-2e971675e55e?source=rss-c781a202ce0a------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e971675e55e</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[takahirom]]></dc:creator>
            <pubDate>Sun, 17 Oct 2021 09:58:07 GMT</pubDate>
            <atom:updated>2021-10-18T03:00:10.130Z</atom:updated>
            <content:encoded><![CDATA[<p>I’m debugging as much as I can just to be sure, but please let me know if I’m writing something wrong.</p><h3>Why learn Inside Jetpack Compose?</h3><p>Jetpack Compose works like magic. For example, it works without any return value and automatically uses differential updates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/0*jNOqkrnAJsUt-rCT" /></figure><p>from: <a href="https://d.android.com/jetpack/compose">https://d.android.com/jetpack/compose</a></p><p>The primary reason is my interest to know how Jetpack Compose works.</p><p>However, considering that it will become the de facto standard for Android development in the future, I believe that knowing what’s inside first was not a waste of time in developing Android applications so far.</p><p><strong>Also, as I found out through this article, the implementation of the Jetpack Compose content is very interesting and I want you to know about it.</strong></p><h3>How do we learn?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iqzJqH64JNuhne5g" /><figcaption>Code for integration between Android and Jetpack Compose</figcaption></figure><p>If you try to use Jetpack Compose on Android as it is and check it out, you will have to look at a lot of Android integration code. But this time I want to know how Compose works, but I can’t easily concentrate on the part of Jetpack Compose that I want to read.</p><p>from: <a href="https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/Wrapper.android.kt;drc=196281eb061d6e3eb1ad2f05b4cb8c5e5fbdd70f">https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/Wrapper.android.kt;drc=196281eb061d6e3eb1ad2f05b4cb8c5e5fbdd70f</a></p><p>Jetpack Compose is an Android toolkit for UI development, but its internal mechanism is also used in Jetpack Compose for Web and other applications.<br><strong>I will show a simple sample code using Jetpack Compose and explain how it works to deepen your understanding of how it works.</strong></p><h3>Introducing the code to process tree structures in a simple way using Jetpack Compose, which will be the example for this article</h3><p>✅ The entire code, including the other functions, can be found here, so if this introduction is hard to read, just look at the code.<br>It’s only about 130 lines long, so it shouldn’t be too difficult.</p><p><a href="https://github.com/takahirom/simple-compose-for-learning-inside-compose/blob/873568ae64965d50cd68abe238e1c5dcb6b30fcc/src/main/kotlin/com/github/takahirom/compose/Main.kt#L82-L92">simple-compose-for-learning-inside-compose/Main.kt at 873568ae64965d50cd68abe238e1c5dcb6b30fcc · takahirom/simple-compose-for-learning-inside-compose</a></p><p>This time I will use a simple sample for illustration, just println() will print the tree.</p><p>The following is what the tree looks like, and Node1 will disappear.</p><pre>RootNode<br>├── Node1(value=node1)<br>└── Node2(value=node2)</pre><p>↓ Three seconds later</p><pre>RootNode<br>└── Node2(value=node2)</pre><p>In the following code, which requires a bit of basic Compose knowledge, the Content() function is a `Composable function`, and the `LaunchedEffect{}` changes the `state` to false 3 seconds after launching Kotlin Coroutines, which makes Node1 disappear.</p><p><strong>Keep this Content() function in mind as it will come up again and again</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab22b077e7ea94f2f916801e26dd459e/href">https://medium.com/media/ab22b077e7ea94f2f916801e26dd459e/href</a></iframe><p>Let’s see how the above code can be made possible with Jetpack Compose.</p><p>First of all, we need a node for the tree to be able to output as shown above.<br>For that, we will simply define a Node class.<br>Here, we have a Node class as the parent class and RootNode, Node1, and Node2 as the child classes.<br>This class is a simple class that does not inherit from any Jetpack Compose class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/856e610119f9c9c13359ef4cc33bb92a/href">https://medium.com/media/856e610119f9c9c13359ef4cc33bb92a/href</a></iframe><p><strong>We need to make Jetpack Compose create a tree structure of these Nodes, but how?</strong></p><p>Applier is a class that is used by Jetpack Compose to manipulate tree structures.<br>Applier is a class that handles tree operations in Jetpack Compose, such as adding, moving, and deleting children of Node.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f06f93374f528ab655db81a53ea2d54/href">https://medium.com/media/0f06f93374f528ab655db81a53ea2d54/href</a></iframe><p>In order to use this Applier to add a Node, we need to have Compose manage the Node.<br>By using ReusableComposeNode, we can add a Node within the Compose mechanism.<br>In ReusableComposeNode, we create a Node with the argument “factory”, and pass the changes with the argument “update”.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd5b2b86ab6c5e5c7756da6611e56574/href">https://medium.com/media/bd5b2b86ab6c5e5c7756da6611e56574/href</a></iframe><p>Now you just need to run the mechanism to execute the above code and it will work. You may be able to understand this area after the other explanations are finished.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e4fff5b3ac8b533c3b6bb08786ec155/href">https://medium.com/media/1e4fff5b3ac8b533c3b6bb08786ec155/href</a></iframe><h3>The overall picture presented in this article</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*uXqIVKtPReEJ3xuA8PGOIw.png" /></figure><p>This diagram can be found in the following repository</p><p><a href="https://github.com/takahirom/inside-jetpack-compose-diagram">GitHub - takahirom/inside-jetpack-compose-diagram</a></p><p>It looks like the following execution flow is taking place. This should help you understand the inner workings of Jetpack Compose.</p><p>At build time</p><ul><li>0. Change the Composable function to be able to create a SlotTable with the Compose Kotlin Compiler Plugin.</li></ul><p>After app launch</p><ul><li>1. Call the Composable function and store the information in the SlotTable</li><li>2. change to MutableState after 3 seconds</li><li>3. Snapshot System catches the change</li><li>4. Recompose</li><li>5. reflect changes to SlotTable using GapBuffer</li></ul><h3>Step 0. Change the Composable function to be able to create a SlotTable with the Compose Kotlin Compiler Plugin.</h3><p>Jetpack Compose can do a diff update. In order to do that, we need to have the information to be able to diff, right? This information is stored by the Composable function in a SlotTable (see below).<br>For this purpose, we will make some changes so that we can create a SlotTable.</p><p>In Android development, Kotlin is converted to Java bytecode, and then the Java bytecode is converted to dex format.<br>Jetpack Compose seems to rewrite this Kotlin IR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/0*04rADNYLsfVvoFNQ" /></figure><p>In other words, by decompiling the converted Java Bytecode, you can see the conversion result of the Compiler Plugin.</p><p>(I’ve created a Gradle Plugin Decomposer that allows you to easily see the results of this decompilation. )</p><p><a href="https://github.com/takahirom/decomposer">GitHub - takahirom/decomposer: Gradle Plugin that allows you to decompile bytecode compiled with Jetpack Compose Compiler Plugin into Java and check it</a></p><p>Let’s check out the lightly decompiled Composable function of Content().<br>You will notice that it has startRestartGroup(), endRestartGroup(), startReplaceableGroup(), and endReplaceableGroup(). Compose has an internal concept of Group. Compose has an internal concept of Group, which allows us to create a tree by Group.<br>It also allows you to register a function to be called again.<br>You can also see other characters such as skip that may allow you to skip the process.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f4805f5b0396bb692a767dbe64331e3/href">https://medium.com/media/9f4805f5b0396bb692a767dbe64331e3/href</a></iframe><h3>Step 1. Call the Composable function and store the information in the SlotTable</h3><p>Now, the app will actually start up, and functions such as `Content()` will be executed.<br>At this time, Jetpack Compose will store the data in something called SlotTable. In this article, we will not look at this step in too much detail because I will focus on the update part.<br>Jetpack Compose is capable of differential updates. In order to do that, we need to have the information to make the difference, right? This information is stored in a SlotTable by the Composable function.</p><h3>Learn about SlotTable</h3><p>The SlotTable consists of the following two data structures, which are used to store the tree structure of the Group.</p><pre>groups: IntArray<br>slots: Array&lt;Any?&gt;</pre><p>Now we have groups, which is the same word as “Group” in the previous example.<br>The IntArray of groups consists of five elements to form one group. Therefore, you can successfully retrieve the data by writing the following code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32a38a2e2de46236865ab3fb4b8f54d9/href">https://medium.com/media/32a38a2e2de46236865ab3fb4b8f54d9/href</a></iframe><p>The slots seem to contain the data held by the group.<br><strong>The index to the slots is stored in the “dataAnchor”, and the “parentAnchor” stores the index of the parent.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/0*ljcqZY51AMYpM93Y" /></figure><p>After startup, the SlotTable is created by calling the Composable function. The SlotTable will be created by calling the Composable function after startup. This is the data that will be stored immediately after startup.</p><p>groups</p><pre>index: 0, key: 100, groupInfo: 2, parentAnchor: -1, size: 16, dataAnchor: 0<br>index: 1, key: 1000, groupInfo: 2, parentAnchor: 0, size: 15, dataAnchor: 1<br>index: 2, key: 200, groupInfo: 536870914, parentAnchor: 1, size: 14, dataAnchor: 1<br>index: 3, key: -985533309, groupInfo: 2, parentAnchor: 2, size: 13, dataAnchor: 2<br>index: 4, key: -337788314, groupInfo: 268435458, parentAnchor: 3, size: 12, dataAnchor: 4<br>index: 5, key: -3687241, groupInfo: 268435456, parentAnchor: 4, size: 1, dataAnchor: 6<br>index: 6, key: -3686930, groupInfo: 268435456, parentAnchor: 4, size: 1, dataAnchor: 8<br>index: 7, key: 1036442245, groupInfo: 268435456, parentAnchor: 4, size: 2, dataAnchor: 11<br>index: 8, key: -3686930, groupInfo: 268435456, parentAnchor: 7, size: 1, dataAnchor: 12<br>index: 9, key: -337788167, groupInfo: 1, parentAnchor: 4, size: 4, dataAnchor: 15<br>index: 10, key: 1815931657, groupInfo: 1, parentAnchor: 9, size: 3, dataAnchor: 15<br>index: 11, key: 1546164276, groupInfo: 268435457, parentAnchor: 10, size: 2, dataAnchor: 16<br>index: 12, key: 125, groupInfo: 1073741824, parentAnchor: 11, size: 1, dataAnchor: 17<br>index: 13, key: 1815931930, groupInfo: 1, parentAnchor: 4, size: 3, dataAnchor: 19<br>index: 14, key: 1546164276, groupInfo: 268435457, parentAnchor: 13, size: 2, dataAnchor: 20<br>index: 15, key: 125, groupInfo: 1073741824, parentAnchor: 14, size: 1, dataAnchor: 21<br>index: 16, key: 0, groupInfo: 0, parentAnchor: 0, size: 0, dataAnchor: 0<br>index: 17, key: 0, groupInfo: 0, parentAnchor: 0, size: 0, dataAnchor: 0<br>index: 18, key: 0, groupInfo: 0, parentAnchor: 0, size: 0, dataAnchor: 0<br>index: 19, key: 0, groupInfo: 0, parentAnchor: 0, size: 0, dataAnchor: 0<br>index: 20, key: 0, groupInfo: 0, parentAnchor: 0, size: 0, dataAnchor: 0<br>index: 21, key: 0, groupInfo: 0, parentAnchor: 0, size: 0, dataAnchor: 0<br>index: 22, key: 0, groupInfo: 0, parentAnchor: 0, size: 0, dataAnchor: 0<br>index: 23, key: 0, groupInfo: 0, parentAnchor: 0, size: 0, dataAnchor: 0<br>index: 24, key: 0, groupInfo: 0, parentAnchor: 0, size: 0, dataAnchor: 0<br>index: 25, key: 0, groupInfo: 0, parentAnchor: 0, size: 0, dataAnchor: 0<br>index: 26, key: 0, groupInfo: 0, parentAnchor: 0, size: 0, dataAnchor: 0<br>index: 27, key: 0, groupInfo: 0, parentAnchor: 0, size: 0, dataAnchor: 0<br>index: 28, key: 0, groupInfo: 0, parentAnchor: 0, size: 0, dataAnchor: 0<br>index: 29, key: 0, groupInfo: 0, parentAnchor: 0, size: 0, dataAnchor: 0<br>index: 30, key: 0, groupInfo: 0, parentAnchor: 0, size: 0, dataAnchor: 0<br>index: 31, key: 0, groupInfo: 0, parentAnchor: 0, size: 0, dataAnchor: 0</pre><p>slots</p><pre>0: {}(class androidx.compose.runtime.external.kotlinx.collections.immutable.implementations.immutableMap.PersistentHashMap)<br>1: OpaqueKey(key=provider)(class androidx.compose.runtime.OpaqueKey)<br>2: androidx.compose.runtime.RecomposeScopeImpl@4fb4ae6(class androidx.compose.runtime.RecomposeScopeImpl)<br>3: androidx.compose.runtime.internal.ComposableLambdaImpl@3b52827(class androidx.compose.runtime.internal.ComposableLambdaImpl)<br>4: C(Content)(class java.lang.String)<br>5: androidx.compose.runtime.RecomposeScopeImpl@b882ad4(class androidx.compose.runtime.RecomposeScopeImpl)<br>6: C(remember):Composables.kt#9igjgp(class java.lang.String)<br>7: MutableState(value=true)<a href="http://twitter.com/167707773">@167707773</a>(class androidx.compose.runtime.ParcelableSnapshotMutableState)<br>8: C(remember)P(1):Composables.kt#9igjgp(class java.lang.String)<br>9: MutableState(value=true)<a href="http://twitter.com/167707773">@167707773</a>(class androidx.compose.runtime.ParcelableSnapshotMutableState)<br>10: Function2&lt;kotlinx.coroutines.CoroutineScope, kotlin.coroutines.Continuation&lt;? super kotlin.Unit&gt;, java.lang.Object&gt;(class com.github.takahirom.compose.MainKt$Content$1$1)<br>11: C(LaunchedEffect)P(1)336@14101L58:Effects.kt#9igjgp(class java.lang.String)<br>12: C(remember)P(1):Composables.kt#9igjgp(class java.lang.String)<br>13: kotlin.Unit(class kotlin.Unit)<br>14: androidx.compose.runtime.LaunchedEffectImpl@8d3f428(class androidx.compose.runtime.LaunchedEffectImpl)<br>15: androidx.compose.runtime.RecomposeScopeImpl@7421fc3(class androidx.compose.runtime.RecomposeScopeImpl)<br>16: C(ReusableComposeNode):Composables.kt#9igjgp(class java.lang.String)<br>17: Node1(name=node1)(class com.github.takahirom.compose.Node$Node1)<br>18: node1(class java.lang.String)<br>19: androidx.compose.runtime.RecomposeScopeImpl@81cf51f(class androidx.compose.runtime.RecomposeScopeImpl)<br>20: C(ReusableComposeNode):Composables.kt#9igjgp(class java.lang.String)<br>21: Node2(name=node2)(class com.github.takahirom.compose.Node$Node2)<br>22: node2(class java.lang.String)<br>23: null(null)<br>24: null(null)<br>25: null(null)<br>26: null(null)<br>27: null(null)<br>28: null(null)<br>29: null(null)<br>30: null(null)<br>31: null(null)</pre><p>By calling the `SlotTable#asString()` method, you can virtually see the data visualized in a tree structure.</p><pre>Group(0) key=100, nodes=2, size=16, slots=[0: {}]<br> Group(1) key=1000, nodes=2, size=15<br>  Group(2) key=200, nodes=2, size=14 objectKey=OpaqueKey(key=provider)<br>   Group(3) key=-985533309, nodes=2, size=13, slots=[2: androidx.compose.runtime.RecomposeScopeImpl@4fb4ae6, androidx.compose.runtime.internal.ComposableLambdaImpl@3b52827]<br>    Group(4) key=-337788314, nodes=2, size=12 aux=C(Content), slots=[5: androidx.compose.runtime.RecomposeScopeImpl@b882ad4]<br>     Group(5) key=-3687241, nodes=0, size=1 aux=C(remember):Composables.kt#9igjgp, slots=[7: MutableState(value=false)<a href="http://twitter.com/167707773">@167707773</a>]<br>     Group(6) key=-3686930, nodes=0, size=1 aux=C(remember)P(1):Composables.kt#9igjgp, slots=[9: MutableState(value=false)<a href="http://twitter.com/167707773">@167707773</a>, Function2&lt;kotlinx.coroutines.CoroutineScope, kotlin.coroutines.Continuation&lt;? super kotlin.Unit&gt;, java.lang.Object&gt;]<br>     Group(7) key=1036442245, nodes=0, size=2 aux=C(LaunchedEffect)P(1)336@14101L58:Effects.kt#9igjgp<br>      Group(8) key=-3686930, nodes=0, size=1 aux=C(remember)P(1):Composables.kt#9igjgp, slots=[13: kotlin.Unit, androidx.compose.runtime.LaunchedEffectImpl@8d3f428]<br>     Group(9) key=-337788167, nodes=1, size=4<br>      Group(10) key=1815931657, nodes=1, size=3, slots=[15: androidx.compose.runtime.RecomposeScopeImpl@7421fc3]<br>       Group(11) key=1546164276, nodes=1, size=2 aux=C(ReusableComposeNode):Composables.kt#9igjgp<br>        Group(12) key=125, nodes=0, size=1 node=Node1(name=node1), slots=[18: node1]<br>     Group(13) key=1815931930, nodes=1, size=3, slots=[19: androidx.compose.runtime.RecomposeScopeImpl@81cf51f]<br>      Group(14) key=1546164276, nodes=1, size=2 aux=C(ReusableComposeNode):Composables.kt#9igjgp<br>       Group(15) key=125, nodes=0, size=1 node=Node2(name=node2), slots=[22: node2]</pre><p><strong>The above data will be retained in the class SlotTable after startup.</strong></p><h3>Step 2, 3 change to MutableState after 3 seconds. Snapshot System catches the change</h3><p>The following code will run the change to MutableState.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3fa1e605a576bdebe0de7c7023d0a61e/href">https://medium.com/media/3fa1e605a576bdebe0de7c7023d0a61e/href</a></iframe><p>What does `by` mean, and what is `remember{}`? What is `mutableStateOf(true)`?<br>`remember{}` and `mutableStateOf(true)` are completely unrelated, but they work well together.<br>`remember{}` is something that extends the lifetime of an instance, and `by` is something due to Kotlin’s Delegated Property.<br>The details are different, but basically, the code is the same as below.</p><p>In other words, we are changing the value of MutableState.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9dce7189c29a0e218cd8dda38e288652/href">https://medium.com/media/9dce7189c29a0e218cd8dda38e288652/href</a></iframe><p>Now, let’s learn how Jetpack Compose catches the MutableState changes from another place by LaunchEffect.</p><h3>Learn about the Snapshot System</h3><blockquote>Also check out “Introduction to the Compose Snapshot system”<br><a href="https://dev.to/zachklipp/introduction-to-the-compose-snapshot-system-19cn">https://dev.to/zachklipp/introduction-to-the-compose-snapshot-system-19cn</a></blockquote><p>Let’s step away from the previous examples for a moment and learn about the Snapshot System. By learning this, we will be able to learn more about Compose.</p><p><a href="https://github.com/takahirom/compose-snapshot-sample/blob/main/src/main/java/Main.kt">compose-snapshot-sample/Main.kt at main · takahirom/compose-snapshot-sample</a></p><h3>How do we detect changes between frames?</h3><p>Compose uses the Snapshot System to detect changes.</p><p>Suppose we have a code like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/47195bfd9d407deca98c3c6b1054ab2d/href">https://medium.com/media/47195bfd9d407deca98c3c6b1054ab2d/href</a></iframe><p>You can play around with Snapshot by using Compose’s Runtime without Compose’s compiler.</p><p>What will be the output of the following code?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5127e28db962fd596e02ddfe0cc76fba/href">https://medium.com/media/5127e28db962fd596e02ddfe0cc76fba/href</a></iframe><p>The correct answer is that nothing will be output.</p><p>What happens in the following code with the addition of Snapshot.sendApplyNotifications()?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25dbefdb95a9e4accecddda44c917d9d/href">https://medium.com/media/25dbefdb95a9e4accecddda44c917d9d/href</a></iframe><p>By adding Snapshot.sendApplyNotifications(), the apply observer passed in registerApplyObserver() will respond</p><pre>registerApplyObserver:MutableState(value=one)<a href="http://twitter.com/1831932724">@1831932724</a></pre><p><strong>This mechanism is used by Jetpack Compose to handle the changes that accumulate in each frame. In this case, the Observer in registerApplyObserver() will be called when the MutableState is changed in LaunchEffect.</strong></p><p><strong>What happens when Compose is actually being recomposed, i.e. when it is calling `Content()`, etc., and is touched by another thread? </strong><br>If you have experience with Java, you may have an idea that this is a bad idea.<br>Jetpack Compose’s Snapshot System solves this problem.</p><h3>How does Jetpack Compose solve the problem of multithreading in MutableState?</h3><p>In fact, in the previous examples, we used a GlobalSnapshot that is held at the top level.<br>Compose will <strong>create a Snapshot with `Snapshot.takeMutableSnapshot()` and recompose within the Snapshot before calling `Content()` or other methods to recompose</strong>.</p><p>You can think of a Snapshot as saved data in a game.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f31da6bc75a21680aa2823f3cd68423/href">https://medium.com/media/2f31da6bc75a21680aa2823f3cd68423/href</a></iframe><p>You can create and use a Snapshot as follows.<br>Take a Snapshot with `Snapshot.takeMutableSnapshot()`.<br>While calling `enter{}` of the Snapshot, the data at the time of `Snapshot.takeMutableSnapshot()` is retrieved, so there is no problem of information being changed in the middle of the Snapshot.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/31040e7532976a15b52a138d7ade04c6/href">https://medium.com/media/31040e7532976a15b52a138d7ade04c6/href</a></iframe><p>Obviously, it was rewritten from another thread, but it’s not “changes from other thread”!</p><pre>in snapshot:MutableState(value=before snapshot)<a href="http://twitter.com/1777466639">@1777466639</a></pre><p><strong>So, what happens if we rewrite the state enter{} at the same time as the thread? In other words, what happens if there is a conflict between the changes?</strong></p><p>By calling Snapshot.apply(), we can reflect the changes in the Snapshot (in enter{}) to the GlobalSnapshot.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36fc0f0102b3d1b094b58fd56cddb9b5/href">https://medium.com/media/36fc0f0102b3d1b094b58fd56cddb9b5/href</a></iframe><p>It runs without error. And it looks like the other thread won.</p><pre>in snapshot before change:MutableState(value=before snapshot)<a href="http://twitter.com/1170114219">@1170114219</a><br>in snapshot after change:MutableState(value=change in snapshot)<a href="http://twitter.com/1170114219">@1170114219</a><br>after apply:MutableState(value=changes from other thread)<a href="http://twitter.com/1170114219">@1170114219</a></pre><p>In fact, MutableState has an argument called `SnapshotMutationPolicy`, which can be used to change the policy as shown below. In this way, it is possible to code for multi-threading.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5e6905119b626d2c76cb09c1e993125/href">https://medium.com/media/f5e6905119b626d2c76cb09c1e993125/href</a></iframe><pre>in snapshot before change:MutableState(value=before snapshot)<a href="http://twitter.com/2058170434">@2058170434</a><br>in snapshot after change:MutableState(value=change in snapshot)<a href="http://twitter.com/2058170434">@2058170434</a><br>after apply:MutableState(value=change in snapshot)<a href="http://twitter.com/2058170434">@2058170434</a></pre><h3>How does Compose find the Composable function that sees the MutableState that has changed?</h3><p>Compose finds the Composable function that is looking at the MutableState that has changed and calls it again (Reompose).<br>How do we do this? <br>`Snapshot.takeMutableSnapshot()` can be passed a readObserver as an argument.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/372c9d4d8ad9c08846ba3ec4d0858017/href">https://medium.com/media/372c9d4d8ad9c08846ba3ec4d0858017/href</a></iframe><p>It is quite simplified, but it is done by keeping the current Scope as a variable and rewriting it, as follows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db0585989b5e145309587745e8febef0/href">https://medium.com/media/db0585989b5e145309587745e8febef0/href</a></iframe><p>The following will be printed, showing that `MutableState(value=init)@1096979270` is seen by `Content()`, which is stored in `observations`.</p><pre>`MutableState(value=init)@1096979270` is observed by `Content()`</pre><p>In the decompiled code of Content(), the lambda for calling the function again was defined by CompilerPlugin, right? In fact, this is what is called when the MutableState is changed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5d404db5adef81ae6842839c8eaa60c/href">https://medium.com/media/b5d404db5adef81ae6842839c8eaa60c/href</a></iframe><p><strong>This allows us to detect changes, and scopes that need to be called back when they are changed. Now that we can get both, all that’s left is for Compose to call the function!</strong></p><h3>What is Snapshot after all?</h3><p>It seems to be called multiversion concurrency control (MVCC).</p><p><a href="https://en.wikipedia.org/wiki/Multiversion_concurrency_control">Multiversion concurrency control - Wikipedia</a></p><blockquote>Multiversion concurrency control (MCC or MVCC), is a concurrency control method commonly used by database management systems to provide concurrent access to the database and in programming languages to implement transactional memory.</blockquote><p>It seems to be a mechanism used in databases.<br>The comments on the Snapshot class also include a link to the following paper.</p><p><a href="https://arxiv.org/pdf/1412.2324.pdf">https://arxiv.org/pdf/1412.2324.pdf</a></p><p>How it is actually implemented is by using the ThreadLocal mechanism of Java.</p><h3>Step 4. Recompose</h3><p>The change detection in the Snapshot shows that there has been a change in `Content()`, so Content() is called again.<br>Here, the current state is stored in the SlotTable, and now this Node1 is about to disappear, but Node2 will remain intact.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/46f409bba7e675c38c2d4e18029fc24b/href">https://medium.com/media/46f409bba7e675c38c2d4e18029fc24b/href</a></iframe><h3>Call only those Composable functions that have been changed (donut-hole skipping)</h3><p><strong>But does Compose just call and rebuild where changes have been made? Compose has more amazing optimizations.</strong></p><p><strong>Skip the places where the data is the same as before. </strong><br>This is an optimization called `donut-hole skipping`, where `Content()` is re-executed as if it had a hole in it, but `Node2()` is not recomposed!</p><blockquote>Also check out “What is “donut-hole skipping” in Jetpack Compose?”<br><a href="https://www.jetpackcompose.app/articles/donut-hole-skipping-in-jetpack-compose">https://www.jetpackcompose.app/articles/donut-hole-skipping-in-jetpack-compose</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/0*Z23KGbTcvzRcEe-u" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/0*Z0rosFAh-nga8F4w" /></figure><p>Is this magic?<br>Some time ago, I mentioned that the following data is kept as a SlotTable. By comparing with this data, the optimization is done by not executing where there is no change.</p><pre>Group(0) key=100, nodes=2, size=16, slots=[0: {}]<br> Group(1) key=1000, nodes=2, size=15<br>...<br>     Group(13) key=1815931930, nodes=1, size=3, slots=[19: androidx.compose.runtime.RecomposeScopeImpl@81cf51f]<br>      Group(14) key=1546164276, nodes=1, size=2 aux=C(ReusableComposeNode):Composables.kt#9igjgp<br>       // **↓I won&#39;t recompose it because it&#39;s the same data I&#39;m holding here!**<br>       Group(15) key=125, nodes=0, size=1 node=Node2(name=node2), slots=[22: node2]</pre><p>This is actually the part of `composer.changed(name)` in the following bytecode, where the contents of the SlotTable are extracted and compared.</p><p>(In fact, it’s a little bit inaccurate around the default arguments, but we’ll skip that this time.)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea2eab297875ea1b0322b9082dd5f409/href">https://medium.com/media/ea2eab297875ea1b0322b9082dd5f409/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QtawQIcgrLuT3os2" /></figure><h3>How do we reflect the changes in the SlotTable?</h3><p>In the previous section, we talked about not rerunning the same part, but we need to keep the SlotTable up to date with changes.<br>While recomposing, the changes are stored in the change list, and finally reflected at once.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/0*bx55ZgzVgwHqKMLL" /></figure><h3>Step 5. Reflect changes to SlotTable using GapBuffer</h3><p>Now, let’s reflect the change list we’ve saved.<br>If you don’t think about it and just do it normally, it will look like this. It’s simple, and nothing seems to go wrong.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/0*NfdodYJFze61huik" /></figure><p>For example, what happens if there are three Nodes that disappear with the above algorithm?</p><p><strong>It will take a lot of time to erase each one because you need to shift the others one by one.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*r9msPobjdaaWFGIS" /></figure><p><strong>groups is an IntArray, so everything has to be shifted one by one for each operation. This is quite computationally expensive. A similar problem occurs when adding a group. </strong><br>In addition, even a relatively simple <a href="https://github.com/DroidKaigi/conference-app-2021">DroidKaigi app</a> has 371 groups, so this method may cause Compose to become heavy just by reflecting these groups. I’m not sure if this is a good idea or not 😂</p><p>In contrast, Jetpack Compose uses a mechanism called Gap Buffer. This is an algorithm used in text editors to save computation when adding or changing files in sequence.</p><p><a href="https://en.wikipedia.org/wiki/Gap_buffer">Gap buffer - Wikipedia</a></p><blockquote>A gap buffer in computer science is a dynamic array that allows <strong>efficient insertion and deletion</strong> operations clustered <strong>near the same location</strong>.</blockquote><p>Create a gap by shifting the data, simply have a variable for the length of the gap, and change that variable to complete the deletion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*70Yc9p2Pg1uumJSy" /></figure><p>Node1 will be deleted using GapBuffer as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZLcAhPvflomYu8Fx" /></figure><p>At the timing of this Group deletion, the first tree manipulating Applier that we talked about will delete Node1. That’s it for this change.</p><h3>Summary</h3><p>As you can see, there are various optimizations that I wouldn’t think of just by building a normal app, and it’s really interesting.</p><ul><li>The Compose Kotlin Compiler Plugin rewrites the Composable function to implement the Group for the SlotTable and re-executeable lambda.</li><li>The app is launched and the SlotTable is created.</li><li>The changes and the Composable function that adapts the changes are detected by using the Snapshot System.</li><li>Recompose (rerun of the composable function) compares it with the SlotTable and executes it efficiently, skipping the same part of the execution (donut-hole skipping).</li><li>The changes are stored in the change list (changes) and are reflected at once.</li><li>Changes are efficiently reflected by Gap Buffer when they are reflected.</li></ul><h3>Code Reading Materials (Japanese)</h3><p><a href="https://qiita.com/takahirom/items/b29b7db652efe277498a">https://qiita.com/takahirom/items/b29b7db652efe277498a</a><br><a href="https://qiita.com/takahirom/items/d2a89560f8ff2065a7c0">https://qiita.com/takahirom/items/d2a89560f8ff2065a7c0</a><br><a href="https://qiita.com/takahirom/items/0e72bee081de8cf4f05f">https://qiita.com/takahirom/items/0e72bee081de8cf4f05f</a><br><a href="https://qiita.com/takahirom/items/11e3ed72eb2f83440b12">https://qiita.com/takahirom/items/11e3ed72eb2f83440b12</a><br><a href="https://qiita.com/takahirom/items/0e0a3559d95b49399c3b">https://qiita.com/takahirom/items/0e0a3559d95b49399c3b</a><br><a href="https://qiita.com/takahirom/items/8e978eeb6d85bf48a330">https://qiita.com/takahirom/items/8e978eeb6d85bf48a330</a><br><a href="https://qiita.com/takahirom/items/64bd9aa3278035671558">https://qiita.com/takahirom/items/64bd9aa3278035671558</a></p><h3>References</h3><p>CustomTreeCompositionSamples<br><a href="https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/runtime/runtime/samples/src/main/java/androidx/compose/runtime/samples/CustomTreeCompositionSamples.kt">https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/runtime/runtime/samples/src/main/java/androidx/compose/runtime/samples/CustomTreeCompositionSamples.kt</a></p><p>Jetpack Compose Internals<br><a href="https://jorgecastillo.dev/book/">https://jorgecastillo.dev/book/</a><br>Under the hood of Jetpack Compose<br><a href="https://medium.com/androiddevelopers/under-the-hood-of-jetpack-compose-part-2-of-2-37b2c20c6cdd">https://medium.com/androiddevelopers/under-the-hood-of-jetpack-compose-part-2-of-2-37b2c20c6cdd</a><br>Introduction to the Compose Snapshot system<br><a href="https://dev.to/zachklipp/introduction-to-the-compose-snapshot-system-19cn">https://dev.to/zachklipp/introduction-to-the-compose-snapshot-system-19cn</a><br>What is “donut-hole skipping” in Jetpack Compose?<br><a href="https://www.jetpackcompose.app/articles/donut-hole-skipping-in-jetpack-compose">https://www.jetpackcompose.app/articles/donut-hole-skipping-in-jetpack-compose</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e971675e55e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>