-
Notifications
You must be signed in to change notification settings - Fork 734
Fix/carousel android rtl jumps #2831
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
src/components/carousel/index.tsx
Outdated
const {containerStyle, children, testID} = this.props; | ||
|
||
const {containerStyle, children: propsChildren, testID} = this.props; | ||
const children = Constants.isRTL && Constants.isAndroid ? React.Children.toArray(propsChildren) : propsChildren; |
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.
What is this for?
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.
For some reason on RTL android sends the children reversed.
src/components/carousel/index.tsx
Outdated
} | ||
|
||
goToNextPage() { | ||
const {currentPage} = this.state; | ||
const pagesCount = presenter.getChildrenLength(this.props); | ||
const {loop} = this.props; | ||
let nextPageIndex; | ||
|
||
if (currentPage === pagesCount + 1) { | ||
return this.goToPage(0, false); |
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.
Did you mean to:
this.goToPage(0, false);
return;
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.
Yes. Fixed
71bec5b
to
34f5fa7
Compare
I moved the goToPage 0 condition to inside the loop condition. Its works even when outside but I think it might make some problems because its not supposed to happen if not looping. |
src/components/carousel/index.tsx
Outdated
@@ -454,14 +457,14 @@ class Carousel extends Component<CarouselProps, CarouselState> { | |||
|
|||
renderCounter() { | |||
const {pageWidth, showCounter, counterTextStyle} = this.props; | |||
const {currentStandingPage} = this.state; |
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.
Is this change needed?
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.
Looks like Android in RTL should move in the opposite direction
const scrollContainerStyle = this.shouldUsePageWidth() | ||
? {paddingRight: this.getItemSpacings(this.props)} | ||
: undefined; | ||
const snapToOffsets = this.getSnapToOffsets(); | ||
const marginBottom = Math.max(0, this.getContainerPaddingVertical() - 16); | ||
const ScrollContainer = animatedScrollOffset ? Animated.ScrollView : ScrollView; | ||
const contentOffset = this.getInitialContentOffset(snapToOffsets); | ||
const _style = Constants.isRTL && Constants.isAndroid ? [styles.invertedView, style] : style; |
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 inverted the view on android rtl so it would behave the same as on ios.
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.
Android looks good!
A couple of small notes and I did not test iOS (cannot install it ATM)
src/components/carousel/index.tsx
Outdated
@@ -305,7 +307,7 @@ class Carousel extends Component<CarouselProps, CarouselState> { | |||
onMomentumScrollEnd = () => { | |||
// finished full page scroll | |||
const {currentStandingPage, currentPage} = this.state; | |||
const index = this.getCalcIndex(currentPage); | |||
const index = currentPage; |
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.
Why not remove index
?
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. Fixed
This reverts commit b997db4.
Description
There was a problem with the currentPage calculation. I removed the usage of the getCalcIndex from the goToPage and moved the page calculation in the goToNextPage. On android RTL the children is passed reversed for some reason so I revered so the first item will show first.
Changelog
Carousel - Fixed Android RTL jumps on random items.
Additional info