Browse Source

TodoApp. Update Decompose to 0.2.0, enable navigation animations. (#544)

pull/548/head 0.4.0-build178
Arkadii Ivanov 4 years ago committed by GitHub
parent
commit
1849838e82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      examples/todoapp/buildSrc/buildSrc/src/main/kotlin/Deps.kt
  2. 20
      examples/todoapp/common/compose-ui/src/commonMain/kotlin/example/todo/common/ui/Crossfade.kt
  3. 9
      examples/todoapp/common/compose-ui/src/commonMain/kotlin/example/todo/common/ui/TodoRootUi.kt
  4. 2
      examples/todoapp/common/root/src/commonMain/kotlin/example/todo/common/root/integration/TodoRootComponent.kt
  5. 2
      examples/todoapp/common/root/src/commonTest/kotlin/example/todo/common/root/integration/TodoRootTest.kt

2
examples/todoapp/buildSrc/buildSrc/src/main/kotlin/Deps.kt

@ -49,7 +49,7 @@ object Deps {
} }
object Decompose { 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 decompose = "com.arkivanov.decompose:decompose:$VERSION"
const val decomposeIosX64 = "com.arkivanov.decompose:decompose-iosx64:$VERSION" const val decomposeIosX64 = "com.arkivanov.decompose:decompose-iosx64:$VERSION"
const val decomposeIosArm64 = "com.arkivanov.decompose:decompose-iosarm64:$VERSION" const val decomposeIosArm64 = "com.arkivanov.decompose:decompose-iosarm64:$VERSION"

20
examples/todoapp/common/compose-ui/src/commonMain/kotlin/example/todo/common/ui/Crossfade.kt

@ -1,20 +0,0 @@
package example.todo.common.ui
import androidx.compose.runtime.Composable
fun <T, K> 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 <T, K> 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<out T, out C>(val child: T, val key: C) {
override fun equals(other: Any?): Boolean = key == (other as? ChildWrapper<*, *>)?.key
override fun hashCode(): Int = key.hashCode()
}

9
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 package example.todo.common.ui
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import com.arkivanov.decompose.extensions.compose.jetbrains.Children 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
import example.todo.common.root.TodoRoot.Child import example.todo.common.root.TodoRoot.Child
@Composable @Composable
fun TodoRootContent(component: TodoRoot) { fun TodoRootContent(component: TodoRoot) {
// Crossfade does not preserve UI state properly since (probably) 0.3.0-build146. Children(routerState = component.routerState, animation = crossfadeScale()) {
// Uncomment when https://issuetracker.google.com/u/1/issues/178729296 is fixed. when (val child = it.instance) {
Children(routerState = component.routerState /*, animation = crossfade()*/) { child, _ ->
when (child) {
is Child.Main -> TodoMainContent(child.component) is Child.Main -> TodoMainContent(child.component)
is Child.Edit -> TodoEditContent(child.component) is Child.Edit -> TodoEditContent(child.component)
} }

2
examples/todoapp/common/root/src/commonMain/kotlin/example/todo/common/root/integration/TodoRootComponent.kt

@ -54,7 +54,7 @@ class TodoRootComponent internal constructor(
router<Configuration, Child>( router<Configuration, Child>(
initialConfiguration = Configuration.Main, initialConfiguration = Configuration.Main,
handleBackButton = true, handleBackButton = true,
componentFactory = ::createChild childFactory = ::createChild
) )
override val routerState: Value<RouterState<*, Child>> = router.state override val routerState: Value<RouterState<*, Child>> = router.state

2
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) } 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 private val Child.component: Any
get() = get() =

Loading…
Cancel
Save