@momo-kits/calculator-keyboard 0.77.22

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.
package/Keys.ts ADDED
@@ -0,0 +1,8 @@
1
+ export const Keys = {
2
+ CALCULATOR_TEXT_INPUT_FOCUSED: 'CALCULATOR_TEXT_INPUT_FOCUSED',
3
+ CALCULATOR_TEXT_INPUT_UNFOCUSED: 'CALCULATOR_TEXT_INPUT_UNFOCUSED',
4
+ CALCULATOR_DISMISS: 'CALCULATOR_DISMISS',
5
+ CALCULATOR_CALCULATE: 'CALCULATOR_CALCULATE',
6
+ CALCULATOR_HEIGHT_UPDATED: 'CALCULATOR_HEIGHT_UPDATED',
7
+ CALULATOR_PUSH_KEY: 'CALULATOR_PUSH_KEY'
8
+ };
@@ -0,0 +1,74 @@
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';
5
+
6
+ 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;
16
+ width: number;
17
+ onPressOut?: () => void;
18
+ onPressIn?: (text: string) => void;
19
+ textStyle?: object;
20
+ }
21
+
22
+ 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
+ },
34
+ });
35
+
36
+ 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 = {},
46
+ }) => {
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>
71
+ );
72
+ };
73
+
74
+ export default KeyButton;
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import { View, StyleSheet } from 'react-native';
3
+
4
+ interface RowProps {
5
+ children?: React.ReactNode;
6
+ }
7
+
8
+ const styles = StyleSheet.create({
9
+ container: {
10
+ flexDirection: 'row',
11
+ flex: 1
12
+ }
13
+ });
14
+
15
+ const Row: React.FC<RowProps> = ({ children }) => {
16
+ return (
17
+ <View style={styles.container}>
18
+ {children}
19
+ </View>
20
+ );
21
+ };
22
+
23
+ export default Row;
Binary file
Binary file
Binary file
package/index.tsx ADDED
@@ -0,0 +1,276 @@
1
+ import React, { useState, useEffect, useRef } from 'react';
2
+ import {
3
+ DeviceEventEmitter,
4
+ Dimensions,
5
+ Keyboard,
6
+ NativeModules,
7
+ StyleSheet,
8
+ View,
9
+ Platform,
10
+ } from 'react-native';
11
+ import { Keys } from './Keys';
12
+ import Row from './components/Row';
13
+ import KeyButton from './components/KeyButton';
14
+ import { Colors as ColorCore, scaleSize } from '@momo-kits/foundation';
15
+
16
+ const SEPERATOR_WIDTH = 3;
17
+ const NUMBER_COLUMN = 4;
18
+ const { width, height } = Dimensions.get('window');
19
+ const BUTTON_WIDTH =
20
+ ((width > 0 ? width : 375) - (NUMBER_COLUMN + 1) * SEPERATOR_WIDTH) /
21
+ NUMBER_COLUMN;
22
+
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);
33
+
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
+ },
67
+ });
68
+
69
+ const { CalculatorKeyboardModule } = NativeModules;
70
+
71
+ const REMOVE_ICON =
72
+ 'https://cdn.mservice.com.vn/app/icon/kits/chat_back_space.png';
73
+
74
+ 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
+ ],
115
+ ];
116
+
117
+ interface KeyboardCalculatorProps {
118
+ onPress?: (key: string) => void;
119
+ }
120
+
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);
125
+
126
+ useEffect(() => {
127
+ keyboardDidShowListener.current = Keyboard.addListener(
128
+ 'keyboardDidShow',
129
+ _keyboardDidShow,
130
+ );
131
+ keyboardDidHideListener.current = Keyboard.addListener(
132
+ 'keyboardDidHide',
133
+ _keyboardDidHide,
134
+ );
135
+
136
+ return () => {
137
+ keyboardDidShowListener.current?.remove();
138
+ keyboardDidHideListener.current?.remove();
139
+ };
140
+ }, []);
141
+
142
+ const _keyboardDidHide = () => {};
143
+
144
+ const _keyboardDidShow = () => {};
145
+
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
+ };
155
+
156
+ const autoBackSpace = (keyType: string) => {
157
+ if (isOnkeyboardIn) {
158
+ onPressIn(keyType);
159
+ setTimeout(() => {
160
+ autoBackSpace(keyType);
161
+ }, 200);
162
+ }
163
+ };
164
+
165
+ const onPressIn = (txt: string) => {
166
+ setIsOnkeyboardIn(true);
167
+
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
+ };
191
+
192
+ const onPressOut = () => {
193
+ setIsOnkeyboardIn(false);
194
+ };
195
+
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
+ );
206
+
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>
270
+ </View>
271
+ );
272
+
273
+ return <View style={styles.container}>{renderContent()}</View>;
274
+ };
275
+
276
+ export default KeyboardCalculator;
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@momo-kits/calculator-keyboard",
3
+ "version": "0.77.22",
4
+ "private": false,
5
+ "main": "index.tsx",
6
+ "peerDependencies": {
7
+ "@momo-kits/foundation": "latest",
8
+ "react": "16.9.0",
9
+ "react-native": ">=0.55",
10
+ "prop-types": "^15.7.2"
11
+ },
12
+ "devDependencies": {
13
+ "@momo-platform/versions": "4.1.11"
14
+ },
15
+ "license": "MoMo",
16
+ "publishConfig": {
17
+ "registry": "https://registry.npmjs.org/"
18
+ },
19
+ "dependencies": {}
20
+ }
package/publish.sh ADDED
@@ -0,0 +1,28 @@
1
+ #!/bin/bash
2
+
3
+ # Prepare dist files
4
+ rm -rf dist
5
+ mkdir dist
6
+ rsync -r --exclude=/dist ./* dist
7
+ cd dist
8
+
9
+
10
+ if [ "$1" == "stable" ]; then
11
+ npm version $(npm view @momo-kits/foundation@stable version)
12
+ npm version patch
13
+ npm publish --tag stable --access=public
14
+ elif [ "$1" == "latest" ]; then
15
+ npm version $(npm view @momo-kits/foundation@latest version)
16
+ npm publish --tag latest --access=public
17
+ else
18
+ npm version $(npm view @momo-kits/avatar@beta version)
19
+ npm version prerelease --preid=beta
20
+ npm publish --tag beta --access=public
21
+ fi
22
+
23
+ PACKAGE_NAME=$(npm pkg get name)
24
+ NEW_PACKAGE_VERSION=$(npm pkg get version)
25
+
26
+ # Clean up
27
+ cd ..
28
+ rm -rf dist