@momo-kits/calculator-keyboard 0.77.22 → 0.77.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,74 +1,82 @@
1
1
  import React from 'react';
2
- import { View, TouchableOpacity, StyleSheet, Text, ImageSourcePropType } from 'react-native';
3
- import { Colors as ColorCore, Image as FastImage } from '@momo-kits/foundation';
4
- import { Source } from 'react-native-fast-image';
2
+ import {StyleSheet, TouchableOpacity, View, Text} from 'react-native';
3
+ import {
4
+ Colors as ColorCore,
5
+ Image as FastImage,
6
+ scaleSize,
7
+ } from '@momo-kits/foundation';
8
+ import {Source} from 'react-native-fast-image';
5
9
 
6
10
  interface KeyButtonProps {
7
- text: string;
8
- icon?: number | Source;
9
- size?: {
10
- width: number;
11
- height: number;
12
- tintColor?: string;
13
- };
14
- backgroundColor?: string;
15
- onLongPress?: (text: string) => void;
11
+ text: string;
12
+ icon?: number | Source;
13
+ size?: {
16
14
  width: number;
17
- onPressOut?: () => void;
18
- onPressIn?: (text: string) => void;
19
- textStyle?: object;
15
+ height: number;
16
+ tintColor?: string;
17
+ };
18
+ backgroundColor?: string;
19
+ onLongPress?: (text: string) => void;
20
+ width: number;
21
+ onPressOut?: () => void;
22
+ onPressIn?: (text: string) => void;
23
+ textStyle?: object;
20
24
  }
21
25
 
22
26
  const styles = StyleSheet.create({
23
- container: {
24
- marginVertical: 1.5,
25
- marginHorizontal: 1.5,
26
- borderRadius: 8,
27
- },
28
- button: {
29
- alignItems: 'center',
30
- justifyContent: 'center',
31
- flex: 1,
32
- borderRadius: 5,
33
- },
27
+ container: {
28
+ marginVertical: 1.5,
29
+ marginHorizontal: 1.5,
30
+ borderRadius: 8,
31
+ },
32
+ button: {
33
+ alignItems: 'center',
34
+ justifyContent: 'center',
35
+ flex: 1,
36
+ borderRadius: 5,
37
+ },
38
+ text: {
39
+ fontSize: scaleSize(24),
40
+ lineHeight: scaleSize(32),
41
+ fontFamily: 'SFProText-Semibold',
42
+ color: ColorCore.black_20,
43
+ },
34
44
  });
35
45
 
36
46
  const KeyButton: React.FC<KeyButtonProps> = ({
37
- text,
38
- icon,
39
- size,
40
- backgroundColor = ColorCore.black_01,
41
- onLongPress = () => {},
42
- width,
43
- onPressOut = () => {},
44
- onPressIn = () => {},
45
- textStyle = {},
47
+ text,
48
+ icon,
49
+ size,
50
+ backgroundColor = ColorCore.black_01,
51
+ onLongPress = () => {},
52
+ width,
53
+ onPressOut = () => {},
54
+ onPressIn = () => {},
55
+ textStyle = {},
46
56
  }) => {
47
- let content = null;
48
- if (icon) {
49
- content = (
50
- <FastImage resizeMode="contain" source={icon} style={size} />
51
- );
52
- } else {
53
- content = <Text style={textStyle}>{text}</Text>;
54
- }
55
-
56
- const buttonLongPress = () => onLongPress(text);
57
- const buttonOnPressIn = () => onPressIn(text);
58
-
59
- return (
60
- <View
61
- key={text}
62
- style={[styles.container, { backgroundColor, width }]}>
63
- <TouchableOpacity
64
- onPressIn={buttonOnPressIn}
65
- onPressOut={onPressOut}
66
- onLongPress={buttonLongPress}
67
- style={styles.button}>
68
- {content}
69
- </TouchableOpacity>
70
- </View>
57
+ let content = null;
58
+ if (icon) {
59
+ content = (
60
+ <FastImage tintColor={ColorCore.black_20} source={icon} style={size} />
71
61
  );
62
+ } else {
63
+ content = <Text style={[textStyle, styles.text]}>{text}</Text>;
64
+ }
65
+
66
+ const buttonLongPress = () => onLongPress(text);
67
+ const buttonOnPressIn = () => onPressIn(text);
68
+
69
+ return (
70
+ <View key={text} style={[styles.container, {backgroundColor, width}]}>
71
+ <TouchableOpacity
72
+ onPressIn={buttonOnPressIn}
73
+ onPressOut={onPressOut}
74
+ onLongPress={buttonLongPress}
75
+ style={styles.button}>
76
+ {content}
77
+ </TouchableOpacity>
78
+ </View>
79
+ );
72
80
  };
73
81
 
74
- export default KeyButton;
82
+ export default KeyButton;
package/index.tsx CHANGED
@@ -1,276 +1,269 @@
1
- import React, { useState, useEffect, useRef } from 'react';
1
+ import React, {useState, useEffect, useRef} from 'react';
2
2
  import {
3
- DeviceEventEmitter,
4
- Dimensions,
5
- Keyboard,
6
- NativeModules,
7
- StyleSheet,
8
- View,
9
- Platform,
3
+ DeviceEventEmitter,
4
+ Dimensions,
5
+ Keyboard,
6
+ NativeModules,
7
+ StyleSheet,
8
+ View,
9
+ Platform,
10
10
  } from 'react-native';
11
- import { Keys } from './Keys';
11
+ import {Keys} from './Keys';
12
12
  import Row from './components/Row';
13
13
  import KeyButton from './components/KeyButton';
14
- import { Colors as ColorCore, scaleSize } from '@momo-kits/foundation';
14
+ import {Colors as ColorCore, scaleSize} from '@momo-kits/foundation';
15
15
 
16
16
  const SEPERATOR_WIDTH = 3;
17
17
  const NUMBER_COLUMN = 4;
18
- const { width, height } = Dimensions.get('window');
18
+ const {width, height} = Dimensions.get('window');
19
19
  const BUTTON_WIDTH =
20
- ((width > 0 ? width : 375) - (NUMBER_COLUMN + 1) * SEPERATOR_WIDTH) /
21
- NUMBER_COLUMN;
20
+ ((width > 0 ? width : 375) - (NUMBER_COLUMN + 1) * SEPERATOR_WIDTH) /
21
+ NUMBER_COLUMN;
22
22
 
23
23
  const isIphoneX = (): boolean =>
24
- Platform.OS === 'ios' &&
25
- !Platform.isPad &&
26
- !Platform.isTVOS &&
27
- (height === 812 ||
28
- width === 812 ||
29
- height === 896 ||
30
- width === 896 ||
31
- width === 844 ||
32
- height === 844);
24
+ Platform.OS === 'ios' &&
25
+ !Platform.isPad &&
26
+ !Platform.isTVOS &&
27
+ (height === 812 ||
28
+ width === 812 ||
29
+ height === 896 ||
30
+ width === 896 ||
31
+ width === 844 ||
32
+ height === 844);
33
33
 
34
34
  const styles = StyleSheet.create({
35
- eqBtnWrapper: {
36
- backgroundColor: '#ad076b',
37
- },
38
- specialBtnWrapper: {
39
- backgroundColor: '#FFF',
40
- },
41
- normalBtnWrapper: {
42
- backgroundColor: ColorCore.black_01,
43
- },
44
- container: { flex: 1, backgroundColor: ColorCore.black_02 },
45
- keyboardView: {
46
- flexDirection: 'row',
47
- flex: 1,
48
- paddingTop: 2,
49
- paddingBottom: isIphoneX() ? 36 : 5,
50
- paddingHorizontal: 1.5,
51
- },
52
- textNormal: {
53
- color: ColorCore.black_17,
54
- fontSize: scaleSize(24),
55
- fontWeight: '500',
56
- },
57
- textPink: {
58
- color: ColorCore.black_01,
59
- fontSize: scaleSize(24),
60
- fontWeight: 'bold',
61
- },
62
- textEqual: {
63
- color: ColorCore.black_01,
64
- fontSize: scaleSize(24),
65
- fontWeight: '600',
66
- },
35
+ eqBtnWrapper: {
36
+ backgroundColor: ColorCore.black_06,
37
+ },
38
+ specialBtnWrapper: {
39
+ backgroundColor: '#FFF',
40
+ },
41
+ normalBtnWrapper: {
42
+ backgroundColor: ColorCore.black_01,
43
+ },
44
+ container: {flex: 1, backgroundColor: ColorCore.black_02},
45
+ keyboardView: {
46
+ flexDirection: 'row',
47
+ flex: 1,
48
+ paddingTop: 2,
49
+ paddingBottom: isIphoneX() ? 36 : 5,
50
+ paddingHorizontal: 1.5,
51
+ },
52
+ textNormal: {
53
+ color: ColorCore.black_17,
54
+ fontSize: scaleSize(24),
55
+ fontWeight: '500',
56
+ },
57
+ textPink: {
58
+ color: ColorCore.black_01,
59
+ fontSize: scaleSize(24),
60
+ fontWeight: 'bold',
61
+ },
62
+ textEqual: {
63
+ color: ColorCore.black_01,
64
+ fontSize: scaleSize(24),
65
+ fontWeight: '600',
66
+ },
67
67
  });
68
68
 
69
- const { CalculatorKeyboardModule } = NativeModules;
69
+ const {CalculatorKeyboardModule} = NativeModules;
70
70
 
71
- const REMOVE_ICON =
72
- 'https://cdn.mservice.com.vn/app/icon/kits/chat_back_space.png';
71
+ const REMOVE_ICON = {
72
+ uri: 'https://cdn.mservice.com.vn/app/icon/kits/chat_back_space.png',
73
+ };
73
74
 
74
75
  const CALCULATOR_BUTTONS = [
75
- [
76
- {
77
- text: 'AC',
78
- icon: null,
79
- backgroundColor: ColorCore.pink_08,
80
- textWeight: 'bold',
81
- textStyle: {
82
- color: ColorCore.black_01,
83
- fontSize: scaleSize(20),
84
- fontWeight: 'bold',
85
- },
86
- },
87
- {
88
- text: '÷',
89
- size: { width: 18, height: 18 },
90
- backgroundColor: ColorCore.pink_08,
91
- textStyle: styles.textPink,
92
- },
93
- {
94
- text: '×',
95
- size: { width: 14, height: 14 },
96
- backgroundColor: ColorCore.pink_08,
97
- textStyle: styles.textPink,
98
- },
99
- ],
100
- [
101
- { text: '7', icon: null, textStyle: styles.textNormal },
102
- { text: '8', icon: null, textStyle: styles.textNormal },
103
- { text: '9', icon: null, textStyle: styles.textNormal },
104
- ],
105
- [
106
- { text: '4', icon: null, textStyle: styles.textNormal },
107
- { text: '5', icon: null, textStyle: styles.textNormal },
108
- { text: '6', icon: null, textStyle: styles.textNormal },
109
- ],
110
- [
111
- { text: '1', icon: null, textStyle: styles.textNormal },
112
- { text: '2', icon: null, textStyle: styles.textNormal },
113
- { text: '3', icon: null, textStyle: styles.textNormal },
114
- ],
76
+ [
77
+ {
78
+ text: 'AC',
79
+ icon: null,
80
+ backgroundColor: ColorCore.black_06,
81
+ },
82
+ {
83
+ text: '÷',
84
+ size: {width: 18, height: 18},
85
+ backgroundColor: ColorCore.black_06,
86
+ },
87
+ {
88
+ text: '×',
89
+ size: {width: 14, height: 14},
90
+ backgroundColor: ColorCore.black_06,
91
+ },
92
+ ],
93
+ [
94
+ {text: '7', icon: null},
95
+ {text: '8', icon: null},
96
+ {text: '9', icon: null},
97
+ ],
98
+ [
99
+ {text: '4', icon: null},
100
+ {text: '5', icon: null},
101
+ {text: '6', icon: null},
102
+ ],
103
+ [
104
+ {text: '1', icon: null},
105
+ {text: '2', icon: null},
106
+ {text: '3', icon: null},
107
+ ],
115
108
  ];
116
109
 
117
110
  interface KeyboardCalculatorProps {
118
- onPress?: (key: string) => void;
111
+ onPress?: (key: string) => void;
119
112
  }
120
113
 
121
- const KeyboardCalculator: React.FC<KeyboardCalculatorProps> = ({ onPress }) => {
122
- const [isOnkeyboardIn, setIsOnkeyboardIn] = useState<boolean>(true);
123
- const keyboardDidShowListener = useRef<any>(null);
124
- const keyboardDidHideListener = useRef<any>(null);
114
+ const KeyboardCalculator: React.FC<KeyboardCalculatorProps> = ({onPress}) => {
115
+ const [isOnkeyboardIn, setIsOnkeyboardIn] = useState<boolean>(true);
116
+ const keyboardDidShowListener = useRef<any>(null);
117
+ const keyboardDidHideListener = useRef<any>(null);
125
118
 
126
- useEffect(() => {
127
- keyboardDidShowListener.current = Keyboard.addListener(
128
- 'keyboardDidShow',
129
- _keyboardDidShow,
130
- );
131
- keyboardDidHideListener.current = Keyboard.addListener(
132
- 'keyboardDidHide',
133
- _keyboardDidHide,
134
- );
119
+ useEffect(() => {
120
+ keyboardDidShowListener.current = Keyboard.addListener(
121
+ 'keyboardDidShow',
122
+ _keyboardDidShow
123
+ );
124
+ keyboardDidHideListener.current = Keyboard.addListener(
125
+ 'keyboardDidHide',
126
+ _keyboardDidHide
127
+ );
135
128
 
136
- return () => {
137
- keyboardDidShowListener.current?.remove();
138
- keyboardDidHideListener.current?.remove();
139
- };
140
- }, []);
129
+ return () => {
130
+ keyboardDidShowListener.current?.remove();
131
+ keyboardDidHideListener.current?.remove();
132
+ };
133
+ }, []);
141
134
 
142
- const _keyboardDidHide = () => {};
135
+ const _keyboardDidHide = () => {};
143
136
 
144
- const _keyboardDidShow = () => {};
137
+ const _keyboardDidShow = () => {};
145
138
 
146
- const onLongPressKeyboardBtn = (keyType: string) => {
147
- if (keyType === 'REMOVE') {
148
- autoBackSpace(keyType);
149
- } else {
150
- if (typeof onPress === 'function') {
151
- onPress(keyType);
152
- }
153
- }
154
- };
139
+ const onLongPressKeyboardBtn = (keyType: string) => {
140
+ if (keyType === 'REMOVE') {
141
+ autoBackSpace(keyType);
142
+ } else {
143
+ if (typeof onPress === 'function') {
144
+ onPress(keyType);
145
+ }
146
+ }
147
+ };
155
148
 
156
- const autoBackSpace = (keyType: string) => {
157
- if (isOnkeyboardIn) {
158
- onPressIn(keyType);
159
- setTimeout(() => {
160
- autoBackSpace(keyType);
161
- }, 200);
162
- }
163
- };
149
+ const autoBackSpace = (keyType: string) => {
150
+ if (isOnkeyboardIn) {
151
+ onPressIn(keyType);
152
+ setTimeout(() => {
153
+ autoBackSpace(keyType);
154
+ }, 200);
155
+ }
156
+ };
164
157
 
165
- const onPressIn = (txt: string) => {
166
- setIsOnkeyboardIn(true);
158
+ const onPressIn = (txt: string) => {
159
+ setIsOnkeyboardIn(true);
167
160
 
168
- if (
169
- txt === '+' ||
170
- txt === '-' ||
171
- txt === '×' ||
172
- txt === '÷' ||
173
- txt === 'REMOVE' ||
174
- txt === 'AC' ||
175
- txt === '='
176
- )
177
- DeviceEventEmitter.emit(Keys.CALULATOR_PUSH_KEY, txt);
178
-
179
- if (txt === 'REMOVE') {
180
- CalculatorKeyboardModule.backSpace();
181
- } else if (txt === 'AC') {
182
- CalculatorKeyboardModule.doDelete();
183
- } else if (txt === 'CLOSE') {
184
- DeviceEventEmitter.emit(Keys.CALCULATOR_DISMISS);
185
- } else if (txt === '=') {
186
- DeviceEventEmitter.emit(Keys.CALCULATOR_CALCULATE);
187
- } else {
188
- CalculatorKeyboardModule.insertText(txt);
189
- }
190
- };
161
+ if (
162
+ txt === '+' ||
163
+ txt === '-' ||
164
+ txt === '×' ||
165
+ txt === '÷' ||
166
+ txt === 'REMOVE' ||
167
+ txt === 'AC' ||
168
+ txt === '='
169
+ )
170
+ DeviceEventEmitter.emit(Keys.CALULATOR_PUSH_KEY, txt);
191
171
 
192
- const onPressOut = () => {
193
- setIsOnkeyboardIn(false);
194
- };
172
+ if (txt === 'REMOVE') {
173
+ CalculatorKeyboardModule.backSpace();
174
+ } else if (txt === 'AC') {
175
+ CalculatorKeyboardModule.doDelete();
176
+ } else if (txt === 'CLOSE') {
177
+ DeviceEventEmitter.emit(Keys.CALCULATOR_DISMISS);
178
+ } else if (txt === '=') {
179
+ DeviceEventEmitter.emit(Keys.CALCULATOR_CALCULATE);
180
+ } else {
181
+ CalculatorKeyboardModule.insertText(txt);
182
+ }
183
+ };
195
184
 
196
- const renderBtn = (params: any) => (
197
- <KeyButton
198
- key={params.text}
199
- onPressIn={onPressIn}
200
- onPressOut={onPressOut}
201
- onLongPress={onLongPressKeyboardBtn}
202
- width={BUTTON_WIDTH}
203
- {...params}
204
- />
205
- );
185
+ const onPressOut = () => {
186
+ setIsOnkeyboardIn(false);
187
+ };
188
+
189
+ const renderBtn = (params: any) => (
190
+ <KeyButton
191
+ key={params.text}
192
+ onPressIn={onPressIn}
193
+ onPressOut={onPressOut}
194
+ onLongPress={onLongPressKeyboardBtn}
195
+ width={BUTTON_WIDTH}
196
+ {...params}
197
+ />
198
+ );
206
199
 
207
- const renderContent = () => (
208
- <View style={styles.keyboardView}>
209
- <View style={{ width: BUTTON_WIDTH * 3 + 2 * SEPERATOR_WIDTH }}>
210
- <Row>{CALCULATOR_BUTTONS[0].map(renderBtn)}</Row>
211
- <Row>{CALCULATOR_BUTTONS[1].map(renderBtn)}</Row>
212
- <Row>{CALCULATOR_BUTTONS[2].map(renderBtn)}</Row>
213
- <Row>{CALCULATOR_BUTTONS[3].map(renderBtn)}</Row>
214
- <Row>
215
- {renderBtn({
216
- width: BUTTON_WIDTH * 2 + 3,
217
- text: '000',
218
- textStyle: styles.textNormal,
219
- })}
220
- {renderBtn({
221
- width: BUTTON_WIDTH,
222
- text: '0',
223
- textStyle: styles.textNormal,
224
- })}
225
- </Row>
226
- </View>
227
- <View style={{ width: BUTTON_WIDTH, marginLeft: 3 }}>
228
- <View style={{ flex: 0.6 }}>
229
- <Row>
230
- {renderBtn({
231
- width: BUTTON_WIDTH,
232
- text: 'REMOVE',
233
- backgroundColor: ColorCore.pink_08,
234
- icon: REMOVE_ICON,
235
- size: {
236
- width: 24,
237
- height: 24,
238
- tintColor: ColorCore.black_01,
239
- },
240
- })}
241
- </Row>
242
- <Row>
243
- {renderBtn({
244
- width: BUTTON_WIDTH,
245
- text: '-',
246
- backgroundColor: ColorCore.pink_08,
247
- textStyle: styles.textPink,
248
- })}
249
- </Row>
250
- <Row>
251
- {renderBtn({
252
- width: BUTTON_WIDTH,
253
- text: '+',
254
- backgroundColor: ColorCore.pink_08,
255
- textStyle: styles.textPink,
256
- })}
257
- </Row>
258
- </View>
259
- <View style={{ flex: 0.4 }}>
260
- <Row>
261
- {renderBtn({
262
- width: BUTTON_WIDTH,
263
- text: '=',
264
- backgroundColor: ColorCore.pink_03,
265
- textStyle: styles.textEqual,
266
- })}
267
- </Row>
268
- </View>
269
- </View>
200
+ const renderContent = () => (
201
+ <View style={styles.keyboardView}>
202
+ <View style={{width: BUTTON_WIDTH * 3 + 2 * SEPERATOR_WIDTH}}>
203
+ <Row>{CALCULATOR_BUTTONS[0].map(renderBtn)}</Row>
204
+ <Row>{CALCULATOR_BUTTONS[1].map(renderBtn)}</Row>
205
+ <Row>{CALCULATOR_BUTTONS[2].map(renderBtn)}</Row>
206
+ <Row>{CALCULATOR_BUTTONS[3].map(renderBtn)}</Row>
207
+ <Row>
208
+ {renderBtn({
209
+ width: BUTTON_WIDTH * 2 + 3,
210
+ text: '000',
211
+ textStyle: styles.textNormal,
212
+ })}
213
+ {renderBtn({
214
+ width: BUTTON_WIDTH,
215
+ text: '0',
216
+ textStyle: styles.textNormal,
217
+ })}
218
+ </Row>
219
+ </View>
220
+ <View style={{width: BUTTON_WIDTH, marginLeft: 3}}>
221
+ <View style={{flex: 0.6}}>
222
+ <Row>
223
+ {renderBtn({
224
+ width: BUTTON_WIDTH,
225
+ text: 'REMOVE',
226
+ backgroundColor: ColorCore.black_06,
227
+ icon: REMOVE_ICON,
228
+ size: {
229
+ width: 24,
230
+ height: 24,
231
+ tintColor: ColorCore.black_20,
232
+ },
233
+ })}
234
+ </Row>
235
+ <Row>
236
+ {renderBtn({
237
+ width: BUTTON_WIDTH,
238
+ text: '-',
239
+ backgroundColor: ColorCore.black_06,
240
+ textStyle: styles.textPink,
241
+ })}
242
+ </Row>
243
+ <Row>
244
+ {renderBtn({
245
+ width: BUTTON_WIDTH,
246
+ text: '+',
247
+ backgroundColor: ColorCore.black_06,
248
+ textStyle: styles.textPink,
249
+ })}
250
+ </Row>
270
251
  </View>
271
- );
252
+ <View style={{flex: 0.4}}>
253
+ <Row>
254
+ {renderBtn({
255
+ width: BUTTON_WIDTH,
256
+ text: '=',
257
+ backgroundColor: ColorCore.black_06,
258
+ textStyle: styles.textEqual,
259
+ })}
260
+ </Row>
261
+ </View>
262
+ </View>
263
+ </View>
264
+ );
272
265
 
273
- return <View style={styles.container}>{renderContent()}</View>;
266
+ return <View style={styles.container}>{renderContent()}</View>;
274
267
  };
275
268
 
276
- export default KeyboardCalculator;
269
+ export default KeyboardCalculator;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/calculator-keyboard",
3
- "version": "0.77.22",
3
+ "version": "0.77.24",
4
4
  "private": false,
5
5
  "main": "index.tsx",
6
6
  "peerDependencies": {
Binary file
Binary file
Binary file