Skip to content

Commit

Permalink
Scene - implemented getPanHandlers prop (#961)
Browse files Browse the repository at this point in the history
* added getPanHandlers api to scene

* cleaned up code
  • Loading branch information
philipshurpik authored and aksonov committed Jul 29, 2016
1 parent a643386 commit 00ca6ad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
6 changes: 6 additions & 0 deletions docs/API_CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ Actions.ROUTE_NAME({type: ActionConst.RESET});
| animationStyle | `function` | | optional interpolation function for scene transitions: `animationStyle={interpolationFunction}` |
| applyAnimation | `function` | | optional if provided overrides the default spring animation |

### Gestures
| Property | Type | Default | Description |
|-----------|--------|---------|--------------------------------------------|
| panHandlers | `object` | | optional, provide null to disable swipe back gesture |
| getPanHandlers | `function` | optional | Optionally override the gesture handlers for scene |

### Scene styles
| Property | Type | Default | Description |
|-----------|--------|---------|--------------------------------------------|
Expand Down
19 changes: 13 additions & 6 deletions src/DefaultRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ export default class DefaultRenderer extends Component {
}
}

getPanHandlers(direction, props) {
return direction === 'vertical' ?
NavigationCardStackPanResponder.forVertical(props) :
NavigationCardStackPanResponder.forHorizontal(props);
}

dispatchFocusAction({ navigationState }) {
if (!navigationState || navigationState.component || navigationState.tabs) {
return;
Expand All @@ -128,7 +134,12 @@ export default class DefaultRenderer extends Component {
}

renderCard(/* NavigationSceneRendererProps */ props) {
const { key, direction, animation, getSceneStyle } = props.scene.navigationState;
const { key,
direction,
animation,
getSceneStyle,
getPanHandlers,
} = props.scene.navigationState;
let { panHandlers, animationStyle } = props.scene.navigationState;

const state = props.navigationState;
Expand All @@ -146,8 +157,6 @@ export default class DefaultRenderer extends Component {

const style = getSceneStyle ? getSceneStyle(props, computedProps) : null;

const isVertical = direction === 'vertical';

// direction overrides animation if both are supplied
const animType = (animation && !direction) ? animation : direction;

Expand All @@ -160,9 +169,7 @@ export default class DefaultRenderer extends Component {
}

if (typeof(panHandlers) === 'undefined') {
panHandlers = panHandlers || (isVertical ?
NavigationCardStackPanResponder.forVertical(props) :
NavigationCardStackPanResponder.forHorizontal(props));
panHandlers = getPanHandlers ? getPanHandlers(props) : this.getPanHandlers(direction, props);
}
return (
<NavigationCard
Expand Down

0 comments on commit 00ca6ad

Please sign in to comment.