<?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[Surf - Medium]]></title>
        <description><![CDATA[Mobile Apps: Flutter, iOS, Android, Kotlin - Medium]]></description>
        <link>https://medium.com/surf-dev?source=rss----a276e4378a50---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Surf - Medium</title>
            <link>https://medium.com/surf-dev?source=rss----a276e4378a50---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 23:09:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/surf-dev" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Testing a Flutter app: tools, pros, and cons]]></title>
            <link>https://medium.com/surf-dev/testing-a-flutter-app-tools-pros-and-cons-5c39188a84e1?source=rss----a276e4378a50---4</link>
            <guid isPermaLink="false">https://medium.com/p/5c39188a84e1</guid>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Surf]]></dc:creator>
            <pubDate>Mon, 10 Oct 2022 15:03:13 GMT</pubDate>
            <atom:updated>2022-10-10T15:03:13.242Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi! I’m Mary, and I’m a QA expert at <a href="https://bit.ly/3VfPaa1">Surf</a>. Our company has been making native apps since 2011, and ever since 2018 we’ve also been <a href="https://bit.ly/3SSsj2w">building Flutter apps</a>.</p><p>In this article, we’ll be comparing testing options available for native and cross-platform apps. I’ll share my experience working with Flutter and tell you what tools we use to test apps at Surf, what makes Flutter practical, and what pitfalls we’ve run into.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1ZX3KNdVyT_kC7li2yCg5Q.png" /></figure><h3>Testing options in Flutter are on par with the native ones</h3><p>When your business changes its approach to development or introduces a new technology, you should try to make it have only little effect on your testing options. Ultimately, QA experts should keep using the familiar stack of trustworthy tools and technologies when handling a new language or framework.</p><p>When we test native apps at Surf, we use automation tests and also intercept and mock packages. You can’t do without automation tests today, especially in regression tests, and without a proxy, app variation and case coverage are lower.</p><p>We needed the familiar options to stay when testing Flutter apps.</p><h4><strong>Automation tests</strong></h4><p>To autotest native apps, Surf uses <em>Calabash</em> and <em>Ruby</em>. When Flutter first appeared, right off the bat we wanted to know if we could avoid using Calabash while having a full-fledged autotesting experience that we were all used to — or even cooler.</p><p>Turns out we not only could do it but were able to do so even without third-party services: Flutter makes integration and widget tests in the console available out of the box.</p><p>Automation tests in Flutter are both cross-platform and native: you can write tests inside an app project, and they will work on both platforms. When there’s an entire project you’re looking at, you can add the missing ids or even catch bugs and fix them, — that’s another chance to improve your app.</p><p>Flutter also supports <em>Behavior Driven Development — BDD</em>. We adopt it in UI tests. Our language of choice is Gherkin: it supports feature files as well as scenarios written in English and Russian. It’s clear, it helps implement scenario steps without extra arguments inside or with them and customize autotest runs: e.g., running specific scenario by tags instead of running all the available tests in full.</p><p>To test Flutter apps with Gherkin, we enabled the <a href="https://github.com/jonsamwell/flutter_gherkin">open source framework flutter_gherkin</a>.</p><p>Once we realized that automation tests are available in Flutter, we just needed to know the difference between Calabash and Dart+Gherkin and which approach is better. Let’s compare them together.</p><p><strong>1. Feature files are absolutely identical in both cases.</strong></p><p>For example, PIN code authorization scenario will be interpreted correctly in both Dart and Ruby with Calabash:</p><pre>Scenario: Correct authorization in an app at the first try(short code)</pre><pre>When I run the app</pre><pre>And I see the short code input screen</pre><pre>Then I enter the correct short code</pre><pre>And I see the home screen</pre><p>Both technologies support English and other languages.</p><p><strong>2. Steps differ in implementation.</strong></p><p><strong>Dart + Flutter_gherkin</strong></p><pre>class TapAnErrorButtonOnPinCodeScreen extends ThenWithWorld&lt;FlutterWorld&gt; {<br>  @override<br>  Future&lt;void&gt; executeStep() async {<br>  final elemFromReportAnErrorScreen = find.byValueKey(‘reportAnErrorButton’);<br>  await<br>FlutterDriverUtils.tap(world.driver, elemFromReportAnErrorScreen);<br> }<br>  @override<br>  RegExp get pattern =&gt; RegExp(r”I press Report an error on the PIN code screen”);<br>}</pre><p><strong>Calabash</strong></p><pre>When(/^I press Report an error on the PIN code screen$/) do<br>wait_element(“* id:’reportAnErrorButton’”)<br>tap_on(“* id:’reportAnErrorButton’”)<br>end</pre><p>It’s hard to pinpoint what is more convenient: the structure inside a specific technology doesn’t change and that’s great.</p><p><strong>3. To configure tests and use them, Flutter has an extra .dart file. When you use Calabash, there’s no such single file.</strong></p><p>We can’t actually say that it’s a drawback for either Flutter or Calabash — it’s just the nuance of using a particular tool or technology.</p><p><strong>4. To make handling elements inside an app easier, each element needs to have its own id.</strong> When you work with automation tests in Calabash, you need to make sure in advance that the test apps have id’s on both platforms. In Dart, you can add an id as you write autotests, without uploading iOS and Android app files again — that’s handy and it saves time.</p><blockquote><strong><em>Our verdict:</em></strong><em> automation tests in Dart are just as good as those in Calabash.</em></blockquote><h4>Proxy</h4><p>To expand the case coverage of an app, Surf turns to specific software to intercept and mock traffic — e.g., Charles. Analyzing client-server interactions helps:</p><ol><li>Find out whether there’s an actual backend interaction.</li><li>Identify, whose side an issue is on: client or server.</li><li>Make tests on ready-to-use test data quicker and with less effort without involving server developers.</li><li>Analyze the behavior of a mobile app in various networking conditions: request failures, delays, big data. Charles helps identify client-server requests generated improperly and avoid loops when referring to a server and thus overheating your device or draining the battery too quickly.</li></ol><p>Dart has its own networking client. Since all the requests pass through it, you need to enter all the necessary proxy settings in your app. To make life easier for QAs, all such settings are rounded up on a separate screen: at Surf, we use the <em>Debug Screen</em> we’ve developed ourselves.</p><p><em>Debug Screen</em> is an extra screen of settings that aids testing and is only available in a debug build. In it, you can choose the server you need, enable intercepting and saving http requests in the app, view the fcm token of your device and much more — there’s plenty of testing options available.</p><p><em>Debug Screen</em> is a custom one: developers supplement it with extra elements if testers request that — for example, the fields you can use to configure a proxy in the app. As a result, we have access to all the options in Charles: we can enable the proxy server on the Debug Screen without having to restart an app.</p><p>As you can see, testing options aren’t limited in a Flutter app. There’s everything we got used to having in a native app and it’s easy to work with. That’s good news.</p><h3>Cons: framework bugs, gaps in third-party libraries, expected native behavior</h3><p>The setbacks we run into when we test Flutter apps occur in native apps as well. I can’t say that they’re inherent to Flutter: addressing an issue in any technology isn’t always clear and easy.</p><p>Let’s see what to look out for when testing a Flutter app. Forewarned is forearmed.</p><h4>Bugs in Flutter framework</h4><p>While testing, we ran into an issue that concerns presentation and styling of fonts in iOS: spacing on iOS was significantly wider than on Android. That led to a large number of visual bugs.</p><p>Turns out the framework itself was to blame. When our mobile developers asked the Flutter community for help fixing this pesky bug, the framework was soon updated and text presentation on iOS was fixed.</p><p>Such cases will most likely come up again. But they can hardly be called more than a hiccup: guys in the Flutter community are quick to respond to issues and willing to support and improve the framework.</p><h4>Gaps in third-party libraries</h4><p>In iOS 10 and 11, we came across some faults in implementation of third-party libraries. For instance, we fixed the bug where permission to access notifications popped up as soon as the app was open and not after the user tapped a button in accordance with the technical specs and design.</p><p>Such things can come up in both cross-platform and native development. You can either fix them within your project or together with the authors of these libraries.</p><h4>Handling expected native behavior</h4><p>When you’ve used and tested native apps on iOS and Android for a long time, it’s easy to predict what users will expect from this or that app behavior. For example, going to the previous screen with a back swipe is a standard gesture in iOS. On Android, however, it’s unnecessary.</p><p>System dialogs differ between the two platforms: on iOS, you need to request permission to access notifications, while on Android you have this permission by default.</p><p>It’s these specific OS details that we often have to finish off manually. Or sometimes yeet them, if the behavior expected on iOS made its way to Android, just as it was with the back swipe.</p><p>In native apps, issues like screen refresh, an app minimized incorrectly, or app behavior not typical for a particular OS are pretty rare: tools and technologies designed to develop apps for a specific platform are supposed to automatically cover all the versions and capabilities of a specific system.</p><p>While testing a Flutter app, we came across an interesting case: screen refresh was unavailable for iOS devices with a fringe — starting with iPhoneX and younger. Meanwhile, iOS devices without the fringe and Android devices were functioning as expected.</p><p>Another bug we ran into on Android 6: once minimized, the app was kicked out of the memory.</p><p>Such bugs were fixed by our developers within the projects.</p><p>iOS are perfectly familiar with their devices and systems, what shticks they’re adding to the new OS and which of them won’t work in the previous versions anymore, what to highlight when they’re updating Swift. Android understand that they need to target a wide range of devices with absolutely different screen sizes and know their specifics as well.</p><p>We’d like the cross-platform to have all the implementation details of native development. Sure, you can see little gaps in Flutter, but that’s no big deal: you just need to find your way round the cross-platform.</p><h3>Pros: single code base, one team of developers</h3><h4>Single code base saves time on testing</h4><p>Bugs can result from unclear technical specs, specific states missing from the design, or breaking changes in the backend. Reporting such bugs is easier since you need to create twice as few tasks, which already saves time.</p><p>You can look for bugs and test features on one platform: they are extremely likely to occur on both platforms — there’s one implementation, after all.</p><p>The logic of new features on both platforms is also equivalent, since there’s a single code base: testing complex processes inside an app boils down to testing them on one platform and confirming them on the other. We run a full cycle of activities on one platform: we run exploratory testing, test features, do smoke/sanity/full tests, and analyze the feedback. Then, all we have to do is confirm the quality with exploratory tests on the other platform. Such an approach saves time testing the logic by about 1.3-fold.</p><blockquote><strong>Example</strong></blockquote><blockquote>Say, the analysts ran into a situation while testing events: according to the technical specs the event must be sent to a corresponding analytical system, but it can’t be tracked. This gap in logic clearly means that the event won’t be sent on both platforms.</blockquote><blockquote>Having fixed the bug and made sure in various scenarios that the app gathers analytical data correctly on one of the platforms (e.g., iOS), we can pretty much suppose that we won’t be seeing this bug (tracking an extra event or missing a specific event in the system analytics) on the other platform (Android).</blockquote><p>If you need to hand in the builds for both platforms on the same day,, you may not have enough time to test them in native development, provided that they come out simultaneously and there’s only one QA engineer on the project: the test cycle has to be run on both platforms separately. Testing cross-platform apps saves time: regression tests on both platforms run within a single cycle.</p><p>We’ve tried giving a rough estimate of the testing process on two similar projects — one on native Android and iOS, and the other one on Flutter — and compared them feature by feature.</p><p>The apps were analyzed and tested on one iOS and one Android device. As practice showed, Flutter actually gives you the headfirst, even though you’re not twice as fast. That’s logical: you can’t get rid of testing on the other platform completely. Whichever way you put it, they have different specifics and different ways to target their users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*MqKFaSSdbTCjBDyys3JuXA.png" /></figure><p>Testing an out-of-the-box feature which doesn’t affect the specifics of the OS by a 100% and isn’t customized to each platform, saves time testing a Flutter app on two platforms about 1.3–1.5-fold. For example, authorization and resetting a password behave similarly on different platforms and require 1.3 times less time when tested in a Flutter app.</p><p>As for the features that require custom behavior on each platform, don’t expect tests to go any faster. They are expected to behave differently on iOS and Android, hence both platforms will have to be tested in full and separately from each other. For example, push notifications often have to be tested in a full cycle on both platforms due to the differences in permissions, enabling notifications, pusher settings on iOS and Android as well as other nuances in implementation — in order to have the app interact with notifications the way the user expects it to while complying with the technical specs and design.</p><h4>Communications inside the team are easier to arrange</h4><p>When there are a lot of people on a project, it’s hard to arrange the process in a way that stops even the smallest nuances from slipping through the cracks. Especially if you’re expecting a lot of things to be finished off later, new features to be implemented and some changes in general. Most of these things are easy to deal with when there’s only one team of developers.</p><p>First off, it’s easier to test only one app implemented by a single team than to deal with an app implemented in two different ways on two platforms. A QA expert would benefit from having all the information available on the app status, both on iOS and Android. Flutter makes it easier.</p><p>Secondly, there’s an important nuance to native development: changes recognized and accepted by one platform must be reported to the other platform, which is sometimes forgotten or lost in the course of vast or intensive change. There’s no such thing in <a href="https://surf.ru/flutter/">Flutter development</a>: there’s only one team — i.e. a single task of finishing something off covers both platforms.</p><h3>We love testing Flutter apps</h3><h4>Being part of a cool community</h4><p>A new framework is a positive thing for us: solving extraordinary cases makes us broaden our horizons. We find a lot of curious and unique bugs that boost our skills and expand our options in mobile testing.</p><p>That said, members of the Flutter community also provide swift feedback on the issues we find, improve their library, and let us contribute to the project: we’re moving forward together and that’s nice to know.</p><h4>Being an expert</h4><p>When you’re dealing with cross-platform apps, you need to keep in mind the differences between the operating systems and stay focused on specifics of each platform. Looking for and seeing the differences where they should normally be minimal, learning something you’ve never come across before — such things help you become a better expert.</p><p>When you develop or test native apps, you can’t build an iOS app in, say, Android Studio or Visual Studio Code. With Flutter, there’s one IDE for both Android and iOS. And that’s cool.</p><h4>Taking on responsibility</h4><p>Working with Flutter, Surf teams have their hands on all sorts of projects: from e-commerce to banking. As far as we’ve learned, a QA engineer can handle testing both platforms on their own. Adding another expert could only be needed as we get closer to release when work gets intense and the time left to do the tasks is running out.</p><h3>Flutter — a step forward</h3><p>Testing cross-platform apps is pretty easy. Sometimes it’s even faster and easier than native tests. All the hard parts you might see can’t outweigh its usability and its pros. The experience of developing and testing Flutter apps has shown Surf that this framework is a great step forward.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c39188a84e1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/surf-dev/testing-a-flutter-app-tools-pros-and-cons-5c39188a84e1">Testing a Flutter app: tools, pros, and cons</a> was originally published in <a href="https://medium.com/surf-dev">Surf</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reactive Data Display Manager. The great refactoring]]></title>
            <link>https://medium.com/surf-dev/reactive-data-display-manager-the-great-refactoring-d29fa156152d?source=rss----a276e4378a50---4</link>
            <guid isPermaLink="false">https://medium.com/p/d29fa156152d</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Surf]]></dc:creator>
            <pubDate>Mon, 03 Oct 2022 14:26:57 GMT</pubDate>
            <atom:updated>2022-10-03T14:26:57.102Z</atom:updated>
            <content:encoded><![CDATA[<p>In mobile development, screens can rarely do without <em>UITableView</em> or <em>UICollectionView. </em>These UI components help divide screens into cells, configure or substitute them separately if necessary. However, along with that comes a lot of routine tasks to configure DataSource and Delegate collections.</p><p>To cut back on routine tasks, we’ve created a library called <em>Reactive Data Display Manager (RDDM). </em>The core of it is an adapter implementing DataSource and Delegate and a generator corresponding to a cell in a collection.</p><p>The library has been getting better and more powerful. But the more improvements we were making, the clearer we saw that there was something wrong with the architecture in the library. The final straw was trying to make RDDM interact with <em>UITableViewDiffableDataSource</em>, which ended in a fiasco.</p><p>Hi! I’m Nick, an iOS teamlead at <a href="https://bit.ly/3C7g77b">Surf</a>. Recently, I’ve been responsible for improvements in RDDM. In this article, I’ll be telling you a story of refactoring that helped rejuvenate the library and make it interact with the latest APIs that handle collections.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*h_Izaqdc64AXvjMU" /></figure><blockquote><strong><em>Want to stay on top of app development trends and know how to create apps millions of people love?</em></strong></blockquote><blockquote><a href="https://twitter.com/intent/follow?screen_name=surfgroupllc"><em>Follow Surf on Twitter!</em></a></blockquote><h3>The struggles behind expansion</h3><p><em>RDDM</em> was brought into life by an idea to make <em>UITableViewDelegate</em> and <em>UITableViewDataSource</em> isolated entities so as not to implement their methods. However, in the course of development, we faced the fact that this solution is hard to modify: each modification brings about a new descendant of an adapter.</p><p>Let’s take a look at an example screen with paging to get a better understanding. This mechanism is often used when there’s no point in loading the entire body of data: e.g., if there is a lot of data of similar type coming from the server and it can’t possibly all be shown on one screen at once.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*SnZYj2Z_4qxkPJnw" /></figure><p>Backend developers provide us an API to load data package by package. What an iOS developer has to do in this case is single out the moment when the next package has to be requested. It’s also a good idea to minimize the delay: anticipate user intentions and request data a bit earlier.</p><p>To do that, you need a delegate method <a href="https://developer.apple.com/documentation/uikit/uitableviewdelegate/1614883-tableview"><em>tableView(_:willDisplay:forRowAt:)</em></a> that starts executing shortly before the cell is rendered. If you have an index, you can identify that the last cell is ready to be rendered, but when using <em>RDDM,</em> one doesn’t simply override a delegate method. You need to inherit =(</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*YbAn_6yAyp6uU59cMzhiBg.png" /></figure><p>It’s not the smartest decision in the long run, but it’s better than copypasting logic from one controller into another, isn’t it? We’ll use this adapter for screens with pagination. But what if we decide to expand what this adapter is capable of? Then, we’ll have another descendant. If we need to combine the capabilities of these adapters, that would be a descendant’s descendant.</p><p>Over the years of using <em>RDDM,</em> we’ve accumulated too many dependents from the basic adapter. Within the <em>nine </em>projects we’ve analyzed, there turned out to be <em>40</em> dependents and their combinations of all kinds. That’s intimidating, right? But it’s not the worst part.</p><p>With iOS 13 released, Apple created a new type, <a href="https://developer.apple.com/documentation/uikit/uitableviewdiffabledatasource"><em>UITableViewDiffableDataSource</em></a>, in addition to the standard <em>UITableViewDataSource. </em>We found ourselves in a tough situation: we couldn’t substitute dataSource and try out the new one because the <em>RDDM </em>adapter was a monolith blend of <em>UITableViewDelegate</em> and <em>UITableViewDataSource.</em></p><p>That’s what made us think about refactoring.</p><h3>Refactoring</h3><h4>The results we were looking for:</h4><ol><li>Expanding without dependents.</li><li>Substituting delegate or dataSource.</li><li>At least partial backward compatibility. The iOS team at Surf has twenty developers. All of them use RDDM in production, so it was important to keep the concept of the library and the interface of the adapter intact.</li></ol><h4>The architecture of the library before refactoring</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/0*3YtLDIRqsVPjmwRx" /></figure><p>The structure of the old architecture</p><p>This is the general structure for <em>UITableView</em> and <em>UICollectionView</em>. Attachment to a cell or collection is mediated through aliases — <em>CollectionType</em>, <em>CellGeneratorType</em>. Stipple marks the parts that have no issues with expandability or substitution. In this case, only with the adapter interface.</p><p>We’ve already discussed the drawbacks to such an architecture above: there are too many dependents on the basic adapter, and the new dataSource type is impossible to use.</p><h4>What we got after refactoring</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*ayoGuFIsoWzD4Txj" /></figure><p>The structure of the new architecture</p><p>The new architecture ended up having a pretty broad range of entities. To combine them into a specific adapter, we use the pattern called Builder.</p><p>Delegate and DataSource are new adapter properties. They can be substituted — granted, you can only do that at initialization, but that’s good enough.</p><p>Animator responds to updates in a table or collection. It can be substituted, but in fact it’s enough to have two ready-to-use implementations you can choose depending on the version of your OS. For iOS older than 11, we paste and delete inside <em>beginUpdates/endUpdates</em>. In further versions, we use <em>performBatchUpdates</em>.</p><p>For minor modifications, we’ve introduced plugins.</p><p>PluginAction provides a reaction to a delegate or source event and interacts with the generator or adapter. For example, we can use it to support paging.</p><p>FeaturePlugin is something we use for more complex features that require substituting the returned value in the delegate or source. For example, when you support swipeActions in a table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/0*B_87rHuAbRdkqvNV" /></figure><p>Generally, a feature equals a plugin. In other words, when we need to grant an adapter a new capability, first we will think of how to implement it with plugins.</p><h4>Use cases</h4><h4>Paging</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*87D8pQSDMcE4biMnbI_yRg.png" /></figure><p>Paging is now dealt with using a plugin. The body of the main method in the plugin speaks for itself. The action plan is equivalent to the one in the descendant adapter. Here, TableEvent is just an enum that describes the events in the delegate or dataSource.</p><p>Enabling the plugin is pretty easy</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*9MfDnW_SkhyaDBGWccfV3w.png" /></figure><h4>Bonus track: stress test adapter</h4><p>The number of plugins is only limited by your imagination.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*U57YCHKVhFlYYmb7ZH-IFQ.png" /></figure><p>The stress test adapter checks plugins for compatibility. One adapter contains 11 plugins:</p><ol><li>Displayable transfers willDisplay and didEndDisplaying to the generator corresponding to the DisplayableItem type.</li><li>Direction defines the scroll direction. The reaction is forwarded to ScrollEvent — the event in ScrollViewDelegate.</li><li>HeaderIsVisible helps set a reaction to a section header being visible.</li><li>We already know what LastCellIsVisible is.</li><li>Selectable transfers didSelect to the generator corresponding to SelectableItem.</li><li>PrefetchablePlugin adds image prefetching. The Example project has a prefetcher implemented for Nuke, but you can use any other library supporting prefetching to load images.</li><li>Foldable supports foldable cells.</li><li>Movable supports movable cells.</li><li>Refreshable is a plugin supporting UIRefreshControl.</li><li>SwipeActions adds support for sipe menu in tables.</li><li>SectionTitleDisplayable helps display index headers.</li></ol><p>11 plugins in a single adapter! Imagine how terrible an inheritance tree would look for an equivalent adapter, if we were writing it in accordance with the old nonexpansible architecture.</p><p>All of these plugins have already been implemented in the library: you can use them in your projects if you get updated to <em>RDDM 7.x</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8kbgfSTmj_1KFIcUSsdGwQ.gif" /></figure><p><em>Перевод подписи: </em>Examples of Foldable and Movable in action</p><h4>Enabling DiffableDataSource</h4><p>It’s pretty obvious that <em>UITableViewDiffableDataSource</em> can’t be enabled with a plugin. Besides, it’s not a specific protocol but a <em>generic</em> class.</p><p>Let’s look at the pros of <em>UITableViewDiffableDataSource </em>in the context of a mutable collection<em>.</em></p><p>More often than not, we receive content from the server and display it unchanged, but sometimes we give users a choice to:</p><ul><li>delete a cell,</li><li>insert a new cell before or after another cell,</li><li>swap cells around.</li></ul><p>I’ll be calling such cases “mutable collections”.</p><p>Cells can be substituted in one of the following ways:</p><ul><li>manually,</li><li>with a third-party library,</li><li>with a new DiffableDataSource.</li></ul><h4>Manual method</h4><p>The manual method suggests following the algorithm:</p><ol><li>identify the index of the element;</li><li>update the array of generators by transferring or deleting the element;</li><li>performed the same operation with indexes in the collection by calling methods insertItems/deleteItems.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*ibyAij_EDZoGZO1L_ih2Og.png" /></figure><p>In this case, there’s a method called performBatchUpdates hiding inside the animator.</p><p>Taken all together, that’s one search operation, two deleting operations, and two inserting operations. That said, you have to delete and insert in the right order for the substitution to end up as expected and not cause the app to crash.</p><p>In a way, the RDDM adapter helps follow the right order of operations because they are hidden inside its implementation. But for every new complex operation, you’ll have to accurately state the IndexPaths and call the operations specific to the collection in the right order.</p><p>It’s a bit of an effort. That’s why solutions like DifferenceKit came to exist. We’re not going to reinvent the wheel — instead, we’ll make our library interact with a third party one.</p><h4>DifferenceKit</h4><p>With <a href="https://github.com/ra1028/DifferenceKit">DifferenceKit</a>, the substitution algorithm is roughly as follows:</p><ol><li>Make generators differentiable. The library has a dedicated framework for that. It’s similar to Equatable but with an additional field for the unique ID.</li><li>Create a snapshot of the generator array.</li><li>Update the generator array by transferring or deleting an element.</li><li>Create a new snapshot of the array.</li><li>Generate changeSet out of the content state before and after the changes were made using the snapshots.</li><li>Apply the changeSet to the collection, specifying the animations needed.</li></ol><p>The library is written via extensions to the collection. It can be used in iOS 9 and younger, i.e., in practically any project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*2ThJhMQqHbfwmkxjB-jFTA.png" /></figure><p>The algorithm now has more steps, but the code has become clearer.</p><p>makeSnapshot transforms an array of sections and generators into a format familiar to DifferenceKit. We take a snapshot once before the changes and once more after the changes.</p><p>StagedChangeset provides a structured set of operations like insertItems/deleteItems. Inside the reload, there’s a block called performBatchUpdates: it’s where all the operations from the set will be performed.</p><p>reload also has a block parameter called interrupt, where you can specify what set of operations triggers the full reloadData in the collection. All in all, the resulting solution is flexible and fits the concept of RDDM perfectly.</p><p>We didn’t put the DifferenceKit inside the RDDM so as not to provide the library with codependencies.</p><p>To see how the two libraries coexist, check out the <a href="https://github.com/surfstudio/ReactiveDataDisplayManager/tree/develop/Example">Example project</a>.</p><h4>DiffableDataSource</h4><p>Besides the third-party solutions, there’s a system approach from Apple. We really wanted to use them, but there’s one serious constraint: DiffableDataSource is only available on iOS 13 and later. Due to that, we can’t use DiffableDataSource in many of our projects yet. But we’re soon about to start projects with this exact target, so we’ve examined the approach in advance and made it interact with RDDM.</p><p>Similar to the previous examples, take a look at what to do to substitute a cell with another cell:</p><ol><li>All generators must be differentiable. SectionIdentifiable and ItemIdentifiable are aliases for Hashable + Equatable.</li><li>Define DiffableDataSource — generic DataSource where all the main methods of the numbersOfSections, cellForRowAt and other types are already defined. To generate cells, headers, and footers, it uses the block that is set at initialization.</li><li>Update the generator array by transferring the element or deleting it.</li><li>Create a snapshot NSDiffableDataSourceSnapshot of the generator array.</li><li>Apply changes.</li></ol><p>The resulting code to substitute one cell with another one looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*lQHZeUiBZwWEfYyzck6mkw.png" /></figure><p>This code combines all the good parts of the two previous solutions:</p><ul><li>The clarity of the manual solution.</li><li>The handiness of the snapshot approach with DifferenceKit.</li></ul><p>The flag animatingDifferences helps choose the animations needed for the cells automatically. The false value is equal to calling reloadData.</p><p>As opposed to the solution with DifferenceKit, we only make a snapshot once by creating it from the generator array after the changes are made.</p><p>The snapshot of the state before changes can always be found inside dataSource. We take advantage of the fact that we always have the chance to make a snapshot of the generator array and don’t create conflicting states.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*5RfP--HO_e7ZEV35cOGyzQ.png" /></figure><p>All operations should be performed via the adapter. The upside of the RDDM adapter is that it combines a delegate and a data source and helps add features with plugins.</p><p>Using DiffableDataSource without RDDM would look a bit different.</p><p>A snapshot can be used instead of an adapter. NSDiffableDataSourceSnapshot is not just a snapshot but an array. It’s a more complex class to which you could apply insert/delete operations — much like the ones in the collection. We don’t need this capability, though. In this case, we:</p><p>— Either replicate the operations just like in the manual method.</p><p>— Or break the correspondence between the states of the adapter and the snapshot, because they are autonomous.</p><p>DiffableDataSource is a must have for search screens or forms where the number of cells or their height is often modified, making them hard to manage manually.</p><p>If your case matches the target requirements, make sure to try it out.</p><blockquote>If you found <em>RDDM </em>interesting and would like to give it a try in your project, you’re most welcome at our <a href="https://github.com/surfstudio/ReactiveDataDisplayManager">repository</a>. Our goal is to keep perfecting this library, and we’re always happy to have more contributors.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d29fa156152d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/surf-dev/reactive-data-display-manager-the-great-refactoring-d29fa156152d">Reactive Data Display Manager. The great refactoring</a> was originally published in <a href="https://medium.com/surf-dev">Surf</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Keyboard access in iOS: cutting back on copypasting]]></title>
            <link>https://medium.com/surf-dev/keyboard-access-in-ios-cutting-back-on-copypasting-8656fa29bde1?source=rss----a276e4378a50---4</link>
            <guid isPermaLink="false">https://medium.com/p/8656fa29bde1</guid>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Surf]]></dc:creator>
            <pubDate>Mon, 26 Sep 2022 09:37:49 GMT</pubDate>
            <atom:updated>2022-09-26T09:38:22.107Z</atom:updated>
            <content:encoded><![CDATA[<p>In almost any mobile app, developers encounter input fields. And where there’s an input field, there’s a keyboard, and logic to process events of its lifecycle: emerging, hiding, resizing.</p><p>Anyone who’s ever written apps for iOS, knows that writing code for keyboards involves adding pretty similar or even identical code, otherwise known as copypasting. To find out how we were trying to tackle it at Surf and how much we managed to reduce the code base by, keep reading.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fNTXUlsVf_2yRC4kr1_j1A.jpeg" /></figure><p>Suppose we have a screen with an input field. If you tap it, it shows the keyboard. What we have to do is process the events of showing and hiding a keyboard depending on its dimensions and show/hide time. The code may look as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4695a05fb4ac14e7ca22167b7dc2b7b3/href">https://medium.com/media/4695a05fb4ac14e7ca22167b7dc2b7b3/href</a></iframe><p>Suppose we now have another screen with input fields. No biggie: let’s copy the methods we’ve already written and change the way the events are processed.</p><p>Then we have another screen, and another one… I guess you know what I’m getting at: all screens will have exactly the same code that only differs in the way the events are processed. The developer is highly unlikely to write this code from scratch instead of copypasting with Cmd+C/Cmd+V.</p><p>It clearly means that it’s high time we consider code reuse to avoid copypasting. That’s how we got the idea to write a utility which would:</p><ul><li>Help subscribe to keyboard events and unsubscribe from them.</li><li>Call a previously specified method on the events of showing and hiding the keyboard.</li><li>In doing so, pass data of specific type (animationDuration, keyboardFrame and so on) instead of a raw Notification object.</li><li>Relieve NotificationCenter, sparing you the pain of trying to remember the right keys and data types every time.</li><li>Help avoid copypasting.</li></ul><h3>How we made the utility</h3><p>The first question that comes between you and clean code is: how do I arrange it in terms of architecture? We want to take processing of keyboard events outside the ViewController, but we’ll need to call its methods. That brings up some questions:</p><ul><li>Where do we process the events then?</li><li>How do we bind ViewController and the object where the events are processed?</li><li>How do we keep the strong-link to this object stored somewhere?</li></ul><p>Base classes won’t do. We want to make the system flexible, and base classes won’t help it.</p><p>To outline the first version of this utility, we use a diagram and a short listing below:</p><pre><strong>public</strong> <strong>protocol</strong> <strong>KeyboardObservable</strong>: <strong>class</strong> {</pre><pre><strong>func</strong> <strong>subscribeOnKeyboardNotifications</strong>()</pre><pre><strong>func</strong> <strong>unsubscribeFromKeyboardNotifications</strong>()</pre><pre><strong>func</strong> <strong>keyboardWillBeShown</strong>(notification: Notification)</pre><pre><strong>func</strong> <strong>keyboardWillBeHidden</strong>(notification: Notification)</pre><pre>}</pre><p>Here’s the basic idea:</p><ul><li>We specify that ViewController complies with the <em>KeyboardObservable</em> protocol.</li><li>The protocol contains 4 methods. Two of them — subscribe and unsubscribe — are implemented in the default extension of this protocol, so there’s no need to implement them.</li><li>While we are subscribing to notifications, we create an object called <em>observer</em>, containing a weak reference to ViewController. This one would be responsible for processing the events of showing and hiding the keyboard: it’s these exact methods that would be called in response to notifications.</li><li>Whenever the keyboard is being shown or hidden, <em>observer </em>will call the two corresponding methods from view.</li></ul><p>Which partly solves the problem: now, we don’t need to implement subscriptions to notifications, since all the same logic will be implemented in one place. But we still have to do something to process the Notification object and draw all the necessary parameters out of it — i.e., we need to implement the remaining two methods in the KeyboardObservable protocol.</p><p>To do that, we’ve made provision for the protocols specified in the diagram as <em>&lt;Specific&gt;KeyboardPresentable</em>. They may look as follows:</p><pre><strong>public</strong> <strong>protocol</strong> <strong>CommonKeyboardPresentable</strong>: <strong>class</strong> {</pre><pre><strong>func</strong> <strong>keyboardWillBeShown</strong>(keyboardHeight: CGFloat, duration: TimeInterval)</pre><pre><strong>func</strong> <strong>keyboardWillBeHidden</strong>(duration: TimeInterval)</pre><pre>}</pre><p>To use the protocol, we need to specify that, besides KeyboardObservable, ViewController also complies with the CommonKeyboardPresentable protocol as well as implement its methods.</p><p>CommonKeyboardPresentable has an extension where the remaining two methods of the KeyboardObservable protocol are implemented. When they are called, the necessary parameters are extracted from the Notification object and the corresponding CommonKeyboardPresentablе methods are called.</p><p>We no longer need to copypaste the logic of processing the payload from the notifications — it will all be implemented in one place. That said, we can still expand the mechanism and write our own <em>&lt;Specific&gt;KeyboardPresentable</em>, where the methods have parameters customized to our needs.</p><p>Particular attention should be given to storing <em>observer</em> in memory. In the diagram, its storage is marked as <em>Pool</em>.</p><ul><li><em>Pool</em> is an observer storage that keeps a strong reference to each of them and doesn’t let them leave the memory.</li><li>Each observer has a weak reference to the ViewController, for which it was created.</li><li>That way, we’ve managed to avoid the reference-cycle between ViewController and the corresponding observer.</li><li>We’re still left with “stray” observers, when an observer object contains view == nil. It’s a case where a ViewController has passed away leaving the observer alone. You can address this by occasionally cleaning such objects out of the pool.</li></ul><p>As a result, we have a flexible system that doesn’t require keeping a large number of constants in mind and writing large chunks of repetitive code. All you have to do is:</p><ul><li>Declare that the ViewController supports the KeyboardObservable protocol.</li><li>Fix the errors that have occurred in Xcode by implementing two methods of the protocol.</li><li>Or declare that the ViewController supports the SpecificKeyboardPresentable protocol and implement its methods.</li></ul><p>The class may have the following structure:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d8778e6bfaf8a9411e398200bff6123/href">https://medium.com/media/9d8778e6bfaf8a9411e398200bff6123/href</a></iframe><p>That said, you can use the protocols available in the utility as SpecificKeyboardPresentable (e.g., CommonKeyboardPresentable), or write your own protocol. All it needs to do is comply with the KeyboardObservable protocol and implement two methods absent from the default implementation.</p><p>As a little extra something, here’s KeyboardInfo, a struct that makes it easier to work with the userInfo dictionary in notifications:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9065cf37cd3e115aea05d7913bd0f51a/href">https://medium.com/media/9065cf37cd3e115aea05d7913bd0f51a/href</a></iframe><h3>Outcome: we’re down by hundreds of absolutely identical lines of code</h3><p>Thanks to this utility, the amount of code within one screen hasn’t gone down drastically: about 15 lines less. But in apps with numerous screens we’ve deleted around 1000 absolutely identical lines of code!</p><p>And the best thing is: now, you don’t need to try and remember the keys for Notification every single time. You don’t even have to remember the names of the methods in protocols: Xcode will suggest declaring the missing methods for you. All you have to do is add the implementation.</p><p>To take a look at the entire code of this utility among the others, check out <a href="https://github.com/surfstudio/iOS-Utils">the Surf repository</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8656fa29bde1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/surf-dev/keyboard-access-in-ios-cutting-back-on-copypasting-8656fa29bde1">Keyboard access in iOS: cutting back on copypasting</a> was originally published in <a href="https://medium.com/surf-dev">Surf</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reasons why the App Store might reject your app: checklist]]></title>
            <link>https://medium.com/surf-dev/reasons-why-the-app-store-might-reject-your-app-checklist-586f403f27f6?source=rss----a276e4378a50---4</link>
            <guid isPermaLink="false">https://medium.com/p/586f403f27f6</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[mobile-testing]]></category>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[app-store]]></category>
            <dc:creator><![CDATA[Surf]]></dc:creator>
            <pubDate>Wed, 21 Sep 2022 12:21:13 GMT</pubDate>
            <atom:updated>2022-09-21T12:21:12.982Z</atom:updated>
            <content:encoded><![CDATA[<p>The App Store is the toughest app distribution platform to get onto. Their reviews take longer and are stricter than at Google Play and the Huawei App Gallery. In 2020, the App Store rejected a million new apps and a million updates.</p><p>On the one hand, such a strict policy is a good thing: it’s easier for users to pick an app and rest assured that it’s safe. For developers, however, it’s a real pain in the neck.</p><p>For example, your app can be rejected if it has content secured by copyright — even if it’s on screenshots from the Apple store. And if your app has to do with healthcare, you’ll have to provide a description of your algorithms and show how accurate the readings your app takes are.</p><p>Hi! My name is Wladyslaw, and I’m a QA-specialist at Surf. My team and I have put together a checklist of reasons why the AppStore rejects apps. Some of them are obvious, while some are not so much. Read on to learn about them in detail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hJIKLlxdOkjH5H93" /></figure><blockquote><strong><em>Want to stay on top of app development trends and know how to create apps millions of people love?</em></strong></blockquote><blockquote><a href="https://twitter.com/intent/follow?screen_name=surfgroupllc"><em>Follow Surf on Twitter!</em></a></blockquote><h3>Breach of confidentiality and user data policy</h3><p>❌<strong>Your app has no link to the user agreement. </strong>The link must be both within the app and on its page in the store. If the link leads to a corporate website, the agreement must be present there and the link must function.</p><p>❌<strong>Data is transferred to third parties.</strong> Apps that control other mobile devices must not sell or transfer data from the devices under their control to any third parties. The same goes for apps that collect data as part of medical studies or collect data on the health of their users. These must not transfer such data to third parties or use it in analytics or to configure context ads.</p><h3>Failure to comply with functional specifications</h3><p>❌<strong>Bugs.</strong> Your app can be rejected if it has low performance, a janky interface, if it takes a long time to load content, crashes when you open it or use it for a small amount of time, or has obvious technical issues.</p><p>❌<strong>Placeholders instead of actual functions and content.</strong> You must finish the app before you submit it for review. It’s crucial that you implement all the intended features before you publish the app. You can’t leave libraries or code that aren’t used anywhere in the app — Apple won’t give your app the green light.</p><p>We once had a situation <a href="https://surf.dev/">at Surf</a> where our app was rejected because it had an Apple Pay library integrated but not used anywhere.</p><p>❌<strong>The UI doesn’t comply with Human Interface Guidelines.</strong> An app that is difficult to use or irrational in the way it behaves and positions the elements will be rejected.</p><p>❌<strong>Groundless requests to grant access to files and capabilities of a device.</strong> It must only request access to the things that your app will need to function. What’s more, you’ll have to justify in detail why your app needs the access — simply saying “Grant access to geolocation” won’t cut it.</p><p>Users have to understand why you need access and decide whether to grant it or not all by themselves. If a user decides to deny access to capabilities or data, your app must be able to keep working. However, you must explain to the user that in this case, the functionality might be limited.</p><p>❌<strong>Unauthorized access to user data.</strong> In 2021, amendments to Apple’s advertising policy came into effect. Now, in order to gather data for ad campaigns, you must ask users for permission to trace their activity.</p><p>❌<strong>Altered behavior of system features, buttons, and gestures.</strong> The behavior of volume buttons or swipe gestures on the control panel must not be altered.</p><p>❌<strong>Third party technologies are used for FaceID.</strong> User identification with FaceID can only be carried out via the <a href="https://developer.apple.com/documentation/localauthentication/">LocalAuthentication </a>library.</p><p>Login with AppleID is unavailable while the app offers to log in using other social media. This is a must in iOS 13 and onwards.</p><h3>Inaccuracies in formalities and visual aspects</h3><p>❌<strong>Other platforms are mentioned in the app description. </strong>The store page or the app itself must not have any references to other manufacturers, third party icons, or devices. Screenshots for an app page at the store should be made in a way that makes it clear that they’re made on an Apple device.</p><p>❌<strong>The app description is incomplete and misleading.</strong> An app must not contain any information users might find misleading: e.g., a description of features it doesn’t have or an attempt to mimic a popular app. Screenshots displayed in the store must not show features that the app doesn’t have.</p><p>❌<strong>The name of the app has “Beta,” “Demo”, or “Debug” in it.</strong> Such apps are prohibited from the App Store. You can publish beta versions at TestFlight.</p><p>❌<strong>An updated app doesn’t have a description of a new feature.</strong> If an app has a new feature, it must be described in the App Store Connect field. Without a clear description, the app won’t pass the review.</p><p>❌<strong>App screenshots, the icon and the other content on the page don’t suit the 4+ audience.</strong> It doesn’t even matter that the app might be targeted at another age group: the audience of the App Store is children over 4 years old.</p><p>❌<strong>The content doesn’t match the rating.</strong> When you publish an app, you need to take a poll to set the rating for your app. If the content doesn’t match that, the app or its update will be rejected.</p><p>You shouldn’t state in the description or the screenshots that the product has something to do with Apple or that its quality is guaranteed by the company if it’s not true. If an app makes it to the App Store Awards, Apple automatically assigns a corresponding icon to it.</p><p>❌<strong>An .ipa file exceeds 50 Mb at the time of publication.</strong></p><p>❌<strong>The app requires authorization but has no demo user for review.</strong></p><p>❌<strong>The app has lotteries, roulette, or a casino but doesn’t specify the terms of participation and winning.</strong> You must clearly state that Apple has nothing to do with the contests and lotteries.</p><p>❌<strong>Ads don’t comply with the age rating.</strong> You must also make sure that it isn’t misleading or distracting users.</p><p>❌<strong>The app is published under the name of its developer.</strong> Apps providing banking, healthcare, and booking services must be published under the name of the company. Apple won’t allow publishing an app like that under a private account of a developer.</p><p>During the pandemic, this point became especially important: Apple keeps a close eye on apps distributing information about COVID-19.</p><p>An app will be rejected if it has to do with informing people about illnesses but isn’t published by an account that has nothing to do with healthcare or other certified domains. Even a simple news aggregator offering news on coronavirus won’t pass the review.</p><p>❌<strong>The content is offensive to people of different races, religions, sexual orientations, or nationalities.</strong></p><p>❌<strong>The app promotes the illegal use of weapons or allows the purchase of them.</strong></p><p>❌<strong>Graphic sexual or pornographic content.</strong></p><p>❌<strong>The app allows sending anonymous text messages/MMS, making anonymous calls, or holding lotteries.</strong></p><p>❌<strong>Encourages the intake</strong> of tobacco products, electronic cigarettes, illicit substances or abuse of alcoholic drinks. It’s especially strict if the app is targeted at minors.</p><p>❌<strong>The loyalty card in the wallet has no company contact details.</strong> This needs to be specified so that users can contact the company if they want to.</p><h3>In-app purchases</h3><p>❌<strong>Digital content purchases are mediated by something other than in-app purchases.</strong> Digital content includes subscriptions, music inside the app, videos, and expanded access to specific features.</p><p>❌<strong>The app doesn’t show the odds of its users getting a specific object from the loot box.</strong> The odds must be specified before this game element is purchased.</p><p>❌<strong>The app forces users to take extra actions to unblock content or features.</strong> For example, rate the app, leave a review, or install another app.</p><p>❌<strong>The app doesn’t provide users with all the necessary information</strong> about a purchase right up until the moment of purchase. This is important if the app uses Apple Pay. In addition to that, the payment window must not be customized.</p><h3>Kids</h3><p>Kids is a whole other category of apps in the App Store. This is the one that Apple reviews the most carefully. The Kids category comprises <em>three subcategories</em>:</p><ul><li>kids under 5 y.o.</li><li>6–8 y.o.</li><li>9–11 y.o.</li></ul><p>❌<strong>External links, purchases, and other distracting factors.</strong> Such elements require extra security and are separated from the features used by kids. The only exception is parental control options.</p><p>❌<strong>Failure to abide by the laws</strong> protecting child confidentiality on the Internet. The apps must not send personal information and device data to third parties.</p><p>❌<strong>Third-party analytics and advertisements.</strong> This includes any analytical system that passes information to another server. The only services allowed are the ones that don’t pass any identifying information about children: their location, name, date of birth, and email address.</p><p>In the comments, feel free to share why your apps were rejected by the App Store.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=586f403f27f6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/surf-dev/reasons-why-the-app-store-might-reject-your-app-checklist-586f403f27f6">Reasons why the App Store might reject your app: checklist</a> was originally published in <a href="https://medium.com/surf-dev">Surf</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to design third party integrations if you’re an analyst]]></title>
            <link>https://medium.com/surf-dev/how-to-design-third-party-integrations-if-youre-an-analyst-e7e1e2e29841?source=rss----a276e4378a50---4</link>
            <guid isPermaLink="false">https://medium.com/p/e7e1e2e29841</guid>
            <category><![CDATA[mobile-analytics]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[app-development]]></category>
            <dc:creator><![CDATA[Surf]]></dc:creator>
            <pubDate>Fri, 16 Sep 2022 12:16:31 GMT</pubDate>
            <atom:updated>2022-09-16T12:16:31.269Z</atom:updated>
            <content:encoded><![CDATA[<p>Howdy-ho, Kyle!</p><p>Let’s discuss a question that is pretty controversial for a business analyst: <strong>how much should you really know about development?</strong> Say, to analyze or pick a way to interact with a third-party system when designing a feature. After all, developers, a priori, are better versed in the tools they have — why ask an amateur a business analyst?</p><p>Outsourced development often involves dealing with suddenly emerging tasks; teams work on different projects — sometimes simultaneously. That’s why they face the choice of integrations pretty often: in my experience, at least once every two months.</p><p>What I mean by third-party integrations is using APIs or SDKs to enhance the functionality of a service, introduce process automation, and address business objectives.</p><p>When you work according to SCRUM, technical specs are put together a sprint or two before they are developed. By the time the developers start decomposing a feature, it should already be designed according to specifics of an SDK along with the detailed integrations and specifics of a product and business objective. Leads can help clear up any doubts, that’s for sure. But it doesn’t negate the fact that the top-level analysis of third party systems and the choice of integrations are the job of an analyst.</p><p>Hi! I’m Diana Statsura, and I specialize in mobile analytics at <a href="http://surf.dev/?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=how-to-design-third-party-integrations-if-you-re-an-analyst">Surf</a>. Based on real-world cases, I’ll show you what situations you can run into while dealing with third-party integrations and share some tips that help me and my colleagues.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_DsHwLi-2hgb55mzBeLBqQ.png" /></figure><blockquote><strong>Want to stay on top of app development trends and know how to create apps millions of people love?</strong></blockquote><blockquote><a href="https://twitter.com/intent/follow?screen_name=surfgroupllc">Follow Surf on Twitter!</a></blockquote><h3>Responsibilities of an analyst</h3><p><em>Anyhow, let’s talk about the tasks that analysts have on projects and their role in the teams. What if it’s in the default job description of an analyst to analyze an SDK, design integrations and program programs, and I’m here rambling for no reason.</em></p><p>I keep an eye on the job market, and I’m also a person who’s tried explaining what I do to my parents. I’d say that my job isn’t as well-defined as, say, that of developers (even though there are so many kinds as well), and includes pretty big bucket terms. Not everyone clearly gets what analysts are and what role they play in product development. Some even try to prove that no one needs an analyst on a project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*51wUoyVnJib3cRCXEHff_A.png" /></figure><p>Our roles vary and depend on the project, team, and company. Despite the fact that the lines are blurred, there’s analytics on every project. In our context, it includes:</p><ul><li>business analysis,</li><li>systems analysis,</li><li>product analysis. If you want to learn more about the product approach and product analysis at Surf.</li></ul><p>Large-scale, complex projects absolutely need analytics: it helps figure out project goals and align processes the right way. That’s why it’s the analyst who sets the direction in which a project is growing.</p><p>Besides the basic tasks detailed for each job opening, analysts are also responsible for the following:</p><ul><li>handling backlog,</li><li>market analysis at the project onset,</li><li>the choice of development tools that best address a challenge in the context of a feature, etc.</li></ul><h3>What’s the difference between leaving developers to decide on integrations and making analysts do it for them?</h3><p>There are two ways you can go about picking an integration: either let developers figure out the feature by themselves or let an analyst examine it first.</p><h4>Option one: developers figure out the feature by themselves</h4><p>Developers pick the implementation they find easiest and most convenient. But:</p><ul><li>They don’t always come from a place of choosing the most user-friendly one or addressing the needs of a client.</li><li>Sure, the feature will be implemented, but it won’t align with business objectives. Say, your client wants to add extra logic to the project. Not all SDKs can provide that. In their search, developers will primarily look for something convenient and stable, which might lead to them overlooking the logic the business was expecting to get. In the end, the client won’t be happy: you didn’t do what they wanted.</li><li>Developers on different platforms may initially pick different integrations: for example, the Android team will pick an SDK, while the iOS team will decide to use an API. Or they’ll both use SDKs — but different ones. In this case they’ll need a third party to settle the debate anyway.</li></ul><h4>Option two: the feature is first examined by an analyst.</h4><p>An analyst examines client and user requirements. What that gives is:</p><ul><li>You’re focused on the results needed: even if something is pretty hard to do, developers won’t be able to skip it and say “It could be done faster and easier if you take away this logic” or “No way that’s impossible”. <em>This is the part where developers boo me out :(</em></li><li>Quality on another level: at least three people work on one feature, which makes it more likely that no case is left behind.</li><li>A choice of a unified solution that suits both platforms at the same time. Besides, you get a unified implementation.</li></ul><h3>How to pick a third party implementation depending on a feature</h3><p>Let’s go over the options again:</p><ul><li>System interaction via an API.</li><li>An SDK.</li><li>A mobile app accesses the backend, which, in turn, interacts with the system (which basically equals the first option).</li></ul><p>For my example, I chose three features:</p><ul><li>digital receipts,</li><li>push notifications,</li><li>chat.</li></ul><p>They’re all different in terms of complexity and, as they were going through development, I’ve run into different business processes (<em>think “problems”</em>:)).</p><p>To choose an implementation, you have to identify the business objective your client wants to address with this feature. To do that, analysts discuss business requirements with their clients and, as a result, provide developers with descriptions of the functionalities required.</p><p>Third-party integration analysis depends a lot on their specifics. There’s no clear guideline on how to describe an integration, but here is some general advice:</p><ul><li>Clearly state a business objective and base your choice of implementation on that.</li><li>Keep in mind the system requirements, i.e., whether the offered functionality is enough. For example, if your context is dividing push notifications into channels.</li><li>Consult with your team every step of the way: from the choice of an SDK to the means of implementing a feature. For instance, do we implement functionality in a custom way or use SDK methods?</li><li>Double check if the client or the team need server interactions and what part of the functionality will be out in the frontend or the backend.</li><li>Look back on what other projects and teams have experienced. Sounds like a “do what’s right, don’t do what’s wrong” situation, but it’s actually useful. In our company, for instance, we share project experience and rely on the knowledge of our colleagues who’ve already dealt with similar features.</li></ul><h4>Example 1. Digital receipts</h4><p>This case will haunt my nightmares is my favorite. The feature turned out to be complicated both in terms of analytics and development. We had to go through numerous conditions together with the developers and find the best implementation.</p><p>One of the most challenging aspects is getting the conditions of the third party system interaction without directly interacting with it. All data was transferred through the backend.</p><p>Let’s look at some examples.</p><p>Business objective. Implement a functionality enabling digital receipts in a mobile app so that a user can choose a digital receipt instead of a paper one.</p><p>Interaction with the loyalty management platform that enables digital receipts was mediated by the server. Sounds like everything’s fine: part of the logic is run by the backend, and we don’t have as much work to do. In fact, it was more like working with your eyes shut because all the requirements for integration came to us in bits and pieces based on what the backend team was saying.</p><p>It’s pretty obvious that, in order to enable digital receipts, you have to pass email in the endpoint and receive HTTP 200 OK in the reply.</p><p>But here are a few pitfalls:</p><ul><li>A user may only have one email attached to the account in the system. That’s where all the receipts will come to.</li><li>If there’s an email already attached to the account, users can’t specify another one.</li><li>If the app shares the backend with a website, you need to listen to the status of the feature: users have multiple pathways to enable or disable the digital receipts.</li><li>Digital receipts are only available to users with a loyalty card attached.</li><li>You need to check whether users have loyalty cards.</li><li>If they don’t, you have to lead users through the flow of creating a new loyalty card.</li></ul><p>To identify business requirements, you must first analyze the way a platform works as well as interactions within the “mobile app — server — third party platform” chain. By analyzing that, you will get a better understanding of what information a mobile app should send and where you could find it.</p><p>To enable digital receipts, you need the following logic:</p><ul><li>Check if the loyalty card is available to identify a user in the system that enables digital receipts.</li><li>Define the way the app gets access to the email that the checks will be bound to.</li><li>Next, pass the loyalty card number or the email directly to the platform or the server, which, in turn, will pass it to the platform.</li></ul><h4>A mini case inside the case</h4><p>And now — the real thing. As I was saying, our mobile app didn’t directly interact with the Loymax loyalty system: all the data was proxied by the server.</p><p>As a result, at the demo we had learned that email forwarded to the third-party system needs to be confirmed. To meet the extra requirement, we had to reconsider the already complicated logic and postpone the release for two weeks to get the feature done.</p><p>What could we have done to avoid that? Have a broader perspective, do an extra analysis of the interaction logic and try not to rely on the backend completely.</p><h4>Example 2. Push notifications</h4><p>In this one, let’s have a closer look at what affects the choice of an SDK.</p><p>Push notifications are short text messages that appear on the screen of a user device. What it does is give some important information: new special offers, order status, account transactions, etc.</p><p>To set a list of requirements for an implementation, you have to know whether you need some of the following:</p><ul><li>Dividing push notifications into channels — these determine what share of users receives a notification. It’s a user segmentation tool used for mailouts and to configure transaction push notifications.</li><li>Configuring special offers for users.</li><li>Switching the notifications on and off in the app settings. <em>Spoiler: it’s a must! Otherwise, the app gets annoyingly persistent and not user friendly at all — such apps must be tossed out of the market :angry as fuk:</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/0*qtKfKXCU3yOKkIFf" /></figure><p>When we initially designed the feature, we were planning to use the SDK suggested by the client. The documents we analyzed seemed to match the functionality available in the SDK (<em>said not by a man, but by a boy</em>).</p><p>I must admit, that was my first analysis of an SDK and feature design with it: I made a lot of mistakes.</p><ul><li>I was mostly reading the documentation, not taking a good look at the features available.</li><li>I designed a feature and wrote technical specs without consulting the developers.</li><li>I first dived into SDK integration and only then started to analyze the functionality. Hence, I looked at the implementation from a pretty narrow perspective.</li></ul><p>The team, in turn, didn’t take a closer look at the feature as well and overlooked the implementation details. It turned out:</p><ul><li>Implementing some of the functionality promised a wad of hydra code and testing complications. For example, the SDK gave no chance to disable push notifications completely.</li><li>The SDK managers took several weeks to reply to our questions (<em>what a life…</em>).</li></ul><p>In the end, we had to give up on that SDK even though most of our work had already been done. Of course, when we looked for an alternative SDK, we didn’t make the same mistakes. We made new ones (<em>jk</em>).</p><p>Based on my subjective experience, I’ve worked out a list of primary criteria to toss out the SDKs that don’t fit. A good SDK:</p><ul><li>Is thoroughly documented.</li><li>Integrates in a way that’s easy to comprehend.</li><li>Has clear methods, such as, descriptions of parameters that split push notifications into channels.</li><li>Platform managers are quick to reply (not 2–3 days), give clear answers as well as access to a user profile and help configure that.</li></ul><p>At this point, most SDKs fall off. Next, you need a deeper analysis and, of course, to run it all by your team.</p><p>For example, to pick another SDK for push notifications, we also looked for:</p><ul><li>Thoroughly described methods.</li><li>Well-organized user profile.</li><li>Push testing capability.</li><li>Push configurations available in the app:</li><li>Disable notifications in the mobile app.</li><li>Partially enable and disable notifications (i.e. enable and disable specific channels).</li><li>Competent and quick managers: without them, you can not, at the very least, configure a user profile.</li></ul><h4>Example 3. In-app chat</h4><p>This example illustrates how important it is to gather business requirements. By doing so, you’ll find it easier to pick the implementation and define the scope of work based on the logic requirements.</p><p>The client’s business objective: an e-commerce app needs a chat to help users contact support any time they need it.</p><p>A support chat is an absolute must have for a banking app and is worth the expense. A custom support chat in an e-commerce app, however, may cost an arm and a leg and remain purely decorative.</p><p>Users will hardly feel the urge to contact the app’s support if they can’t order a new sweatshirt or a squeaky ball. Most likely, the chat simply shows that the client is focused on customers: “You’ll get help if something goes wrong with your order.” Chat features and quick response are not the priority in this case: the client hardly wants to pay extra for custom features.</p><p>On the other hand, if the client wants a cheap chat, there are three ways you can do that:</p><ul><li>an SDK,</li><li>a third-party API,</li><li>redirecting users to chats in messengers.</li></ul><p>The client initially wanted to build the chat with an SDK. We’ve examined the options and found some issues with them:</p><ul><li>The support ignored our questions and took weeks to answer.</li><li>Odd integration and messy documentation.</li><li>Ill-organized API. For example, the SDK we were supposed to use for the chat didn’t have a separate endpoint to receive a list of chats. Instead, you had to call a list of tickets and filter them according to their user_id (<em>I know you didn’t get that — neither did we</em>).</li><li>Bad code and a great chance of crushing (<em>and I’m not talking about all of a sudden locking your eyes with a cutie pie while you’re walking down the street and realizing it’s your destiny</em>).</li></ul><p>Initially, the team just wanted to find another SDK, but… finding a good SDK with well written code that doesn’t crash and quick or at least functioning support turned out to be pretty hard.</p><p>That’s why, based on the business objectives, deadlines, costs, and implementations available, we opted to redirect users to messengers. That reduced the amount of work the team did and the time spent on the feature.</p><p>Analysts can identify some of the issues if they analyze the documentation and discuss implementations available with system managers. However, some issues may stay out of their picture — at least because they’re not looking at code. For instance, in this case, the person drawing our attention to the bad code and high crash risk was our team lead.</p><p>That’s why it’s crucial to involve developers in the process and run it by them at all stages of your SDK analysis. It might turn out you’re inventing the wheel at the expense of your client (<em>enormous expense</em>). Sometimes, the simplest implementation is the best fit.</p><h3>Writing technical specs</h3><p>So, we’ve covered the tools. Now let’s think about what should be reflected in the specs.</p><p>If an SDK documentation or a description of a third-party API is a general guideline, technical specs are what must be done exactly to tackle a task. Analysts have to describe the task to developers in as much detail as possible so that the implementation meets the expectations.</p><p><strong>The key points</strong> affecting the implementation of a feature are:</p><ul><li>What methods of an SDK or a third-party API to use for an integration.</li><li>What parameters to pass.</li><li>Whether or not keys need to be generated to connect (to an SDK).</li><li>How to get the information provided by a platform to display it in the app.</li><li>Add links to a more detailed description (e.g., methods used or how to generate keys) if it has more exhaustive information that shouldn’t be included in the specs.</li><li>Done! You’re awesome.</li></ul><p>Push-wise you’ll need to write:</p><ul><li>how to generate keys.</li><li>how to connect to the system itself.</li><li>what option to choose when sending events: through server or via an SDK.</li><li>how to divide them into channels.</li><li>data.payload.</li></ul><p>Based on real-life cases, I wanted to show you what analysts are responsible for and how deep they need to dive into their projects and development.</p><p>Analysts don’t have to climb under the hood of an SDK and analyze code. They need to think carefully when choosing development tools and keep various factors in mind. All they need for that is standard skills:</p><ul><li>being able to communicate with the team and the client,</li><li>understanding technical documentation,</li><li>critical analysis of this or that implementation,</li><li>understanding product values and business logic.</li></ul><p>Thanks for reading up to this point, and I’ll see you around! Peace out to all the cutie pies out there!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/112/0*DCUhLQCLDqTcv_dr" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7e1e2e29841" width="1" height="1" alt=""><hr><p><a href="https://medium.com/surf-dev/how-to-design-third-party-integrations-if-youre-an-analyst-e7e1e2e29841">How to design third party integrations if you’re an analyst</a> was originally published in <a href="https://medium.com/surf-dev">Surf</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Material You: breaking down the updates in Material]]></title>
            <link>https://medium.com/surf-dev/material-you-breaking-down-the-updates-in-material-9c96fa4c84b5?source=rss----a276e4378a50---4</link>
            <guid isPermaLink="false">https://medium.com/p/9c96fa4c84b5</guid>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[mobile-design]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Surf]]></dc:creator>
            <pubDate>Fri, 02 Sep 2022 10:53:02 GMT</pubDate>
            <atom:updated>2022-09-06T11:54:08.172Z</atom:updated>
            <content:encoded><![CDATA[<p>In 2014, alongside the release of Android 5.0 Lollipop, Google showcased the concept of Material Design. Each element of the system is made of “material”, the idea of which was neatly described by Matias Duarte, “Unlike real paper, our digital material can expand and reform intelligently. Material has physical surfaces and edges. Seams and shadows provide meaning about what you can touch.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mlcz2L4UsGBxP7t7pM9InA.png" /></figure><p>2018 has seen the second version of Material. This one had more options to make things custom:</p><ul><li>updated color scheme,</li><li>updated guidelines on fonts,</li><li>support of shapes (component shapes).</li></ul><p>Thanks to that, we had more ways to express the Material identity — the visual brand interface — through standard components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*C13c5tKlDTy_9APl" /></figure><p>But Google didn’t stop there, and that’s why you’re reading this article right now. In 2021, Google I/O showcased the concept of Material You — a new version of Material under number 3. Unlike the previous update, this one really shows a lot of changes. The aim of the new concept is to make the user experience individualized.</p><p>Hi! I’m Timur Zadvornov, and I’m an Android developer <a href="http://surf.dev/?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=material-you-breaking-down-the-updates-in-material">at Surf</a>. In this article you’ll find out about the following:</p><ul><li><a href="#8d93">The basics of the Material color scheme</a></li><li><a href="#c2e6">Updated color scheme</a></li><li><a href="#1c48">Dynamic Color</a></li><li><a href="#1ce5">Updated UI components</a></li><li><a href="#0384">Other updates</a></li></ul><p>But before that — an introduction: we’ll break down the basic structure of the Material color scheme. This will help you get a better hang of the updates in Material 3: what they mean and how to approach them.</p><blockquote>Disclaimer: this article is about design rather than development and using the components in your code.</blockquote><blockquote>Want to stay on top of app development trends and know how Surf creates apps millions of people love?</blockquote><blockquote><a href="https://twitter.com/intent/follow?screen_name=surfgroupllc">Follow Surf on Twitter!</a></blockquote><h3>The basics of the Material color scheme</h3><p>Material-palette is made up of six key colors:</p><ul><li><em>Primary</em></li><li><em>Secondary</em></li><li><em>Background</em></li><li><em>Surface</em></li><li><em>Error</em></li><li><em>Outline</em></li></ul><p><em>Primary</em> and <em>Secondary</em> are the main accentuating colors of the app; brand colors, if you will. It’s all pretty clear. For example, the <em>Primary</em> color of YouTube is #ff0000 (red), and the color of Twitter is #1d9bf0 (blue).</p><p><em>Background</em> and <em>Surface</em> are the colors of underlying surfaces serving as backgrounds for the content. <em>Background</em> is the background color of an app, while <em>Surface</em> is the color of component surfaces in an app. A perfect example is Card View. Card View has a standard <em>Surface </em>color.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qgnHvZj-MqeCxoSp" /></figure><p>Background and Surface seem like the same thing. But they’re not: they don’t really stand out in a light theme, but they’re quite visible in a dark one.</p><p>Let’s brush up on the basics of Material. How are the app components positioned with respect to each other? <a href="https://go.surf.dev/hr/android/habr/materialyou1">Material guidelines </a>give a very detailed description, but we’re going to skim them real quick.</p><p>App components are positioned at different heights with respect to the Z axis (elevation). Light themes show elevation by means of shadows under components. Dark themes don’t work that way: you won’t be able to see a shadow. The beauty of the solution is its simplicity: the more elevated the content is along the Z axis, the closer it is to the light source (the screen surface) and the lighter it is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*y_yrj2TOZcy4j-z0" /></figure><p>And here’s when <em>Surface</em> color comes to the rescue! If you set the <em>Surface</em> color, your content will change automatically according to the elevation — no extra lines of code needed. The way elevation is mapped to brightness is pretty well-documented and is also illustrated in the animation below. This is a pretty confusing topic, so I’m looking forward to your questions about colors in the comments — let’s dispute :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Hc7Mcw-sSchw_RyD" /></figure><p><em>Error</em> is the color of errors. I guess that’s pretty self-explanatory.</p><p><em>Outline</em> is the color of outlines around particular components. A great example of that is Outlined Text Field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uWf6h-QMY7OoVkZP" /></figure><p>Now, we’re done with the key colors. The only thing we have left is their variations — <em>on-colors</em>. <em>On-colors</em> are the colors that would look <em>perfect</em> on the “surface” filled with a primary or secondary color, surface, background, or error color.</p><p>A quick example straight away: a red <em>Error color </em>will obviously have a white <em>OnError color</em> because it reads well on a red background. Each color, except for <em>Outline</em>, has a matching <em>on-color</em>: <em>Primary</em> has an <em>OnPrimary</em>, <em>Surface</em> has an <em>OnSurface</em>, and so on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VwD6KiejaPFHx4nj" /></figure><h3>Updated color scheme</h3><p>Now that we’ve covered the basics of the Material color scheme, let’s move on to the updatestes.</p><p>The palette is now expanded with a <em>Tertiary</em> color and all of its variations. <em>Tertiary</em> is the third color we can use to enhance brand identity, alongside <em>Primary</em> and <em>Secondary</em>: some brands find the choice of two colors limiting.</p><p>We now have a new <em>Surface</em> color — <em>SurfaceVariant</em> (along with <em>OnSurfaceVariant</em>). It’s the second option for a surface color. You can use it as, say, a text color on surfaces or a color for dividers.</p><p>Another brand new thing in the Material palette is <em>Container colors</em>. <em>Container colors</em> are a new variation of colors used in containers with components in them. A striking example of that is the Floating Action Button. Starting with Material 3, the background color of this button is <em>PrimaryContainer</em>, while the color of its content is <em>OnPrimaryContainer</em>. <em>Container</em> variations also have doppelgangers — <em>On-colors</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GuPGBG8zYT-xDr3O" /></figure><h3>Dynamic Color</h3><p>How is Google going to make devices more individualized with Material You? The answer is Dynamic Color — one of the key updates in Material 3!</p><p>Dynamic Color is a feature that derives a color palette from a user’s wallpaper and applies it across the apps in the system (the ones that accept Dynamic Color, of course).</p><p>How are the colors generated? The color palette is created by the new Monet Engine available in Android 12: it extracts a so-called seed color from the wallpaper and generates a color palette based on that.</p><p>The spectrum consists of thirteen tones, including black and white. A tonal value of 100 is equivalent to maximum lighting and results in the color white. A tonal value of 0 is a clear black. Every tonal value between 0 and 100 represents the amount of light that shines on the color.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JA4iuBMIPAUAekXZ" /></figure><p>Android generates five key colors:</p><ul><li><em>Accent1</em> (used for <em>Primary</em>),</li><li><em>Accent2</em> (for <em>Secondary</em>),</li><li><em>Accent3</em> (for <em>Tertiary</em>),</li><li><em>Neutral1</em> (for <em>Background</em> and <em>Surface</em>),</li><li><em>Neutral2</em> (for <em>SurfaceVariant</em> and <em>Outline</em>).</li></ul><p>Plus, 13 shades of them. You can check out the resulting palette in an Easter egg widget on Android 12.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*y-kRIz-x8EJUOpD9" /></figure><p>If we put all the data together, we’ve got ourselves a huge generated color palette and a Material color system. The picture below shows the color scheme of an app generated by as little as a single seed color.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1e2aYnIIK1cN2cH8" /></figure><p>You can also generate your own M3 palette with <a href="https://go.surf.dev/hr/android/habr/materialyou2">Material Theme Builder</a>. In addition to that, you can download the resulting themes as XML and Jetpack Compose styles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*i4blGvTxWYgYH9zu" /></figure><h3>Updated UI components</h3><p>Material 3 provides updated guidelines on UI components: buttons, chips, dialogs, cards, and the navigation panel. Сolor mapping of all components complies with Material 3 guidelines and accepts Dynamic Color. Let’s talk about each component in detail.</p><h4>Buttons</h4><p>All have been updated: regular buttons, FABs (floating action buttons), and Extended FABs.</p><p>What’s new in regular buttons:</p><ul><li>Completely rounded angles.</li><li>Bigger size: standard height is now between 36dp and 40dp, icons inside buttons are 18dp.</li><li>Text inside buttons has changed from all caps to sentence case.</li><li>3 new types of buttons: filled — with primary, secondary, tertiary or any other background; filled tonal — with container background) and elevated buttons — with shadows.</li></ul><p>Here they are, left to right: <em>Filled</em>, <em>Filled Tonal</em>, <em>Elevated</em>, <em>Outlined</em>, <em>Text</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pajMajsTKlnSw4iz" /></figure><p>What’s new in FABs:</p><ul><li>New shape: FABs are now rounded squares instead of circles.</li><li>New type — Large FAB.</li><li>Updated color palette for buttons: according to the guidelines, the background should now be a <em>Container color </em>(<em>Primary</em>, <em>Secondary</em>, or <em>Tertiary</em>), while the content on the button should be a corresponding <em>On-Container</em> color.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hIU0cejmzRgkje3e" /></figure><p><em>Small elevated FAB</em></p><p><em>Large FAB</em></p><p><em>Regular FAB</em></p><p><em>Large elevated FAB</em></p><p>What’s new in Extended FABs:</p><ul><li>New shape: Extended FAB are now rounded squares as well.</li><li>Updated color scheme as with regular FABs.</li><li>Updated sizes for text buttons: now it’s the same height as a regular FAB.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Sqai_ACq3uAbKeZZ" /></figure><h4>Chips</h4><p>Chips are components that help users enter and filter information. What’s new:</p><ul><li>Updated shape. Now they all look the same: like rounded rectangles.</li><li>Chips are grouped into 4 types: <em>Assist</em>, <em>Filter</em>, <em>Input</em>, and <em>Suggestion</em>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NxGhJDzqvPIQ2znY" /></figure><p><em>Assist</em> is for “smart” or automated actions, such as adding an event to your calendar. The closest visual analogy is a regular button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Vvb4ByMsNM0c-Axr" /></figure><p><em>Filter</em> is a button that filters data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OgbPVtOhUDF0Zgyb" /></figure><p><em>Input</em> is data previously entered by the user. A striking example of that is email address input, when data is transformed from a text field and into data on a chip.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bvJB5EWKzFDOhpv0" /></figure><p><em>Suggestion</em> chips help narrow down user intentions by giving dynamic suggestions of possible user actions, for example, response suggestions in a messenger.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6yV_Qc8S-ARYix0e" /></figure><h4>Dialogs</h4><p>Dialog updates:</p><ul><li>Bigger content padding.</li><li>Bigger radius for rounded angles.</li><li>Updated fonts.</li><li>An icon is added over the heading in standard dialogs.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1DcsXXzD7xlhjOIa" /></figure><p>On top of that, Google rolled out new guidelines on implementing full-screen dialogs. These could be used for data input on mobile screens. That being said, on tablets, it will be a regular dialog rather than a full-screen one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*O1fGYCYappyRf1Az" /></figure><h4>Navigation</h4><p>On Android, there have only been two ways to build a user-friendly interface all along: a side bar and a bottom bar. With Material 3 introduced, Android unified the way navigation bars are named and added a new type — <em>Navigation Rail</em>.</p><ul><li><em>Navigation Bar — formerly</em> known as Bottom Navigation.</li><li><em>Navigation Drawer</em> — a side navigation panel. To view it, users need to swipe a finger from the left edge of the screen, or, if the screen is big, by anchoring it to the left edge.</li><li><em>Navigation Rail</em> — also a side navigation panel but a narrower one: just like a vertical Navigation Bar.</li></ul><p>There aren’t as many updates for the navigation bars: the updated color scheme, the rounded edges, and several resized components.</p><p>The only thing I’d like to focus on is <em>Navigation Rail</em>. According to the guidelines, it should be used on big screens instead of the <em>Navigation Bar </em>which usually stretches to fill the entire width at the bottom of the screen and looks messy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xwIrJ6NHhgCVX7cJ" /></figure><h3>Other updates</h3><p>The updates have also covered large screens. With Android 12L coming up, Google has revealed the guidelines on app design, adapted to various screen sizes: mobile, foldable, and large.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*alDUnxqiU_elpjHU" /></figure><p>The update has covered a great number of components that we don’t need to bother discussing in detail. The cards, however, haven’t changed much. Apart from the color scheme, there’s little change:</p><ul><li>Not all cards are elevated now.</li><li>They are grouped into 3 types: <em>Elevated</em>, <em>Filled</em>, and <em>Outlined</em>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bQd8482T0GH68lEH" /></figure><p>The same goes for toolbars: there are slight alterations in color scheme, text positioning on various types of toolbars, updated fonts, and no elevation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4JYu43yR3riB4IXm" /></figure><h3>Material You is the best thing that happened to Material</h3><p>The third update of the Material concept is a pretty bulky one and has brought about a lot of new things to Android design in particular. In summary:</p><ul><li>There are a lot of new things in the Material palette (I hope you found my brief overview of the palette helpful).</li><li>Dynamic Color is an exciting thing. What I like is that, <a href="https://go.surf.dev/hr/android/habr/materialyou3">starting with Android 13, all vendors will have to support this feature</a>. I doubt that all third-party apps will start supporting dynamic colors anytime soon though.</li><li>Updated components and their APIs for Material Design Components. The APIs for other platforms (Jetpack Compose, Flutter, Web) are undergoing updates as well.</li></ul><p>Sadly, Material You is still a little crude. As of September 2022:</p><ul><li>Not all components are updated. Currently, Material You guidelines are only fully supported by Material Design Components — the old approach to Android development.</li><li>First beta version of the <a href="https://go.surf.dev/hr/android/habr/materialyou4">Material 3 library</a> came out for Jetpack Compose.</li><li>Support for the new guidelines for Flutter is <a href="https://github.com/flutter/flutter/issues/91605">deep in development</a></li><li>Support for the Web is on <a href="https://m3.material.io/libraries/additional">the roadmap</a>.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c96fa4c84b5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/surf-dev/material-you-breaking-down-the-updates-in-material-9c96fa4c84b5">Material You: breaking down the updates in Material</a> was originally published in <a href="https://medium.com/surf-dev">Surf</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elementary: a New Approach to Architecture in Flutter Apps]]></title>
            <link>https://medium.com/surf-dev/elementary-a-new-approach-to-architecture-in-flutter-apps-5774a3c69370?source=rss----a276e4378a50---4</link>
            <guid isPermaLink="false">https://medium.com/p/5774a3c69370</guid>
            <category><![CDATA[mvvm]]></category>
            <category><![CDATA[clean-architecture]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Vlad Konoshenko]]></dc:creator>
            <pubDate>Mon, 27 Dec 2021 16:40:18 GMT</pubDate>
            <atom:updated>2022-09-12T15:50:31.271Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi everyone! It’s <a href="http://surf.dev/?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=elementary-a-new-approach-to-architecture-in-flutter-apps">Surf</a>. To implement Clean Architecture in our Flutter projects we’re using our very own solution called Elementary. If you’re already familiar with its ancestor — Model-Widget-WidgetModel (<a href="http://go.surf.ru/hr/flutter/medium/elementary_vlad1">MWWM</a>), you’ll probably have no trouble catching on. Otherwise, buckle up!</p><p>My name’s Vlad Konoshenko and I’m a Flutter developer. In this article, we’ll be looking into Elementary: I’ll give you an example of how to separate a presentation layer from business logic and make your codebase cleaner and easier to maintain.</p><p>The package is already available at <a href="http://go.surf.ru/hr/flutter/medium/elementary_vlad2">pub.dev</a> and you can check out the source code at <a href="http://go.surf.ru/hr/flutter/medium/elementary_vlad3">GitHub</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*XUTX30Z5oe6J6mqam84aeA.png" /></figure><h3>What is Elementary</h3><p>Elementary is a library enabling developers to write apps in accordance with the fundamentals of Clean Architecture where the modules are separated into distinct blocks. This library is based on the Model-View-ViewModel (MVVM) pattern. In the upcoming articles, we’ll get into more detail about what’s under the hood in Elementary. But for now, we’ll show you how easy it is to use it.</p><p>The idea behind this library is to split code into different responsibility layers: UI, business logic, and presentation logic. What we get as a result are well-structured independent modules. To get the gist of it, all you have to keep in mind are these three entities:</p><p>ElementaryWidget is where the screen layout is put together.</p><p>WidgetModel (WM) contains presentation logic.</p><p>ElementaryModel contains business logic and component logic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*sQdrdcpzN6ryuWud" /><figcaption>Graphical representation of interactions between components in Elementary</figcaption></figure><h3>An example project with Elementary</h3><p>To appreciate how easy it is to work with Elementary, let’s build a simple weather forecast app. It will only have two screens: the location screen and the forecast screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*4j5IeHGNcRVvhv1t" /><figcaption>You can check out the finished app <a href="http://go.surf.ru/hr/flutter/medium/elementary_vlad4">in my GitHub repository</a>.</figcaption></figure><h4>Creating the location screen</h4><p><a href="http://go.surf.ru/hr/flutter/medium/elementary_vlad5">Source code at Github</a></p><h4><strong>ElementaryModel</strong></h4><p>In order to handle data, we use a Model class. It has AddressService and AppModel parameters. We accept them as class parameters so that we can easily test the class later.</p><p>The service is an object that will process the forecast data. In the context of this example, it doesn’t matter how it’s implemented. AppModel will keep the data relevant for the location selected.</p><p>Let’s create a public method to gain access to our repository. We shouldn’t grant access to a repository in WM because it goes against the single responsibility principle. Once it’s ready, the class should look as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ej1y6Hp3ztx_rJBvo0kjqg.png" /></figure><h4><strong>Widget Model</strong></h4><p>Widget Model stores the data necessary for UI. In our case — the search box and the list of cities matching our search parameters.</p><p>WM inherits from the WidgetModel class. The model we receive as a parameter should be passed to the <em>super </em>method. This model will then be available as a WidgetModel field, just as shown in the example. We can then refer to it via <em>model</em>.</p><p>Let’s also introduce a createSelectAddressWM function that receives context so that we can later get dependencies by means of di and pass them to the model. This function will be called in the UI layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d9hc1mQcJVKwAPRiW7RRXg.png" /></figure><h4><strong>ElementaryWidget</strong></h4><p>We leave all of the layouts in the build method. Note that when we create a widget, we pass the function that creates a WM — the one we wrote in the previous step.</p><h3>Creating the forecast screen</h3><p><a href="http://go.surf.ru/hr/flutter/medium/elementary_vlad6">Source code at Github</a></p><h4>ElemetaryModel</h4><p>The model will contain the forecast service and Location that provides the information on which location is picked. Next, we request the forecast details in the getWeather method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-HRB0PI8PeftnfrXKV6ASA.png" /></figure><h4><strong>WidgetModel</strong></h4><p>In this case, WM is an intermediate layer that provides data to a widget element. It only contains a single method that tries loading data once again in case of an error. To display the current data status, we use EntityStateNotifier. It’s a class that forms a part of the Elementary package and contains certain mechanisms based on the functions of ValueNotifier.</p><p>EntityStateNotifier has content, error, and loading methods. With the help of these, we identify a current state without any extra flags. Another abstract class — IWeatherWm — lets us define the values we grant access to on the part of the widget.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dtEQ74FYZbtvrOBT4Z3n6g.png" /></figure><h4><strong>ElementaryWidget</strong></h4><p>This screen contains a standard <em>build</em>, where we use EntityStateNotifierBuilder widget (that comes with the Elementary package).</p><p>This widget has 3 crucial callbacks: errorBuilder, loadingBuilder, and builder. Each of them corresponds to a state of EntityStateNotifier in our model. As a result, it allows us to divide the states into separate widgets, thus making our code more readable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bPSb6jqhcDHInFPvSG_T-Q.png" /></figure><h3>Some practical tips</h3><ol><li>Pass all dependencies to a model to get all data regarding the current module.</li><li>WM is where you have to pass services and wrappers dealing with the context (theme, dialogs, navigation).</li><li>Create a system of widgets that will be updated independently from each other with the help of various builders (StreamBuilder, ValueListenableBuilder).</li><li>It’s preferable to use ValueChangeNotifiers or streams to avoid any unnecessary interface updates.</li><li>If you use interfaces to build a UI, you can’t violate the Law of Demeter. It’s better not to refer to context in UI via wm.context or refer to a model via wm.model.</li><li>It’s better to get all styles and localization from WM, thus providing the UI with the relevant information only.</li><li>All necessary dependencies have to be passed as parameters so that you can change them when you run tests.</li><li>Sometimes a widget can have no data to handle, in which case you can create StubModel and pass it as a stub.</li></ol><p>We’re constantly working on this solution to make Flutter development even more convenient. The most recent version is available at <a href="http://go.surf.ru/hr/flutter/medium/elementary_vlad2">pub.dev</a>.</p><blockquote><strong>Want to stay on top of app development trends and know how to create apps millions of people love?</strong></blockquote><blockquote><a href="https://twitter.com/intent/follow?screen_name=surfgroupllc">Follow Surf on Twitter!</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5774a3c69370" width="1" height="1" alt=""><hr><p><a href="https://medium.com/surf-dev/elementary-a-new-approach-to-architecture-in-flutter-apps-5774a3c69370">Elementary: a New Approach to Architecture in Flutter Apps</a> was originally published in <a href="https://medium.com/surf-dev">Surf</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[BottomSheet in iOS 15: ​​UISheetPresentationController and its capabilities]]></title>
            <link>https://medium.com/surf-dev/bottomsheet-in-ios-15-uisheetpresentationcontroller-and-its-capabilities-5e913661c9f?source=rss----a276e4378a50---4</link>
            <guid isPermaLink="false">https://medium.com/p/5e913661c9f</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[bottomsheet]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Dmitry Demyanov]]></dc:creator>
            <pubDate>Wed, 15 Dec 2021 11:29:45 GMT</pubDate>
            <atom:updated>2022-09-09T14:21:14.575Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*ipg7_mOLY4_-S7XKxCe_Lg.png" /></figure><p>Back before iOS 15, developers had no fast and easy ways to show content in a form of a sheet that would only take up a part of the screen. All we could do is invent our own ways of implementing this modal presentation.</p><p>However, in the current version of the iOS UI Kit, we finally have a native BottomSheet functionality (even though it’s not an official term according to Apple).</p><p>Hi! I’m Dmitry Demianov, an iOS developer at <a href="http://surf.dev/?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=bottomsheet-in-ios-15-uisheetpresentationcontroller-and-its-capabilities">Surf</a>. In this article I’ll tell you about:</p><ul><li>the way ​​UISheetPresentationController interacts with the keyboard, gestures inside the sheet, and background controllers.</li><li>extra customization options currently available to developers.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*R9NlaU1VUkOLcjqdVsulFA.gif" /></figure><h4>How was BottomSheet implemented before iOS 15?</h4><p>Previously we had to use third-party libraries or create our own implementations. Both of the options had their drawbacks.</p><p><strong>Third-party libraries.</strong> Here we were often limited by the customization options at hand. One way to solve that is to fork the repository containing the library and add the changes you need. This was the most common choice made in the projects I came across.</p><p><strong>Custom implementation.</strong> In this case, we’re free to do what we want, but the nuances take too much time to add. The solution has to be reusable, so the choice that makes sense is to divide the whole thing into a container controller that is responsible for presentation, and a controller with the content that has to go inside the first container.</p><p>Here’s one way to implement that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*CbTthIvd3dtS8irRVwEDCg.png" /></figure><ul><li><em>UIViewControllerTransitioningDelegate</em> — a protocol containing methods that return the objects, defining the custom modal presentation.</li><li><em>UIViewControllerAnimatedTransitioning</em> tells the system to animate the bottom sheet sliding up and down.</li><li><em>UIViewControllerInteractiveTransitioning</em> responds to touch events enabling users to expand the bottom sheet or swipe it down.</li><li><em>UIPresentationController</em> defines presentation parameters such as size or background dimming.</li></ul><p>The thing worth noting here is the presentation size. It can either be fixed or calculated via AutoLayout. What’s more, it can be changed after it’s already displayed.</p><p>And here’s something we should also keep in mind:</p><ul><li>Keyboard interactions.</li><li>Interactions between the swiping gestures that expand or remove the bottom sheet and scrolling gestures inside ContentViewController, say, when users scroll through a list or a collection.</li><li>Enabling users to interact with elements in the background.</li></ul><p>All in all, it’s hardly a 20-minute in-and-out adventure and it’s the main drawback of this option.</p><h4>What do we have in the iOS 15 UI Kit? UISheetPresentationController</h4><p>Let’s get straight to the code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85b4f2df80c2519d8c2bb203645345f4/href">https://medium.com/media/85b4f2df80c2519d8c2bb203645345f4/href</a></iframe><p>This much is already enough to display a <em>SheetViewController</em> half the size of a screen. On the right, there’s a typical modal implementation just for the sake of comparison.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*aoBfbrCmyGr9lGleD7NJOA.png" /></figure><h4>Detents. Medium and Large.</h4><p>Let’s take a closer look at the code, namely, the <em>detents</em> property.</p><p><em>detent</em> defines the height of the presentation containing the controller. The default value is <em>[.large()]</em>, which corresponds to the typical full-screen modal presentation (the example on the right). In our code, we gave it a <em>medium</em> value. As a result, it takes up half the screen.</p><p><em>detents</em> accepts a list of several values, i.e. you can write both options at one go.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/213657379046b3e8dd973de073263ef8/href">https://medium.com/media/213657379046b3e8dd973de073263ef8/href</a></iframe><p>This way users will be able to change the size of the sheet by swiping it up and down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*R9NlaU1VUkOLcjqdVsulFA.gif" /></figure><p><a href="http://go.surf.ru/hr/ios/medium/bottomsheet2">The Apple docs</a> say that detents values should be specified in descending order. Otherwise, we get the following:</p><ul><li>The controller goes full-screen straight away.</li><li>We no longer have a stack of controllers at the top of the screen.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*D5LnXcBmE-CpoUvC0QFSUQ.gif" /></figure><p>Is it a bug or a feature? The first one is definitely something you don’t want. If you actually need the sheet to slide up to full-screen right away, all you need to do is put <em>sheet.selectedDetentIdentifier = .large</em> after you write the list in <em>detents</em>. Not having the stack effect is quite a questionable result as well. All in all, it’s not worth working against the guidelines.</p><p>You can also change the detent programmatically:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ec28837eedd74f710415bd79fbebbda/href">https://medium.com/media/3ec28837eedd74f710415bd79fbebbda/href</a></iframe><p>When creating the sheet, we wrote<em> sheet.detents = [.medium(), .large()]</em>. Therefore, the sheet will first go up to the middle of the screen and then go fullscreen once the <em>changeHeight()</em> is called.</p><p>However… it doesn’t happen. In fact, the above code doesn’t work at all, and it’s all about <em>oldValue</em>. The <em>selectedDetentIdentifier</em> has a default value of <em>nil</em>.</p><p>There are two ways to fix that:</p><ul><li>Specify the initial value when you create the sheet.</li><li>Assign the default value to <em>oldValue</em>. In this case, it’s <em>medium</em>, since, once opened, the sheet picks the smallest possible size value:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc2b41898fa4a38d21399feb3f3da928/href">https://medium.com/media/fc2b41898fa4a38d21399feb3f3da928/href</a></iframe><p>Now the height of our sheet can actually be changed programmatically. In addition to that, the value will always stay relevant: once a user swipes the sheet up or down, <em>selectedDetentIdentifier</em> gets updated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*5nqNOSdSv6gRs2vOrlKRww.gif" /></figure><p>However, I doubt anyone would like the way this transition looks without animation. Thankfully, it’s really easy to fix. Simply add any changes you need to make animated to the <em>animateChanges</em> block:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7cb5a393e2b95082151ee39541dc6c9a/href">https://medium.com/media/7cb5a393e2b95082151ee39541dc6c9a/href</a></iframe><p>Now, that’s much better.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*XSZLlK-vN-LB_sfi-wO1_Q.gif" /></figure><h4>Custom detents values</h4><p>Now let’s have a look at other <em>detents</em> values available. Oh, wait! There aren’t any… Can it be that <em>medium</em> and <em>large</em> are the only options? I mean, this list is clearly begging for the <em>small</em> value. That way we could choose between quarter-of-the-screen, half-screen, and full-screen modes.</p><p>Unfortunately, we’ll have to deal with it: if you need your bottom sheet to take up less than half the screen, you can forget about <em>UISheetPresentationController</em> for now.</p><p>I’m hoping we’ll see the <em>small</em> value in the upcoming iOS — after all, it seems like a perfect addition. Not to mention that having a list of values clearly implies that the list is going to be expanded.</p><p>If you want the size of your bottom sheet to automatically match the amount of content it shows, <em>UISheetPresentationController</em> won’t be of any use. In that case, you’ll once again be left with the choice between a third-party library and a custom implementation.</p><h4>Keyboard interaction</h4><p>Whenever a keyboard slides up, the sheet height automatically changes to large. That’s handy!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*bxn_bwnooROGi6q1tJPSlw.gif" /></figure><p>And what if we don’t put <em>large</em> in the list of available detents when we create the sheet? The sheet will still go up but not to the fullscreen mode. Instead, its height will increase by keyboard’s height value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*HU65Ps0WpvRxH_zeSbck9Q.png" /></figure><p>So <em>detent</em> can actually have some values other than <em>medium</em> and <em>large</em> after all. But for now, it only works when you use the keyboard.</p><h4>Interaction with the gestures inside the sheet</h4><p>Let’s check if the gesture we use to swipe the sheet up or down in any way clashes with the gestures we use inside the sheet: e.g. scrolling through a list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*Ce1tcYgMi9b7zvYHyS35qQ.gif" /></figure><p>As long as we have only one <em>detents</em> value, nothing goes wrong. We can see a smooth transition between scrolling the content and swiping down the sheet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*GTgSFH9bAyyGGOciSMg2Vw.gif" /></figure><p>If both detents are available, swipe gestures are given priority over scrolling. You can change it as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf313ac486defd83c9142a67d2470bee/href">https://medium.com/media/bf313ac486defd83c9142a67d2470bee/href</a></iframe><p>Now when you scroll through the table, it behaves the same way as it did in the previous example with a single <em>detent</em> available. And you can still swipe the sheet up or down if you drag it by an empty part.</p><h4>Interaction with the background controller</h4><p>Whenever the bottom sheet appears, the background is dimmed. Whenever you tap on it, the sheet slides down. That’s predictable and logical, but with <em>UISheetPresentationController</em> you can avoid using <em>dimmingView</em>. As a result, users will be able to interact with both the bottom sheet and the background.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20f31e12461d83dd6ba9a80f61c68dbf/href">https://medium.com/media/20f31e12461d83dd6ba9a80f61c68dbf/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*9deCbFpuo6ODhu7vlpSEgA.gif" /></figure><p>In this property, you set the maximum sheet height that still allows for interaction with background elements. So far the only value that makes sense is <em>medium</em>. However, it also seems to be hinting at the list of detents being extended in the upcoming iOS updates.</p><h4>Additional customization options</h4><p>You can also show or hide the grabber view on top of the sheet and change the corner radius of the sheet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1cb7e61be1a55e3dda9e8aa388c92294/href">https://medium.com/media/1cb7e61be1a55e3dda9e8aa388c92294/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*5rOleZXLa-pWSqs062-5pg.gif" /></figure><p>But then again, no one said you can’t replace the grabber with a simple <em>UIView</em> and customize it any way you like. For example, change its color or thickness, or add some space between the grabber and the upper edge of the sheet.</p><h4>When is UISheetPresentationController worth using?</h4><p>So far you can use it anytime the meager choice of detents doesn’t bother you. Apart from that, it’s a handy and flexible implementation. For one thing, it fits the system apps pretty well: e.g. the list of favorites in Safari.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*slbognL8QtbqeZ7EBmo-jw.png" /></figure><p>I’m sure the following iOS updates will provide more detents, turning it into a comprehensive time-saving solution.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e913661c9f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/surf-dev/bottomsheet-in-ios-15-uisheetpresentationcontroller-and-its-capabilities-5e913661c9f">BottomSheet in iOS 15: ​​UISheetPresentationController and its capabilities</a> was originally published in <a href="https://medium.com/surf-dev">Surf</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RecyclerView.ItemDecoration: Making the Most of It]]></title>
            <link>https://medium.com/surf-dev/recyclerview-itemdecoration-making-the-most-of-it-41d34f74c948?source=rss----a276e4378a50---4</link>
            <guid isPermaLink="false">https://medium.com/p/41d34f74c948</guid>
            <category><![CDATA[itemdecoration]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[recyclerview]]></category>
            <dc:creator><![CDATA[Oleg Zhilo]]></dc:creator>
            <pubDate>Wed, 20 Oct 2021 05:33:45 GMT</pubDate>
            <atom:updated>2022-09-26T10:44:39.369Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi everyone! My name is Oleg Zhilo and for the last 5 years, I’ve been an Android developer at <a href="http://surf.dev/?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=recyclerview-itemdecoration-making-the-most-of-it">Surf</a>. Throughout this time, I’ve taken part in all sorts of kick-ass projects, but I’ve had some experience with legacy code as well.</p><p>All of those projects had at least one thing in common: all of the apps had a list of elements. For instance, a list of contacts in a phone book, or a list of account settings.</p><p>To add a list to a project we use <em>RecyclerView</em>. I’m not going to tell you how to write an Adapter for RecyclerView, or how to properly update the listed data. In this article, I will tell you about another important component that often gets overlooked — <em>RecyclerView.ItemDecoration</em>. I’ll show you what it’s capable of and how to implement it when rendering a list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gDV9waw_k0_H33WBlC4r4Q.png" /></figure><p>Apart from listed data, <em>RecyclerView</em> has some crucial decorative elements, such as scroll bars and dividers between items. And that’s where <em>RecyclerView.ItemDecoration</em> can help us draw all of the elements without having to spawn any unnecessary <em>Views</em> while we render items and screens.</p><p><em>ItemDecoration</em> is an abstract class with 3 methods:</p><p>Any content drawn by this method will appear underneath the <em>ViewHolder</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/871bf8d8b3acf9ebec15a88501c405ea/href">https://medium.com/media/871bf8d8b3acf9ebec15a88501c405ea/href</a></iframe><p>Any content drawn by this method will appear over the <em>ViewHolder</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4da3c75b3524e21c7d2343ec2a0f15c2/href">https://medium.com/media/4da3c75b3524e21c7d2343ec2a0f15c2/href</a></iframe><p>A method that sets offsets to a <em>ViewHolder</em> in <em>RecyclerView</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d37afe936ed827bc1cf6eaa445c99318/href">https://medium.com/media/d37afe936ed827bc1cf6eaa445c99318/href</a></iframe><p>If you look at signatures of onDraw* methods, you can see there are 3 main components used to draw decorations.</p><ul><li><em>Canvas </em>— basically, a canvas to draw any necessary decorations on.</li><li><em>RecyclerView</em> — accesses parameters of RecyclerVIew itself.</li><li><em>RecyclerView.State</em> — stores the state of RecyclerView.</li></ul><h4>Adding Decorations to RecyclerView</h4><p>There are two methods you can use to add an <em>ItemDecoration</em> instance to <em>RecyclerView</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e37aa369ec0bf642e5255446462f92c/href">https://medium.com/media/2e37aa369ec0bf642e5255446462f92c/href</a></iframe><p>All added instances of <em>RecyclerView.ItemDecoration</em> are put in a single list and drawn simultaneously.</p><p>In addition to that, there are methods you can use to manage <em>ItemDecorations</em> in <em>RecyclerView</em>.</p><p>Remove <em>ItemDecoration</em> at position index</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b9ccc1498762408ecdcf3e75a667ff0/href">https://medium.com/media/1b9ccc1498762408ecdcf3e75a667ff0/href</a></iframe><p>Remove an instance of <em>ItemDecoration</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee6a73815a131828259a9a989b8a2038/href">https://medium.com/media/ee6a73815a131828259a9a989b8a2038/href</a></iframe><p>Get an <em>ItemDecoration</em> at position index</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c57c0066130e4e7d0354cfbc83d61fe/href">https://medium.com/media/8c57c0066130e4e7d0354cfbc83d61fe/href</a></iframe><p>Find out the amount of <em>ItemDecorations</em> currently added to <em>RecyclerView</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d9e413a316170646641e80da77731b5/href">https://medium.com/media/0d9e413a316170646641e80da77731b5/href</a></iframe><p>Redraw the current list of <em>ItemDecorations</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5317229321f525ced240b2e150d7696e/href">https://medium.com/media/5317229321f525ced240b2e150d7696e/href</a></iframe><p>You can already find implementations of <em>RecyclerView.ItemDecoration</em>, such as <em>DividerItemDecoration</em>, in SDK. It helps you draw dividers between items.</p><p>It’s pretty straightforward: you use a drawable and <em>DividerItemDecoration</em> sets it for your divider.</p><p>Let’s create a divider_drawable.xml:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84942f6babab65343eb4c58daacc9358/href">https://medium.com/media/84942f6babab65343eb4c58daacc9358/href</a></iframe><p>and bind <em>DividerItemDecoration</em> to <em>RecyclerView</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a5ac607cdbb874cff804bc8ac48f68c/href">https://medium.com/media/5a5ac607cdbb874cff804bc8ac48f68c/href</a></iframe><p>Here’s what we’ll get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*smU98a0QNRK_Wte4wf2yZA.png" /></figure><p>It’s perfect for simple cases.</p><p>If we look under the hood, <em>DividerItemDecoration</em> is pretty straightforward:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56ed2cadeaba52467630ad493b11eda5/href">https://medium.com/media/56ed2cadeaba52467630ad493b11eda5/href</a></iframe><p>Every time onDraw(…) is called, we go through all the <em>Views</em> there are in <em>RecyclerView</em> in a cycle and draw the passed drawable.</p><p>However, the layout elements on your screen can be more complex than a list of identical elements. A screen can have:</p><p>A. Several types of items,</p><p>B. Several types of dividers,</p><p>C. Items with rounded corners,</p><p>D. Items with different vertical and horizontal margins depending on this or that condition,</p><p>E. All of the above at the same time.</p><p>Let’s pick item E — the toughest challenge — and see how we can take it on.</p><p>The Challenge:</p><ul><li>We’ve got 3 types of unique items on the screen. Let’s call them <strong>A</strong>, <strong>B</strong>, and <strong>C</strong>.</li><li>All items have a horizontal offset of 16dp.</li><li>In addition to that, item <strong>B </strong>has a vertical offset of 8dp.</li><li>Item <strong>A </strong>has rounded corners either at the top (if it’s the first one in the group) or at the bottom (if it’s the last one in the group).</li><li>We need to draw dividers between items, BUT there has to be no divider after the last item.</li><li>Item <strong>C </strong>has to have a parallax background image.</li></ul><p>The result should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*xbnydOYATFo2_G-ZLFKDBQ.gif" /></figure><p>Let’s see what options we have:</p><p><strong>Adding different types of items to a list</strong></p><p>You could write your own Adapter or use your favourite library.</p><p>I’ll use <a href="https://github.com/surfstudio/EasyAdapter">EasyAdapter</a>.</p><p><strong>Spacing the items</strong></p><p>Here we have three options:</p><ol><li>Set <em>paddingStart</em> and <em>paddingEnd</em> for RecyclerView.<br>This option won’t work if paddings are not the same for all the items.</li><li>Set <em>layout_marginStart</em> and <em>layout_marginEnd</em> for each item.<br>We’ll have to set the same margin for each of the items in the list.</li><li>Write an implementation of ItemDecoration and override the <em>getItemOffsets</em> method.<br>That’s more like it. The resulting solution will be more flexible and reusable.</li></ol><p><strong>Items with rounded corners</strong></p><p>This one seems obvious: just add an enum {Start, Middle, End } and set it for each item together with the data. But here’s what can go wrong:</p><ul><li>The data model gets more complex.</li><li>To pull it off, we’ll need to calculate the enum for each item in advance.</li><li>Every time an item is removed from or added to the list, we’ll need to do the counting again.</li><li><em>ItemDecoration</em>. You can figure out which item of the group you’re dealing with and draw a corresponding background using the onDraw* method in <em>ItemDecoration</em>.</li></ul><p><strong>Dividers</strong></p><p>Drawing dividers inside items is a bad practice. You’ll end up with an overcomplicated layout and, if the screen is complex, you’ll have trouble displaying the dividers dynamically. That’s why <em>ItemDecoration</em> wins again. A ready-made <em>DividerItemDecoration</em> from an SDK won’t do, because it draws dividers after every single item and there’s no way to fix it out of the box. We have to write our own implementation.</p><p><strong>Parallax background image</strong></p><p>What you may come up with is registering <em>RecyclerView OnScrollListener</em> and using a custom View to draw the image. But once again <em>ItemDecoration</em> comes to the rescue since it has access to the Canvas of the Recycler and all the parameters we may need.</p><p>Bottom line — we need to write at least 4 implementations of <em>ItemDecoration</em>. It’s pretty cool that we can simply narrow all of it down to <em>ItemDecoration</em> and stay out of the layout and business logic of a feature. What’s more, all the implementations of <em>ItemDecoration</em> can be reused, if there are any similar cases in the app.</p><p>However, over the last few years, complex lists have become more common in our practice. As a result, we had to write a new set of <em>ItemDecoration</em> for each project. We needed our solution to be more flexible so it could be reused in other projects.</p><p>What we strived to achieve:</p><ol><li>Write as few implementations of ItemDecoration as possible.</li><li>Separate the logic of drawing on Canvas from offsets.</li><li>Benefit from onDraw and onDrawOver methods.</li><li>Make decorator configurations more flexible (e.g., draw dividers for specific items depending on conditions you set).</li><li>Create a solution that’s not centered around dividers. After all, ItemDecoration can do so much more than draw horizontal and vertical lines.</li><li>Something you can easily use taking a sample project as a reference.</li></ol><p>That’s how we ended up with a library called <a href="https://github.com/ozh-dev/recycler-decorator-library-sample">RecyclerView decorator.</a></p><p>This library has a simple Builder interface and separate interfaces for Canvas and paddings. Moreover, it supports <em>onDraw</em> and <em>onDrawOver</em> methods. And there’s only one implementation of ItemDecoration.</p><p>Let’s get back to our challenge and see what we can do using this library.</p><p>The Builder we have in our decorator looks pretty simple:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e396665db2ac437b0066ddf0d7cb0ac/href">https://medium.com/media/5e396665db2ac437b0066ddf0d7cb0ac/href</a></iframe><ul><li>.underlay(…) — draws under a ViewHolder.</li><li>.overlay(…) — draws over a ViewHolder.</li><li>.offset(…) — sets offsets for a ViewHolder.</li></ul><p>It takes 3 interfaces to draw decorations and set offsets.</p><ul><li><em>RecyclerViewDecor </em>— draws decorations in RecyclerView.</li><li><em>ViewHolderDecor</em> — draws decorations in RecyclerView while giving you access to a ViewHolder.</li><li><em>OffsetDecor</em> — sets offsets.</li></ul><p>But that’s not it. You can bind <em>ViewHolderDecor</em> and <em>OffsetDecor</em> to a particular ViewHolder using <em>viewType</em>, thus combining several types of decorations in a single list or even a single item. If you don’t pass <em>viewType</em>, <em>ViewHolderDecor</em> and <em>OffsetDecor</em> simply apply to all <em>ViewHolders</em> in <em>RecyclerView</em>. <em>RecyclerViewDecor</em> can’t do that since it’s only designed to work with <em>RecyclerView</em> in general and not with <em>ViewHolders</em>. Moreover, the same instance of <em>ViewHolderDecor/RecyclerViewDecor</em> can be passed to both overlay(…) and underlay(…).</p><p><strong>Let’s get down to coding</strong></p><p>In order to create a ViewHolder, the EasyAdapter library uses ItemControllers. In short, they create and identify ViewHolders. In our case a single controller that can display multiple distinct ViewHolders will suffice. All that matters is that each type of item layout has to have a unique viewType. This is how it looks:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9029ead41d4e2011bd8e7e0dedaf93d2/href">https://medium.com/media/9029ead41d4e2011bd8e7e0dedaf93d2/href</a></iframe><p>In order to have offsets we need an <em>OffsetDecor</em> implementation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b9e45b3d9c109bf9c9e2d8471c14ede/href">https://medium.com/media/6b9e45b3d9c109bf9c9e2d8471c14ede/href</a></iframe><p>To draw a ViewHolder with rounded corners, we need <em>ViewHolderDecor</em>. We’ll also need the <em>OutlineProvider</em> so that a pressed item can also have rounded corners.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/684b0e0f9364c5da1b208bd6fb416648/href">https://medium.com/media/684b0e0f9364c5da1b208bd6fb416648/href</a></iframe><p>To draw dividers we’ll add one more implementation of <em>ViewHolderDecor</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/08d32a3c636ccad29380e71aeaa4b844/href">https://medium.com/media/08d32a3c636ccad29380e71aeaa4b844/href</a></iframe><p>In order to configure our divider, we’ll use a <em>Gap.kt</em> class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/986ccad53f697b16f6b2e12c2c807110/href">https://medium.com/media/986ccad53f697b16f6b2e12c2c807110/href</a></iframe><p>This one will help us set the color, height, horizontal padding, and parameters of the divider.</p><p>And there’s only one <em>ViewHolderDecor</em> implementation left. This one will apply parallax to the background image.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98a228fc1fdb7e088368721a13d88a8e/href">https://medium.com/media/98a228fc1fdb7e088368721a13d88a8e/href</a></iframe><p>Now let’s put it all together.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dcfce32bf5c643e0a4eecf2acb1ed25a/href">https://medium.com/media/dcfce32bf5c643e0a4eecf2acb1ed25a/href</a></iframe><p>Let’s initialize <em>RecyclerView</em> and add our decorator and controllers:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/006c415bb87cf4921fabb4262c319379/href">https://medium.com/media/006c415bb87cf4921fabb4262c319379/href</a></iframe><p>Done! We’ve got all the decorations for our list.</p><p>We’ve written a set of decorators that can easily be reused and adjusted.</p><p>Let’s see where else we could apply the decorators.</p><p><strong>PageIndicator for horizontal RecyclerView</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*I7lxvXGdZj7wvEQdMcgWVA.gif" /></figure><p><a href="https://github.com/ozh-dev/DD/blob/habr_article/app/src/main/java/ru/ozh/recycler/decorator/pager/CarouselDecoratorActivityView.kt">CarouselDecoratorActivityView.kt</a></p><p><strong>Message bubbles in a chat and a scroll bar</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SWUcbJrwsFoyZVuP1_eI-w.png" /></figure><p><a href="https://github.com/ozh-dev/DD/blob/habr_article/app/src/main/java/ru/ozh/recycler/decorator/chat/ChatActivityView.kt">ChatActivityView.kt</a></p><p>A more complex case — <strong>drawing shapes and icons</strong> and changing themes without having to refresh the screen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*ea43O3xvsIMOWeXI-pL_0A.png" /></figure><p><a href="https://github.com/ozh-dev/DD/blob/habr_article/app/src/main/java/ru/ozh/recycler/decorator/timeline/TimeLineActivity.kt">TimeLineActivity.kt</a></p><p><strong>Sticky header</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*x1Z5bgPFHum1UUKJa16iLg.gif" /></figure><p><a href="https://github.com/ozh-dev/recycler-decorator-library-sample/blob/habr_article/app/src/main/java/ru/ozh/recycler/decorator/chat/decor/StickyHeaderDecor.kt">StickyHeaderDecor.kt</a></p><p><a href="https://github.com/ozh-dev/DD">Source code and examples</a></p><h3>Summary</h3><p>Despite its simple interface, ItemDecoration can help you do some complex stuff to a list without having to alter the layout. So, you should definitely check it out. And make sure to try our library, you’ll find it makes it much easier to decorate a list.</p><blockquote>Want to stay on top of app development trends and know how to create apps millions of people love?</blockquote><blockquote><a href="https://twitter.com/intent/follow?screen_name=surfgroupllc">Follow Surf on Twitter!</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41d34f74c948" width="1" height="1" alt=""><hr><p><a href="https://medium.com/surf-dev/recyclerview-itemdecoration-making-the-most-of-it-41d34f74c948">RecyclerView.ItemDecoration: Making the Most of It</a> was originally published in <a href="https://medium.com/surf-dev">Surf</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Accompanist — the first chord. A Jetpack Compose library reviewed]]></title>
            <link>https://medium.com/surf-dev/accompanist-the-first-chord-a-jetpack-compose-library-reviewed-9e007771db70?source=rss----a276e4378a50---4</link>
            <guid isPermaLink="false">https://medium.com/p/9e007771db70</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[accompanist]]></category>
            <category><![CDATA[libraries]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Oleg Zhilo]]></dc:creator>
            <pubDate>Wed, 11 Aug 2021 19:48:01 GMT</pubDate>
            <atom:updated>2022-09-09T14:21:47.706Z</atom:updated>
            <content:encoded><![CDATA[<h3>Accompanist — the first chord. A Jetpack Compose library reviewed</h3><p>Normally new frameworks tend to lack good use cases, tutorials, and tools. This, however, is not the case with Jetpack Compose: along with the framework Google has been working on the repository offering a wide range of use cases. As a result a set of handy utilities, reusable widgets, and other perks has been shaping up.</p><p>And just like that the repository full of use cases has evolved into the <a href="https://github.com/google/accompanist">Accompanist</a> — a set of libraries for Jetpack Compose you can add to your project as a dependency.</p><p>Hi! This is <a href="http://surf.dev/?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=accompanist-the-first-chord-a-jetpack-compose-library-reviewed">Surf</a>, and in this article we’ll take a closer look at the tooling it offers.</p><blockquote><strong>Want to stay on top of app development trends and know how to create apps millions of people love?</strong></blockquote><blockquote><a href="https://twitter.com/intent/follow?screen_name=surfgroupllc">Follow Surf on Twitter!</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kKDfZteJFgFDzTtkpSv_mw.png" /></figure><h3>AppCompat Theme Adapter</h3><p>A theme can be quite massive in a legacy project, consisting of a huge subtree of themes and custom attributes. Legacy projects usually have the AppCompat theme, while Compose uses the MaterialTheme. This means you need to have a “bridge” between the two on them.</p><p>Accompanist offers an AppCompatTheme — a handy wrapper that can take your theme out of the world of legacy and XML and into the world of Compose. The source code is pretty simple: you can add something to it or create your own version based off of it, if your theme needs lots of custom parameters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5M4dLZhXRdXR0ktn" /></figure><p>If your project already has the Material Design Theme, then according to the <a href="https://google.github.io/accompanist/appcompat-theme/">documentation</a> you need to use an <a href="https://github.com/material-components/material-components-android-compose-theme-adapter">MDC-Android Compose Theme Adapter</a> from Material Design Components.</p><h3>SystemUiController</h3><p>SystemUiController is a handy wrapper for the <a href="https://developer.android.com/reference/androidx/core/view/WindowInsetsControllerCompat"><em>WindowInsetsControllerCompat</em></a>. With the help of this one, you can change the properties of a system bar (transparency and color) with just your code. It’s a must-have if your project supports an API level 21 or higher (Android 5.0).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*uW6z2sg5nnYfPVGbRGxcSQ.gif" /></figure><h3>Insets</h3><p>Insets is a wrapper for the WindowInsetsCompat and a set of extensions providing compatibility with Compose. With the help of this one, you can listen to changes in Insets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*YP5XyqBkEWGhJgDSKWbNpA.gif" /></figure><p>Apart from parameters in WindowInsetsCompat, you can also use Modifier extensions.</p><p>Paddings:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8q0mUFGoQhD12MUa" /></figure><p>Dimensions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ALpOfUj8E2uz2n-p" /></figure><h3>Permissions</h3><p>It takes some effort to request <a href="https://source.android.com/devices/tech/config/runtime_perms">dangerous permissions</a>. What you have to do is:</p><ul><li>Set up a specific permission request for your user.</li><li>Explain why you need this permission showing a custom dialogue (view, snackbar, etc.).</li><li>Accurately process the response you get.</li><li>Let the user switch to the application settings and decide what permissions to grant.</li></ul><p>The authors of Accompanist have done a great job for us to feel comfortable working with permissions. And the coolest part is — they made it so you can request permissions via <a href="https://developer.android.com/training/basics/intents/result">ActivityResultLauncher</a>: no more overriding onActivityResult in Activity, and the contract can now be explicitly written for a permission request.</p><p>The API is quite simple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XphYSpZX4Ut7_qKW" /></figure><p><strong>permissionState</strong> — the state with request parameters. Together with boolean flags, it is what’s needed to request permissions.</p><p><strong>permissionNotGrantedContent</strong> — the content displayed when no permission is granted.</p><p><strong>permissionNotAvailableContent</strong> — the content displayed when permission is not available. The user is then redirected to app settings.</p><p><strong>content </strong>— the content shown when permission is granted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gMa_Q-UH0EVmATql3vOWvg.png" /></figure><p><a href="https://github.com/google/accompanist/blob/main/sample/src/main/java/com/google/accompanist/sample/permissions/RequestPermissionSample.kt">Request Permission Sample</a></p><h3>FlowLayout</h3><p><a href="https://github.com/google/flexbox-layout">FlexBoxLayout </a>is a container offering flexible options for your layouts. This one makes it easier to arrange elements horizontally or vertically: e.g., to display a collection of items. It can work out the dimensions all by itself and figure out the best way to move an item to the next row or column.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*SnUGyTHTtmcpW-D7eCDd-Q.gif" /></figure><p>FlexBox for Android is not a native layout container. The first version of FlexBoxLayout for CSS was announced in 2009 but it made it to Android development a lot later: the first alpha version of it came out in 2016. There’s been a lot of versions released ever since, the latest one being 3.0.0.</p><p>There’s also a FlexBoxLayoutManager available for RecyclerView. This container is pretty handy so it had to be available in Compose. The essence of it stayed the same but the name got changed to FlowLayout. The new name is just as neat and self-explanatory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*3XbzBQQpIq6TE5D-l_BC3w.png" /></figure><p>Just like its predecessors, it’s got the same layout parameters. So if you’ve ever tried it before, you won’t have any trouble creating a layout with Compose.</p><h3>SwipeRefreshLayout</h3><p>SwipeRefreshLayout is one of the most commonly used containers in Android development.</p><p>It’s easy to use: for instance, to refresh the content on your screen in XML you need to take a container with some content in it, wrap it with SwipeRefreshLayout and then you need to implement the OnRefreshListener interface in the code. Everything seems fine, what else is there to need?</p><p>But say you need to customize a loader. This is where things get tough. The options you have are limited despite how fat the code is (~1200 lines).</p><p>You can recolor an arrow, resize the indicator, or change the way it appears on screen out-of-the-box. If you need to change the color of an indicator or (Lord, save us) “make it look like in iOS”, you’ll have to look for a third-party library or write it yourself. Both options take time and are quite risky.</p><p>The Accompanist helps deal with that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*y57JS1ZMGi-1mKXkiKBCFA.gif" /></figure><p>There’s no XML in the Accompanist, but it works the same way: you still need to wrap the content in SwipeRefresh and use a lambda to trigger the relevant action when the screen is refreshed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_h_WblOTRm71mYC2" /></figure><p>Let’s look at what an out-of-the-box SwipeRefresh can do and what it can customize.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VFyuI7fM4SPEulx0" /></figure><p><strong>state</strong> — stores the loading state and the progress of the animation the refresh indicator has.</p><p><strong>onRefresh </strong>— a lambda-trigger that causes the app to refresh the content of your screen.</p><p><strong>modifier</strong> — modifies the container: its size, padding, etc.</p><p><strong>swipeEnabled </strong>— enables and disables a container’s reaction to a swipe.</p><p><strong>refreshTriggerDistance</strong> — sets the minimum distance at which the animation is triggered. The bigger the distance, the later the indicator reacts to swipes.</p><p><strong>indicatorAlignment </strong>— equivalent to Gravity. It’s a neat functionality you may need to implement a custom indicator.</p><p><strong>indicatorPadding </strong>— an easy way to customize indicator padding. You can add padding to one particular side or make it equal on both sides.</p><p><strong>indicator</strong> — implements the indicator itself. You can get a standard indicator from the material design out of the box, but you can also tweak that or create your own indicator.</p><p><strong>clipIndicatorToPadding </strong>— a flag enabling you to clip an indicator to the padding of the content.</p><p><strong>content </strong>— the actual content within SwipeRefresh.</p><p>Here are some examples of how SwipeRefresh works taken from the sample in the Accompanist’s library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*6oCBo7k_upjYP3cuOOid6w.gif" /></figure><p><a href="https://github.com/google/accompanist/blob/main/sample/src/main/java/com/google/accompanist/sample/swiperefresh/SwipeRefreshBasicSample.kt">SwipeRefreshBasicSample</a></p><p><a href="https://github.com/google/accompanist/blob/main/sample/src/main/java/com/google/accompanist/sample/swiperefresh/SwipeRefreshTweakedIndicatorSample.kt">SwipeRefreshTweakedIndicatorSample</a></p><p><a href="https://github.com/google/accompanist/blob/main/sample/src/main/java/com/google/accompanist/sample/swiperefresh/SwipeRefreshCustomIndicatorSample.kt">SwipeRefreshCustomIndicatorSample</a></p><p>An out-of-the-box SwipeRefresh can already offer pretty neat customization options for the SwipeRefreshLayout as we know it. It takes about 600 lines to add a container and an indicator.</p><h3>Pager</h3><p>In UI a pager is a horizontal or a vertical list where each element takes up the whole screen or a part of it. The key difference between this one here and a regular list is the Snap effect, i.e. scroll snapping.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*LN4UlELM8Z5vFbthVe85Kg.gif" /></figure><p>The Pager, or ViewPager, has gone through a number of stages as an Android UI element. First, there was ViewPager, then there came RecyclerView, which was then adapted to paging. More recently, ViewPager2 was introduced, which has the same RecyclerView under the hood.</p><p>Let’s see what the Pager can look like written in Compose. ViewPager, ViewPager2, and RecyclerView all have one thing in common: since they are UI elements that display collections, they need an adapter to fill containers with data. However, in Compose the Pager doesn’t need that: instead of an adapter, you need to initialize PagerState. So let’s start there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*88ye6BSyKZEjZUZL" /></figure><p>There aren’t many parameters and you only need to specify one of them to initialize the PagerState.</p><p><strong>pageCount</strong> — number of elements.</p><p><strong>currentPage</strong> — current page.</p><p><strong>currentPageOffset</strong> — page offset can have values from 0.0 to 1.0 and can be used to implement physical scrolling.</p><p><strong>offscreenLimit </strong>— defines the number of pages that should be retained on either side of the current element.</p><p><strong>infiniteLoop</strong> — a scroll loop.</p><p>And right from the get-go you can tell which of the out-of-the-box functionalities is the coolest. Scroll loop. Duh. Oh, the many band-aid fixes there are to loop ViewPager and RecyclerView! :)</p><p>Accompanist offers two ways to implement a pager: HorizontalPager and VerticalPager. If you look at the source code, both of them are simple — just a wrapper function for Compose. The only difference is in the way the isVertical parameter is initialized.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SVxNSF2U_R_ekQnK" /></figure><p>You may be familiar with many of the parameters from RecyclerView and ViewPager. So let’s look at the ones you won’t have out of the box.</p><p><strong>verticalAlignment</strong> — an equivalent of Gravity used to align an element in the center: e.g., to adjust the scroll offset to an edge of a container, not the middle of it.</p><p><strong>horizontalAlignment</strong> — similar to vercticalAligment, only it’s horizontal.</p><p><strong>flingBehavior </strong>— helps adjust scroll animation, when a user stops scrolling or makes a flings motion. What is noteworthy about these parameters is that they aren’t easily configured out-of-the-box in either ViewPager or RecyclerView. In ViewPager you’d have to tinker with the parameters of the adapter and the ViewPager itself. RecyclerView, on the other hand, implements scroll snapping with SnapHelper extensions.</p><p>The code looks pretty straightforward: you initialize PagerState and add elements to the pager.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7QtOd7yDgnYjTAVe" /></figure><p>Pagers often need to have page indicators, tabs, and swipe animation. Accompanist has a solution for that as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*fc8F_NzVps5aChQ-iaS7mQ.gif" /></figure><p>As I was saying, states of the Pager are stored in the PagerState. You can reuse it to add animated indicators, swipe animation and tabs. It’s pretty handy: a single state for all components — no need to register listeners. As a bonus, we get maximum consistency.</p><h3>Coil</h3><p><a href="https://coil-kt.github.io/coil/">Coil</a> (Coroutine Image Loader) is a relatively new library: the first version of it was out in 2019. It’s written in Kotlin and backed by Kotlin Coroutines, which is why it wins over Glide and Picasso. It has a simple and flexible API, can easily be integrated into a Kotlin project, and supports Svg, Gif, and videos.</p><p>Until quite recently, Accompanist used to be integrated with Coil and Glide as well. However, starting with version 0.15.0 this toolkit is deprecated: Coil developers have added support for Compose taking Accompanist as a basis with some slight changes introduced. That’s why the following examples of code will be from Coil instead of the Accompanist.</p><p>In order to understand how Coil integrates with Compose, we need to look at ImageView parameters in Compose. Almost all of them may turn out to be familiar to an Android developer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tWq75gsfcMST477X" /></figure><p><strong>painter</strong> — an image parameter that can draw a color, a Bitmap, or a Vector image.</p><p><strong>contentDescription </strong>— a parameter specifically designed to work with Accessibility. Hopefully, you’re a good developer and don’t put null in here, right? :)</p><p><strong>modifier </strong>— sets parameters of an element: its size, padding, etc.</p><p><strong>alignment</strong> — equivalent to Gravity.</p><p><strong>contentScale </strong>— equivalent to ScaleType in ImageView.</p><p><strong>alpha</strong> — transparency of images drawn with painter.</p><p><strong>colorFilter </strong>— a color filter applied to images drawn with the painter.</p><p>All of the magic happens in the painter, specifically when you extend the abstract class Painter. In fact, Coil offers its own implementations of Painter for integration.</p><p>CrossFadePainter animates the change between two Painters with a Crossfade effect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eMNRo4MxstfJ76o9" /><figcaption>CrossFadePainter</figcaption></figure><p>DrawablePainter — the simplest type of Painters in the library, but a handy one nonetheless. It can display Drawable and AnimatableDrawable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VPVwIiWDTkPberqT" /><figcaption>DrawablePainter</figcaption></figure><p>ImagePainter — the most powerful of all, supporting String, Uri (“android.resource”, “content”, “file”, “http”, and “https”), HttpUrl, File, DrawableRes, Drawable, and Bitmap.</p><p>ImageRequest and ImageLoader are two base classes from Coil.</p><ul><li>ImageRequest describes where an image should be loaded from: a link, listeners, Cashe and Decode policies.</li><li>ImageLoader executes ImageRequest and contains settings that you need to work with images. It usually needs to be adjusted once and can then be reused throughout the whole app.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EgqSGE1P7jlikMBy" /><figcaption>ImagePainter</figcaption></figure><h3>PlaceHolder</h3><p>Skeleton-loaders have long become standard in many platforms. While the screen is loading users see a mockup layout: based on sizes and shapes of elements you can guess where texts/photos/controls will be. This provides a positive user experience.</p><p>Accompanist offers a number of placeholders you can implement to create skeleton loaders:</p><ul><li>Basic — a placeholder without animation.</li><li>Fade — a fade in/out placeholder.</li><li>Shimmer — a placeholder with a shimmer effect.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*xVvOa0KgJndFHB4No8LMDA.gif" /></figure><h3>Accompanist is a great backup for those trying Compose while it’s still fresh</h3><p>Even though Accompanist doesn’t yet have a 1.0 version, the library already has a set of tools powerful enough for you to avoid many of the common mistakes.</p><p>Finally, I must say that Accompanist isn’t the only library you can use to support Compose or integrate it into your project. Compose can already be integrated with <a href="https://developer.android.com/jetpack/compose/libraries">Hilt, Rx, Jetpack Navigation, and Jetpack Paging</a>. In addition to that, <a href="http://airbnb.io/lottie/#/android-compose">Lottie 4.0.0</a> also supports Compose.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e007771db70" width="1" height="1" alt=""><hr><p><a href="https://medium.com/surf-dev/accompanist-the-first-chord-a-jetpack-compose-library-reviewed-9e007771db70">Accompanist — the first chord. A Jetpack Compose library reviewed</a> was originally published in <a href="https://medium.com/surf-dev">Surf</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>