Skip to content

Commit

Permalink
update to compose 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Tlaster committed Sep 30, 2024
1 parent 276c933 commit 418a4a8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 76 deletions.
18 changes: 9 additions & 9 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ libVersion = "1.6.2"
compileSdk = "34"
minSdk = "21"
java = "11"
androidx-animation = "1.6.8"
androidx-foundation = "1.6.8"
androidx-animation = "1.7.2"
androidx-foundation = "1.7.2"
androidx-appcompat = "1.7.0"
androidx-coreKtx = "1.13.1"
androidxActivityVer = "1.9.2"
androidGradlePlugin = "8.6.0"
androidGradlePlugin = "8.6.1"
junit = "4.13.2"
junitJupiterEngine = "5.11.0"
junitJupiterApi = "5.11.0"
kotlin = "2.0.0"
lifecycleRuntimeKtx = "2.8.5"
material = "1.6.8"
kotlinxCoroutinesCore = "1.8.1"
lifecycleRuntimeKtx = "2.8.6"
material = "1.7.2"
kotlinxCoroutinesCore = "1.9.0"
moleculeRuntime = "2.0.0"
savedstateKtx = "1.2.1"
spotless = "6.25.0"
jetbrainsComposePlugin = "1.6.11"
jetbrainsComposePlugin = "1.7.0-beta02"
skiko = "0.8.12"
koin = "4.0.0-RC2"
koin = "4.0.0"
uuid = "0.8.4"
webpackCliVersion = "5.1.4"
nodeVersion = "20.14.0"
Expand All @@ -48,7 +48,7 @@ molecule-runtime = { module = "app.cash.molecule:molecule-runtime", version.ref
skiko = { module = "org.jetbrains.skiko:skiko", version.ref = "skiko" }
skiko-js = { module = "org.jetbrains.skiko:skiko-js-wasm-runtime", version.ref = "skiko" }
koin = { module = "io.insert-koin:koin-core", version.ref = "koin" }
koin-compose = { module = "io.insert-koin:koin-compose", version = "4.0.0-RC2" }
koin-compose = { module = "io.insert-koin:koin-compose", version.ref = "koin" }
uuid = { module = "com.benasher44:uuid", version.ref = "uuid" }

[plugins]
Expand Down
4 changes: 2 additions & 2 deletions precompose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ kotlin {
sourceSetTree.set(KotlinSourceSetTree.test)

dependencies {
androidTestImplementation("androidx.compose.ui:ui-test-junit4-android:1.6.8")
debugImplementation("androidx.compose.ui:ui-test-manifest:1.6.7")
androidTestImplementation("androidx.compose.ui:ui-test-junit4-android:1.7.2")
debugImplementation("androidx.compose.ui:ui-test-manifest:1.7.2")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ actual fun PreComposeApp(
) {
val viewModel = androidx.lifecycle.viewmodel.compose.viewModel<PreComposeViewModel>()

val lifecycle = androidx.compose.ui.platform.LocalLifecycleOwner.current.lifecycle
val lifecycle = androidx.lifecycle.compose.LocalLifecycleOwner.current.lifecycle
val onBackPressedDispatcher = checkNotNull(androidx.activity.compose.LocalOnBackPressedDispatcherOwner.current) {
"No OnBackPressedDispatcherOwner was provided via LocalOnBackPressedDispatcherOwner"
}.onBackPressedDispatcher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.animation.core.SeekableTransitionState
import androidx.compose.animation.core.rememberTransition
import androidx.compose.animation.core.tween
import androidx.compose.animation.core.updateTransition
import androidx.compose.animation.rememberSplineBasedDecay
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.gestures.AnchoredDraggableState
import androidx.compose.foundation.gestures.DraggableAnchors
Expand Down Expand Up @@ -140,7 +141,8 @@ fun NavHost(
val state = if (actualSwipeProperties != null) {
val density = LocalDensity.current
val width = constraints.maxWidth.toFloat()
remember {
val decayAnimationSpec = rememberSplineBasedDecay<Float>()
remember(actualSwipeProperties) {
AnchoredDraggableState(
initialValue = DragAnchors.Start,
anchors = DraggableAnchors {
Expand All @@ -149,7 +151,8 @@ fun NavHost(
},
positionalThreshold = actualSwipeProperties.positionalThreshold,
velocityThreshold = { actualSwipeProperties.velocityThreshold.invoke(density) },
animationSpec = tween(),
snapAnimationSpec = tween(),
decayAnimationSpec = decayAnimationSpec,
)
}.also { state ->
LaunchedEffect(
Expand All @@ -159,13 +162,13 @@ fun NavHost(
if (state.currentValue == DragAnchors.End && !state.isAnimationRunning) {
// play the animation to the end
progress = 1f
state.snapTo(DragAnchors.Start)
}
}
LaunchedEffect(state.progress) {
if (state.progress != 1f) {
inPredictiveBack = state.progress > 0f
progress = state.progress
val stateProgress = state.progress(DragAnchors.Start, DragAnchors.End)
LaunchedEffect(stateProgress) {
if (stateProgress != 1f) {
inPredictiveBack = stateProgress > 0f
progress = stateProgress
} else if (state.currentValue != DragAnchors.End && inPredictiveBack) {
// reset the state to the initial value
progress = -1f
Expand All @@ -185,20 +188,21 @@ fun NavHost(
}
val transition = if (showPrev) {
val transitionState by remember(sceneEntry) {
mutableStateOf(SeekableTransitionState(sceneEntry, prevSceneEntry!!))
mutableStateOf(SeekableTransitionState(sceneEntry))
}
LaunchedEffect(progress) {
if (progress == 1f) {
// play the animation to the end
transitionState.animateToTargetState()
transitionState.animateTo(prevSceneEntry!!)
inPredictiveBack = false
navigator.goBack()
progress = 0f
state?.snapTo(DragAnchors.Start)
} else if (progress >= 0) {
transitionState.snapToFraction(progress)
transitionState.seekTo(progress, targetState = prevSceneEntry!!)
} else if (progress == -1f) {
// reset the state to the initial value
transitionState.animateToCurrentState()
transitionState.seekTo(0f, targetState = prevSceneEntry!!)
inPredictiveBack = false
progress = 0f
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.remember
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.window.FrameWindowScope
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowScope
import androidx.compose.ui.window.WindowState
import androidx.compose.ui.window.rememberWindowState
import moe.tlaster.precompose.lifecycle.Lifecycle
import moe.tlaster.precompose.lifecycle.LifecycleOwner
import moe.tlaster.precompose.lifecycle.LifecycleRegistry
Expand All @@ -25,55 +21,6 @@ import java.awt.Window
import java.awt.event.WindowAdapter
import java.awt.event.WindowEvent

@Deprecated(
message = """
Use Window directly instead. And make sure wrap your content with PreComposeApp.
PreComposeWindow will be removed in the future release.
For migration guide, please refer to https://github.com/Tlaster/PreCompose/releases/tag/1.5.5
""",
replaceWith = ReplaceWith("PreComposeWindow"),
)
@Composable
fun PreComposeWindow(
onCloseRequest: () -> Unit,
state: WindowState = rememberWindowState(),
visible: Boolean = true,
title: String = "Untitled",
icon: Painter? = null,
undecorated: Boolean = false,
transparent: Boolean = false,
resizable: Boolean = true,
enabled: Boolean = true,
focusable: Boolean = true,
alwaysOnTop: Boolean = false,
onPreviewKeyEvent: (KeyEvent) -> Boolean = { false },
onKeyEvent: (KeyEvent) -> Boolean = { false },
content: @Composable FrameWindowScope.() -> Unit,
) {
Window(
onCloseRequest = onCloseRequest,
state = state,
visible = visible,
title = title,
icon = icon,
undecorated = undecorated,
transparent = transparent,
resizable = resizable,
enabled = enabled,
focusable = focusable,
alwaysOnTop = alwaysOnTop,
onPreviewKeyEvent = onPreviewKeyEvent,
onKeyEvent = onKeyEvent,
content = {
ProvidePreComposeLocals {
PreComposeApp {
content.invoke(this)
}
}
},
)
}

val LocalWindow = staticCompositionLocalOf<Window> {
error("No Window for PreCompose, please use ProvidePreComposeLocals in WindowScope to setup your desktop project")
}
Expand Down

0 comments on commit 418a4a8

Please sign in to comment.