Google and Jetbrains have released the first stable build of Jetpack Compose 1.0, the new Kotlin-based UI framework for Android.
If you have used to work with ReactNative, you definitelly like its framework React UI. The minimal components of React UI could be reused anywhere to build very beautiful UI and interactive. This methodology enable developers to engage unlimited elastic and expandable capacity of high performance application development.
Get back to Android, we always keep in mind that it should keep View hierarchy as flat as possible. So that it is too hard to approach like ReactNative does, which lead to complexity and difficulty in source code maintenance.
Jetpack Compose 1.0 - solve the critical problem
Basically, Jetpack Compose have a mechanism like React, Litho or Flutter. The legacy Android UI framework was born in 2008 and as other rule of time, it is old now and not suitable with complex requirements of 2021 applications.
Jetpack Compose was born in order to solve "his brother" problem and start a new era of UI component-based design. Jetpack Compose Framework was written with these main purposes:
Platform release in-dependency: your application is now not affected by major release of Android, it allow developers to modify, fix or even release applications faster than ever.
Less UI components: it does not exist View or Fragment anymore when create your application UI. All things appearing on your UI is now component, and they can interact freely together.
Clarify state ownership and event processing: one of the most important and complex issue of mega application is processing data flow and UI state, it make developers headache for decades. Jetpack Compose is more clear about which component is control UI state and how we process the event. For easily understand, it is like what React did.
Less source code: we've written a book of source code within 1 application UI, especially when application is complex (example working with RecyclerView). Jetpack Compose reduce much source code explicitly.
It mean we now have a easy mechanism to create and reuse in-dependent component, you will have more time to focus on user experience (UX) instead of user interface (UI) as usual.
A simple Jetpack Compose application: Hello World
Let's see a simple sample Jetpack Compose application named Hello World
class ComposeActivity : Activity() {
override fun onCreate(savedInstanceState:Bundle?) {
super.onCreate(savedInstanceState)
setContent { CraneWrapper { MyApp() } }
}
@Composable
fun MyApp() {
MaterialTheme {
Text(text ="Hello world!", style =+themeTextStyle { h3 })
}
}
}
In method onCreate, we set the content of application by calling setContent. This is an method initializing widget tree and wrap it within FrameLayout.
Comments