@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.
Files changed (30) hide show
  1. package/README.md +45 -3
  2. package/android/src/main/java/com/calculatorkeyboard/CalculatorKeyboardPackage.kt +1 -1
  3. package/android/src/main/java/com/calculatorkeyboard/CustomKeyboardView.kt +184 -95
  4. package/android/src/main/java/com/calculatorkeyboard/Event.kt +36 -0
  5. package/android/src/main/java/com/calculatorkeyboard/InputCalculatorViewManager.kt +270 -0
  6. package/android/src/main/java/com/calculatorkeyboard/KeyboardOverplayHost.kt +232 -0
  7. package/ios/CalculatorKeyboardView.h +30 -0
  8. package/ios/CalculatorKeyboardView.mm +231 -0
  9. package/ios/NativeInputCalculator.h +11 -0
  10. package/ios/NativeInputCalculator.mm +369 -0
  11. package/package.json +21 -131
  12. package/react-native-calculator-keyboard.podspec +5 -4
  13. package/src/InputCalculatorNativeComponent.ts +62 -0
  14. package/src/index.tsx +124 -82
  15. package/android/src/main/java/com/calculatorkeyboard/RCTInputCalculator.kt +0 -339
  16. package/ios/CalculatorKeyboardView.swift +0 -165
  17. package/ios/InputCalculator-Bridging-Header.h +0 -23
  18. package/ios/InputCalculator.m +0 -85
  19. package/ios/InputCalculator.swift +0 -158
  20. package/ios/extension.swift +0 -23
  21. package/lib/commonjs/index.js +0 -72
  22. package/lib/commonjs/index.js.map +0 -1
  23. package/lib/module/index.js +0 -68
  24. package/lib/module/index.js.map +0 -1
  25. package/lib/typescript/commonjs/package.json +0 -1
  26. package/lib/typescript/commonjs/src/index.d.ts +0 -31
  27. package/lib/typescript/commonjs/src/index.d.ts.map +0 -1
  28. package/lib/typescript/module/package.json +0 -1
  29. package/lib/typescript/module/src/index.d.ts +0 -31
  30. 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.150.2-phuc.13",
3
+ "version": "0.151.1-beta.1",
4
4
  "description": "react native calculator keyboard",
5
- "source": "./src/index.tsx",
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
- "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
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
- "devDependencies": {
66
- "@commitlint/config-conventional": "^17.0.2",
67
- "@evilmartians/lefthook": "^1.5.0",
68
- "@react-native-community/cli": "15.0.1",
69
- "@react-native/eslint-config": "^0.73.1",
70
- "@release-it/conventional-changelog": "^9.0.2",
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
- "plugins": {
118
- "@release-it/conventional-changelog": {
119
- "preset": "angular"
56
+ "ios": {
57
+ "componentProvider": {
58
+ "NativeInputCalculator": "NativeInputCalculator"
120
59
  }
121
60
  }
122
61
  },
123
- "eslintConfig": {
124
- "root": true,
125
- "extends": [
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
- "react-native-builder-bob": {
155
- "source": "src",
156
- "output": "lib",
157
- "targets": [
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
- "create-react-native-library": {
180
- "type": "legacy-view",
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 = "0.0.1"
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,swift}"
18
- s.resources = "**/Assets/**/*.{json}"
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
- type NativeSyntheticEvent,
4
- type TextInputChangeEventData,
5
- type TextInputProps,
6
- type ColorValue,
7
- processColor,
8
- UIManager,
9
- findNodeHandle,
5
+ type NativeSyntheticEvent,
6
+ type TextInputProps,
7
+ StyleSheet,
8
+ StyleProp,
9
+ TextStyle,
10
10
  } from 'react-native';
11
- import { requireNativeComponent } from 'react-native';
11
+ import NativeInputCalculator, {
12
+ TextAttributes,
13
+ } from './InputCalculatorNativeComponent';
14
+ import { Commands } from './InputCalculatorNativeComponent';
12
15
 
13
- const NAME = 'RCTInputCalculator';
14
- const NativeInput = requireNativeComponent<any>(NAME);
16
+ const NativeInput = NativeInputCalculator;
15
17
 
16
18
  type KeyPressEvent = { nativeEvent: { key: string } };
17
19
 
18
- export enum CustomKeyBackground {
19
- Default = 0, Primary = 1
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
- Default = 0, Disable = 1
34
+ Default = 'default',
35
+ Disable = 'disable',
24
36
  }
25
37
 
26
- interface InputCalculatorProps extends TextInputProps {
27
- text?: string | undefined;
28
- keyboardColor?: ColorValue;
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
- focus: () => void;
38
- blur: () => void;
44
+ focus: () => void;
45
+ blur: () => void;
39
46
  };
40
47
 
41
- const InputCalculator = React.forwardRef<InputCalculatorRef, InputCalculatorProps>(
42
- (props, ref) => {
43
- const nativeRef = React.useRef<any>(null);
44
-
45
- const _onChange = (
46
- event: NativeSyntheticEvent<TextInputChangeEventData>
47
- ) => {
48
- const currentText = event.nativeEvent.text;
49
- props.onChange && props.onChange(event);
50
- props.onChangeText && props.onChangeText(currentText);
51
- };
52
-
53
- const _onKeyPress = React.useCallback((e: any) => {
54
- props.onKeyPress?.(e as KeyPressEvent);
55
- }, [props.onKeyPress]);
56
-
57
- const _onCustomKeyEvent = React.useCallback(() => {
58
- props.onCustomKeyEvent?.();
59
- }, [props.onCustomKeyEvent]);
60
-
61
- const text = props.text ?? props.defaultValue ?? '';
62
- const customKeyBackground = props.customKeyBackground == 0 ? "#D8D8D8" : "#EB2F96"
63
- const customKeyTextColor = props.customKeyBackground == 0 ? "#FFFFFF" : "#000000"
64
-
65
- React.useImperativeHandle(ref, () => ({
66
- focus() {
67
- const node = findNodeHandle(nativeRef.current);
68
- if (!node) return;
69
- const config = UIManager.getViewManagerConfig(NAME);
70
- if (config?.Commands?.focus != null) {
71
- UIManager.dispatchViewManagerCommand(node, config.Commands.focus, []);
72
- }
73
- },
74
- blur() {
75
- const node = findNodeHandle(nativeRef.current);
76
- if (!node) return;
77
- const config = UIManager.getViewManagerConfig(NAME);
78
- if (config?.Commands?.blur != null) {
79
- UIManager.dispatchViewManagerCommand(node, config.Commands.blur, []);
80
- }
81
- },
82
- }));
83
-
84
- return (
85
- <NativeInput
86
- {...props}
87
- ref={nativeRef}
88
- onChange={_onChange}
89
- onKeyPress={_onKeyPress}
90
- value={text}
91
- keybardColor={processColor(props.keyboardColor)}
92
- customKeyText={props.customKeyText}
93
- customKeyBackground={customKeyBackground}
94
- customKeyTextColor={customKeyTextColor}
95
- customKeyState={props.customKeyState}
96
- onCustomKeyEvent={_onCustomKeyEvent}
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;