JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
16.27k stars 1.18k forks source link

Compilation aborts when trying to compile a project with Navigation Compose and AnchoredDraggableState #4677

Closed sodove closed 6 months ago

sodove commented 6 months ago

Describe the bug Compilation aborts when trying to compile a project with Navigation Compose and AnchoredDraggableState, when navigation is not added to the project - the project is built normally.

None of the following functions can be called with the arguments supplied: 

public constructor AnchoredDraggableState<T>(initialValue: TypeVariable(T), positionalThreshold: (totalDistance: Float) -> Float, velocityThreshold: () -> Float, snapAnimationSpec: AnimationSpec<Float>, decayAnimationSpec: DecayAnimationSpec<Float>, confirmValueChange: (newValue: TypeVariable(T)) -> Boolean = ...) defined in androidx.compose.foundation.gestures.AnchoredDraggableState

public constructor AnchoredDraggableState<T>(initialValue: TypeVariable(T), anchors: DraggableAnchors<TypeVariable(T)>, positionalThreshold: (totalDistance: Float) -> Float, velocityThreshold: () -> Float, snapAnimationSpec: AnimationSpec<Float>, decayAnimationSpec: DecayAnimationSpec<Float>, confirmValueChange: (newValue: TypeVariable(T)) -> Boolean = ...) defined in androidx.compose.foundation.gestures.AnchoredDraggableState

Affected platforms

Versions

To Reproduce Reproduction sample: https://github.com/sodove/anchored_repro

  1. Add next code to project
    
    enum class DrawerState {
    Opened,
    Closed,
    }

... val state = remember { AnchoredDraggableState( initialValue = DrawerState.Closed, anchors = DraggableAnchors { DrawerState.Opened at -startAnchor DrawerState.Closed at 0f }, positionalThreshold = { distance: Float -> distance * 0.5f }, velocityThreshold = { with(density) { 100.dp.toPx() } }, animationSpec = tween(), ) } ...


2. Add the following dependency to your commonMain source set
implementation("org.jetbrains.androidx.navigation:navigation-compose:2.8.0-alpha01")
3. Try to compile project

**Expected behavior**
The project has to build and run
MatkovIvan commented 6 months ago

Please note that Compose Multiplatform doesn't re-compile Google's binaries and reuses them as-is. This problem is about Compose 1.7.0 compatibility and tracked here: https://issuetracker.google.com/issues/324975816

In your project you can see that in the dependency graph Jetpack Compose is resolved to 1.7.0-alpha05:

./gradlew dependencies

...
+--- org.jetbrains.androidx.navigation:navigation-compose:2.8.0-alpha01
|    \--- androidx.navigation:navigation-compose:2.8.0-alpha05
|         +--- androidx.activity:activity-compose:1.8.0 -> 1.8.2 (*)
|         +--- androidx.compose.animation:animation:1.7.0-alpha05 (*)
|         +--- androidx.compose.runtime:runtime:1.7.0-alpha05 (*)
|         +--- androidx.compose.runtime:runtime-saveable:1.7.0-alpha05 (*)
|         +--- androidx.compose.ui:ui:1.7.0-alpha05 (*)
...

That's an unfortunate situation because Compose Multiplatform is not adopted to 1.7.0 yet. I'll think how to mitigate this.

For now I can only suggest this workaround: ``` configurations.configureEach { resolutionStrategy { eachDependency { if (requested.group in listOf( "androidx.compose.animation", "androidx.compose.runtime", "androidx.compose.ui", "androidx.compose.foundation" )) { useVersion("1.6.5") } } } } ```

UPD: The workaround above is incorrect because navigation 2.8.* uses SeekableTransitionState from compose 1.7

Lonchi78 commented 5 months ago

Got the same issue, and not using Compose Multiplatform

MatkovIvan commented 5 months ago

@Lonchi78 The issue is about mixing 1.6 and 1.7 while using experimental API that were changed between these versions

okushnikov commented 4 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.