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&rsquo;ll analyze multiple alternatives to solve it, using different Compose text APIs. We&rsquo;ll review pros and cons and, as a bonus, the&nbsp;<a href="https://developer.android.com/jetpack/compose/performance" rel="noopener ugc nofollow" target="_blank">performance</a>&nbsp;of each solution.</p> <blockquote> <p><strong>Caveat:</strong>&nbsp;We don&rsquo;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&nbsp;<code>Text</code>&nbsp;composable in a container.</li> <li>Text has a maximum of 2 lines.</li> <li>The container&rsquo;s height is always the height of 2 lines of text, no matter the actual number of lines the text would occupy.&nbsp;<strong>This</strong>&nbsp;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>