-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
90 lines (79 loc) · 3.26 KB
/
index.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
import React from 'react';
import PropTypes from 'prop-types'
import { NativeModules, View, Platform, TouchableOpacity, TouchableHighlight, TouchableNativeFeedback, TouchableWithoutFeedback } from 'react-native';
import Swipeout from 'react-native-swipeout'; //https://github.com/dancormier/react-native-swipeout
import { ActionSheetCustom as ActionSheet } from 'react-native-actionsheet' //https://github.com/beefe/react-native-actionsheet
export default class SwipeOutLongPressForAndroid extends React.Component{
showActionSheet = () => {
this._actionsheet.show();
}
selectActionSeet = (idx) => {
console.log('press action sheet : ', idx);
}
render()
{
if(Platform.OS == 'ios'){
return (
<Swipeout {...this.props}>
{this.props.children}
</Swipeout>
);
}
else
{
buttons = this.props.right.map((swipeitem) => {
return swipeitem.text;
})
if(this.props.AndroidCancelbuttonTitle != null)
buttons.push(this.props.AndroidCancelbuttonTitle);
else
buttons.push('Cancel');
action = (idx) => {
if(idx < this.props.right.length)
this.props.right[idx].onPress();
}
actionsheet = <ActionSheet key='actionsheet'
ref={comp => this._actionsheet = comp}
title={this.props.AndroidTitle}
cancelButtonIndex={buttons.length - 1}
destructiveButtonIndex={this.props.AndroidDestructiveButtonIndex}
tintColor={this.props.AndroidTextColor}
options={buttons}
onPress={action}/>;
var hasTouchable = false;
React.Children.forEach(this.props.children, (child) => {
// console.log('child : ', child.type.displayName);
if(child.type == TouchableOpacity
|| child.type == TouchableHighlight
|| child.type == TouchableNativeFeedback
|| child.type == TouchableWithoutFeedback)
hasTouchable = true;
});
if(hasTouchable)
{
newchildren = React.Children.map(this.props.children, (child) => {
// console.log('child : ', child.type.displayName);
return React.cloneElement(child, {onLongPress:this.showActionSheet, style:[this.props.style, child.props.style]});
});
newchildren.key = 'newchildren';
return [newchildren, actionsheet]
}
else{
return (
<TouchableWithoutFeedback onLongPress={this.showActionSheet}>
<View>
{this.props.children}
{actionsheet}
</View>
</TouchableWithoutFeedback>
);
}
}
}
}
SwipeOutLongPressForAndroid.propTypes = {
AndroidTitle: PropTypes.string,
AndroidCancelbuttonTitle: PropTypes.string,
AndroidTextColor: PropTypes.string,
AndroidDestructiveButtonIndex: PropTypes.number
}