-
Notifications
You must be signed in to change notification settings - Fork 28.7k
Add peek feature to PageView #8539
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
Conversation
double get peek => _peek; | ||
double _peek; | ||
set peek (double newValue) { | ||
assert(newValue != null); |
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.
maybe assert > 0
, <= 1.0
?
(would it work with > 1.0
?)
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.
Oh, I see, peek values are absolute pixels. This seems surprising, I would have expected it to be a fraction of the viewportMainAxisExtent.
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.
I guess it works either way. I don't know what our customers prefer.
@@ -264,4 +264,42 @@ void main() { | |||
expect(find.text('Alaska'), findsOneWidget); | |||
}); | |||
|
|||
testWidgets('PageView peek', (WidgetTester tester) async { |
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.
we should test that this handles the main axis extent changing (without rebuilding) when the peek is non-zero.
I didn't verify the math, but LGTM. |
final int initialPage; | ||
|
||
/// The number of pixels of the next and previous page that should be visible | ||
/// before and after the current page. | ||
final double peek; |
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.
Another way to define this would have been been pageWidth as a percentage of the viewport's width. The default and the maximum would be 1.0.
On a wide screen, like a tablet, you might want to define the pageWidth with a small enough value so that the entire next/prev pages are visible.
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.
Maybe that's better. I'll give that a try.
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.
Yeah, that seems cleaner.
@override | ||
PageScrollPhysics applyTo(ScrollPhysics parent) => new PageScrollPhysics(parent: parent); | ||
|
||
double _getPage(ScrollPosition position) { |
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.
Does this work if peek > viewportDimension / 4, i.e. if 3 or more pages are visible after the pageview has settled?
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.
I'll add a test for that, but it should work in theory.
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.
That works. I also tested viewportFractions greater than one.
This feature lets you see a portion of the next and previous page in a PageView. Fixes flutter#8408
This feature lets you see a portion of the next and previous page in a
PageView.
Fixes #8408