Skip to content

add support for gestureResponseDistance prop #54

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions modules/ReducerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ export function createPartialState(
const transition = currentRoute.transition;
const onSwipeBack = currentRoute.onSwipeBack;
const onSwipeForward = currentRoute.onSwipeForward;
const gestureResponseDistance = currentRoute.gestureResponseDistance;
const reducer = currentRoute.reducer;

const indexRoute = getIndexRoute(currentRoute);
Expand Down Expand Up @@ -357,6 +358,7 @@ export function createPartialState(
reducer,
onSwipeBack,
onSwipeForward,
gestureResponseDistance,
};

if (prevState) {
Expand Down
2 changes: 2 additions & 0 deletions modules/Route.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Props = {
transition: ?string,
onSwipeBack: Function,
onSwipeForward: Function,
gestureResponseDistance?: ?number,
};

const { ROUTE } = RouteTypes;
Expand All @@ -42,6 +43,7 @@ class Route extends Component<any, Props, any> {
transition: PropTypes.string,
onSwipeBack: PropTypes.func,
onSwipeForward: PropTypes.func,
gestureResponseDistance: PropTypes.number,
};

static defaultProps = {
Expand Down
2 changes: 2 additions & 0 deletions modules/StackRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Props = {
reducer: Function,
routeType: string,
transition: string,
gestureResponseDistance?: ?number,
};

const { STACK_ROUTE } = RouteTypes;
Expand All @@ -39,6 +40,7 @@ class StackRoute extends Component<any, Props, any> {
reducer: PropTypes.func.isRequired,
routeType: PropTypes.string.isRequired,
transition: PropTypes.string.isRequired,
gestureResponseDistance: PropTypes.number,
};

static defaultProps = {
Expand Down
10 changes: 9 additions & 1 deletion modules/StackRouteView.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,14 @@ class StackRouteView extends Component<any, Props, any> {
return null;
}

const { transition: parentTransition } = props.navigationState;
const {
transition: parentTransition,
gestureResponseDistance: parentGestureResponseDistance,
} = props.navigationState;

const {
transition: sceneTransition,
gestureResponseDistance,
onSwipeBack,
onSwipeForward,
} = scene.route;
Expand All @@ -112,6 +117,9 @@ class StackRouteView extends Component<any, Props, any> {
const viewStyle = styleInterpolator(props);
const panHandlers = panResponder({
...props,
// NavigationCardStackPanResponder defaults to 30; this is not enough to conform to the
// touch area provided by the native IOS back swipe behaviour => double the default to 60
gestureResponseDistance: gestureResponseDistance || parentGestureResponseDistance || 60,
onNavigateBack: () => onSwipeBack && onSwipeBack(router),
onNavigateForward: () => onSwipeForward && onSwipeForward(router),
});
Expand Down
2 changes: 2 additions & 0 deletions modules/TabsRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Props = {
reducer: Function,
routeType: string,
transition: string,
gestureResponseDistance?: ?number,
};

const { TABS_ROUTE } = RouteTypes;
Expand All @@ -39,6 +40,7 @@ class TabsRoute extends Component<any, Props, any> {
reducer: PropTypes.func.isRequired,
routeType: PropTypes.string.isRequired,
transition: PropTypes.string.isRequired,
gestureResponseDistance: PropTypes.number,
};

static defaultProps = {
Expand Down
10 changes: 9 additions & 1 deletion modules/TabsRouteView.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,14 @@ class TabsRouteView extends Component<any, Props, any> {
return null;
}

const { transition: parentTransition } = props.navigationState;
const {
transition: parentTransition,
gestureResponseDistance: parentGestureResponseDistance,
} = props.navigationState;

const {
transition: sceneTransition,
gestureResponseDistance,
onSwipeBack,
onSwipeForward,
} = scene.route;
Expand All @@ -111,6 +116,9 @@ class TabsRouteView extends Component<any, Props, any> {
const viewStyle = styleInterpolator(props);
const panHandlers = panResponder({
...props,
// NavigationCardStackPanResponder defaults to 30; this is not enough to conform to the
// touch area provided by the native IOS back swipe behaviour => double the default to 60
gestureResponseDistance: gestureResponseDistance || parentGestureResponseDistance || 60,
onNavigateBack: () => onSwipeBack && onSwipeBack(router),
onNavigateForward: () => onSwipeForward && onSwipeForward(router),
});
Expand Down
2 changes: 2 additions & 0 deletions modules/TypeDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type EnhancedNavigationRoute = {
reducer: Function,
onSwipeBack: ?Function,
onSwipeForward: ?Function,
gestureResponseDistance: ?number,
};

export type IndexRouteDef = {
Expand All @@ -51,6 +52,7 @@ export type RouteDef = {
reducer: Function,
onSwipeBack: ?Function,
onSwipeForward: ?Function,
gestureResponseDistance?: number,
};

export type NoPathRouteDef = {
Expand Down