Skip to content

Instantly share code, notes, and snippets.

@raulh82vlc
Created March 1, 2021 11:21
Show Gist options
  • Save raulh82vlc/016560afc489172519712ab94338a2fa to your computer and use it in GitHub Desktop.
Save raulh82vlc/016560afc489172519712ab94338a2fa to your computer and use it in GitHub Desktop.
SearchStateHandler collects state and passes it directly to the SearchComposablesUI
@ActivityScope
class SearchStateHandler @Inject constructor(@Named("CoroutineUIScope") private val scope: CoroutineScope) {
private var searchComposablesUI: SearchComposablesUI? = null
private lateinit var stateFlow: StateFlow<TweetsUIState>
fun initStateFlowAndViews(
val stateFlow: StateFlow<TweetsUIState>,
val searchComposablesUI: SearchComposablesUI
) {
this.stateFlow = stateFlow
this.searchComposablesUI = searchComposablesUI
}
fun processStateCollection() {
stateFlow.onEach { uiState ->
searchComposablesUI?.startComposingViews(uiState)
}.launchIn(scope)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment