mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 01:40:08 +00:00
Migrate NavigationCardStack
Summary: As discussed in #8262. Closes https://github.com/facebook/react-native/pull/8268 Reviewed By: hedgerwang Differential Revision: D3462059 Pulled By: ericvicenti fbshipit-source-id: 1f48db3a15668e5a1122b7dcb244bd4352acf9a9
This commit is contained in:
parent
9c47742176
commit
47a728907f
@ -32,7 +32,7 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const NavigationAnimatedView = require('NavigationAnimatedView');
|
||||
const NavigationTransitioner = require('NavigationTransitioner');
|
||||
const NavigationCard = require('NavigationCard');
|
||||
const NavigationCardStackStyleInterpolator = require('NavigationCardStackStyleInterpolator');
|
||||
const NavigationCardStackPanResponder = require('NavigationCardStackPanResponder');
|
||||
@ -40,6 +40,7 @@ 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');
|
||||
|
||||
@ -50,6 +51,7 @@ import type {
|
||||
NavigationState,
|
||||
NavigationSceneRenderer,
|
||||
NavigationSceneRendererProps,
|
||||
NavigationTransitionProps,
|
||||
} from 'NavigationTypeDefinition';
|
||||
|
||||
import type {
|
||||
@ -85,6 +87,7 @@ type DefaultProps = {
|
||||
* +------------+
|
||||
*/
|
||||
class NavigationCardStack extends React.Component<DefaultProps, Props, void> {
|
||||
_render : NavigationSceneRenderer;
|
||||
_renderScene : NavigationSceneRenderer;
|
||||
|
||||
static propTypes = {
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -155,7 +199,10 @@ class NavigationCardStack extends React.Component<DefaultProps, Props, void> {
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
animatedView: {
|
||||
container: {
|
||||
flex: 1,
|
||||
},
|
||||
scenes: {
|
||||
flex: 1,
|
||||
},
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user