Skip to content
This repository was archived by the owner on Nov 27, 2022. It is now read-only.

Commit af70210

Browse files
lebedevosdnk
authored andcommitted
feat: allow passing additional props to pager
In cases when TabView is used along with another handler of react-native-gesture-handler, it's required to pass additional props to underlying PanGestureHandler, such as various refs to wait for/simultaneously work with etc. Different people need to pass different props, so I decided to accept and spread just an object of props instead of listing each of "allowed" additional props. There are no Flow typedefs in react-native-gesture-handler, so the type of pagerProps is just Object.
1 parent f9f9e64 commit af70210

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,17 @@ Style to apply to the view wrapping each screen. You can pass this to override s
348348

349349
Style to apply to the tab view container.
350350

351+
##### `gestureHandlerProps`
352+
353+
An object with props to be passed to undelying [`PanGestureHandler`](https://kmagiera.github.io/react-native-gesture-handler/docs/handler-pan.html#properties). For example:
354+
355+
```js
356+
pagerProps={{
357+
maxPointers: 1,
358+
waitFor: [someRef]
359+
}}
360+
```
361+
351362
### `TabBar`
352363

353364
Material design themed tab bar. To customize the tab bar, you'd need to use the `renderTabBar` prop of `TabView` to render the `TabBar` and pass additional props.

src/Pager.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type Props<T extends Route> = PagerCommonProps & {
3535
jumpTo: (key: string) => void;
3636
}
3737
) => React.ReactNode;
38+
gestureHandlerProps: React.ComponentProps<typeof PanGestureHandler>;
3839
};
3940

4041
const {
@@ -595,6 +596,7 @@ export default class Pager<T extends Route> extends React.Component<Props<T>> {
595596
swipeEnabled,
596597
children,
597598
removeClippedSubviews,
599+
gestureHandlerProps,
598600
} = this.props;
599601

600602
const translateX = this.getTranslateX(
@@ -615,6 +617,7 @@ export default class Pager<T extends Route> extends React.Component<Props<T>> {
615617
onHandlerStateChange={this.handleGestureEvent}
616618
activeOffsetX={[-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM]}
617619
failOffsetY={[-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM]}
620+
{...gestureHandlerProps}
618621
>
619622
<Animated.View
620623
removeClippedSubviews={removeClippedSubviews}

src/TabView.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ViewStyle,
77
LayoutChangeEvent,
88
} from 'react-native';
9+
import { PanGestureHandler } from 'react-native-gesture-handler';
910
import Animated from 'react-native-reanimated';
1011
import TabBar, { Props as TabBarProps } from './TabBar';
1112
import Pager from './Pager';
@@ -39,6 +40,7 @@ type Props<T extends Route> = PagerCommonProps & {
3940
removeClippedSubviews?: boolean;
4041
sceneContainerStyle?: StyleProp<ViewStyle>;
4142
style?: StyleProp<ViewStyle>;
43+
gestureHandlerProps: React.ComponentProps<typeof PanGestureHandler>;
4244
};
4345

4446
type State = {
@@ -61,6 +63,7 @@ export default class TabView<T extends Route> extends React.Component<
6163
removeClippedSubviews: false,
6264
springConfig: {},
6365
timingConfig: {},
66+
gestureHandlerProps: {},
6467
};
6568

6669
state = {
@@ -111,6 +114,7 @@ export default class TabView<T extends Route> extends React.Component<
111114
renderLazyPlaceholder,
112115
sceneContainerStyle,
113116
style,
117+
gestureHandlerProps,
114118
} = this.props;
115119
const { layout } = this.state;
116120

@@ -129,6 +133,7 @@ export default class TabView<T extends Route> extends React.Component<
129133
onSwipeEnd={onSwipeEnd}
130134
onIndexChange={this.jumpToIndex}
131135
removeClippedSubviews={removeClippedSubviews}
136+
gestureHandlerProps={gestureHandlerProps}
132137
>
133138
{({ position, render, addListener, removeListener, jumpTo }) => {
134139
// All of the props here must not change between re-renders

0 commit comments

Comments
 (0)