-
Notifications
You must be signed in to change notification settings - Fork 5
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
showModalExprollable doesn't grow correctly when using a mouse to scroll #37
Comments
Thank you for your reporting! |
Oh, sorry, I missed the title. Do you mean the problem that occurs on the desktop or on a desktop browser? |
The macOS one demonstrates how it snaps to the top. The chrome one also demonstrates that it works in touch mode (at the end of the video) To answer your question, it happens on both. When there is a touch screen in use it works correctly (or when the touch screen is emulated by chrome). |
I have watched the video and confirmed that I can reproduce the problem. The cause of the problem is that when scrolling with the mouse wheel, I created a minimum project to reproduce this problem: The codeimport 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
late final ScrollController controller;
@override
void initState() {
super.initState();
controller = MyScrollController()
..addListener(() {
debugPrint("[ScrollController] offset = ${controller.offset}");
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
controller: controller,
itemBuilder: (_, index) => ListTile(
title: Text("Item#$index"),
),
),
);
}
}
class MyScrollPosition extends ScrollPositionWithSingleContext {
MyScrollPosition({
required super.physics,
required super.context,
super.oldPosition,
super.initialPixels,
super.keepScrollOffset,
});
@override
double setPixels(double newPixels) {
debugPrint("[ScrollPosition] setPixels($newPixels)");
return super.setPixels(newPixels);
}
}
class MyScrollController extends ScrollController {
@override
ScrollPosition createScrollPosition(ScrollPhysics physics,
ScrollContext context, ScrollPosition? oldPosition) {
return MyScrollPosition(
physics: physics,
context: context,
initialPixels: initialScrollOffset,
oldPosition: oldPosition,
keepScrollOffset: keepScrollOffset,
);
}
} And the results (Ran on macbook air) : scroll-by-trackpad-420p.movscroll-by-mouse-420p.movIn the first video, I am scrolling the If I can find a reason why |
It seems that when scrolling the list view with a mouse, |
This is because the pointerScroll method tells the scroll physics to start a ballistic animation that snaps the viewport inset to specified snap positions (maybe, not confirmed). |
Adding the following code to the @override
// The code was mostly borrowed from [super.pointerScroll]:
void pointerScroll(double delta) {
if (delta == 0.0) {
goBallistic(0.0);
return;
}
final double targetPixels =
(impliedPixels + delta).clamp(impliedMinScrollExtent, maxScrollExtent);
if (targetPixels != impliedPixels) {
goIdle();
updateUserScrollDirection(
-delta > 0.0 ? ScrollDirection.forward : ScrollDirection.reverse,
);
final double oldPixels = pixels;
isScrollingNotifier.value = true;
forcePixels(targetPixels);
didStartScroll();
didUpdateScrollPositionBy(pixels - oldPixels);
didEndScroll();
goBallistic(0.0);
}
} 2023-06-12.22.03.22.mov2023-06-13.11.03.49.mov |
I decided to implement the landscape mode that is mentioned in #47. This will disable the expanding/shrinking page animation in landscape mode, which won't fix the problem, but it will workaround it. In addition, this behavior is also implemented in the original UI of Apple Books app which this package is trying to emulate: 2023-08-06.23.09.16.mov |
i think this is a great decision to support more than portrait view on mobile. let me know if you want any testing/review |
I noticed that when you are using the
showModalExprollable
function, the "grow on scroll" animation snaps toViewportInset.expanded
when on a device without touch or on web.This has been confirmed to be reproducible in the examples.
The text was updated successfully, but these errors were encountered: