TouchView.js
1.85 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
import React from 'react'
import {View, StyleSheet, Animated, PanResponder, Text, TouchableOpacity,Platform,Keyboard} from 'react-native'
import {width} from "../pages/Home";
import {observable} from "mobx";
import {observer} from 'mobx-react/native'
import Interactable from 'react-native-interactable';
const styles = StyleSheet.create({
container: {
width: width + 65,
flexDirection: 'row'
},
delView: {
width: 65,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: "#ea281a",
},
delText: {
color: "white",
fontSize: 16,
}
})
@observer
export default class TouchView extends React.Component {
@observable
x = 0
@observable
show=false
@observable
height=20
xy=new Animated.ValueXY()
_xy={x:0,y:0}
moveBack(){
this.view&&this.view.snapTo({x:0,index:0})
// this.view&&this.view.changePosition({x:0})
this.show=false
}
onPress = async () => {
if (this.props.onPress) {
await this.props.onPress()
}
}
onDrag=v=>{
const {nativeEvent}=v
console.log(nativeEvent)
if(nativeEvent.x<0){
this.show=true
this.props.call(this.props.id)
}else{
this.show=false
}
console.log(this.show)
}
render() {
return (
<View style={[styles.container]}>
<Interactable.View
style={[styles.container]}
onLayout={v=>{this.height=v.nativeEvent.layout.height}}
horizontalOnly={true}
snapPoints={[{x: 0}, {x: -65}]}
springPoints={[{x: 0, tension: 3000, damping: 0.1, influenceArea: {left: 0}}]}
ref={v=>this.view=v}
onDrag={this.onDrag}
>
{this.props.children}
<TouchableOpacity style={styles.delView} onPress={this.onPress}>
<Text style={styles.delText}>删除</Text>
</TouchableOpacity>
{this.show&&<TouchableOpacity style={{width,height:this.height,position:"absolute",left:0}} onPress={()=>this.moveBack()}>
</TouchableOpacity>}
</Interactable.View>
</View>
)
}
}