Skip to content

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

Merged
merged 1 commit into from
Mar 3, 2017
Merged

Add peek feature to PageView #8539

merged 1 commit into from
Mar 3, 2017

Conversation

abarth
Copy link
Contributor

@abarth abarth commented Mar 2, 2017

This feature lets you see a portion of the next and previous page in a
PageView.

Fixes #8408

@abarth
Copy link
Contributor Author

abarth commented Mar 2, 2017

@HansMuller @Hixie

double get peek => _peek;
double _peek;
set peek (double newValue) {
assert(newValue != null);
Copy link
Contributor

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?)

Copy link
Contributor

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.

Copy link
Contributor

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 {
Copy link
Contributor

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.

@Hixie
Copy link
Contributor

Hixie commented Mar 2, 2017

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;
Copy link
Contributor

@HansMuller HansMuller Mar 3, 2017

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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
@abarth abarth merged commit 0403ed4 into flutter:master Mar 3, 2017
@abarth abarth deleted the page_peek branch March 3, 2017 05:09
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Would like to be able to peek next and previous pages in addition to current
4 participants