forked from lyxia/react-native-yusha-customKeyboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomKeyboardView.js
115 lines (101 loc) · 2.83 KB
/
CustomKeyboardView.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
import React from 'react';
import { StyleSheet, View } from 'react-native';
class CustomKeyboardView extends React.Component {
state;
backSpaceRequest;
insertTextRequest;
clearFocusRequest;
clearAllRequest;
state = {
width: 0,
};
handleDelete = () => {
this.backSpaceRequest && cancelAnimationFrame(this.backSpaceRequest);
this.backSpaceRequest = requestAnimationFrame(() => {
this.props.backSpace(this.props.tag);
});
};
handleKeyPress = (key) => {
this.insertTextRequest && cancelAnimationFrame(this.insertTextRequest);
this.insertTextRequest = requestAnimationFrame(() => {
this.props.insertText(this.props.tag, key);
});
};
clearFocus = () => {
this.clearFocusRequest && cancelAnimationFrame(this.clearFocusRequest);
this.clearFocusRequest = requestAnimationFrame(() => {
this.props.clearFocus(this.props.tag);
});
};
handleClearAll = () => {
this.clearAllRequest && cancelAnimationFrame(this.clearAllRequest);
this.clearAllRequest = requestAnimationFrame(() => {
this.props.clearAll(this.props.tag);
});
};
componentWillUnmount() {
this.clearFocusRequest && cancelAnimationFrame(this.clearFocusRequest);
this.insertTextRequest && cancelAnimationFrame(this.insertTextRequest);
this.backSpaceRequest && cancelAnimationFrame(this.backSpaceRequest);
this.clearAllRequest && cancelAnimationFrame(this.clearAllRequest);
}
render() {
const { KeyboardView } = this.props;
return (
<View
onLayout={this.onLayout}
style={styles.container}
ref="keyboard"
pointerEvents="box-none"
>
<View
style={{
height: this.props.keyboardContainerHeight,
backgroundColor: 'transparent',
}}
key="keyboard"
>
<KeyboardView
{...this.props}
onKeyPress={this.handleKeyPress}
onDelete={this.handleDelete}
onClearAll={this.handleClearAll}
onClearFocus={this.clearFocus}
keyboardContainerHeight={this.props.keyboardContainerHeight}
keyboardViewHeight={this.props.keyboardViewHeight}
/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
backgroundColor: 'transparent',
justifyContent: 'flex-start',
},
top: {
height: 36,
borderTopWidth: StyleSheet.hairlineWidth,
borderTopColor: '#a5a5a5',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
},
topLeft: {
paddingLeft: 15,
flexDirection: 'row',
},
topDesText: {
color: '#adadad',
fontSize: 15,
paddingHorizontal: 8,
},
topCompleteText: {
color: '#0297fa',
fontSize: 15,
paddingHorizontal: 15,
paddingVertical: 10,
},
});
export default CustomKeyboardView;