@momo-kits/calculator-keyboard 0.150.2-phuc.13 → 0.151.1-beta.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/README.md +45 -3
- package/android/src/main/java/com/calculatorkeyboard/CalculatorKeyboardPackage.kt +1 -1
- package/android/src/main/java/com/calculatorkeyboard/CustomKeyboardView.kt +184 -95
- package/android/src/main/java/com/calculatorkeyboard/Event.kt +36 -0
- package/android/src/main/java/com/calculatorkeyboard/InputCalculatorViewManager.kt +270 -0
- package/android/src/main/java/com/calculatorkeyboard/KeyboardOverplayHost.kt +232 -0
- package/ios/CalculatorKeyboardView.h +30 -0
- package/ios/CalculatorKeyboardView.mm +231 -0
- package/ios/NativeInputCalculator.h +11 -0
- package/ios/NativeInputCalculator.mm +369 -0
- package/package.json +21 -131
- package/react-native-calculator-keyboard.podspec +5 -4
- package/src/InputCalculatorNativeComponent.ts +62 -0
- package/src/index.tsx +124 -82
- package/android/src/main/java/com/calculatorkeyboard/RCTInputCalculator.kt +0 -339
- package/ios/CalculatorKeyboardView.swift +0 -165
- package/ios/InputCalculator-Bridging-Header.h +0 -23
- package/ios/InputCalculator.m +0 -85
- package/ios/InputCalculator.swift +0 -158
- package/ios/extension.swift +0 -23
- package/lib/commonjs/index.js +0 -72
- package/lib/commonjs/index.js.map +0 -1
- package/lib/module/index.js +0 -68
- package/lib/module/index.js.map +0 -1
- package/lib/typescript/commonjs/package.json +0 -1
- package/lib/typescript/commonjs/src/index.d.ts +0 -31
- package/lib/typescript/commonjs/src/index.d.ts.map +0 -1
- package/lib/typescript/module/package.json +0 -1
- package/lib/typescript/module/src/index.d.ts +0 -31
- package/lib/typescript/module/src/index.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momo-kits/calculator-keyboard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.151.1-beta.1",
|
|
4
4
|
"description": "react native calculator keyboard",
|
|
5
|
-
"
|
|
6
|
-
"main": "./lib/commonjs/index.js",
|
|
7
|
-
"module": "./lib/module/index.js",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"import": {
|
|
11
|
-
"types": "./lib/typescript/module/src/index.d.ts",
|
|
12
|
-
"default": "./lib/module/index.js"
|
|
13
|
-
},
|
|
14
|
-
"require": {
|
|
15
|
-
"types": "./lib/typescript/commonjs/src/index.d.ts",
|
|
16
|
-
"default": "./lib/commonjs/index.js"
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
},
|
|
5
|
+
"main": "./src/index.tsx",
|
|
20
6
|
"files": [
|
|
21
7
|
"src",
|
|
22
8
|
"lib",
|
|
@@ -40,9 +26,7 @@
|
|
|
40
26
|
"test": "jest",
|
|
41
27
|
"typecheck": "tsc",
|
|
42
28
|
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
43
|
-
"
|
|
44
|
-
"build": "bob build",
|
|
45
|
-
"release": "release-it"
|
|
29
|
+
"build": "echo"
|
|
46
30
|
},
|
|
47
31
|
"keywords": [
|
|
48
32
|
"react-native",
|
|
@@ -62,124 +46,30 @@
|
|
|
62
46
|
"publishConfig": {
|
|
63
47
|
"registry": "https://registry.npmjs.org/"
|
|
64
48
|
},
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
|
|
71
|
-
"@types/jest": "^29.5.5",
|
|
72
|
-
"@types/react": "^18.2.44",
|
|
73
|
-
"commitlint": "^17.0.2",
|
|
74
|
-
"del-cli": "^5.1.0",
|
|
75
|
-
"eslint": "^8.51.0",
|
|
76
|
-
"eslint-config-prettier": "^9.0.0",
|
|
77
|
-
"eslint-plugin-prettier": "^5.0.1",
|
|
78
|
-
"jest": "^29.7.0",
|
|
79
|
-
"prettier": "^3.0.3",
|
|
80
|
-
"react": "18.3.1",
|
|
81
|
-
"react-native": "0.76.5",
|
|
82
|
-
"react-native-builder-bob": "^0.32.0",
|
|
83
|
-
"release-it": "^17.10.0",
|
|
84
|
-
"turbo": "^1.10.7",
|
|
85
|
-
"typescript": "^5.2.2"
|
|
86
|
-
},
|
|
87
|
-
"resolutions": {
|
|
88
|
-
"@types/react": "^18.2.44"
|
|
89
|
-
},
|
|
90
|
-
"peerDependencies": {
|
|
91
|
-
"react": "*",
|
|
92
|
-
"react-native": "*"
|
|
93
|
-
},
|
|
94
|
-
"jest": {
|
|
95
|
-
"preset": "react-native",
|
|
96
|
-
"modulePathIgnorePatterns": [
|
|
97
|
-
"<rootDir>/example/node_modules",
|
|
98
|
-
"<rootDir>/lib/"
|
|
99
|
-
]
|
|
100
|
-
},
|
|
101
|
-
"commitlint": {
|
|
102
|
-
"extends": [
|
|
103
|
-
"@commitlint/config-conventional"
|
|
104
|
-
]
|
|
105
|
-
},
|
|
106
|
-
"release-it": {
|
|
107
|
-
"git": {
|
|
108
|
-
"commitMessage": "chore: release ${version}",
|
|
109
|
-
"tagName": "v${version}"
|
|
110
|
-
},
|
|
111
|
-
"npm": {
|
|
112
|
-
"publish": true
|
|
113
|
-
},
|
|
114
|
-
"github": {
|
|
115
|
-
"release": true
|
|
49
|
+
"codegenConfig": {
|
|
50
|
+
"name": "CalculatorKeyboardSpecs",
|
|
51
|
+
"type": "components",
|
|
52
|
+
"jsSrcsDir": "src",
|
|
53
|
+
"android": {
|
|
54
|
+
"javaPackageName": "com.calculatorkeyboard"
|
|
116
55
|
},
|
|
117
|
-
"
|
|
118
|
-
"
|
|
119
|
-
"
|
|
56
|
+
"ios": {
|
|
57
|
+
"componentProvider": {
|
|
58
|
+
"NativeInputCalculator": "NativeInputCalculator"
|
|
120
59
|
}
|
|
121
60
|
}
|
|
122
61
|
},
|
|
123
|
-
"
|
|
124
|
-
"
|
|
125
|
-
"
|
|
126
|
-
"@react-native",
|
|
127
|
-
"prettier"
|
|
128
|
-
],
|
|
129
|
-
"rules": {
|
|
130
|
-
"react/react-in-jsx-scope": "off",
|
|
131
|
-
"prettier/prettier": [
|
|
132
|
-
"error",
|
|
133
|
-
{
|
|
134
|
-
"quoteProps": "consistent",
|
|
135
|
-
"singleQuote": true,
|
|
136
|
-
"tabWidth": 2,
|
|
137
|
-
"trailingComma": "es5",
|
|
138
|
-
"useTabs": false
|
|
139
|
-
}
|
|
140
|
-
]
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
"eslintIgnore": [
|
|
144
|
-
"node_modules/",
|
|
145
|
-
"lib/"
|
|
146
|
-
],
|
|
147
|
-
"prettier": {
|
|
148
|
-
"quoteProps": "consistent",
|
|
149
|
-
"singleQuote": true,
|
|
150
|
-
"tabWidth": 2,
|
|
151
|
-
"trailingComma": "es5",
|
|
152
|
-
"useTabs": false
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"react": "19.0.0",
|
|
64
|
+
"react-native": "0.80.1"
|
|
153
65
|
},
|
|
154
|
-
"
|
|
155
|
-
"
|
|
156
|
-
"
|
|
157
|
-
"
|
|
158
|
-
[
|
|
159
|
-
"commonjs",
|
|
160
|
-
{
|
|
161
|
-
"esm": true
|
|
162
|
-
}
|
|
163
|
-
],
|
|
164
|
-
[
|
|
165
|
-
"module",
|
|
166
|
-
{
|
|
167
|
-
"esm": true
|
|
168
|
-
}
|
|
169
|
-
],
|
|
170
|
-
[
|
|
171
|
-
"typescript",
|
|
172
|
-
{
|
|
173
|
-
"project": "tsconfig.build.json",
|
|
174
|
-
"esm": true
|
|
175
|
-
}
|
|
176
|
-
]
|
|
177
|
-
]
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"react": "*",
|
|
68
|
+
"react-native": "*",
|
|
69
|
+
"@momo-kits/foundation": "latest"
|
|
178
70
|
},
|
|
179
|
-
"
|
|
180
|
-
"
|
|
181
|
-
"languages": "kotlin-swift",
|
|
182
|
-
"version": "0.45.5"
|
|
71
|
+
"engines": {
|
|
72
|
+
"node": ">=18.0.0"
|
|
183
73
|
},
|
|
184
74
|
"dependencies": {}
|
|
185
75
|
}
|
|
@@ -5,7 +5,7 @@ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1
|
|
|
5
5
|
|
|
6
6
|
Pod::Spec.new do |s|
|
|
7
7
|
s.name = "react-native-calculator-keyboard"
|
|
8
|
-
s.version = "
|
|
8
|
+
s.version = package["version"]
|
|
9
9
|
s.summary = package["description"]
|
|
10
10
|
s.homepage = package["homepage"]
|
|
11
11
|
s.license = package["license"]
|
|
@@ -14,9 +14,10 @@ Pod::Spec.new do |s|
|
|
|
14
14
|
s.platforms = { :ios => min_ios_version_supported }
|
|
15
15
|
s.source = { :git => "https://github.com/wem2017/react-native-calculator-keyboard.git/react-native-calculator-keyboard.git", :tag => "#{s.version}" }
|
|
16
16
|
|
|
17
|
-
s.source_files = "ios/**/*.{h,m,mm
|
|
18
|
-
s.
|
|
19
|
-
|
|
17
|
+
s.source_files = "ios/**/*.{h,m,mm}"
|
|
18
|
+
# s.public_header_files = "ios/CalculatorKeyboardView.h"
|
|
19
|
+
# s.private_header_files = "ios/NativeInputCalculator.h"
|
|
20
|
+
|
|
20
21
|
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
21
22
|
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
|
22
23
|
if respond_to?(:install_modules_dependencies, true)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { HostComponent, ViewProps } from 'react-native';
|
|
3
|
+
import {
|
|
4
|
+
CodegenTypes,
|
|
5
|
+
codegenNativeComponent,
|
|
6
|
+
codegenNativeCommands,
|
|
7
|
+
} from 'react-native';
|
|
8
|
+
|
|
9
|
+
export type CustomKeyBackground = 'primary' | 'default' | string;
|
|
10
|
+
|
|
11
|
+
export enum CustomKeyState {
|
|
12
|
+
Default = 'default',
|
|
13
|
+
Disable = 'disable',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export enum Mode {
|
|
17
|
+
NumDefault = 'NumDefault',
|
|
18
|
+
NumWithCTA = 'NumWithCTA',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type OnKeyPressEvent = Readonly<{
|
|
22
|
+
key: string;
|
|
23
|
+
}>;
|
|
24
|
+
|
|
25
|
+
export type OnChangeEvent = Readonly<{
|
|
26
|
+
text: string;
|
|
27
|
+
}>;
|
|
28
|
+
|
|
29
|
+
export type TextAttributes = Readonly<{
|
|
30
|
+
fontSize?: CodegenTypes.Float;
|
|
31
|
+
fontWeight?: string;
|
|
32
|
+
}>;
|
|
33
|
+
|
|
34
|
+
export interface NativeInputCalculatorProps extends ViewProps {
|
|
35
|
+
value?: string;
|
|
36
|
+
textAttributes?: TextAttributes;
|
|
37
|
+
mode?: string;
|
|
38
|
+
customKeyText?: string;
|
|
39
|
+
customKeyBackground?: string;
|
|
40
|
+
customKeyTextColor?: string;
|
|
41
|
+
customKeyState?: string;
|
|
42
|
+
onChange?: CodegenTypes.BubblingEventHandler<OnChangeEvent>;
|
|
43
|
+
onKeyPress?: CodegenTypes.BubblingEventHandler<OnKeyPressEvent>;
|
|
44
|
+
onCustomKeyEvent?: CodegenTypes.DirectEventHandler<{}>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface NativeInputCalculatorCommands {
|
|
48
|
+
focus(
|
|
49
|
+
viewRef: React.ElementRef<HostComponent<NativeInputCalculatorProps>>,
|
|
50
|
+
): void;
|
|
51
|
+
blur(
|
|
52
|
+
viewRef: React.ElementRef<HostComponent<NativeInputCalculatorProps>>,
|
|
53
|
+
): void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const Commands = codegenNativeCommands<NativeInputCalculatorCommands>({
|
|
57
|
+
supportedCommands: ['focus', 'blur'],
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export default codegenNativeComponent<NativeInputCalculatorProps>(
|
|
61
|
+
'NativeInputCalculator',
|
|
62
|
+
);
|
package/src/index.tsx
CHANGED
|
@@ -1,102 +1,144 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useContext } from 'react';
|
|
3
|
+
import { ApplicationContext, Colors } from '@momo-kits/foundation';
|
|
2
4
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
UIManager,
|
|
9
|
-
findNodeHandle,
|
|
5
|
+
type NativeSyntheticEvent,
|
|
6
|
+
type TextInputProps,
|
|
7
|
+
StyleSheet,
|
|
8
|
+
StyleProp,
|
|
9
|
+
TextStyle,
|
|
10
10
|
} from 'react-native';
|
|
11
|
-
import {
|
|
11
|
+
import NativeInputCalculator, {
|
|
12
|
+
TextAttributes,
|
|
13
|
+
} from './InputCalculatorNativeComponent';
|
|
14
|
+
import { Commands } from './InputCalculatorNativeComponent';
|
|
12
15
|
|
|
13
|
-
const
|
|
14
|
-
const NativeInput = requireNativeComponent<any>(NAME);
|
|
16
|
+
const NativeInput = NativeInputCalculator;
|
|
15
17
|
|
|
16
18
|
type KeyPressEvent = { nativeEvent: { key: string } };
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
interface InputCalculatorProps extends TextInputProps {
|
|
21
|
+
text?: string | undefined;
|
|
22
|
+
mode?: Mode;
|
|
23
|
+
onKeyPress?: (e: KeyPressEvent) => void;
|
|
24
|
+
customKeyText?: string | undefined;
|
|
25
|
+
customKeyBackground?: CustomKeyBackground;
|
|
26
|
+
customKeyState?: CustomKeyState;
|
|
27
|
+
onCustomKeyEvent?: () => void;
|
|
28
|
+
style?: StyleProp<TextStyle>;
|
|
20
29
|
}
|
|
21
30
|
|
|
31
|
+
export type CustomKeyBackground = 'primary' | 'default' | string;
|
|
32
|
+
|
|
22
33
|
export enum CustomKeyState {
|
|
23
|
-
|
|
34
|
+
Default = 'default',
|
|
35
|
+
Disable = 'disable',
|
|
24
36
|
}
|
|
25
37
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
onKeyPress?: (e: KeyPressEvent) => void;
|
|
30
|
-
customKeyText?: string | undefined;
|
|
31
|
-
customKeyBackground?: CustomKeyBackground;
|
|
32
|
-
customKeyState?: CustomKeyState;
|
|
33
|
-
onCustomKeyEvent?: () => void;
|
|
38
|
+
export enum Mode {
|
|
39
|
+
NumDefault = 'NumDefault',
|
|
40
|
+
NumWithCTA = 'NumWithCTA',
|
|
34
41
|
}
|
|
35
42
|
|
|
36
43
|
export type InputCalculatorRef = {
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
focus: () => void;
|
|
45
|
+
blur: () => void;
|
|
39
46
|
};
|
|
40
47
|
|
|
41
|
-
const
|
|
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
|
-
|
|
48
|
+
const omitUndefined = <T extends object>(obj: T): T =>
|
|
49
|
+
Object.fromEntries(
|
|
50
|
+
Object.entries(obj).filter(([, v]) => v !== undefined),
|
|
51
|
+
) as T;
|
|
52
|
+
|
|
53
|
+
function isEmpty(obj: object | undefined | null) {
|
|
54
|
+
return !obj || Object.keys(obj).length === 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function styleToTextAttributes(
|
|
58
|
+
style?: StyleProp<TextStyle>,
|
|
59
|
+
): Readonly<TextAttributes> {
|
|
60
|
+
const s = StyleSheet.flatten(style) ?? {};
|
|
61
|
+
const attrs: TextAttributes = {
|
|
62
|
+
fontSize: s.fontSize ?? undefined,
|
|
63
|
+
fontWeight: (s.fontWeight as TextAttributes['fontWeight']) ?? undefined,
|
|
64
|
+
};
|
|
65
|
+
return Object.freeze(omitUndefined(attrs));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const InputCalculator = React.forwardRef<
|
|
69
|
+
InputCalculatorRef,
|
|
70
|
+
InputCalculatorProps
|
|
71
|
+
>(
|
|
72
|
+
(
|
|
73
|
+
{
|
|
74
|
+
customKeyBackground = 'default',
|
|
75
|
+
mode = Mode.NumDefault,
|
|
76
|
+
customKeyText,
|
|
77
|
+
onKeyPress,
|
|
78
|
+
customKeyState = CustomKeyState.Default,
|
|
79
|
+
onCustomKeyEvent,
|
|
80
|
+
style,
|
|
81
|
+
...props
|
|
82
|
+
},
|
|
83
|
+
ref,
|
|
84
|
+
) => {
|
|
85
|
+
const { theme } = useContext(ApplicationContext);
|
|
86
|
+
const nativeRef = React.useRef<any>(null);
|
|
87
|
+
|
|
88
|
+
const _onChange = (event: NativeSyntheticEvent<any>) => {
|
|
89
|
+
const currentText = event.nativeEvent.text;
|
|
90
|
+
props.onChange?.(event);
|
|
91
|
+
props.onChangeText?.(currentText);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const text = props.text ?? props.defaultValue ?? '';
|
|
95
|
+
let keyBackground = Colors.black_06;
|
|
96
|
+
let textKeyColor = Colors.black_20;
|
|
97
|
+
|
|
98
|
+
if (mode === Mode.NumWithCTA) {
|
|
99
|
+
if (customKeyBackground === 'primary') {
|
|
100
|
+
keyBackground = theme.colors.primary;
|
|
101
|
+
textKeyColor = Colors.black_01;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (customKeyState === CustomKeyState.Disable) {
|
|
105
|
+
keyBackground = theme.colors.background.disable;
|
|
106
|
+
textKeyColor = Colors.black_01;
|
|
107
|
+
}
|
|
99
108
|
}
|
|
109
|
+
|
|
110
|
+
React.useImperativeHandle(ref, () => ({
|
|
111
|
+
focus() {
|
|
112
|
+
if (nativeRef.current) Commands.focus(nativeRef.current);
|
|
113
|
+
},
|
|
114
|
+
blur() {
|
|
115
|
+
if (nativeRef.current) Commands.blur(nativeRef.current);
|
|
116
|
+
},
|
|
117
|
+
}));
|
|
118
|
+
|
|
119
|
+
const derivedTA = React.useMemo(
|
|
120
|
+
() => styleToTextAttributes(style),
|
|
121
|
+
[style],
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<NativeInput
|
|
126
|
+
{...props}
|
|
127
|
+
style={style}
|
|
128
|
+
textAttributes={isEmpty(derivedTA) ? undefined : derivedTA}
|
|
129
|
+
ref={nativeRef}
|
|
130
|
+
onChange={_onChange}
|
|
131
|
+
onKeyPress={onKeyPress}
|
|
132
|
+
value={text}
|
|
133
|
+
mode={mode}
|
|
134
|
+
customKeyText={customKeyText}
|
|
135
|
+
customKeyBackground={keyBackground}
|
|
136
|
+
customKeyTextColor={textKeyColor}
|
|
137
|
+
customKeyState={customKeyState}
|
|
138
|
+
onCustomKeyEvent={onCustomKeyEvent}
|
|
139
|
+
/>
|
|
140
|
+
);
|
|
141
|
+
},
|
|
100
142
|
);
|
|
101
143
|
|
|
102
144
|
export default InputCalculator;
|