Skip to content

Commit

Permalink
Pass TransitionProps to configureTransition for <NavigationTransiti…
Browse files Browse the repository at this point in the history
…oner />

Summary:
This follows up the PR #8306

= Changes

1. Provides the TransitionProps (current and previous) to the function
`configureTransition`.

2. Adds a new member `timing` to `NavigationTransitionSpec`.

= Why

1. Helps people to customize the animation between transitions
2. Helps people to migrate from the deprecated `applyAnimation` prop.

Reviewed By: ericvicenti

Differential Revision: D3470802

fbshipit-source-id: be49becccd53aed7bc57093da1c7dae20153febd
  • Loading branch information
Hedger Wang authored and Facebook Github Bot 1 committed Jun 30, 2016
1 parent e19fa82 commit d72f844
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
20 changes: 15 additions & 5 deletions Libraries/NavigationExperimental/NavigationTransitioner.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ import type {
NavigationLayout,
NavigationScene,
NavigationState,
NavigationTransitionConfigurator,
NavigationTransitionProps,
NavigationTransitionSpec,
} from 'NavigationTypeDefinition';

type Props = {
configureTransition: NavigationTransitionConfigurator,
configureTransition: (
a: NavigationTransitionProps,
b: ?NavigationTransitionProps,
) => NavigationTransitionSpec,
navigationState: NavigationState,
onTransitionEnd: () => void,
onTransitionStart: () => void,
Expand All @@ -49,6 +52,7 @@ const {PropTypes} = React;
const DefaultTransitionSpec = {
duration: 250,
easing: Easing.inOut(Easing.ease),
timing: Animated.timing,
};

class NavigationTransitioner extends React.Component<any, Props, State> {
Expand Down Expand Up @@ -126,18 +130,24 @@ class NavigationTransitioner extends React.Component<any, Props, State> {

// get the transition spec.
const transitionUserSpec = nextProps.configureTransition ?
nextProps.configureTransition() :
nextProps.configureTransition(
this._transitionProps,
this._prevTransitionProps,
) :
null;

const transitionSpec = {
...DefaultTransitionSpec,
...transitionUserSpec,
};

const {timing} = transitionSpec;
delete transitionSpec.timing;

progress.setValue(0);

const animations = [
Animated.timing(
timing(
progress,
{
...transitionSpec,
Expand All @@ -148,7 +158,7 @@ class NavigationTransitioner extends React.Component<any, Props, State> {

if (nextProps.navigationState.index !== this.props.navigationState.index) {
animations.push(
Animated.timing(
timing(
position,
{
...transitionSpec,
Expand Down
4 changes: 2 additions & 2 deletions Libraries/NavigationExperimental/NavigationTypeDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ export type NavigationTransitionSpec = {
duration?: number,
// An easing function from `Easing`.
easing?: () => any,
// A timing function such as `Animated.timing`.
timing?: (value: NavigationAnimatedValue, config: any) => any,
};

// Functions.
Expand All @@ -111,5 +113,3 @@ export type NavigationSceneRenderer = (
export type NavigationStyleInterpolator = (
props: NavigationSceneRendererProps,
) => Object;

export type NavigationTransitionConfigurator = () => NavigationTransitionSpec;

0 comments on commit d72f844

Please sign in to comment.