Skip to content

Commit bda9ace

Browse files
authored
fix(ios): emit correct progress values for overdrag (#396)
1 parent d617614 commit bda9ace

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

example/src/component/ProgressBar.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ export class ProgressBar extends React.Component<Props> {
1313
render() {
1414
const fractionalPosition =
1515
this.props.progress.position + this.props.progress.offset;
16-
1716
const size = fractionalPosition / (this.props.numberOfPages - 1);
18-
console.log(size);
17+
const clampedSize = Math.max(0, Math.min(1, size));
1918
return (
2019
<View style={styles.progressBarContainer}>
21-
<View style={[styles.progressBar, { width: `${size * 100}%` }]} />
20+
<View
21+
style={[styles.progressBar, { width: `${clampedSize * 100}%` }]}
22+
/>
2223
</View>
2324
);
2425
}

ios/ReactNativePageView.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,22 +392,25 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
392392

393393

394394
BOOL isAnimatingBackwards = ([self isLtrLayout] && offset<0) || (![self isLtrLayout] && offset > 0.05f);
395-
if(isAnimatingBackwards && position > 0){
395+
if(isAnimatingBackwards){
396396
position = self.currentIndex - 1;
397397
absoluteOffset = fmax(0, 1 - absoluteOffset);
398398
}
399399

400400
if (!_overdrag) {
401401
NSInteger maxIndex = _reactPageIndicatorView.numberOfPages - 1;
402-
BOOL isFirstPage = [self isLtrLayout] ? _currentIndex == 0 : _currentIndex == maxIndex;
403-
BOOL isLastPage = [self isLtrLayout] ? _currentIndex == maxIndex : _currentIndex == 0;
402+
NSInteger firstPageIndex = [self isLtrLayout] ? 0 : maxIndex;
403+
NSInteger lastPageIndex = [self isLtrLayout] ? maxIndex : 0;
404+
BOOL isFirstPage = _currentIndex == firstPageIndex;
405+
BOOL isLastPage = _currentIndex == lastPageIndex;
404406
CGFloat contentOffset =[self isHorizontal] ? scrollView.contentOffset.x : scrollView.contentOffset.y;
405407
CGFloat topBound = [self isHorizontal] ? scrollView.bounds.size.width : scrollView.bounds.size.height;
406408

407409
if ((isFirstPage && contentOffset <= topBound) || (isLastPage && contentOffset >= topBound)) {
408410
CGPoint croppedOffset = [self isHorizontal] ? CGPointMake(topBound, 0) : CGPointMake(0, topBound);
409411
scrollView.contentOffset = croppedOffset;
410412
absoluteOffset=0;
413+
position = isLastPage ? lastPageIndex : firstPageIndex;
411414
}
412415
}
413416

0 commit comments

Comments
 (0)