@momo-kits/calculator-keyboard 0.92.7-rc.25
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/index.tsx +135 -0
- package/package.json +17 -0
- package/publish.sh +27 -0
- package/styles.ts +18 -0
- package/types.ts +7 -0
package/index.tsx
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import React, {useEffect, useRef, useState} from 'react';
|
|
2
|
+
import {
|
|
3
|
+
AppState,
|
|
4
|
+
Platform,
|
|
5
|
+
requireNativeComponent,
|
|
6
|
+
TextInput,
|
|
7
|
+
} from 'react-native';
|
|
8
|
+
import {InputCalculatorProps} from './types';
|
|
9
|
+
|
|
10
|
+
const {State: TextInputState} = TextInput;
|
|
11
|
+
|
|
12
|
+
export const Keys = {
|
|
13
|
+
CALCULATOR_TEXT_INPUT_FOCUSED: 'CALCULATOR_TEXT_INPUT_FOCUSED',
|
|
14
|
+
CALCULATOR_TEXT_INPUT_UNFOCUSED: 'CALCULATOR_TEXT_INPUT_UNFOCUSED',
|
|
15
|
+
CALCULATOR_DISMISS: 'CALCULATOR_DISMISS',
|
|
16
|
+
CALCULATOR_CALCULATE: 'CALCULATOR_CALCULATE',
|
|
17
|
+
CALCULATOR_HEIGHT_UPDATED: 'CALCULATOR_HEIGHT_UPDATED',
|
|
18
|
+
CALULATOR_PUSH_KEY: 'CALULATOR_PUSH_KEY',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const CalculatorKeyboard: React.FC<InputCalculatorProps> = props => {
|
|
22
|
+
// const [isFocus, setIsFocus] = useState(false);
|
|
23
|
+
const [lastNativeText, setLastNativeText] = useState(props.value);
|
|
24
|
+
const inputRef = useRef<TextInput>(null);
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const nativeProps = {};
|
|
28
|
+
if (lastNativeText !== props.value && typeof props.value === 'string') {
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
nativeProps.text = props.value;
|
|
31
|
+
}
|
|
32
|
+
if (
|
|
33
|
+
Object.keys(nativeProps).length > 0 &&
|
|
34
|
+
inputRef.current &&
|
|
35
|
+
inputRef.current.setNativeProps
|
|
36
|
+
) {
|
|
37
|
+
inputRef.current.setNativeProps(nativeProps);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (props.selectionState && props.selection && props.selection.end) {
|
|
41
|
+
props.selectionState.update(props.selection.start, props.selection.end);
|
|
42
|
+
}
|
|
43
|
+
}, [props.value, props.selection, props.selectionState, lastNativeText]);
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
AppState.addEventListener('change', handleAppStateChange);
|
|
47
|
+
return () => {
|
|
48
|
+
AppState.addEventListener('change', handleAppStateChange);
|
|
49
|
+
};
|
|
50
|
+
}, []);
|
|
51
|
+
|
|
52
|
+
const handleAppStateChange = (nextAppState: string) => {
|
|
53
|
+
if (nextAppState === 'background' && Platform.OS === 'android') {
|
|
54
|
+
blur();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const blur = () => {
|
|
59
|
+
if (inputRef.current && typeof inputRef.current.blur === 'function') {
|
|
60
|
+
inputRef.current.blur();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// const focus = () => {
|
|
65
|
+
// if (inputRef.current && typeof inputRef.current.focus === 'function') {
|
|
66
|
+
// inputRef.current.focus();
|
|
67
|
+
// }
|
|
68
|
+
// };
|
|
69
|
+
|
|
70
|
+
const getText = () => {
|
|
71
|
+
if (typeof props.value === 'string') {
|
|
72
|
+
console.log('props.value', props.value);
|
|
73
|
+
return props.value;
|
|
74
|
+
}
|
|
75
|
+
if (typeof props.defaultValue === 'string') {
|
|
76
|
+
return props.defaultValue;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return '';
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const onFocus = (event: any) => {
|
|
83
|
+
// setIsFocus(true);
|
|
84
|
+
if (props.onFocus) {
|
|
85
|
+
props.onFocus(event);
|
|
86
|
+
}
|
|
87
|
+
if (inputRef.current != null && TextInputState) {
|
|
88
|
+
TextInputState.focusTextInput(inputRef.current);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const onBlur = (event: any) => {
|
|
93
|
+
// setIsFocus(false);
|
|
94
|
+
if (props.onBlur) {
|
|
95
|
+
props.onBlur(event);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const onChange = (event: any) => {
|
|
100
|
+
if (inputRef.current && inputRef.current.setNativeProps) {
|
|
101
|
+
inputRef.current.setNativeProps({
|
|
102
|
+
mostRecentEventCount: event.nativeEvent.eventCount,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const {text} = event.nativeEvent;
|
|
107
|
+
if (props.onChange) {
|
|
108
|
+
props.onChange(event);
|
|
109
|
+
}
|
|
110
|
+
if (props.onChangeText) {
|
|
111
|
+
props.onChangeText(text);
|
|
112
|
+
}
|
|
113
|
+
if (!inputRef) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
setLastNativeText(text);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<RCTInputCalculator
|
|
121
|
+
{...props}
|
|
122
|
+
ref={inputRef}
|
|
123
|
+
onFocus={onFocus}
|
|
124
|
+
onBlur={onBlur}
|
|
125
|
+
onChange={onChange}
|
|
126
|
+
text={getText()}
|
|
127
|
+
/>
|
|
128
|
+
);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// @ts-ignore
|
|
132
|
+
const RCTInputCalculator =
|
|
133
|
+
requireNativeComponent<InputCalculatorProps>('RCTInputCalculator');
|
|
134
|
+
|
|
135
|
+
export default CalculatorKeyboard;
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@momo-kits/calculator-keyboard",
|
|
3
|
+
"version": "0.92.7-rc.25",
|
|
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
|
+
"dependencies": {}
|
|
17
|
+
}
|
package/publish.sh
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
if [ "$1" == "stable" ]; then
|
|
10
|
+
npm version $(npm view @momo-kits/foundation@stable version)
|
|
11
|
+
npm version patch
|
|
12
|
+
npm publish --tag stable --access=public
|
|
13
|
+
elif [ "$1" == "latest" ]; then
|
|
14
|
+
npm version $(npm view @momo-kits/foundation@latest version)
|
|
15
|
+
npm publish --tag latest --access=public
|
|
16
|
+
else
|
|
17
|
+
npm version $(npm view @momo-kits/avatar@beta version)
|
|
18
|
+
npm version prerelease --preid=beta
|
|
19
|
+
npm publish --tag beta --access=public
|
|
20
|
+
fi
|
|
21
|
+
|
|
22
|
+
PACKAGE_NAME=$(npm pkg get name)
|
|
23
|
+
NEW_PACKAGE_VERSION=$(npm pkg get version)
|
|
24
|
+
|
|
25
|
+
# Clean up
|
|
26
|
+
cd ..
|
|
27
|
+
rm -rf dist
|
package/styles.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {StyleSheet} from 'react-native';
|
|
2
|
+
|
|
3
|
+
export default StyleSheet.create({
|
|
4
|
+
icon: {
|
|
5
|
+
position: 'absolute',
|
|
6
|
+
overflow: 'hidden',
|
|
7
|
+
},
|
|
8
|
+
|
|
9
|
+
container: {
|
|
10
|
+
alignItems: 'center',
|
|
11
|
+
justifyContent: 'center',
|
|
12
|
+
borderWidth: 1,
|
|
13
|
+
},
|
|
14
|
+
image: {
|
|
15
|
+
width: '100%',
|
|
16
|
+
height: '100%',
|
|
17
|
+
},
|
|
18
|
+
});
|