-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwipeableCard.js
127 lines (119 loc) · 3.57 KB
/
SwipeableCard.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
116
117
118
119
120
121
122
123
124
125
126
127
import React, { Component } from "react";
import {
View,
Animated,
Text,
StyleSheet,
PanResponder,
Image,
Dimensions
} from "react-native";
export default class SwipeableCard extends Component {
translateY = new Animated.Value(0);
scale = new Animated.Value(0.9);
_panResponder = PanResponder.create({
onMoveShouldSetResponderCapture: () => true,
onMoveShouldSetPanResponderCapture: () => true,
onPanResponderMove: Animated.event([
null,
{
dy: this.translateY,
}
]),
onPanResponderRelease: (e, { vy, dy }) => {
const screenHeight = Dimensions.get("window").height;
if (Math.abs(vy) >= 0.5 || Math.abs(dy) >= 0.5 * screenHeight) {
console.log(dy);
Animated.timing(this.translateY, {
toValue: dy > 0 ? screenHeight : -screenHeight,
duration: 200
}).start(this.props.onDismiss);
Animated.timing(this.scale, {
toValue: 1,
duration: 200
}).start();
} else {
Animated.spring(this.translateY, {
toValue: 0,
bounciness: 0
}).start();
}
}
});
render() {
return (
<View style={{ flex: 1, ...StyleSheet.absoluteFillObject }}>
<Animated.View
style={[
{
transform: [{ translateY: this.translateY }]
},
styles.animatedCardStyle
]}
{...this._panResponder.panHandlers}
>
<Card />
</Animated.View>
<Animated.View
style={[
{
transform: [
{ scale: this.scale }
]
},
styles.animatedCardStyle
]}
{...this._panResponder.panHandlers}
>
<Card />
</Animated.View>
</View>
);
}
}
class Card extends Component {
render() {
return (
<View style={{ flex: 1 }}>
<View style={{ flex: 4, backgroundColor: "lightgray" }}>
<Image
style={{ flex: 1, height: undefined, width: undefined }}
resizeMode="cover"
source={{
uri:
"https://images.pexels.com/photos/236047/pexels-photo-236047.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"
}}
/>
</View>
<View style={{ flex: 6, backgroundColor: "#F4F4F4", padding: 10 }}>
<Text style={{ fontSize: 20, color: "#212121" }}>
Lorem ipsum dolor sit amet, cu saperet volumus ponderum sea, vix cu.
</Text>
<Text style={{ color: "gray", paddingTop: 20, letterSpacing: 1 }}>
Lorem ipsum dolor sit amet, mel accusata incorrupte assueverit te.
Cu case necessitatibus duo, magna prima repudiandae ne vim, est ea
veri invidunt. Nec ad aeterno euripidis theophrastus, cu est dicant
corrumpit. Ad dico imperdiet ullamcorper ius, ea cum nullam
instructior, ne lorem pericula reprimique mel. In mutat viris
tamquam vim. Te tale facilis qui. Atqui ignota persecuti et est, ex
graecis torquatos eos. Sea id dicant mandamus postulant, usu vero
ludus impedit te. Ei assum postulant per, docendi gubergren
assentior ei eum, vix prima instructior an. Eam quas justo commune
</Text>
</View>
</View>
);
}
}
const styles = {
animatedCardStyle: {
flex: 1,
...StyleSheet.absoluteFillObject,
borderRadius: 10,
shadowColor: "#000",
shadowOffset: { width: 0, height: 5 },
shadowOpacity: 0.6,
shadowRadius: 2,
elevation: 1
}
};