ritesh
03/27/2022, 8:47 AMSide-effect
part?
More in ๐งตritesh
03/27/2022, 8:47 AM@Composable
fun MyComposable(somCondn:Boolean){
var show by remember { mutableStateOf(false) }
ComposableWhichAnimatesFromTop(show = show) // slides in from top
if(somCondn){
LaunchedEffect(Unit) { // is there a better of doing this, Considering MyComposable can be called on every button click
try {
if (!show) {
show = true
delay(3000L)
}
} catch (ex: Exception) {
show = false
} finally {
show = false
}
}
} else {
// Show Loading
}
}
Chris Sinco [G]
03/27/2022, 9:52 AMritesh
03/27/2022, 9:55 AMsomCondn
is false to showLoading
(the else block) and then it's true
to show network-error.ritesh
03/27/2022, 9:56 AMritesh
03/27/2022, 10:23 AMritesh
03/27/2022, 10:25 AMif(somCondn){
LaunchedEffect(Unit) { // is there a better of doing this, Considering MyComposable can be called on every button click
try {
if (!show) {
show = true
delay(3000L)
}
} catch (ex: Exception) {
show = false
} finally {
show = false
}
}
}
every time LaunchedEffect
enter composition, it checks for the show
flag, so there will be no multiple slide-ins.
every time LaunchedEffect
leaves or finishes it will make it false.ritesh
03/27/2022, 10:26 AMtry catch and finally
Chris Sinco [G]
03/27/2022, 7:59 PMChris Sinco [G]
03/27/2022, 11:32 PMritesh
03/27/2022, 11:57 PMtry/catch/finally
block for cases when my LaunchedEffect
gets cancelled in between (catch
block) or completed successfully (finally
block).
It can just be try {} finally {}
block and drop catch {}
as in the end i am just making the show=false
to slide it up.Chris Sinco [G]
03/28/2022, 12:38 AMAnimatedVisibility
API then which you can pass show
as the targetState
then define different animations when entering versus exiting e.g. sliding in versus sliding outritesh
03/28/2022, 12:49 AMMyComposable
will be always part of view-tree and ComposableWhichAnimatesFromTop(show = show)
does takes the show
as param and it internally uses AnimatedVisibility
Sorry, if i was not clear before and thanks for bearing with me!
Thanks Chris.Chris Sinco [G]
03/28/2022, 12:54 AM