A nice stop sign

Day 1

11 Mar 2021

21:38

I have jumped into the next step and saw the modifier.

inline val Int.dp: Dp get() = Dp(value = this.toFloat())

22:02

RIP RecyclerView… Maybe it is early to say it but look at this code, please.

@Composable
fun MyScreenContent(names: List<String> = listOf("Android", "there")) {
Column {
for (name in names) {
Greeting(name = name)
Divider(color = Color.Black)
}
}
}

Right now I’m not able to visualize it in my mind but pretty sure Composables should be able to do anything you can do with a RecyclerView.

22:17

Reacting to the state of the application is the next step. remember and mutableStateOf are methods that are used to have the “LiveData” of the Composable. Learned that there is a Kotlin compiler plugin to be able to update the UI when the data is changed. It is optimized too. Great so far.

@Composable
fun Counter() {

val count = remember { mutableStateOf(0) }

Button(onClick = { count.value++ }) {
Text("I've been clicked ${count.value} times")
}
}

I feel like the actual variable is not going to be inside of the Composable function. I’ll try to pass the counter, which is a MutableState<Int>, as a parameter to the Counter function.

Ok, a wrong approach.

The value should be passed and I feel like there should be a listener for the click events. We cannot leave any logic in the Composable function.

I’ll pass this part for now. (Shhh, couldn’t figure out it yet.)

22:34

State Hoisting… No, it is not a typo (at least that was what I thought.) What I was just saying is here. I’ll leave the rest to the 3rd day.

https://developer.android.com/codelabs/jetpack-compose-basics#4

Android Developer @Teckro.com