forked from voximplant/react-native-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Keypad.js
118 lines (104 loc) · 3.67 KB
/
Keypad.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
116
117
118
/*
* Copyright (c) 2011-2018, Zingaya, Inc. All rights reserved.
*/
'use strict';
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
TouchableOpacity
} from 'react-native';
class KeypadButton extends Component {
static propTypes = {
...TouchableOpacity.propTypes,
style: View.propTypes.style,
};
render() {
var touchableProps = {}, letters;
touchableProps.onPress = function() {
var digit = this.props.txt1;
if (this.props.txt1 === "*") digit = 10;
if (this.props.txt1 === "#") digit = 11;
this.props.onPress(parseInt(digit));
}.bind(this);
touchableProps.onPressIn = this.props.onPressIn;
touchableProps.onPressOut = this.props.onPressOut;
touchableProps.onLongPress = this.props.onLongPress;
if (this.props.txt2 != "") {
letters = (
<Text style={ [styles.letters, { alignSelf: 'center' }] }>{ this.props.txt2 }</Text>
);
}
return (
<TouchableOpacity {...touchableProps}>
<View style={[this.props.style, {flexDirection: 'column'}]}>
<Text style={[styles.digits, {alignSelf: 'center'}]}>{ this.props.txt1 }</Text>
{letters}
</View>
</TouchableOpacity>
);
}
}
class Keypad extends Component {
handleKeypadPressed(value) {
this.props.keyPressed(value);
}
render() {
return (<View style={ styles.keypad }>
<View style={ styles.keypadrow }>
<KeypadButton style={ styles.keypadbutton } txt1="1" txt2="" onPress={ (e) => this.handleKeypadPressed(e) }/>
<KeypadButton style={ styles.keypadbutton } txt1="2" txt2="A B C" onPress={ (e) => this.handleKeypadPressed(e) }/>
<KeypadButton style={ styles.keypadbutton } txt1="3" txt2="D E F" onPress={ (e) => this.handleKeypadPressed(e) }/>
</View>
<View style={ styles.keypadrow }>
<KeypadButton style={ styles.keypadbutton } txt1="4" txt2="G H I" onPress={ (e) => this.handleKeypadPressed(e) }/>
<KeypadButton style={ styles.keypadbutton } txt1="5" txt2="J K L" onPress={ (e) => this.handleKeypadPressed(e) }/>
<KeypadButton style={ styles.keypadbutton } txt1="6" txt2="M N O" onPress={ (e) => this.handleKeypadPressed(e) }/>
</View>
<View style={ styles.keypadrow }>
<KeypadButton style={ styles.keypadbutton } txt1="7" txt2="P Q R S" onPress={ (e) => this.handleKeypadPressed(e) }/>
<KeypadButton style={ styles.keypadbutton } txt1="8" txt2="T U V" onPress={ (e) => this.handleKeypadPressed(e) }/>
<KeypadButton style={ styles.keypadbutton } txt1="9" txt2="W X Y Z" onPress={ (e) => this.handleKeypadPressed(e) }/>
</View>
<View style={ styles.keypadrow }>
<KeypadButton style={ styles.keypadbutton } txt1="*" txt2="" onPress={ (e) => this.handleKeypadPressed(e) }/>
<KeypadButton style={ styles.keypadbutton } txt1="0" txt2="+" onPress={ (e) => this.handleKeypadPressed(e) }/>
<KeypadButton style={ styles.keypadbutton } txt1="#" txt2="" onPress={ (e) => this.handleKeypadPressed(e) }/>
</View>
</View>);
}
}
var styles = StyleSheet.create({
keypad: {
flex: 1,
marginTop: 0,
marginBottom: 10
},
keypadrow: {
flexDirection: 'row',
alignSelf: 'center'
},
keypadbutton: {
margin: 10,
width: 70,
height: 70,
borderWidth: 0.5,
borderColor: '#2B2B2B',
borderRadius: 35,
paddingTop: 7
},
digits: {
fontFamily: 'Helvetica Neue',
fontSize: 36
},
letters: {
fontFamily: 'Helvetica Neue',
marginTop: -5,
fontSize: 8
}
});
export {
Keypad as Keypad,
KeypadButton as KeypadButton
}