Ash
06/17/2020, 12:09 AMval intentChannel = Channel<Intent>()
val state: StateFlow<ChannelState>
// Setup Ambient
val CurrAppState = ambientOf<ChannelState> { ChannelState.Edit }
In a Composable want to use the Ambient
@Composable
fun Foo(appState: StateFlow<ChannelState>){
val currState by appState.collectAsState(initial = ChannelState.NotEdit)
CurrAppState.provides(currState)
Passing currState
down the tree everything works perferct but if use CurrAppState.current
get the wrong state.
Think I am doing something dumb. Thanks for the help.Adam Powell
06/17/2020, 12:25 AM@Composable
fun foo(appState: StateFlow<ChannelState>){
val currState by appState.collectAsState(initial = ChannelState.NotEdit)
Providers(CurrAppState provides currState) {
// Content that should see currState
}
Ash
06/17/2020, 12:28 AMAdam Powell
06/17/2020, 12:32 AMalexgrafl
06/17/2020, 7:16 AMZach Klippenstein (he/him) [MOD]
06/17/2020, 12:31 PMchildren
composable functions (sometimes I've seen these referred to as "slots") and pass lambdas down that close over your state. This is a more extensible approach since it reduces coupling and dependencies on specific types. It's the same approach that composables like Button take, where there's an overload that accepts a composable function for text instead of a string.