len
06/01/2021, 2:14 PMLaunchedEffect
and DisposableEffect
when you don't actually need any cleanup? I've seen in the official samples some `DisposableEffect`s with an empty onDispose {}
, and that makes me think LaunchedEffect
should be a better option, but I'm in doubt 🤔Adam Powell
06/01/2021, 2:17 PMSideEffect
Adam Powell
06/01/2021, 2:18 PMlen
06/01/2021, 2:36 PMFocusable
the other day and saw a few of these:
https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]in/kotlin/androidx/compose/foundation/Focusable.kt;l=79;bpv=1
https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]Demo&ss=androidx%2Fplatform%2Fframeworks%2Fsupport:compose%2F
And I was wondering why it's using a DisposableEffect
if there's nothing to dispose of rather than a simpler LaunchedEffect
. My guess is that it doesn't matter (they're doing the same), but maybe I'm missing something, and that's why I asked simple smileAdam Powell
06/01/2021, 3:03 PMAdam Powell
06/01/2021, 3:07 PMAdam Powell
06/01/2021, 3:08 PMAdam Powell
06/01/2021, 3:09 PMlen
06/01/2021, 4:10 PMLaunchedEffect
was delayed by a frame, but I didn't know DisposableEffect
isn't delayed. Maybe it's worth mentioning this in the Effects.kt
file?
My initial thinking was that they're the same but one allows to dispose of something if the key changes or it leaves the compositionlen
06/01/2021, 4:13 PMLaunchedEffect
on one of my screens of a BottomNavigation
which receives a function to allow to hide the bottom navigation based on a condition (when selection mode is enabled on the screen or a bottom sheet is shown:
LaunchedEffect(vm.selectionMode, sheetState.targetValue) {
requestHideBottomNav(vm.selectionMode || sheetState.targetValue != ModalBottomSheetValue.Hidden)
}
In this case, maybe it's worth changing this to a DisposableEffect
in case for some reason the app is started in selection mode, so that hiding the bottom nav isn't delayed by a frame 🤔len
06/01/2021, 4:15 PMMutableState
)Adam Powell
06/01/2021, 5:18 PMSideEffect
Adam Powell
06/01/2021, 5:19 PMlen
06/01/2021, 6:07 PMSideEffect
does not call its effect when those mutable states are changed 🤔len
06/01/2021, 6:12 PMMutableState
that is managed by the parent (the one that contains the Scaffold and BottomNav)len
06/01/2021, 6:12 PMAdam Powell
06/01/2021, 6:15 PMlen
06/01/2021, 6:16 PMval (requestedHideBottomNav, requestHideBottomNav) = remember { mutableStateOf(false) }
And the bottom nav uses this logic to show/hide
val isVisible = TopLevelRoutes.isTopLevelRoute(currentRoute) && !requestedHideBottomNav
len
06/01/2021, 6:22 PMBackHandler
where the inner-most call takes precedence/control) but I found this easier to implement. I just wanted to give a child screen/composable the ability to control the visibility of the bottom nav, rather than leaking that logic into the parent (as if it were a God activity) so the parent doesn't need to know the details of the child implementation