FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge pull request #402 from android/nb/js_anim_launch · jcode9/compose-samples@e3bd277 · GitHub

Commit e3bd277

Browse files
authored
Merge pull request android#402 from android/nb/js_anim_launch
[Jetsnack] Correct creation of coroutines within composition.
2 parents d3e192c + 4e81ef5 commit e3bd277

1 file changed

Lines changed: 2 additions & 7 deletions

File tree

  • Jetsnack/app/src/main/java/com/example/jetsnack/ui/home

‎Jetsnack/app/src/main/java/com/example/jetsnack/ui/home/Home.kt‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import androidx.compose.runtime.LaunchedEffect
4646
import androidx.compose.runtime.getValue
4747
import androidx.compose.runtime.mutableStateOf
4848
import androidx.compose.runtime.remember
49-
import androidx.compose.runtime.rememberCoroutineScope
5049
import androidx.compose.runtime.saveable.rememberSaveable
5150
import androidx.compose.ui.Alignment
5251
import androidx.compose.ui.Modifier
@@ -75,7 +74,6 @@ import com.example.jetsnack.ui.home.cart.Cart
7574
import com.example.jetsnack.ui.home.search.Search
7675
import com.example.jetsnack.ui.theme.JetsnackTheme
7776
import dev.chrisbanes.accompanist.insets.navigationBarsPadding
78-
import kotlinx.coroutines.launch
7977

8078
@Composable
8179
fun Home(onSnackSelected: (Long) -> Unit) {
@@ -189,13 +187,10 @@ private fun JetsnackBottomNavLayout(
189187
Animatable(if (i == selectedIndex) 1f else 0f)
190188
}
191189
}
192-
val scope = rememberCoroutineScope()
193190
selectionFractions.forEachIndexed { index, selectionFraction ->
194191
val target = if (index == selectedIndex) 1f else 0f
195-
if (selectionFraction.targetValue != target) {
196-
scope.launch {
197-
selectionFraction.animateTo(target, animSpec)
198-
}
192+
LaunchedEffect(target, animSpec) {
193+
selectionFraction.animateTo(target, animSpec)
199194
}
200195
}
201196

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL