-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.android.js
111 lines (100 loc) · 2.96 KB
/
index.android.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
/**
* author:徐航
* time:2016年12月12日13:35:29
* blogs:http://www.iloveplus.cn
*/
import React, { Component } from 'react';
import {
View,
Text,
StyleSheet,
TouchableHighlight,
ListView,
Clipboard,
TextInput,
AppRegistry,
Dimensions
} from 'react-native';
import ToolTip from './library/components/ToolTip';
export default class ToolTipDemo extends Component{
constructor(props) {
super(props);
this.state={
tipTop:{
isShow:false,
top:0,
left:0,
sectionID:-1,
data:{}
},
data:[
{title:"这是测试案例1",id:"001"},
{title:"这是测试案例2",id:"002"},
{title:"这是测试案例3",id:"003"},
{title:"这是测试案例4",id:"004"},
{title:"这是测试案例5",id:"005"},
{title:"这是测试案例6",id:"006"},
{title:"这是测试案例7",id:"007"},
{title:"这是测试案例8",id:"008"}
],
content:""
}
};
longPress(e,rowData,sectionID){
let nativeEvent=e.nativeEvent;
this.setState({tipTop:{isShow:true,top:nativeEvent.pageY - nativeEvent.locationY,left:nativeEvent.pageX,sectionID:sectionID,data:rowData}});
};
_Press=(rowData)=>{
if(this.state.tipTop.isShow){
this.setState({tipTop:{isShow:false,top:0,left:0,sectionID:-1,data:{}}});
}else{
alert("点击响应!")
}
};
_copy=()=>{
Clipboard.setString(this.state.tipTop.data.title);
alert("复制成功!");
};
_paste=()=>{
try {
var content = Clipboard.getString();
this.setState({content});
} catch (e) {
this.setState({content:e.message});
}
};
_renderRow=(rowData, sectionID, rowID) => {
return (
<TouchableHighlight style={[styles.item,{backgroundColor:rowID==this.state.tipTop.sectionID?"#F5FCFF":"white"}]} onLongPress={(e)=>{this.longPress(e,rowData,rowID)}} onPress={()=>{this._Press(rowData)}} underlayColor={"#F5FCFF"}>
<Text>{rowData.title}</Text>
</TouchableHighlight>
)
};
render() {
return (
<View style={{flex:1,width:Dimensions.get('window').width,position:"relative"}}>
<ListView style={{flex:1}}
dataSource={new ListView.DataSource({rowHasChanged: (r1, r2)=>r1 !== r2}).cloneWithRows(this.state.data)}
renderRow={this._renderRow}/>
<TextInput style={{borderWidth:StyleSheet.hairlineWidth,borderColor:"red",height:40}}/>
<ToolTip
actions={[
{text: '复制', onPress:this._copy},
{text: '粘贴', onPress: this._paste}
]}
isCenter={false}
tipTop={this.state.tipTop}
/>
</View>
)
}
}
const styles = StyleSheet.create({
item: {
width: Dimensions.get('window').width,
height:45,
borderWidth:StyleSheet.hairlineWidth,
borderColor:"black"
}
});
AppRegistry.registerComponent('tooltip', () => ToolTipDemo);