-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomCardStackTransitioner.js
115 lines (101 loc) · 3.93 KB
/
CustomCardStackTransitioner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import React, { Component } from 'react';
import { NativeModules, Easing, Dimensions, Animated, View } from 'react-native';
import { CardStack, Transitioner, CardStackStyleInterpolator, NavigationActions } from 'react-navigation';
import RouteConfig from './routes'
import { navigator } from './navigator'
import FancyAnimation from './FancyAnimation'
class CardStackTransitioner extends Component<DefaultProps, Props, void> {
static defaultProps = {
mode: 'card',
};
componentDidMount() {
Object.assign(navigator, {
goBack: () => {
this.props.navigation.dispatch(NavigationActions.back())
},
push: (route, props) => {
if (typeof route == "string") {
this.props.navigation.dispatch(NavigationActions.navigate(route, props))
} else {
this.props.navigation.dispatch(NavigationActions.navigate(route.pathname, route.props))
}
}
})
console.log(navigator)
}
render() {
return (
<Transitioner
configureTransition={this._configureTransition}
navigation={this.props.navigation}
render={this._render}
style={this.props.style}
onTransitionStart={this.props.onTransitionStart}
onTransitionEnd={this.props.onTransitionEnd}
/>
);
}
_configureTransition = (transitionProps, prevTransitionProps) => {
return {
timing: Animated.timing,
delay: 500,
}
};
_render = (transitionProps) => {
const scenes = transitionProps.scenes.map(scene => this._renderScene(transitionProps, scene));
return (
<View style={{ flex: 1 }}>
{scenes}
</View>
);
};
_renderScene(transitionProps, scene) {
const { position } = transitionProps;
const { index } = scene;
const translateY = position.interpolate({
inputRange: [index - 1, index, index + 1],
outputRange: [Dimensions.get('window').height, 0, 0]
});
const Scene = this.props.router.getComponentForRouteName(scene.route.routeName);
const mode = RouteConfig[scene.route.routeName].mode
const tmp = this.props.navigation.state.routes[scene.index]
let props = tmp && tmp.params ? tmp.params.props : {}
switch (mode) {
case 'modal': {
return (
<Animated.View style={[{ transform: [{ translateY }] }, { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }]} key={scene.index}>
<Scene {...props} />
</Animated.View>
);
}
case 'fade-in': {
return (
<Animated.View style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, opacity: position }} key={scene.index}>
<Scene {...props} />
</Animated.View>
)
}
case 'pop-in': {
return (
<Animated.View style={[{ transform: [{ scale: position }] }, { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }]} key={scene.index}>
<Scene {...props} />
</Animated.View>
)
}
case 'fancy': {
return (
<FancyAnimation key={scene.index}>
</FancyAnimation>
)
}
default: {
return (
<View style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }} key={scene.index}>
<Scene navigation={this.props.navigation} {...props} />
</View>
)
}
}
}
}
export default CardStackTransitioner;