GithubHelp home page GithubHelp logo

fabricethilaw / notable-ui-compose Goto Github PK

View Code? Open in Web Editor NEW
20.0 20.0 3.0 192 KB

Notable UI aims to provide plenty of consistent Compose UI widgets to enrich your Android applications.

Home Page: https://www.notableui.com

License: Apache License 2.0

Shell 12.36% Kotlin 87.64%

notable-ui-compose's People

Contributors

fabricethilaw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

notable-ui-compose's Issues

Text measure during composition phase

First of all thanks for such a cool library and extensive documentation.

One thing I noticed is that the library uses BoxWithConstraints(Subcomposition) to obtain constraints during composition and measure the text in the same phase.

https://github.com/fabricethilaw/notable-ui-compose/blob/master/components/notable-ui/src/main/java/com/notable/ui/text/ResponsiveText.kt#L326

Text measure, or referred to as text layout from here on, should be part of layout phase in Compose. To learn more about what these phases mean please check out https://developer.android.com/jetpack/compose/phases

You can see an example of this in BasicText composable.

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/BasicText.kt%3Bl=142?q=basictext.kt

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/CoreText.kt;l=306

As it's highlighted in the linked source code, BasicText obtains the constraints during layout phase using Layout composable. After, text layout is cached in TextController to be drawn in the next phase which is Draw.

I suggest that this library follow the same path for better performance. Subcomposition already introduces some overhead, additionally doing text measure multiple times in composition is definitely not ideal. So instead of using BoxWithConstraints, please consider using @Composable Box + Modifier.layout or just @Composable Layout to

  1. receive Constraints
  2. do the text size computation in layout
  3. cache the final TextLayoutResult in e.g. DynamicTextScalingHelper
  4. Draw the cached result in draw phase using Modifier.drawBehind

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.