Problem solving in Compose Text
<p>Given a requirement, sometimes multiple alternatives may be available to implement it. In this blog we look at a practical use case for positioning text in Compose. We’ll analyze multiple alternatives to solve it, using different Compose text APIs. We’ll review pros and cons and, as a bonus, the <a href="https://developer.android.com/jetpack/compose/performance" rel="noopener ugc nofollow" target="_blank">performance</a> of each solution.</p>
<blockquote>
<p><strong>Caveat:</strong> We don’t expect you to undertake such an analysis for every piece of code you write, however we considered it interesting to share our approach to discover what options you have to solve a concrete scenario and how we went about choosing among them.</p>
</blockquote>
<p>Consider the following use case:</p>
<ul>
<li>Vertically center a <code>Text</code> composable in a container.</li>
<li>Text has a maximum of 2 lines.</li>
<li>The container’s height is always the height of 2 lines of text, no matter the actual number of lines the text would occupy. <strong>This</strong> is the requirement which made the implementation non trivial.</li>
</ul>
<p><a href="https://medium.com/androiddevelopers/problem-solving-in-compose-text-d1dd1feafe4a"><strong>Click Here</strong></a></p>