Google berkomitmen untuk mendorong terwujudnya keadilan rasial bagi komunitas Kulit Hitam. Lihat caranya.

androidx.ui.livedata

Extension functions summary

For androidx.lifecycle.LiveData
State<T?>
LiveData<T>.observeAsState()

Starts observing this LiveData and represents its values via State.

State<R>
LiveData<T>.observeAsState(initial: R)

Starts observing this LiveData and represents its values via State.

Extension functions

observeAsState

@Composable inline fun <T> LiveData<T>.observeAsState(): State<T?>

Starts observing this LiveData and represents its values via State. Every time there would be new value posted into the LiveData the returned State will be updated causing recomposition of every State.value usage.

The inner observer will automatically be removed when this composable disposes or the current LifecycleOwner moves to the Lifecycle.State.DESTROYED state.

import androidx.ui.foundation.Text
import androidx.ui.livedata.observeAsState

val value: String? by liveData.observeAsState()
Text("Value is $value")

observeAsState

@Composable fun <R, T : R> LiveData<T>.observeAsState(initial: R): State<R>

Starts observing this LiveData and represents its values via State. Every time there would be new value posted into the LiveData the returned State will be updated causing recomposition of every State.value usage.

The inner observer will automatically be removed when this composable disposes or the current LifecycleOwner moves to the Lifecycle.State.DESTROYED state.

import androidx.ui.foundation.Text
import androidx.ui.livedata.observeAsState

val value: String by liveData.observeAsState("initial")
Text("Value is $value")