https://kotlinlang.org logo
#compose
Title
# compose
g

Gil Goldzweig

05/28/2019, 5:25 AM
Will the system handle memory and resources cleanup? And will individual components be lifecycle aware? for example: dialogs
m

matvei

05/28/2019, 6:46 PM
Now about activity/fragment life-cycle, but we have lifecycle aware effects, so you can init / cleanup some resources then component enters / leaves the composition. Something like
Copy code
@Composable
fun UserRow(userId: Int) {
    val user = +state<User?> { null }
    +onActive {
        val dispose = Api.getUserAsync(userId) { user.value = it }
        onDispose { dispose() }
    }
    if (user.value == null) {
        LoadingIndicator()
    } else {
        Row {
            Image(src = user.value.profileImage)
            Text(text = user.value.name)
        }
    }
}
the final APIs is still TBD, but that's what we have right now
you can use +onDispose separately as well
Copy code
fun LoggedText(text: string) {
    +onDispose { Log.i(TAG, "text leaves composition") }
    Text(text)
}
and also we have +onCommit, which will trigger every time the composition commits
g

Gil Goldzweig

05/29/2019, 3:22 AM
Cool, that was what I aimed for with me question
3 Views