vector / com.haroldadmin.vector / VectorFragment / renderState

renderState

protected inline fun <reified S :VectorState> renderState(state:S, renderer: (S) ->Unit):Unit

Renders the UI based on the given state parameter using the renderer block. If your fragment is tied to a VectorViewModel then consider using the overloaded version of the method which takes in a viewModel as an input parameter.

Parameters

state - The state instance using which the UI should be rendered

renderer - The method which updates the UI stateprotected inline fun <S :VectorState> renderState(viewModel:VectorViewModel<S>, crossinline renderer: suspend CoroutineScope.(S) ->Unit):Unit

Renders the UI based on emitted state updates from the given viewModel using the renderer block.

Launches a coroutine in the view's lifecycle scope which collects state updates from the given viewModel and calls the renderer method on it. The renderer method interacts with the Fragment's views, and therefore must only be called within the lifecycle of the view. As such, use it in or after onCreateView.

The renderer parameter is a suspending function with a CoroutineScope of the Fragment's view lifecycle. It can be used to safely run coroutines which affect the UI.

Parameters

viewModel - The ViewModel whose VectorViewModel.state flow is used to receive state updates and render the UI

renderer - The method which updates the UI