Skip to content

Commit

Permalink
Migrate NavigationCardStack
Browse files Browse the repository at this point in the history
Summary:
As discussed in #8262.
Closes #8268

Reviewed By: hedgerwang

Differential Revision: D3462059

Pulled By: ericvicenti

fbshipit-source-id: 1f48db3a15668e5a1122b7dcb244bd4352acf9a9
  • Loading branch information
jmurzy authored and Facebook Github Bot 3 committed Jun 21, 2016
1 parent 9c47742 commit 47a7289
Showing 1 changed file with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@
*/
'use strict';

const NavigationAnimatedView = require('NavigationAnimatedView');
const NavigationTransitioner = require('NavigationTransitioner');
const NavigationCard = require('NavigationCard');
const NavigationCardStackStyleInterpolator = require('NavigationCardStackStyleInterpolator');
const NavigationCardStackPanResponder = require('NavigationCardStackPanResponder');
const NavigationPropTypes = require('NavigationPropTypes');
const React = require('React');
const ReactComponentWithPureRenderMixin = require('ReactComponentWithPureRenderMixin');
const StyleSheet = require('StyleSheet');
const View = require('View');

const emptyFunction = require('fbjs/lib/emptyFunction');

Expand All @@ -50,6 +51,7 @@ import type {
NavigationState,
NavigationSceneRenderer,
NavigationSceneRendererProps,
NavigationTransitionProps,
} from 'NavigationTypeDefinition';

import type {
Expand Down Expand Up @@ -85,6 +87,7 @@ type DefaultProps = {
* +------------+
*/
class NavigationCardStack extends React.Component<DefaultProps, Props, void> {
_render : NavigationSceneRenderer;
_renderScene : NavigationSceneRenderer;

static propTypes = {
Expand All @@ -105,6 +108,7 @@ class NavigationCardStack extends React.Component<DefaultProps, Props, void> {
}

componentWillMount(): void {
this._render = this._render.bind(this);
this._renderScene = this._renderScene.bind(this);
}

Expand All @@ -118,15 +122,55 @@ class NavigationCardStack extends React.Component<DefaultProps, Props, void> {

render(): ReactElement<any> {
return (
<NavigationAnimatedView
<NavigationTransitioner
navigationState={this.props.navigationState}
renderOverlay={this.props.renderOverlay}
renderScene={this._renderScene}
style={[styles.animatedView, this.props.style]}
render={this._render}
style={this.props.style}
/>
);
}

_render(props: NavigationTransitionProps): ReactElement<any> {
const {
navigationState,
} = props;

let overlay = null;
const renderOverlay = this.props.renderOverlay;

if (renderOverlay) {
const route = navigationState.routes[navigationState.index];

const activeScene = props.scenes.find(
scene => !scene.isStale && scene.route === route ? scene : undefined
);

overlay = renderOverlay({
...props,
scene: activeScene
});
}

const scenes = props.scenes.map(
scene => this._renderScene({
...props,
scene,
}),
this
);

return (
<View
style={styles.container}>
<View
style={styles.scenes}>
{scenes}
</View>
{overlay}
</View>
);
}

_renderScene(props: NavigationSceneRendererProps): ReactElement<any> {
const isVertical = this.props.direction === 'vertical';

Expand Down Expand Up @@ -155,7 +199,10 @@ class NavigationCardStack extends React.Component<DefaultProps, Props, void> {
}

const styles = StyleSheet.create({
animatedView: {
container: {
flex: 1,
},
scenes: {
flex: 1,
},
});
Expand Down

0 comments on commit 47a7289

Please sign in to comment.