From 1849838e82b7b5209a1c3727ab5dfea50df6b5dc Mon Sep 17 00:00:00 2001 From: Arkadii Ivanov Date: Mon, 29 Mar 2021 07:57:03 +0100 Subject: [PATCH] TodoApp. Update Decompose to 0.2.0, enable navigation animations. (#544) --- .../buildSrc/buildSrc/src/main/kotlin/Deps.kt | 2 +- .../example/todo/common/ui/Crossfade.kt | 20 ------------------- .../example/todo/common/ui/TodoRootUi.kt | 9 +++++---- .../root/integration/TodoRootComponent.kt | 2 +- .../common/root/integration/TodoRootTest.kt | 2 +- 5 files changed, 8 insertions(+), 27 deletions(-) delete mode 100644 examples/todoapp/common/compose-ui/src/commonMain/kotlin/example/todo/common/ui/Crossfade.kt diff --git a/examples/todoapp/buildSrc/buildSrc/src/main/kotlin/Deps.kt b/examples/todoapp/buildSrc/buildSrc/src/main/kotlin/Deps.kt index 8d1fbbd66e..6e96136abb 100644 --- a/examples/todoapp/buildSrc/buildSrc/src/main/kotlin/Deps.kt +++ b/examples/todoapp/buildSrc/buildSrc/src/main/kotlin/Deps.kt @@ -49,7 +49,7 @@ object Deps { } object Decompose { - private const val VERSION = "0.1.9" + private const val VERSION = "0.2.0" const val decompose = "com.arkivanov.decompose:decompose:$VERSION" const val decomposeIosX64 = "com.arkivanov.decompose:decompose-iosx64:$VERSION" const val decomposeIosArm64 = "com.arkivanov.decompose:decompose-iosarm64:$VERSION" diff --git a/examples/todoapp/common/compose-ui/src/commonMain/kotlin/example/todo/common/ui/Crossfade.kt b/examples/todoapp/common/compose-ui/src/commonMain/kotlin/example/todo/common/ui/Crossfade.kt deleted file mode 100644 index 133f75c4e7..0000000000 --- a/examples/todoapp/common/compose-ui/src/commonMain/kotlin/example/todo/common/ui/Crossfade.kt +++ /dev/null @@ -1,20 +0,0 @@ -package example.todo.common.ui - -import androidx.compose.runtime.Composable - -fun crossfade(): @Composable (currentChild: T, currentKey: K, children: @Composable (T, K) -> Unit) -> Unit = - { currentChild: T, currentKey: K, children: @Composable (T, K) -> Unit -> - KeyedCrossfade(currentChild, currentKey, children) - } - -@Composable -private fun KeyedCrossfade(currentChild: T, currentKey: K, children: @Composable (T, K) -> Unit) { - androidx.compose.animation.Crossfade(ChildWrapper(currentChild, currentKey)) { - children(it.child, it.key) - } -} - -private class ChildWrapper(val child: T, val key: C) { - override fun equals(other: Any?): Boolean = key == (other as? ChildWrapper<*, *>)?.key - override fun hashCode(): Int = key.hashCode() -} diff --git a/examples/todoapp/common/compose-ui/src/commonMain/kotlin/example/todo/common/ui/TodoRootUi.kt b/examples/todoapp/common/compose-ui/src/commonMain/kotlin/example/todo/common/ui/TodoRootUi.kt index 1e24da948b..644445c3a7 100644 --- a/examples/todoapp/common/compose-ui/src/commonMain/kotlin/example/todo/common/ui/TodoRootUi.kt +++ b/examples/todoapp/common/compose-ui/src/commonMain/kotlin/example/todo/common/ui/TodoRootUi.kt @@ -1,16 +1,17 @@ +@file:Suppress("EXPERIMENTAL_API_USAGE") + package example.todo.common.ui import androidx.compose.runtime.Composable import com.arkivanov.decompose.extensions.compose.jetbrains.Children +import com.arkivanov.decompose.extensions.compose.jetbrains.animation.child.crossfadeScale import example.todo.common.root.TodoRoot import example.todo.common.root.TodoRoot.Child @Composable fun TodoRootContent(component: TodoRoot) { - // Crossfade does not preserve UI state properly since (probably) 0.3.0-build146. - // Uncomment when https://issuetracker.google.com/u/1/issues/178729296 is fixed. - Children(routerState = component.routerState /*, animation = crossfade()*/) { child, _ -> - when (child) { + Children(routerState = component.routerState, animation = crossfadeScale()) { + when (val child = it.instance) { is Child.Main -> TodoMainContent(child.component) is Child.Edit -> TodoEditContent(child.component) } diff --git a/examples/todoapp/common/root/src/commonMain/kotlin/example/todo/common/root/integration/TodoRootComponent.kt b/examples/todoapp/common/root/src/commonMain/kotlin/example/todo/common/root/integration/TodoRootComponent.kt index fef255d9c4..30808239bb 100644 --- a/examples/todoapp/common/root/src/commonMain/kotlin/example/todo/common/root/integration/TodoRootComponent.kt +++ b/examples/todoapp/common/root/src/commonMain/kotlin/example/todo/common/root/integration/TodoRootComponent.kt @@ -54,7 +54,7 @@ class TodoRootComponent internal constructor( router( initialConfiguration = Configuration.Main, handleBackButton = true, - componentFactory = ::createChild + childFactory = ::createChild ) override val routerState: Value> = router.state diff --git a/examples/todoapp/common/root/src/commonTest/kotlin/example/todo/common/root/integration/TodoRootTest.kt b/examples/todoapp/common/root/src/commonTest/kotlin/example/todo/common/root/integration/TodoRootTest.kt index f4a75347e0..1530efb764 100644 --- a/examples/todoapp/common/root/src/commonTest/kotlin/example/todo/common/root/integration/TodoRootTest.kt +++ b/examples/todoapp/common/root/src/commonTest/kotlin/example/todo/common/root/integration/TodoRootTest.kt @@ -51,7 +51,7 @@ class TodoRootTest { todoEdit = { _, itemId, output -> TodoEditFake(itemId, output) } ) - private val TodoRoot.activeChild: Child get() = routerState.value.activeChild.component + private val TodoRoot.activeChild: Child get() = routerState.value.activeChild.instance private val Child.component: Any get() =