Chris Johnson
08/30/2021, 5:58 PMCompositionLocalProvider
to other composables from your main composable? I assume this would be good for composables that you don't plan on re-using and are coupled tightly to that uiState. Rather than passing in my uiState to every composable that needs it.
Or is this already a smell because each composable should only have things passed into it it needs? I've thought about this when let's say composable B needs to send data to composable C from composable A (from the uiState) and rather than pass in 8 things to composable B, I'd rather pass in a uiState so I have access to everything I need. (If a composable only needs 1-2 things then it makes sense to only pass those, but for composable dependencies that need 7-8 fields does this make sense to do?)Zach Klippenstein (he/him) [MOD]
08/30/2021, 6:00 PMZach Klippenstein (he/him) [MOD]
08/30/2021, 6:01 PMChris Johnson
08/30/2021, 6:04 PMZach Klippenstein (he/him) [MOD]
08/30/2021, 6:06 PMZach Klippenstein (he/him) [MOD]
08/30/2021, 6:06 PMChris Johnson
08/30/2021, 6:06 PMZach Klippenstein (he/him) [MOD]
08/30/2021, 6:07 PMZach Klippenstein (he/him) [MOD]
08/30/2021, 6:07 PMChris Johnson
08/30/2021, 6:08 PMChris Johnson
08/30/2021, 6:08 PMZach Klippenstein (he/him) [MOD]
08/30/2021, 6:10 PMZach Klippenstein (he/him) [MOD]
08/30/2021, 6:11 PMChris Johnson
08/30/2021, 6:12 PMZach Klippenstein (he/him) [MOD]
08/30/2021, 6:13 PMZach Klippenstein (he/him) [MOD]
08/30/2021, 6:14 PMZach Klippenstein (he/him) [MOD]
08/30/2021, 6:19 PMAnimatedContent
) to keep the actual semantic content of the function more clear.
It’s also more reusable that way, but reuse isn’t the primary goal here. The animation details were just too complex and not related to the main purpose of this particular function, which is to define what data to show.Chris Johnson
08/30/2021, 6:19 PMZach Klippenstein (he/him) [MOD]
08/30/2021, 6:25 PMChris Johnson
08/30/2021, 6:27 PMKirill Grouchnikov
08/30/2021, 9:24 PMadjpd
08/31/2021, 12:05 PMCompositionLocalProvider
as a default parameter to give my composables access to those.
My functions basically look like this:
@Composable
fun SomeComp(
someParam: String,
myVM: MyViewModel = LocalAppViewModel.current,
) {
}
Initially, I was passing state and callbacks into every Composable but that got tiring. So my business logic and my state now live in my view models, and those are passed to every Composable as a default parameter.
This means the composables are tied to the view model. Yet it's no problem. Firstly, these aren't reusable components. Secondly, when needed, refactoring them to take two extra params instead of the ViewModel is less work than figuring our their behaviour before I code them and before I iteratively test their UI behaviour.
I'm happy to receive any feedback.