-
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7d2e030
Formattings
nitzanyiz 34f5fa7
Logic Changes
nitzanyiz 9c2706a
Fixed return
nitzanyiz d2bbd6e
Moved the resesting inside the loop condition
nitzanyiz 44fe30e
Removed children array line from renderAccessibleLayout
nitzanyiz 0a0e47c
reverted counter change
nitzanyiz 3408395
Fixes android scrolls to opposite direction
nitzanyiz 91e02f3
Changed standing page calculation
nitzanyiz 33130cf
Set page control to use currentStandingPage
nitzanyiz e7441b3
Last small changes
nitzanyiz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,7 @@ class Carousel extends Component<CarouselProps, CarouselState> { | |
const defaultPageWidth = props.loop || !props.pageWidth ? Constants.screenWidth : props.pageWidth; | ||
const pageHeight = props.pageHeight ?? Constants.screenHeight; | ||
this.isAutoScrolled = false; | ||
|
||
this.state = { | ||
containerWidth: undefined, | ||
// @ts-ignore (defaultProps) | ||
|
@@ -195,28 +195,30 @@ class Carousel extends Component<CarouselProps, CarouselState> { | |
} | ||
|
||
goToPage(pageIndex: number, animated = true) { | ||
this.setState({currentPage: this.getCalcIndex(pageIndex)}, () => this.updateOffset(animated)); | ||
this.setState({currentPage: pageIndex}, () => this.updateOffset(animated)); | ||
} | ||
|
||
goToNextPage() { | ||
const {currentPage} = this.state; | ||
const pagesCount = presenter.getChildrenLength(this.props); | ||
const {loop} = this.props; | ||
let nextPageIndex; | ||
|
||
if (loop) { | ||
if (currentPage === pagesCount + 1) { | ||
this.goToPage(0, false); | ||
return; | ||
} | ||
nextPageIndex = currentPage + 1; | ||
} else { | ||
nextPageIndex = Math.min(pagesCount - 1, currentPage + 1); | ||
} | ||
|
||
this.goToPage(nextPageIndex, true); | ||
|
||
// in case of a loop, after we advanced right to the cloned first page, | ||
// we return silently to the real first page | ||
if (loop && currentPage === pagesCount) { | ||
this.goToPage(0, false); | ||
} | ||
// // in case of a loop, after we advanced right to the cloned first page, | ||
// // we return silently to the real first page | ||
// if (loop && currentPage === pagesCount) { | ||
// this.goToPage(0, false); | ||
// } | ||
} | ||
|
||
getCalcIndex(index: number): number { | ||
|
@@ -239,10 +241,8 @@ class Carousel extends Component<CarouselProps, CarouselState> { | |
if (containerWidth) { | ||
const spacings = pageWidth === containerWidth ? 0 : this.getItemSpacings(this.props); | ||
const initialBreak = pageWidth - (containerWidth - pageWidth - spacings) / 2; | ||
const snapToOffsets = _.times( | ||
presenter.getChildrenLength(this.props), | ||
index => initialBreak + index * pageWidth + this.getContainerMarginHorizontal() | ||
); | ||
const snapToOffsets = _.times(presenter.getChildrenLength(this.props), | ||
index => initialBreak + index * pageWidth + this.getContainerMarginHorizontal()); | ||
return snapToOffsets; | ||
} | ||
}; | ||
|
@@ -355,10 +355,11 @@ class Carousel extends Component<CarouselProps, CarouselState> { | |
}; | ||
|
||
onScrollEvent = Animated.event([ | ||
{nativeEvent: | ||
{contentOffset: | ||
// @ts-ignore | ||
{y: this.props?.animatedScrollOffset?.y, x: this.props?.animatedScrollOffset?.x} | ||
{ | ||
M-i-k-e-l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
nativeEvent: { | ||
contentOffset: | ||
// @ts-ignore | ||
{y: this.props?.animatedScrollOffset?.y, x: this.props?.animatedScrollOffset?.x} | ||
} | ||
} | ||
], | ||
|
@@ -404,9 +405,10 @@ class Carousel extends Component<CarouselProps, CarouselState> { | |
}; | ||
|
||
renderChildren() { | ||
const {children, loop} = this.props; | ||
const {children: propsChildren, loop} = this.props; | ||
const length = presenter.getChildrenLength(this.props); | ||
|
||
const children = | ||
Constants.isRTL && Constants.isAndroid ? React.Children.toArray(propsChildren).reverse() : propsChildren; | ||
const childrenArray = React.Children.map(children, (child, index) => { | ||
return this.renderChild(child, `${index}`); | ||
}); | ||
|
@@ -455,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 commentThe reason will be displayed to describe this comment to others. Learn more. Is this change needed? |
||
const {currentPage} = this.state; | ||
const pagesCount = presenter.getChildrenLength(this.props); | ||
|
||
if (showCounter && !pageWidth) { | ||
return ( | ||
<View center style={styles.counter}> | ||
<Text grey80 text90 style={[{fontWeight: 'bold'}, counterTextStyle]}> | ||
{currentStandingPage + 1}/{pagesCount} | ||
{currentPage + 1}/{pagesCount} | ||
</Text> | ||
</View> | ||
); | ||
|
@@ -471,7 +473,6 @@ class Carousel extends Component<CarouselProps, CarouselState> { | |
|
||
renderAccessibleLayout() { | ||
const {containerStyle, children, testID} = this.props; | ||
|
||
return ( | ||
<View style={containerStyle} onLayout={this.onContainerLayout}> | ||
<ScrollView | ||
|
@@ -501,11 +502,7 @@ class Carousel extends Component<CarouselProps, CarouselState> { | |
const ScrollContainer = animatedScrollOffset ? Animated.ScrollView : ScrollView; | ||
const contentOffset = this.getInitialContentOffset(snapToOffsets); | ||
return ( | ||
<View | ||
animated={animated} | ||
style={[{marginBottom}, containerStyle]} | ||
onLayout={this.onContainerLayout} | ||
> | ||
<View animated={animated} style={[{marginBottom}, containerStyle]} onLayout={this.onContainerLayout}> | ||
M-i-k-e-l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<ScrollContainer | ||
showsHorizontalScrollIndicator={false} | ||
showsVerticalScrollIndicator={false} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.