2021년 2월 6일 토요일

[Android] Jetpack Compose

https://www.youtube.com/watch?v=U5BwfqBpiWU

 Today I would like to tell you about jetpack compose. If you haven't heard about it, Jetpack compose is android's next generation UI Toolkit, written entirely in Kotlin to build high quality applications for Android easily and quickly.

But the best way for you to understand what jetpack compose is and why it's different from existing UI Toolkit is to look at a little bit of code.

so, we'll start with this.

@Composable
fun ProductLabel() {
}

it's a function, it has a single annotation called @Composable and that's pretty much all you need to create  a new widget, what we call composable in the compose world.

you don't have to extend a class,you don't have to overwrite constructors or methods.
you create a function or method and that's it.

it can be private, public, whatever you want, it's just a function. So then to actually generate the UI from that, you gonna take some input.

So in my example, I want to produce a lable for a product.

So I take my product as a parameter of the function, once again, very simple.just a function.
And from then on, I can do what we call "emit the UI".

So i'm going to invoke another composable function,  

@Composable
fun ProductLabel() {
  Text("${Product.quantity}x${product.name}");
}

this one is one of the default composable functions that are part of  jetpack compose, it's called Text.


....


0 comments:

댓글 쓰기