-
Notifications
You must be signed in to change notification settings - Fork 60
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 scrolling when we change LazyListState #769
Fix scrolling when we change LazyListState #769
Conversation
Fixes JetBrains/compose-multiplatform#3551 When the new state is passed to LazyList, it goes down to `Modifier.pointerScrollable` as `controller: ScrollableState`, and wraps to `rememberUpdatedState`, which is always the same instance. Because it is the same instance, MouseWheelScrollableElement.update is never called. Passing it is as a value now, as MouseWheelScrollableElement doesn't need a state.
e2ad8fe
to
e665cce
Compare
.../foundation/src/skikoTest/kotlin/androidx/compose/foundation/gestures/SkikoScrollableTest.kt
Show resolved
Hide resolved
It seems there is test that checks equality of the modifier across compositions. Probably for optimization. Remembering scrolling logic seems logical here, and shouldn't add overhead. In 1.6 it was fully rewritten to modifier node: https://github.com/androidx/androidx/blob/a7e6bdf524be186baca08e9ddf7272b834a14bd2/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Scrollable.kt#L276
.nestedScroll(nestedScrollConnection, nestedScrollDispatcher.value) | ||
} | ||
|
||
// {} isn't being memoized for us, so extract this to make sure we compare equally on recomposition. | ||
private val NoOpOnDragStarted: suspend CoroutineScope.(startedPosition: Offset) -> Unit = {} | ||
|
||
@Composable | ||
private fun rememberScrollingLogic( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems there is test that checks equality of the modifier across compositions. Probably for optimization. remember
fixes the test.
Remembering scrolling logic seems logical here, and shouldn't add overhead.
In 1.6 it was fully rewritten to modifier node:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which test was failing before adding rememberScrollingLogic
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. The tests passed on my machine too.
* Fix scrolling when we change LazyListState Fixes JetBrains/compose-multiplatform#3551 When the new state is passed to LazyList, it goes down to `Modifier.pointerScrollable` as `controller: ScrollableState`, and wraps to `rememberUpdatedState`, which is always the same instance. Because it is the same instance, MouseWheelScrollableElement.update is never called. Passing it is as a value now, as MouseWheelScrollableElement doesn't need a state. * Remember ScrollingLogic It seems there is test that checks equality of the modifier across compositions. Probably for optimization. Remembering scrolling logic seems logical here, and shouldn't add overhead. In 1.6 it was fully rewritten to modifier node: https://github.com/androidx/androidx/blob/a7e6bdf524be186baca08e9ddf7272b834a14bd2/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Scrollable.kt#L276
* Fix scrolling when we change LazyListState Fixes JetBrains/compose-multiplatform#3551 When the new state is passed to LazyList, it goes down to `Modifier.pointerScrollable` as `controller: ScrollableState`, and wraps to `rememberUpdatedState`, which is always the same instance. Because it is the same instance, MouseWheelScrollableElement.update is never called. Passing it is as a value now, as MouseWheelScrollableElement doesn't need a state. * Remember ScrollingLogic It seems there is test that checks equality of the modifier across compositions. Probably for optimization. Remembering scrolling logic seems logical here, and shouldn't add overhead. In 1.6 it was fully rewritten to modifier node: https://github.com/androidx/androidx/blob/a7e6bdf524be186baca08e9ddf7272b834a14bd2/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Scrollable.kt#L276
* Set scroll progress state on mouse events * Animate mouse wheel scroll * Refactor changes * Add helper inline functions * Batch offsets * Filter zero values and apply raw delta only without animation * Use scrollBy inside animation, fix parameter usage in lambda * Fix tests * Add TODOs and comments * Fix more tests * Cleanup mouse hover test helper class * Add test for scroll during animation * Address feedback (part 1) * Make smooth scrolling configurable * Do not animate scroll on events from trackpads * Fix internal type for tests * Make animation scrolling speed density dependant * Fix conditionally applying scroll modifier * Fix cancel animation condition * Cache smooth scrolling flag * Adjust scrolling animation threshold * Add isScrollInProgress TODO * Add test for isSmoothScrollingEnabled flag * Reset flag in finally * Use strict comparison to detect consuming event mouse [bugfix, hard] foundation. mouse. Fix missing scrolling events (#527) * Move awaitPointerEventScope outside the loop * Add test for multi-event regression mouse [bugfix, simple] foundation. mouse. Handle scroll cancellation exception (#696) * Catch scroll cancellation exception * Fix demo mouse [feature, hard] foundation. mouse. Fix scrolling when we change LazyListState (#769) * Fix scrolling when we change LazyListState Fixes JetBrains/compose-multiplatform#3551 When the new state is passed to LazyList, it goes down to `Modifier.pointerScrollable` as `controller: ScrollableState`, and wraps to `rememberUpdatedState`, which is always the same instance. Because it is the same instance, MouseWheelScrollableElement.update is never called. Passing it is as a value now, as MouseWheelScrollableElement doesn't need a state. * Remember ScrollingLogic It seems there is test that checks equality of the modifier across compositions. Probably for optimization. Remembering scrolling logic seems logical here, and shouldn't add overhead. In 1.6 it was fully rewritten to modifier node: https://github.com/androidx/androidx/blob/a7e6bdf524be186baca08e9ddf7272b834a14bd2/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Scrollable.kt#L276 mouse [bugfix, simple] foundation. mouse. Take into account `enabled` in `scrollable` for mouse input (#880) Fixes JetBrains/compose-multiplatform#3816 ## Testing 1. The new test 2. Manual testing of `Modifier.verticalScroll(enabled = false`
Fixes JetBrains/compose-multiplatform#3551
When the new state is passed to LazyList, it goes down to
Modifier.pointerScrollable
ascontroller: ScrollableState
, and wraps torememberUpdatedState
, which is always the same instance. Because it is the same instance, MouseWheelScrollableElement.update is never called.Passing it is as a value now, as MouseWheelScrollableElement doesn't need a state.
Testing