Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions js/ViewPager.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ function getViewManagerConfig(viewManagerName) {
*/

class ViewPager extends React.Component<ViewPagerProps> {
isScrolling = false;

componentDidMount() {
// On iOS we do it directly on the native side
if (Platform.OS === 'android') {
Expand Down Expand Up @@ -114,6 +116,7 @@ class ViewPager extends React.Component<ViewPagerProps> {
if (this.props.onPageScrollStateChanged) {
this.props.onPageScrollStateChanged(e);
}
this.isScrolling = e.nativeEvent.pageScrollState === 'dragging';
};

_onPageSelected = (e: PageSelectedEvent) => {
Expand Down Expand Up @@ -159,6 +162,13 @@ class ViewPager extends React.Component<ViewPagerProps> {
);
};

_onMoveShouldSetResponderCapture = () => {
if (Platform.OS === 'ios') {
return this.isScrolling;
}
return false;
};

render() {
return (
<NativeViewPager
Expand All @@ -168,6 +178,7 @@ class ViewPager extends React.Component<ViewPagerProps> {
onPageScroll={this._onPageScroll}
onPageScrollStateChanged={this._onPageScrollStateChanged}
onPageSelected={this._onPageSelected}
onMoveShouldSetResponderCapture={this._onMoveShouldSetResponderCapture}
children={childrenWithOverriddenStyle(this.props.children)}
/>
);
Expand Down
20 changes: 19 additions & 1 deletion js/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
* @format
* @flow strict-local
*/

import * as React from 'react';
import {View} from 'react-native';
import type {Node} from 'react';
import type {SyntheticEvent} from 'react-native/Libraries/Types/CoreEventTypes';
import type {ViewStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet';

type ViewProps = React.ElementProps<typeof View>;
type ResponderCaptureType = $PropertyType<
ViewProps,
'onMoveShouldSetResponderCapture',
>;

export type PageScrollState = 'idle' | 'dragging' | 'settling';

export type PageScrollEvent = SyntheticEvent<
Expand Down Expand Up @@ -95,6 +102,17 @@ export type ViewPagerProps = $ReadOnly<{|

style?: ?ViewStyleProp,

/**
* If a parent `View` wants to prevent a child `View` from becoming responder
* on a move, it should have this handler which returns `true`.
*
* `View.props.onMoveShouldSetResponderCapture: (event) => [true | false]`,
* where `event` is a synthetic touch event as described above.
*
* See http://facebook.github.io/react-native/docs/view.html#onMoveShouldsetrespondercapture
*/
onMoveShouldSetResponderCapture?: ?ResponderCaptureType,

/**
* iOS only
*/
Expand Down
8 changes: 7 additions & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export interface ViewPagerOnPageSelectedEventData {
position: number;
}

export interface PageScrollStateChangedEvent {
pageScrollState: 'idle' | 'dragging' | 'settling';
}

export interface ViewPagerProps extends ReactNative.ViewProps {
/**
* Index of initial page that should be selected. Use `setPage` method to
Expand Down Expand Up @@ -50,7 +54,7 @@ export interface ViewPagerProps extends ReactNative.ViewProps {
* - settling, meaning that there was an interaction with the page scroller, and the
* page scroller is now finishing it's closing or opening animation
*/
onPageScrollStateChanged?: (state: "Idle" | "Dragging" | "Settling") => void;
onPageScrollStateChanged?: (event: ReactNative.NativeSyntheticEvent<PageScrollStateChangedEvent>) => void;

/**
* Determines whether the keyboard gets dismissed in response to a drag.
Expand All @@ -64,6 +68,8 @@ export interface ViewPagerProps extends ReactNative.ViewProps {
* edge-to-edge.
*/
pageMargin?: number;

onMoveShouldSetResponderCapture?: (event: any) => boolean;

/**
* iOS only
Expand Down