Skip to content

Commit

Permalink
Migrate to decompose 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
xxfast committed May 26, 2024
1 parent e7c3ee5 commit 9822ae9
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import com.arkivanov.decompose.ExperimentalDecomposeApi
import com.arkivanov.decompose.extensions.compose.jetbrains.pages.PagesScrollAnimation
import com.arkivanov.decompose.extensions.compose.pages.PagesScrollAnimation
import com.arkivanov.decompose.router.pages.select
import io.github.xxfast.decompose.router.pages.RoutedContent
import io.github.xxfast.decompose.router.pages.Router
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package io.github.xxfast.decompose.router.screens.stack

import androidx.compose.runtime.Composable
import com.arkivanov.decompose.ExperimentalDecomposeApi
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.predictiveback.predictiveBackAnimation
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.slide
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.stackAnimation
import com.arkivanov.decompose.extensions.compose.stack.animation.fade
import com.arkivanov.decompose.extensions.compose.stack.animation.plus
import com.arkivanov.decompose.extensions.compose.stack.animation.predictiveback.androidPredictiveBackAnimatable
import com.arkivanov.decompose.extensions.compose.stack.animation.predictiveback.predictiveBackAnimation
import com.arkivanov.decompose.extensions.compose.stack.animation.scale
import com.arkivanov.decompose.extensions.compose.stack.animation.stackAnimation
import com.arkivanov.decompose.router.stack.pop
import com.arkivanov.decompose.router.stack.push
import io.github.xxfast.decompose.router.LocalRouterContext
Expand All @@ -24,9 +27,10 @@ fun StackScreen() {
RoutedContent(
router = router,
animation = predictiveBackAnimation(
animation = stackAnimation(slide()),
backHandler = LocalRouterContext.current.backHandler,
fallbackAnimation = stackAnimation(fade() + scale()),
selector = { backEvent, _, _ -> androidPredictiveBackAnimatable(backEvent) },
onBack = { router.pop() },
backHandler = LocalRouterContext.current.backHandler
)
) { screen ->
when (screen) {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ buildscript {
classpath(libs.agp)
classpath(libs.compose.multiplatform)
classpath(libs.kotlin.gradle.plugin)
classpath(libs.kotlinx.serialization)
classpath(libs.kotlin.serialization.plugin)
}
}

Expand Down
2 changes: 1 addition & 1 deletion decompose-router/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ kotlin {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(libs.decompose.compose.multiplatform)
implementation(libs.kotlinx.serialization)
implementation(libs.kotlinx.serialization.core)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package io.github.xxfast.decompose.router
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import com.arkivanov.decompose.value.Value
import com.arkivanov.decompose.value.observe
import com.arkivanov.decompose.value.subscribe
import com.arkivanov.essenty.lifecycle.Lifecycle

internal fun <T : Any> Value<T>.asState(lifecycle: Lifecycle): State<T> {
val state = mutableStateOf(value)
observe(lifecycle = lifecycle) { state.value = it }
subscribe(lifecycle = lifecycle) { state.value = it }
return state
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import com.arkivanov.decompose.ExperimentalDecomposeApi
import com.arkivanov.decompose.extensions.compose.jetbrains.pages.Pages
import com.arkivanov.decompose.extensions.compose.jetbrains.pages.PagesScrollAnimation
import com.arkivanov.decompose.extensions.compose.jetbrains.pages.defaultHorizontalPager
import com.arkivanov.decompose.extensions.compose.pages.Pages
import com.arkivanov.decompose.extensions.compose.pages.PagesScrollAnimation
import com.arkivanov.decompose.extensions.compose.pages.defaultHorizontalPager
import com.arkivanov.decompose.router.pages.select
import io.github.xxfast.decompose.router.LocalRouterContext
import kotlinx.serialization.Serializable
Expand All @@ -29,7 +29,7 @@ fun <C : @Serializable Any> RoutedContent(
content: @Composable (C) -> Unit,
) {
Pages(
pages = router.pages,
pages = router.pages.value,
onPageSelected = { index -> router.select(index) },
modifier = modifier,
pager = pager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package io.github.xxfast.decompose.router.stack
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.Children
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.StackAnimation
import com.arkivanov.decompose.extensions.compose.stack.Children
import com.arkivanov.decompose.extensions.compose.stack.animation.StackAnimation
import io.github.xxfast.decompose.router.LocalRouterContext
import io.github.xxfast.decompose.router.RouterContext
import kotlinx.serialization.Serializable
Expand Down
2 changes: 1 addition & 1 deletion docs/topics/platform-configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ You will need to tie root `RouterContext`'s lifecycle to an `AppDelegate`.
> }
> }
>
> sourceSets {
> sourceSets {
> val commonMain by getting {
> dependencies {
> // Only need to add this as api if you wish to add your own AppDelegate in swift
Expand Down
16 changes: 9 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
agp = "8.1.1"
androidx-activity ="1.7.2"
androidx-fragment ="1.6.1"
compose-multiplatform = "1.5.11"
compose-multiplatform = "1.6.1"
compose-test-rule = "1.5.1"
decompose = "2.2.0-compose-experimental-beta02"
essenty = "1.3.0-beta01"
decompose = "3.0.0"
essenty = "2.0.0"
horologist = "0.5.7"
kotlin = "1.9.20"
kotlin = "1.9.23"
kotlinx-coroutines = "1.7.3"
kotlinx-serialization = "1.6.0"
kotlinx-serialization = "1.6.2"
wear-compose = "1.3.0-alpha03"

[libraries]
Expand All @@ -21,11 +21,13 @@ compose-multiplatform = { module = "org.jetbrains.compose:compose-gradle-plugin"
compose-ui-junit4 = { module = "androidx.compose.ui:ui-test-junit4", version.ref = "compose-test-rule" }
compose-ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest", version.ref = "compose-test-rule" }
decompose = { module = "com.arkivanov.decompose:decompose", version.ref = "decompose" }
decompose-compose-multiplatform = { module = "com.arkivanov.decompose:extensions-compose-jetbrains", version.ref = "decompose" }
decompose-compose-multiplatform = { module = "com.arkivanov.decompose:extensions-compose", version.ref = "decompose" }
horologist-compose-layouts = { module = "com.google.android.horologist:horologist-compose-layout", version.ref = "horologist" }
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlinx-coroutines-swing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "kotlinx-coroutines" }
kotlinx-serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlinx-serialization" }
kotlin-serialization-plugin = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" }
kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinx-serialization" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlin-serialization-json", version.ref = "kotlinx-serialization" }
wear-compose-foundation = { module = "androidx.wear.compose:compose-foundation", version.ref = "wear-compose" }
wear-compose-material = { module = "androidx.wear.compose:compose-material", version.ref = "wear-compose" }
wear-compose-ui-tooling = { module = "androidx.wear.compose:compose-ui-tooling", version.ref = "wear-compose" }

0 comments on commit 9822ae9

Please sign in to comment.