Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix closing scene during scroll animation #1096

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private class AnimatedMouseWheelScrollPhysics(
var requiredAnimation = true
var lastValue = 0f
val anim = AnimationState(0f)
while (requiredAnimation) {
while (requiredAnimation && coroutineContext.isActive) {
requiredAnimation = false
val durationMillis = (abs(target - anim.value) / speed)
.roundToInt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,34 @@
package androidx.compose.foundation.gestures

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.v2.runBlockingIfPossible
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.runtime.withFrameNanos
import androidx.compose.ui.InternalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.input.pointer.PointerEventType
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.ScrollWheel
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performMouseInput
import androidx.compose.ui.test.performTouchInput
import androidx.compose.ui.test.runComposeUiTest
import androidx.compose.ui.test.runSkikoComposeUiTest
import androidx.compose.ui.test.swipe
import androidx.compose.ui.unit.dp
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.jetbrains.skiko.KotlinBackend
import org.jetbrains.skiko.OS
import org.jetbrains.skiko.hostOs
Expand Down Expand Up @@ -132,4 +133,27 @@ class SkikoScrollableTest {
}
runOnIdle { assertTrue(state.firstVisibleItemIndex > 0) }
}

@OptIn(InternalComposeUiApi::class)
@Test
fun closeSceneDuringScrollAnimation() = runSkikoComposeUiTest(
size = Size(100f, 100f),
) {
setContent {
val state = rememberScrollState()
Column(Modifier.size(10.dp).verticalScroll(state)) {
Box(Modifier.size(10.dp, 210.dp))
}
}
scene.sendPointerEvent(
eventType = PointerEventType.Scroll,
position = Offset(0f, 0f),
scrollDelta = Offset(0f, 10000f)
)
/*
* This test doesn't contain any real assertions - its primary function is to ensure
* it doesn't freeze. This was an issue previously, as inside the scroll animation, there
* was a handler for the CancellationException that used to stop the scene from closing.
*/
}
}
Loading