setState

inline fun <T, R : View> R.setState(state: NonNullState<T>, crossinline apply: R.(T) -> Unit): StateSubscription

Set the Hikage state value.

Usage:

val textState = mutableStateOf("Hello World!")
var text by textState
TextView {
setState(textState) {
text = it
}
}
// Modify the state.
text = "Hello Hikage!"

This function binds the state observer to the View lifecycle.

The observer will be subscribed when the View is attached to window and automatically canceled when it is detached.

Return

StateSubscription

Parameters

state

the state to be set.

apply

the apply body.


inline fun <T, R : View> R.setState(state: NullableState<T>, crossinline apply: R.(T?) -> Unit): StateSubscription

Set the Hikage state value.

Return

StateSubscription

Parameters

state

the state to be set.

apply

the apply body.

See also


inline fun <T, R> R.setState(state: NonNullState<T>, crossinline apply: R.(T) -> Unit): StateSubscription

Set the Hikage state value.

This function creates a long lifecycle observer and will not be automatically canceled.

If you use it with short lifecycle objects, keep the returned StateSubscription and call StateSubscription.cancel manually.

Return

StateSubscription

Parameters

state

the state to be set.

apply

the apply body.


inline fun <T, R> R.setState(state: NullableState<T>, crossinline apply: R.(T?) -> Unit): StateSubscription

Set the Hikage state value.

This function creates a long lifecycle observer and will not be automatically canceled.

If you use it with short lifecycle objects, keep the returned StateSubscription and call StateSubscription.cancel manually.

Return

StateSubscription

Parameters

state

the state to be set.

apply

the apply body.

See also