Skip to content

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

Merged
merged 10 commits into from
Dec 5, 2023
Merged

Conversation

nitzanyiz
Copy link
Collaborator

@nitzanyiz nitzanyiz commented Nov 29, 2023

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

@nitzanyiz nitzanyiz requested a review from M-i-k-e-l November 29, 2023 13:43
@nitzanyiz nitzanyiz marked this pull request as ready for review November 29, 2023 13:43
@nitzanyiz nitzanyiz self-assigned this Nov 30, 2023
const {containerStyle, children, testID} = this.props;

const {containerStyle, children: propsChildren, testID} = this.props;
const children = Constants.isRTL && Constants.isAndroid ? React.Children.toArray(propsChildren) : propsChildren;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

Copy link
Collaborator Author

@nitzanyiz nitzanyiz Nov 30, 2023

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.

}

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);
Copy link
Collaborator

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;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Fixed

@nitzanyiz nitzanyiz force-pushed the fix/carouselAndroidRTLJumps branch from 71bec5b to 34f5fa7 Compare November 30, 2023 10:20
@M-i-k-e-l M-i-k-e-l assigned M-i-k-e-l and unassigned nitzanyiz Nov 30, 2023
@nitzanyiz
Copy link
Collaborator Author

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.

@nitzanyiz nitzanyiz requested a review from M-i-k-e-l November 30, 2023 15:00
@@ -454,14 +457,14 @@ class Carousel extends Component<CarouselProps, CarouselState> {

renderCounter() {
const {pageWidth, showCounter, counterTextStyle} = this.props;
const {currentStandingPage} = this.state;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change needed?

Copy link
Collaborator

@M-i-k-e-l M-i-k-e-l left a 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;
Copy link
Collaborator Author

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.

Copy link
Collaborator

@M-i-k-e-l M-i-k-e-l left a 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)

@@ -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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not remove index?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Fixed

@M-i-k-e-l M-i-k-e-l merged commit b997db4 into master Dec 5, 2023
@nitzanyiz nitzanyiz deleted the fix/carouselAndroidRTLJumps branch December 5, 2023 09:48
nitzanyiz added a commit that referenced this pull request Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants