forked from software-mansion/react-native-gesture-handler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGmailStyleSwipeableRow.js
More file actions
84 lines (79 loc) · 2.06 KB
/
GmailStyleSwipeableRow.js
File metadata and controls
84 lines (79 loc) · 2.06 KB
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
import React, { Component } from 'react';
import { Animated, StyleSheet, Text, View } from 'react-native';
import { RectButton } from 'react-native-gesture-handler';
import Swipeable from 'react-native-gesture-handler/Swipeable';
import Icon from 'react-native-vector-icons/MaterialIcons';
const AnimatedIcon = Animated.createAnimatedComponent(Icon);
export default class AppleStyleSwipeableRow extends Component {
renderLeftActions = (progress, dragX) => {
const scale = dragX.interpolate({
inputRange: [0, 80],
outputRange: [0, 1],
extrapolate: 'clamp',
});
return (
<RectButton style={styles.leftAction} onPress={this.close}>
<AnimatedIcon
name="archive"
size={30}
color="#fff"
style={[styles.actionIcon, { transform: [{ scale }] }]}
/>
</RectButton>
);
};
renderRightActions = (progress, dragX) => {
const scale = dragX.interpolate({
inputRange: [-80, 0],
outputRange: [1, 0],
extrapolate: 'clamp',
});
return (
<RectButton style={styles.rightAction} onPress={this.close}>
<AnimatedIcon
name="delete-forever"
size={30}
color="#fff"
style={[styles.actionIcon, { transform: [{ scale }] }]}
/>
</RectButton>
);
};
updateRef = ref => {
this._swipeableRow = ref;
};
close = () => {
this._swipeableRow.close();
};
render() {
const { children } = this.props;
return (
<Swipeable
ref={this.updateRef}
friction={2}
leftThreshold={80}
rightThreshold={40}
renderLeftActions={this.renderLeftActions}
renderRightActions={this.renderRightActions}>
{children}
</Swipeable>
);
}
}
const styles = StyleSheet.create({
leftAction: {
flex: 1,
backgroundColor: '#388e3c',
justifyContent: 'center',
},
actionIcon: {
width: 30,
marginHorizontal: 10,
},
rightAction: {
alignItems: 'flex-end',
backgroundColor: '#dd2c00',
flex: 1,
justifyContent: 'center',
},
});