-
Notifications
You must be signed in to change notification settings - Fork 627
/
Card.js
91 lines (78 loc) 路 2.31 KB
/
Card.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
/* @flow */
import { createElement, Component, PropTypes } from 'rax';
import Animated from 'rax-animated';
import StyleSheet from 'universal-stylesheet';
import CardStackPanResponder from './CardStackPanResponder';
import CardStackStyleInterpolator from './CardStackStyleInterpolator';
import createPointerEventsContainer from './PointerEventsContainer';
import NavigationPropTypes from '../PropTypes';
// type Props = NavigationSceneRendererProps & {
// onComponentRef: (ref: any) => void,
// onNavigateBack: ?Function,
// panHandlers: ?NavigationPanHandlers,
// pointerEvents: string,
// renderScene: NavigationSceneRenderer,
// style: any,
// };
/**
* Component that renders the scene as card for the <NavigationCardStack />.
*/
class Card extends Component {
// props: Props;
static propTypes = {
...NavigationPropTypes.SceneRendererProps,
onComponentRef: PropTypes.func.isRequired,
onNavigateBack: PropTypes.func,
panHandlers: NavigationPropTypes.panHandlers,
pointerEvents: PropTypes.string.isRequired,
renderScene: PropTypes.func.isRequired,
style: PropTypes.any,
};
render() {
const {
panHandlers,
pointerEvents,
renderScene,
style,
...props /* NavigationSceneRendererProps */
} = this.props;
const viewStyle = style === undefined ?
CardStackStyleInterpolator.forHorizontal(props) :
style;
const viewPanHandlers = panHandlers === undefined ?
CardStackPanResponder.forHorizontal({
...props,
onNavigateBack: this.props.onNavigateBack,
}) :
panHandlers;
return (
<Animated.View
{...viewPanHandlers}
pointerEvents={pointerEvents}
ref={this.props.onComponentRef}
style={[styles.main, viewStyle]}
>
{renderScene(props)}
</Animated.View>
);
}
}
const styles = StyleSheet.create({
main: {
backgroundColor: '#E9E9EF',
bottom: 0,
left: 0,
position: 'absolute',
right: 0,
shadowColor: 'black',
shadowOffset: { width: 0, height: 0 },
shadowOpacity: 0.4,
shadowRadius: 10,
top: 0,
},
});
/* eslint-disable no-class-assign */
Card = createPointerEventsContainer(Card);
Card.CardStackPanResponder = CardStackPanResponder;
Card.CardStackStyleInterpolator = CardStackStyleInterpolator;
export default Card;