11package com.flipcash.app.pools.internal.betting.components
22
33import androidx.compose.animation.AnimatedContent
4+ import androidx.compose.animation.ContentTransform
5+ import androidx.compose.animation.EnterTransition
6+ import androidx.compose.animation.ExitTransition
47import androidx.compose.animation.animateColorAsState
58import androidx.compose.animation.core.Spring
69import androidx.compose.animation.core.spring
@@ -26,9 +29,12 @@ import androidx.compose.foundation.layout.padding
2629import androidx.compose.foundation.shape.ZeroCornerSize
2730import androidx.compose.material.Text
2831import androidx.compose.runtime.Composable
32+ import androidx.compose.runtime.LaunchedEffect
2933import androidx.compose.runtime.getValue
34+ import androidx.compose.runtime.mutableStateOf
3035import androidx.compose.runtime.remember
3136import androidx.compose.runtime.rememberUpdatedState
37+ import androidx.compose.runtime.setValue
3238import androidx.compose.ui.Alignment
3339import androidx.compose.ui.Modifier
3440import androidx.compose.ui.graphics.Color
@@ -60,6 +66,7 @@ internal fun BidOptions(
6066 outcomes : List <PoolBetOutcome >,
6167 totals : Map <PoolBetOutcome , Int >,
6268 selectedOutcome : PoolBetOutcome ? ,
69+ isLoaded : Boolean ,
6370 resolution : PoolResolution ,
6471 modifier : Modifier = Modifier ,
6572 contentPadding : PaddingValues = PaddingValues (horizontal = CodeTheme .dimens.inset),
@@ -92,9 +99,35 @@ internal fun BidOptions(
9299 possibleOutcomes.fastForEach { item ->
93100 val isSelected = remember(
94101 item,
95- selectedOutcome
102+ selectedOutcome,
103+ isLoaded,
96104 ) { item.key == selectedOutcome?.key }
97105
106+ // State to track if the composable has been initialized
107+ var isInitialized by remember { mutableStateOf(false ) }
108+
109+ // State to control animation trigger
110+ var triggerAnimation by remember { mutableStateOf(false ) }
111+
112+ var showContent by remember { mutableStateOf(false ) }
113+
114+ // Detect selection change after data is loaded
115+ LaunchedEffect (isSelected) {
116+ if (isInitialized) {
117+ // Selection changed from false to true after data is loaded
118+ triggerAnimation = true
119+ }
120+
121+ showContent = isSelected
122+ }
123+
124+ // Set isInitialized to true after first composition
125+ LaunchedEffect (isLoaded) {
126+ if (isLoaded) {
127+ isInitialized = true
128+ }
129+ }
130+
98131 Column (
99132 modifier = Modifier
100133 .fillMaxHeight()
@@ -113,16 +146,24 @@ internal fun BidOptions(
113146 ) { onOutcomeSelected(item) }
114147
115148 AnimatedContent (
116- targetState = isSelected ,
149+ targetState = showContent ,
117150 modifier = Modifier .align(Alignment .CenterHorizontally ),
118151 contentKey = { (item.key + it).hashCode() },
119152 transitionSpec = {
120- slideInVertically(
121- spring(
122- dampingRatio = Spring .DampingRatioMediumBouncy ,
123- stiffness = Spring .StiffnessMediumLow ,
153+ if (triggerAnimation && targetState) {
154+ slideInVertically(
155+ spring(
156+ dampingRatio = Spring .DampingRatioMediumBouncy ,
157+ stiffness = Spring .StiffnessMediumLow ,
158+ )
159+ ) + fadeIn() togetherWith fadeOut() + slideOutVertically()
160+ } else {
161+ // No animation for initial load, data change, or deselection
162+ ContentTransform (
163+ targetContentEnter = EnterTransition .None ,
164+ initialContentExit = ExitTransition .None
124165 )
125- ) + fadeIn() togetherWith fadeOut() + slideOutVertically()
166+ }
126167 },
127168 ) { show ->
128169 if (show) {
0 commit comments