@momo-kits/calculator-keyboard 0.112.1-rn80.4 → 0.112.1-rn80.5-kits.1
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/package.json +1 -1
- package/src/index.tsx +35 -8
package/package.json
CHANGED
package/src/index.tsx
CHANGED
|
@@ -5,18 +5,28 @@ import {
|
|
|
5
5
|
type TextInputProps,
|
|
6
6
|
type ColorValue,
|
|
7
7
|
processColor,
|
|
8
|
+
UIManager,
|
|
9
|
+
findNodeHandle,
|
|
8
10
|
} from 'react-native';
|
|
9
|
-
import { requireNativeComponent
|
|
11
|
+
import { requireNativeComponent } from 'react-native';
|
|
10
12
|
|
|
11
|
-
const
|
|
13
|
+
const NAME = 'RCTInputCalculator';
|
|
14
|
+
const NativeInput = requireNativeComponent<any>(NAME);
|
|
12
15
|
|
|
13
16
|
interface InputCalculatorProps extends TextInputProps {
|
|
14
17
|
text?: string | undefined;
|
|
15
18
|
keyboardColor?: ColorValue;
|
|
16
19
|
}
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
export type InputCalculatorRef = {
|
|
22
|
+
focus: () => void;
|
|
23
|
+
blur: () => void;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const InputCalculator = React.forwardRef<InputCalculatorRef, InputCalculatorProps>(
|
|
19
27
|
(props, ref) => {
|
|
28
|
+
const nativeRef = React.useRef<any>(null);
|
|
29
|
+
|
|
20
30
|
const _onChange = (
|
|
21
31
|
event: NativeSyntheticEvent<TextInputChangeEventData>
|
|
22
32
|
) => {
|
|
@@ -25,14 +35,33 @@ const InputCalculator = React.forwardRef<TextInput, InputCalculatorProps>(
|
|
|
25
35
|
props.onChangeText && props.onChangeText(currentText);
|
|
26
36
|
};
|
|
27
37
|
|
|
28
|
-
const text = props.text
|
|
38
|
+
const text = props.text ?? props.defaultValue ?? '';
|
|
39
|
+
|
|
40
|
+
React.useImperativeHandle(ref, () => ({
|
|
41
|
+
focus() {
|
|
42
|
+
const node = findNodeHandle(nativeRef.current);
|
|
43
|
+
if (!node) return;
|
|
44
|
+
const config = UIManager.getViewManagerConfig(NAME);
|
|
45
|
+
if (config?.Commands?.focus != null) {
|
|
46
|
+
UIManager.dispatchViewManagerCommand(node, config.Commands.focus, []);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
blur() {
|
|
50
|
+
const node = findNodeHandle(nativeRef.current);
|
|
51
|
+
if (!node) return;
|
|
52
|
+
const config = UIManager.getViewManagerConfig(NAME);
|
|
53
|
+
if (config?.Commands?.blur != null) {
|
|
54
|
+
UIManager.dispatchViewManagerCommand(node, config.Commands.blur, []);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
}));
|
|
29
58
|
|
|
30
59
|
return (
|
|
31
60
|
<NativeInput
|
|
32
61
|
{...props}
|
|
33
|
-
ref={
|
|
62
|
+
ref={nativeRef}
|
|
34
63
|
onChange={_onChange}
|
|
35
|
-
|
|
64
|
+
value={text}
|
|
36
65
|
keybardColor={processColor(props.keyboardColor)}
|
|
37
66
|
/>
|
|
38
67
|
);
|
|
@@ -40,5 +69,3 @@ const InputCalculator = React.forwardRef<TextInput, InputCalculatorProps>(
|
|
|
40
69
|
);
|
|
41
70
|
|
|
42
71
|
export default InputCalculator;
|
|
43
|
-
|
|
44
|
-
export type { InputCalculatorProps };
|