Skip to content

Commit 25c02f9

Browse files
authored
Revert "Add overdrag property on iOS (#107)" (#114)
This reverts commit e70c315.
1 parent 8249e31 commit 25c02f9

File tree

8 files changed

+28
-79
lines changed

8 files changed

+28
-79
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ const styles = StyleSheet.create({
125125
|`orientation: Orientation`|Set `horizontal` or `vertical` scrolling orientation (it does **not** work dynamically)|both
126126
|`transitionStyle: TransitionStyle`|Use `scroll` or `curl` to change transition style (it does **not** work dynamically)|iOS
127127
|`showPageIndicator: boolean`|Shows the dots indicator at the bottom of the view|iOS
128-
|`overdrag: boolean`|Allows for overscrolling after reaching the end or very beginning or pages|iOS
129128

130129
## Preview
131130

example/ViewPagerExample.js

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ type State = {
3636
pages: Array<CreatePage>,
3737
scrollState: PageScrollState,
3838
dotsVisible: boolean,
39-
overdragEnabled: boolean,
4039
};
4140

4241
export default class ViewPagerExample extends React.Component<*, State> {
@@ -61,7 +60,6 @@ export default class ViewPagerExample extends React.Component<*, State> {
6160
pages: pages,
6261
scrollState: 'idle',
6362
dotsVisible: false,
64-
overdragEnabled: true,
6563
};
6664
this.viewPager = React.createRef();
6765
}
@@ -119,13 +117,7 @@ export default class ViewPagerExample extends React.Component<*, State> {
119117
};
120118

121119
render() {
122-
const {
123-
page,
124-
pages,
125-
animationsAreEnabled,
126-
dotsVisible,
127-
overdragEnabled,
128-
} = this.state;
120+
const {page, pages, animationsAreEnabled, dotsVisible} = this.state;
129121
return (
130122
<SafeAreaView style={styles.container}>
131123
<ViewPager
@@ -141,8 +133,7 @@ export default class ViewPagerExample extends React.Component<*, State> {
141133
// Lib does not support dynamically transitionStyle change
142134
transitionStyle="scroll"
143135
showPageIndicator={dotsVisible}
144-
ref={this.viewPager}
145-
overdrag={overdragEnabled}>
136+
ref={this.viewPager}>
146137
{pages.map(p => this.renderPage(p))}
147138
</ViewPager>
148139
<View style={styles.buttons}>
@@ -155,19 +146,6 @@ export default class ViewPagerExample extends React.Component<*, State> {
155146
this.setState({scrollEnabled: !this.state.scrollEnabled})
156147
}
157148
/>
158-
<Button
159-
enabled={true}
160-
text={
161-
this.state.overdragEnabled
162-
? 'Overdrag Enabled'
163-
: 'Overdrag Disabled'
164-
}
165-
onPress={() =>
166-
this.setState(state => {
167-
overdragEnabled: !state.overdragEnabled;
168-
})
169-
}
170-
/>
171149
<Button
172150
enabled={true}
173151
text={dotsVisible ? 'Hide dots' : 'Show dots'}

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ PODS:
182182
- React-cxxreact (= 0.61.4)
183183
- React-jsi (= 0.61.4)
184184
- React-jsinspector (0.61.4)
185-
- react-native-viewpager (3.1.0):
185+
- react-native-viewpager (2.0.2):
186186
- React
187187
- React-RCTActionSheet (0.61.4):
188188
- React-Core/RCTActionSheetHeaders (= 0.61.4)
@@ -326,7 +326,7 @@ SPEC CHECKSUMS:
326326
React-jsi: ca921f4041505f9d5197139b2d09eeb020bb12e8
327327
React-jsiexecutor: 8dfb73b987afa9324e4009bdce62a18ce23d983c
328328
React-jsinspector: d15478d0a8ada19864aa4d1cc1c697b41b3fa92f
329-
react-native-viewpager: 66c02e8a18d2d11eef08c84ed9a406b149791751
329+
react-native-viewpager: 88f4269c19d626d2ccd5f7c7f5f7f76422ddb9e3
330330
React-RCTActionSheet: 7369b7c85f99b6299491333affd9f01f5a130c22
331331
React-RCTAnimation: d07be15b2bd1d06d89417eb0343f98ffd2b099a7
332332
React-RCTBlob: 8e0b23d95c9baa98f6b0e127e07666aaafd96c34

ios/ReactNativePageView.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ NS_ASSUME_NONNULL_BEGIN
1212
@property(strong, nonatomic, readonly) UIPageViewController *reactPageViewController;
1313
@property(strong, nonatomic, readonly) UIPageControl *reactPageIndicatorView;
1414
@property(nonatomic, readonly) RCTEventDispatcher *eventDispatcher;
15-
@property(nonatomic) BOOL overdrag;
1615

1716
@property(nonatomic, strong) NSMutableArray<UIViewController *> *childrenViewControllers;
1817
@property(nonatomic) NSInteger initialPage;

ios/ReactNativePageView.m

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ - (instancetype) initWithReactTag:(NSNumber *)reactTag
3232
coalescingKey:(uint16_t)coalescingKey;
3333
{
3434
RCTAssertParam(reactTag);
35-
35+
3636
if ((self = [super init])) {
3737
_viewTag = reactTag;
3838
_position = position;
@@ -99,7 +99,7 @@ - (instancetype) initWithReactTag:(NSNumber *)reactTag
9999
coalescingKey:(uint16_t)coalescingKey;
100100
{
101101
RCTAssertParam(reactTag);
102-
102+
103103
if ((self = [super init])) {
104104
_viewTag = reactTag;
105105
_state = state;
@@ -165,7 +165,7 @@ - (instancetype) initWithReactTag:(NSNumber *)reactTag
165165
coalescingKey:(uint16_t)coalescingKey;
166166
{
167167
RCTAssertParam(reactTag);
168-
168+
169169
if ((self = [super init])) {
170170
_viewTag = reactTag;
171171
_position = position;
@@ -222,7 +222,6 @@ - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher {
222222
_dismissKeyboard = UIScrollViewKeyboardDismissModeNone;
223223
_coalescingKey = 0;
224224
_eventDispatcher = eventDispatcher;
225-
_overdrag = YES;
226225
}
227226
return self;
228227
}
@@ -260,7 +259,7 @@ - (void)addPages {
260259
_childrenViewControllers = tempChildrenViewControllers;
261260
_reactPageIndicatorView.numberOfPages = _childrenViewControllers.count;
262261
[self goTo:[NSNumber numberWithInteger:_currentIndex] animated:NO];
263-
262+
264263
} else {
265264
RCTLog(@"getParentViewController returns nil");
266265
}
@@ -272,37 +271,37 @@ - (void)embed {
272271
dictionaryWithObjectsAndKeys:
273272
[NSNumber numberWithLong:_pageMargin],
274273
UIPageViewControllerOptionInterPageSpacingKey, nil];
275-
274+
276275
UIPageViewController *reactPageViewController =
277276
[[UIPageViewController alloc]
278277
initWithTransitionStyle:_transitionStyle
279278
navigationOrientation:_orientation
280279
options:options];
281-
280+
282281
_reactPageViewController = reactPageViewController;
283282
_reactPageViewController.delegate = self;
284283
_reactPageViewController.dataSource = self;
285-
284+
286285
for (UIView *subview in _reactPageViewController.view.subviews) {
287286
if([subview isKindOfClass:UIScrollView.class]){
288287
((UIScrollView *)subview).delegate = self;
289288
((UIScrollView *)subview).keyboardDismissMode = _dismissKeyboard;
290289
((UIScrollView *)subview).delaysContentTouches = NO;
291290
}
292291
}
293-
292+
294293
[self renderChildrenViewControllers];
295294
_reactPageIndicatorView = [self createPageIndicator:self];
296295
_reactPageIndicatorView.hidden = !_showPageIndicator;
297-
296+
298297
[[self reactViewController] addChildViewController:_reactPageViewController];
299298
[reactPageViewController.view addSubview:_reactPageIndicatorView];
300299
[self addSubview:reactPageViewController.view];
301300
_reactPageViewController.view.frame = [self bounds];
302-
301+
303302
[_reactPageViewController didMoveToParentViewController:[self reactViewController]];
304303
[self shouldScroll:_scrollEnabled];
305-
304+
306305
// Add the page view controller's gesture recognizers to the view controller's view so that the gestures are started more easily.
307306
self.gestureRecognizers = _reactPageViewController.gestureRecognizers;
308307
_reactPageIndicatorView.translatesAutoresizingMaskIntoConstraints = NO;
@@ -343,7 +342,7 @@ - (void)renderChildrenViewControllers {
343342
[vc.view removeFromSuperview];
344343
}
345344
[_childrenViewControllers removeAllObjects];
346-
345+
347346
for (UIView *view in [self reactSubviews]) {
348347
[view removeFromSuperview];
349348
UIViewController *pageViewController = [self createChildViewController:view];
@@ -374,7 +373,7 @@ - (void)setReactViewControllers:(NSInteger)index
374373
if (weakSelf.eventDispatcher) {
375374
[weakSelf.eventDispatcher sendEvent:[[RCTOnPageSelected alloc] initWithReactTag:weakSelf.reactTag position:[NSNumber numberWithInteger:index] coalescingKey:coalescingKey]];
376375
}
377-
376+
378377
}];
379378
}
380379

@@ -387,20 +386,20 @@ - (UIViewController *)createChildViewController:(UIView *)view {
387386
- (void)goTo:(NSNumber *)index animated:(BOOL)animated {
388387
if (_currentIndex >= 0 &&
389388
index.integerValue < _childrenViewControllers.count) {
390-
389+
391390
_reactPageIndicatorView.currentPage = index.integerValue;
392391
UIPageViewControllerNavigationDirection direction =
393392
(index.integerValue > _currentIndex)
394393
? UIPageViewControllerNavigationDirectionForward
395394
: UIPageViewControllerNavigationDirectionReverse;
396-
395+
397396
UIViewController *viewController =
398397
[_childrenViewControllers objectAtIndex:index.integerValue];
399398
[self setReactViewControllers:index.integerValue
400399
with:viewController
401400
direction:direction
402401
animated:animated];
403-
402+
404403
}
405404
}
406405

@@ -426,7 +425,7 @@ - (void)pageViewController:(UIPageViewController *)pageViewController
426425
UIViewController* currentVC = pageViewController.viewControllers[0];
427426
_currentIndex = [_childrenViewControllers indexOfObject:currentVC];
428427
[_eventDispatcher sendEvent:[[RCTOnPageSelected alloc] initWithReactTag:self.reactTag position:[NSNumber numberWithInteger:_currentIndex] coalescingKey:_coalescingKey++]];
429-
428+
430429
[_eventDispatcher sendEvent:[[RCTOnPageScrollEvent alloc] initWithReactTag:self.reactTag position:[NSNumber numberWithInteger:_currentIndex] offset:[NSNumber numberWithFloat:0] coalescingKey:_coalescingKey++]];
431430
_reactPageIndicatorView.currentPage = _currentIndex;
432431
}
@@ -437,13 +436,13 @@ - (UIViewController *)pageViewController:
437436
(UIPageViewController *)pageViewController
438437
viewControllerAfterViewController:(UIViewController *)viewController {
439438
NSUInteger index = [_childrenViewControllers indexOfObject:viewController];
440-
439+
441440
if (index == NSNotFound) {
442441
return nil;
443442
}
444-
443+
445444
index++;
446-
445+
447446
if (index == [_childrenViewControllers count]) {
448447
return nil;
449448
}
@@ -456,15 +455,15 @@ - (UIViewController *)pageViewController:
456455
(UIPageViewController *)pageViewController
457456
viewControllerBeforeViewController:(UIViewController *)viewController {
458457
NSUInteger index = [_childrenViewControllers indexOfObject:viewController];
459-
458+
460459
if (index == NSNotFound) {
461460
return nil;
462461
}
463-
462+
464463
if (index == 0) {
465464
return nil;
466465
}
467-
466+
468467
index--;
469468
return [_childrenViewControllers objectAtIndex:index];
470469
}
@@ -506,13 +505,6 @@ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
506505
}
507506

508507
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
509-
if (!_overdrag) {
510-
if (_currentIndex == 0 && scrollView.contentOffset.x <= scrollView.bounds.size.width) {
511-
*targetContentOffset = CGPointMake(scrollView.bounds.size.width, 0);
512-
} else if (_currentIndex == _reactPageIndicatorView.numberOfPages-1 && scrollView.contentOffset.x >= scrollView.bounds.size.width) {
513-
*targetContentOffset = CGPointMake(scrollView.bounds.size.width, 0);
514-
}
515-
}
516508
[_eventDispatcher sendEvent:[[RCTOnPageScrollStateChanged alloc] initWithReactTag:self.reactTag state:@"settling" coalescingKey:_coalescingKey++]];
517509
}
518510

@@ -521,14 +513,6 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
521513
}
522514

523515
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
524-
if (!_overdrag) {
525-
if (_currentIndex == 0 && scrollView.contentOffset.x < scrollView.bounds.size.width) {
526-
scrollView.contentOffset = CGPointMake(scrollView.bounds.size.width, 0);
527-
} else if (_currentIndex == _reactPageIndicatorView.numberOfPages-1 && scrollView.contentOffset.x > scrollView.bounds.size.width) {
528-
scrollView.contentOffset = CGPointMake(scrollView.bounds.size.width, 0);
529-
}
530-
}
531-
532516
CGPoint point = scrollView.contentOffset;
533517
float offset = (point.x - self.frame.size.width)/self.frame.size.width;
534518
if(fabs(offset) > 1) {

ios/ReactViewPagerManager.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ @implementation ReactViewPagerManager
1212

1313
RCT_EXPORT_VIEW_PROPERTY(transitionStyle, UIPageViewControllerTransitionStyle)
1414
RCT_EXPORT_VIEW_PROPERTY(orientation, UIPageViewControllerNavigationOrientation)
15-
RCT_EXPORT_VIEW_PROPERTY(overdrag, BOOL)
1615
RCT_EXPORT_VIEW_PROPERTY(onPageSelected, RCTDirectEventBlock)
1716
RCT_EXPORT_VIEW_PROPERTY(onPageScroll, RCTDirectEventBlock)
1817
RCT_EXPORT_VIEW_PROPERTY(onPageScrollStateChanged, RCTDirectEventBlock)

js/types.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,4 @@ export type ViewPagerProps = $ReadOnly<{|
101101
orientation?: Orientation,
102102
transitionStyle?: TransitionStyle,
103103
showPageIndicator?: boolean,
104-
/**
105-
* Determines whether it's possible to overscroll a bit
106-
* after reaching end or very beginning of pages.
107-
*/
108-
overdrag?: boolean,
109104
|}>;

typings/index.d.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,13 @@ export interface ViewPagerProps extends ReactNative.ViewProps {
6464
* edge-to-edge.
6565
*/
6666
pageMargin?: number;
67-
67+
6868
/**
6969
* iOS only
7070
*/
7171
orientation?: 'horizontal' | 'vertical',
7272
transitionStyle?: 'scroll' | 'curl',
7373
showPageIndicator?: boolean,
74-
/**
75-
* Determines whether it's possible to overscroll a bit
76-
* after reaching end or very beginning of pages.
77-
*/
78-
overdrag?: boolean,
7974
}
8075

8176
declare class ViewPagerComponent extends React.Component<ViewPagerProps> {}

0 commit comments

Comments
 (0)