diff --git a/README.md b/README.md index 8f1820585..26fb9df38 100644 --- a/README.md +++ b/README.md @@ -102,8 +102,9 @@ class App extends React.Component { | type | string | 'push' or 'jump' | Defines how the new screen is added to the navigator stack. One of `push`, `jump`, `replace`, `reset`. If parent container is tabbar (tabs=true), jump will be automatically set. | tabs| bool | false | Defines 'TabBar' scene container, so child scenes will be displayed as 'tabs'. If no `component` is defined, built-in `TabBar` is used as renderer. All child scenes are wrapped into own navbar. | initial | bool | false | Set to `true` if this is the initial scene | -| duration | number | 250 | Duration of transition (in ms) | +| duration | number | | optional. acts as a shortcut to writing an `applyAnimation` function with `Animated.timing` for a given duration (in ms). | | direction | string | 'horizontal' | direction of animation horizontal/vertical | +| applyAnimation | function | | optional if provided overrides the default spring animation | | title | string | null | The title to be displayed in the navigation bar | | navBar | React.Component | | optional custom NavBar for the scene. Check built-in NavBar of the component for reference | | hideNavBar | bool | false | hides the navigation bar for this scene | diff --git a/src/DefaultRenderer.js b/src/DefaultRenderer.js index d8ffc8b24..4337862cf 100644 --- a/src/DefaultRenderer.js +++ b/src/DefaultRenderer.js @@ -47,20 +47,31 @@ export default class DefaultRenderer extends Component { const selected = navigationState.children[navigationState.index]; //return - const DEFAULT_DURATION = 250; - const stateDuration = navigationState.duration >= 0 ? navigationState.duration : DEFAULT_DURATION; - const duration = selected.duration >= 0 ? selected.duration : stateDuration; + let applyAnimation = selected.applyAnimation || navigationState.applyAnimation; + let style = selected.style || navigationState.style; + let direction = selected.direction || navigationState.direction || "horizontal"; + + let optionals = {}; + if (applyAnimation) { + optionals.applyAnimation = applyAnimation; + } else { + let duration = selected.duration; + if (duration === null || duration === undefined) duration = navigationState.duration; + if (duration !== null && duration !== undefined) { + optionals.applyAnimation = function (pos, navState) { + Animated.timing(pos, {toValue: navState.index, duration}).start(); + }; + } + } return ( - Animated.timing(pos, {toValue: navState.index, duration}).start() - } + direction={direction} renderScene={this._renderCard} + {...optionals} /> ); } @@ -76,6 +87,7 @@ export default class DefaultRenderer extends Component { return ( ; + } else { + // for < 0.24 + return ; + } + } + render(){ const state = this.props.navigationState; let selected = state.children[state.index]; @@ -33,12 +44,7 @@ export default class extends Component { ( - - )} + renderScene={this._renderScene} /> {!hideTabBar && state.children.filter(el=>el.icon).length>0 &&