Jetpack Compose Frequently Asked Questions
Knowledge base about glorious new android ui framework in the form of simple FAQ
🤔 What is Jetpack Compose?
🤔 How it differs from Anko/Anvil/Splitties-View-DSL or other kotlin UI dsl's?
🤔 So, do I have to rewrite my entire app from scratch?
ComposeView which could be used to juggle between both ui frameworks. Also, check out
@GenerateView annotation - this would help you to create a plain old Android View out of your composable
🤔 How it differs from React?
🤔 Why all composables return Unit instead of some structure, like VDOM?
🤔 Why do I need to write
+ to load something or get a theme value?
+ is a syntax for executing the Effect, which is basically a memoized computation. You can see more of that in this video or in this blogpost. Note that
+ syntax is considered ugly and is a subject to change.
🤔 When JC will be ready for production?
🤔 Will JC support other platforms besides Android?
🤔 Will JC support animations?
:ui:ui-animation and related projects (like
:ui:ui-animation:integration-tests:ui-animation-demos) in jetpack compose source repo for more examples.
🤔 How will dialog and popup window work?
🤔 Does Jetpack Compose support Android Studio Layout Preview?
@Preview annotation on your composable function without parameters to get a basic live preview of your composable to see it in action.
🤔 Does JC work with Constraint Layout?
🤔 How do I make list widget, like RecyclerView?
VerticalScroller with a
Column inside it.
🤔 How do I access
android.content.Context in composables?
val context = +ambient(ContextAmbient)
🤔 How do I access vector assets in composables?
val vector = +vectorResource(vectorResourceId)
🤔 How do I manage component state?
☝ Although it is strongly recommended to design your composable is such way that they are pure and depend only on their arguments, sometimes you need to have state somewhere.
This can be achieved by using
+state(initial) effect. This will give you a nice place to store and update your immutable state.
🤔 What does
@Model annotation do?
☝ Apart from
+state effect there is another way to handle state in a more imperative way as a mutable data class. Just annotate your class with
@Model and all mutable properties referenced in composition context will create a binding which will trigger recomposition of referencing chunk of UI.
🤔 During composition, there is static variable
currentComposer maybe better was to make Composables extension functions on top of this Composer context?
🤔 I found a bug where to submit it?
🤔 I did not find answer for my question here, what can I do?
#compose channel there. Feel free to ask for any help!
If you speak Russian, you also might be interested in joining telegram community dedicated to Declarative UI on Android.