Skip to content
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

[NavigationExperimental] Migrate NavigationCardStack #8268

Closed
wants to merge 1 commit into from
Closed
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
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,56 @@ 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;

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

const activeScene = props.scenes.find(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call of method renderOverlay Function cannot be called on possibly undefined value undefined

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call of method renderOverlay Function cannot be called on possibly null value null

scene => !scene.isStale && scene.route === route ? scene : undefined
);

overlay = this.props.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 +200,10 @@ class NavigationCardStack extends React.Component<DefaultProps, Props, void> {
}

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