-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
[ViewPager] Add setPageWithoutAnimation #3621
[ViewPager] Add setPageWithoutAnimation #3621
Conversation
By analyzing the blame information on this pull request, we identified @mkonicek to be a potential reviewer. |
Thanks Brent! Will take a look. |
@@ -41,6 +41,11 @@ public void setSelectedPage(ReactViewPager view, int page) { | |||
view.setCurrentItemFromJs(page); | |||
} | |||
|
|||
@ReactProp(name = "animatePageTransition") | |||
public void setAnimatePageTransition(ReactViewPager view, boolean animatedPageTransition) { |
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.
nit: animated
-> animate
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.
Going to get rid of this as per comment below :)
@mkonicek - updated! |
@brentvatne updated the pull request. |
Oh sorry I meant:
Do you think that API would make sense? It's similar to how you set the With the current solution there are two ways to set a page which seems a bit confusing to me. Looking at the API I would think: logically a ViewPager only has one selected page, why does it also have a |
Is it sufficient for you to create a ViewPager that never animates, or do you need to flip between animated and instant page sets dynamically? The dynamic case is harder: I think we should have some way to set both |
Just talked to Krzysztof who made a really good point - another option is not to have a We think this requires more discussion, will chat about it with more people at fb to get more opinions. |
This is the exact approach that we are currently using with this PR 😄 -- the public interface for props only exposes Internally, when
rather than its current implementation:
|
@mkonicek - ok thinking about this some more and I think the currently implemented approach of using props to update the page is flawed. Think of the following situation:
So, I think for values that live on the native side like this and scroll position and such, we either need to have a very good approach for keeping that in sync with the JS side or just use the approach from ScrollView to set them imperatively. |
I need this feature too to make a looping carousel. |
@brentvatne I realized we also want to make the Therefore I think we should get rid of the prop and have a function to do the paging imperatively, like We should make this work exactly the same way as on iOS. It doesn't look like
We should support that on both platforms. We can make this consistent in steps:
|
@machard Appreciate your help! You can read the code for |
@brentvatne Your example with setting the page to 5, scrolling and then setting it again is great! Should have thought of it. Luckily it's not so hard to change it :) |
@brentvatne updated the pull request. |
1 similar comment
@brentvatne updated the pull request. |
Hiya @mkonicek!
Yup! That would be nice to have eventually.
Correct! Right now you have to just know the width of each page and multiply that by the page that you want to be on. Would be nice to have this on both though, agreed.
Sounds good! I took care of #1 here. |
A brief thought on paginated scrollviews and ViewPager -- we may want (hypothetically speaking) ViewPager.ios.js to use a paginated ScrollView instead of having ScrollView sometimes render a ViewPager. I think of ScrollView as a lower-level component than ViewPager, and it might be easier to implement ViewPager on iOS using a ScrollView, than it is to implement a paginated ScrollView on Android using a ViewPager (think of all the scroll responder APIs). |
That's a good point @ide. @brentvatne Looks awesome! I think you might be able to inline the Does the |
@brentvatne updated the pull request. |
Done!
It does now! Updated example to add a button to toggle between using |
return this.refs[VIEWPAGER_REF].getInnerViewNode(); | ||
}, | ||
|
||
_childrenWithOverridenStyle: function() { | ||
_childrenWithOverridenStyle: function(): Array { |
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.
Not great with flow -- what should I put here as the return type @mkonicek?
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.
Good question. Try Array<ReactElement>
and run flow
from the root of the repo and see if that works.
Doesn't look like the React codebase uses Flow and not sure how the Flow handles the boundaries between code that uses Flow and code that doesn't.
If Array<ReactElement>
doesn't work I'd go for Array
or Array<Object>
. It's a private function you're using just in this file.
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 is no longer required to override styles this way here. We did this initially because we didn't have view flattening on android back then. Now that view flattening is there we should just wrap children in views positioned absolutely and with collapsable=false
similarly to how we do it here: https://github.com/facebook/react-native/blob/master/Libraries/Components/ScrollView/RecyclerViewBackedScrollView.android.js#L95
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.
@kmagiera It's a good point and looked into doing that when open sourcing the view pager but decided not to (don't remember the exact reason anymore). I think changing this is outside the scope of Brent's PR though. I'll pull this in as it looks good otherwise.
Looks awesome! 👍 Thanks for improving the example and using Flow too! Sorry for the delay. Feel free to try out what return type works best for |
@facebook-github-bot shipit |
Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/568096366678113/int_phab to review. |
Summary: In some cases it's desirable to set the page in the ViewPager without animating it -- we have this in ScrollView with `scrollWithoutAnimationTo`. This PR adds `setPageWithoutAnimation` on ViewPager. cc ide kmagiera Closes facebook#3621 Reviewed By: svcscm Differential Revision: D2652056 Pulled By: mkonicek fb-gh-sync-id: 6f1f38558c41ffdd863c0ebb2f046c75b5c0392c
Summary: In some cases it's desirable to set the page in the ViewPager without animating it -- we have this in ScrollView with `scrollWithoutAnimationTo`. This PR adds `setPageWithoutAnimation` on ViewPager. cc ide kmagiera Closes facebook#3621 Reviewed By: svcscm Differential Revision: D2652056 Pulled By: mkonicek fb-gh-sync-id: 6f1f38558c41ffdd863c0ebb2f046c75b5c0392c
Summary: In some cases it's desirable to set the page in the ViewPager without animating it -- we have this in ScrollView with `scrollWithoutAnimationTo`. This PR adds `setPageWithoutAnimation` on ViewPager. cc ide kmagiera Closes facebook#3621 Reviewed By: svcscm Differential Revision: D2652056 Pulled By: mkonicek fb-gh-sync-id: 6f1f38558c41ffdd863c0ebb2f046c75b5c0392c
Summary: In some cases it's desirable to set the page in the ViewPager without animating it -- we have this in ScrollView with `scrollWithoutAnimationTo`. This PR adds `setPageWithoutAnimation` on ViewPager. cc ide kmagiera Closes facebook/react-native#3621 Reviewed By: svcscm Differential Revision: D2652056 Pulled By: mkonicek fb-gh-sync-id: 6f1f38558c41ffdd863c0ebb2f046c75b5c0392c
Summary: In some cases it's desirable to set the page in the ViewPager without animating it -- we have this in ScrollView with `scrollWithoutAnimationTo`. This PR adds `setPageWithoutAnimation` on ViewPager. cc ide kmagiera Closes facebook/react-native#3621 Reviewed By: svcscm Differential Revision: D2652056 Pulled By: mkonicek fb-gh-sync-id: 6f1f38558c41ffdd863c0ebb2f046c75b5c0392c
In some cases it's desirable to set the page in the ViewPager without animating it -- we have this in ScrollView with
scrollWithoutAnimationTo
. This PR addssetPageWithoutAnimation
on ViewPager.cc @ide @kmagiera