@react-native-ohos/react-native-text-input-mask 3.1.6-rc.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 (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.OpenSource +11 -0
  3. package/README.md +134 -0
  4. package/dist/babel.config.d.ts +7 -0
  5. package/dist/babel.config.js +16 -0
  6. package/dist/babel.config.js.map +1 -0
  7. package/dist/index.d.ts +138 -0
  8. package/dist/index.js +92 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/src/RNNativeTextInputMask.d.ts +129 -0
  11. package/dist/src/RNNativeTextInputMask.js +8 -0
  12. package/dist/src/RNNativeTextInputMask.js.map +1 -0
  13. package/dist/src/index.d.ts +8 -0
  14. package/dist/src/index.harmony.d.ts +127 -0
  15. package/dist/src/index.harmony.js +23 -0
  16. package/dist/src/index.harmony.js.map +1 -0
  17. package/dist/src/index.js +27 -0
  18. package/dist/src/index.js.map +1 -0
  19. package/dist/tsconfig.tsbuildinfo +1 -0
  20. package/harmony/text_input_mask/BuildProfile.ets +17 -0
  21. package/harmony/text_input_mask/Index.ets +7 -0
  22. package/harmony/text_input_mask/build-profile.json5 +31 -0
  23. package/harmony/text_input_mask/consumer-rules.txt +0 -0
  24. package/harmony/text_input_mask/hvigorfile.ts +6 -0
  25. package/harmony/text_input_mask/obfuscation-rules.txt +23 -0
  26. package/harmony/text_input_mask/oh-package.json5 +11 -0
  27. package/harmony/text_input_mask/src/main/cpp/CMakeLists.txt +9 -0
  28. package/harmony/text_input_mask/src/main/cpp/RNTextInputMask.cpp +415 -0
  29. package/harmony/text_input_mask/src/main/cpp/RNTextInputMask.h +93 -0
  30. package/harmony/text_input_mask/src/main/cpp/RNTextInputMaskPackage.h +32 -0
  31. package/harmony/text_input_mask/src/main/cpp/common/Compiler.h +175 -0
  32. package/harmony/text_input_mask/src/main/cpp/common/FormatError.h +23 -0
  33. package/harmony/text_input_mask/src/main/cpp/common/FormatSanitizer.h +231 -0
  34. package/harmony/text_input_mask/src/main/cpp/common/Mask.h +378 -0
  35. package/harmony/text_input_mask/src/main/cpp/common/RTLMask.h +79 -0
  36. package/harmony/text_input_mask/src/main/cpp/common/model/AffinityCalculationStrategy.h +58 -0
  37. package/harmony/text_input_mask/src/main/cpp/common/model/CaretString.h +76 -0
  38. package/harmony/text_input_mask/src/main/cpp/common/model/CaretStringIterator.h +58 -0
  39. package/harmony/text_input_mask/src/main/cpp/common/model/Next.h +25 -0
  40. package/harmony/text_input_mask/src/main/cpp/common/model/Notation.h +25 -0
  41. package/harmony/text_input_mask/src/main/cpp/common/model/RTLCaretStringIterator.h +23 -0
  42. package/harmony/text_input_mask/src/main/cpp/common/model/State.h +302 -0
  43. package/harmony/text_input_mask/src/main/cpp/common/model/common.h +95 -0
  44. package/harmony/text_input_mask/src/main/ets/RNTextInputMaskPackage.ts +29 -0
  45. package/harmony/text_input_mask/src/main/ets/RNTextInputMaskTurboModle.ts +33 -0
  46. package/harmony/text_input_mask/src/main/module.json5 +11 -0
  47. package/harmony/text_input_mask/src/main/resources/base/element/string.json +8 -0
  48. package/harmony/text_input_mask/src/main/resources/en_US/element/string.json +8 -0
  49. package/harmony/text_input_mask/src/main/resources/zh_CN/element/string.json +8 -0
  50. package/harmony/text_input_mask/ts.ts +8 -0
  51. package/harmony/text_input_mask.har +0 -0
  52. package/index.tsx +258 -0
  53. package/package.json +50 -0
  54. package/src/RNNativeTextInputMask.ts +143 -0
  55. package/src/index.harmony.ts +147 -0
  56. package/src/index.ts +36 -0
package/index.tsx ADDED
@@ -0,0 +1,258 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ import React, {
8
+ DependencyList,
9
+ forwardRef,
10
+ useEffect,
11
+ useImperativeHandle,
12
+ useRef,
13
+ useState
14
+ } from 'react'
15
+
16
+ import { findNodeHandle, Platform, TextInput, TextInputProps } from 'react-native'
17
+ import exportMasker from './src/index'
18
+ import HarmonyTextInputMask from './src/index.harmony'
19
+ const isIosAndroid = Platform.OS === 'ios' || Platform.OS === 'android';
20
+ export const mask = exportMasker.mask
21
+ export const unmask = exportMasker.unmask
22
+ export const setMask = exportMasker.setMask
23
+ export const unmaskWithRightToLeft = HarmonyTextInputMask.unmaskWithRightToLeft
24
+ const TextInputMask = forwardRef<Handles, TextInputMaskProps>(({
25
+ mask: primaryFormat,
26
+ defaultValue,
27
+ value ,
28
+ multiline,
29
+ onChangeText,
30
+ affineFormats,
31
+ customNotations,
32
+ affinityCalculationStrategy,
33
+ autocomplete= true,
34
+ autoskip = true,
35
+ rightToLeft,
36
+ ...rest
37
+ }, ref) => {
38
+ const input = useRef<TextInput>(null)
39
+ const [ maskedValue, setMaskedValue ] = useState<string>()
40
+ const didLayout = useRef(false);
41
+ const handleLayout = () => {
42
+ didLayout.current = true;
43
+ const nodeId = findNodeHandle(input.current);
44
+ if (primaryFormat && nodeId) {
45
+ setMask(nodeId, primaryFormat, { affineFormats, affinityCalculationStrategy, customNotations, autocomplete, autoskip, rightToLeft });
46
+ }
47
+ };
48
+
49
+ useEffectAsync(async () => {
50
+ const initialValue = value ?? defaultValue
51
+ if (!initialValue) return
52
+ if (primaryFormat) {
53
+ const masked = await mask(primaryFormat, initialValue, false)
54
+ setMaskedValue(masked)
55
+ } else {
56
+ setMaskedValue(initialValue)
57
+ }
58
+ }, [])
59
+
60
+ useEffectAsync(async () => {
61
+ if (value === maskedValue) return
62
+ if (primaryFormat && value) {
63
+ const masked = await mask(primaryFormat, value, false)
64
+ setMaskedValue(masked)
65
+ } else {
66
+ setMaskedValue(value)
67
+ }
68
+ }, [value])
69
+
70
+ useEffect(() => {
71
+ if (didLayout.current) {
72
+ const nodeId = findNodeHandle(input.current)
73
+ if (primaryFormat && nodeId) {
74
+ setMask(nodeId, primaryFormat, { affineFormats, affinityCalculationStrategy, customNotations, autocomplete, autoskip, rightToLeft })
75
+ }
76
+ }
77
+ }, [primaryFormat])
78
+
79
+ useImperativeHandle(ref, () => ({
80
+ focus: () => {
81
+ input.current?.focus()
82
+ },
83
+ blur: () => {
84
+ input.current?.blur()
85
+ }
86
+ }))
87
+
88
+ return (
89
+ <TextInput
90
+ {...rest}
91
+ ref={input}
92
+ value={maskedValue}
93
+ multiline={primaryFormat && Platform.OS === 'ios' ? false : multiline}
94
+ onLayout={handleLayout}
95
+ onChangeText={async (masked) => {
96
+ setMaskedValue(masked)
97
+ if (primaryFormat) {
98
+ if (isIosAndroid) {
99
+ const unmasked = await unmask(primaryFormat, masked, true)
100
+ onChangeText?.(masked, unmasked)
101
+ } else {
102
+ const unmasked = await unmaskWithRightToLeft(primaryFormat, masked, true, rightToLeft === undefined ? false : rightToLeft)
103
+ onChangeText?.(masked, unmasked)
104
+ }
105
+ } else {
106
+ onChangeText?.(masked)
107
+ }
108
+ }}
109
+ />
110
+ )
111
+ })
112
+
113
+ export const useEffectAsync = (
114
+ operation: () => Promise<void>,
115
+ deps?: DependencyList
116
+ ) => {
117
+ useEffect(() => {
118
+ operation().then()
119
+ }, deps)
120
+ }
121
+
122
+ interface MaskOptions {
123
+ affineFormats?: string[]
124
+ customNotations?: Notation[]
125
+ affinityCalculationStrategy?: AffinityCalculationStrategy
126
+ /**
127
+ * autocomplete pattern while editing text
128
+ */
129
+ autocomplete?: boolean
130
+ /**
131
+ * automatically remove mask characters on backspace
132
+ */
133
+ autoskip?: boolean
134
+ rightToLeft?: boolean
135
+ }
136
+
137
+ type AffinityCalculationStrategy =
138
+ /**
139
+ * Default strategy.
140
+ *
141
+ * Uses ```Mask``` built-in mechanism to calculate total affinity between the text and the mask format.
142
+ *
143
+ * For example:
144
+ * ```
145
+ * format: [00].[00]
146
+ *
147
+ * input1: 1234
148
+ * input2: 12.34
149
+ * input3: 1.234
150
+ *
151
+ * affinity1 = 4 (symbols) - 1 (missed dot) = 3
152
+ * affinity2 = 5 (symbols) = 5
153
+ * affinity3 = 5 (symbols) - 1 (superfluous dot) - 1 (missed dot) = 3
154
+ * ```
155
+ */
156
+ 'WHOLE_STRING' |
157
+
158
+ /**
159
+ * Finds the longest common prefix between the original text and the same text after applying the mask.
160
+ *
161
+ * For example:
162
+ * ```
163
+ * format1: +7 [000] [000]
164
+ * format2: 8 [000] [000]
165
+ *
166
+ * input: +7 12 345
167
+ * affinity1 = 5
168
+ * affinity2 = 0
169
+ *
170
+ * input: 8 12 345
171
+ * affinity1 = 0
172
+ * affinity2 = 4
173
+ * ```
174
+ */
175
+ 'PREFIX' |
176
+
177
+ /**
178
+ * Affinity is tolerance between the length of the input and the total amount of text current mask can accommodate.
179
+ *
180
+ * If current mask can't accommodate all the text, the affinity equals `Int.min`.
181
+ *
182
+ * For example:
183
+ * ```
184
+ * format1: [00]-[0]
185
+ * format2: [00]-[000]
186
+ * format3: [00]-[00000]
187
+ *
188
+ * input affinity1 affinity2 affinity3
189
+ * 1 -3 -5 -7
190
+ * 12 -2 -4 -6
191
+ * 123 -1 -3 -5
192
+ * 12-3 0 -2 -4
193
+ * 1234 0 -2 -4
194
+ * 12345 Int.MIN_VALUE -1 -3
195
+ * 123456 Int.MIN_VALUE 0 -2
196
+ * ```
197
+ *
198
+ * This affinity calculation strategy comes in handy when the mask format radically changes depending on the input
199
+ * length.
200
+ *
201
+ * N.B.: Make sure the widest mask format is the primary mask format.
202
+ */
203
+ 'CAPACITY' |
204
+
205
+ /**
206
+ * Affinity is tolerance between the length of the extracted value and the total extracted value length current mask can accommodate.
207
+ *
208
+ * If current mask can't accommodate all the text, the affinity equals `Int.min`.
209
+ *
210
+ * For example:
211
+ * ```
212
+ * format1: [00]-[0]
213
+ * format2: [00]-[000]
214
+ * format3: [00]-[00000]
215
+ *
216
+ * input affinity1 affinity2 affinity3
217
+ * 1 -2 -4 -6
218
+ * 12 -1 -3 -5
219
+ * 123 0 -2 -4
220
+ * 12-3 0 -2 -4
221
+ * 1234 Int.MIN_VALUE -1 -3
222
+ * 12345 Int.MIN_VALUE 0 -2
223
+ * 123456 Int.MIN_VALUE Int.MIN_VALUE -1
224
+ * ```
225
+ *
226
+ * This affinity calculation strategy comes in handy when the mask format radically changes depending on the value
227
+ * length.
228
+ *
229
+ * N.B.: Make sure the widest mask format is the primary mask format.
230
+ */
231
+ 'EXTRACTED_VALUE_CAPACITY'
232
+
233
+ interface Notation {
234
+ /**
235
+ * A symbol in format string.
236
+ */
237
+ character: string,
238
+ /**
239
+ * An associated character set of acceptable input characters.
240
+ */
241
+ characterSet: string,
242
+ /**
243
+ * Is it an optional symbol or mandatory?
244
+ */
245
+ isOptional: boolean
246
+ }
247
+
248
+ export interface TextInputMaskProps extends TextInputProps, MaskOptions{
249
+ mask?: string
250
+ onChangeText?: (formatted: string, extracted?: string) => void
251
+ }
252
+
253
+ interface Handles {
254
+ focus: () => void
255
+ blur: () => void
256
+ }
257
+
258
+ export default TextInputMask
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@react-native-ohos/react-native-text-input-mask",
3
+ "version": "3.1.6-rc.1",
4
+ "description": "Text input mask for React Native.",
5
+ "main": "dist/index.js",
6
+ "typings": "dist/index.d.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/react-native-community/react-native-text-input-mask"
10
+ },
11
+ "keywords": [
12
+ "react",
13
+ "native",
14
+ "mask",
15
+ "text input",
16
+ "android",
17
+ "ios",
18
+ "harmony"
19
+ ],
20
+ "harmony": {
21
+ "alias":"react-native-text-input-mask"
22
+ },
23
+ "scripts": {
24
+ "prepublish": "npx tsc"
25
+ },
26
+ "dependencies": {
27
+ "react-native-text-input-mask": "^3.2.0"
28
+ },
29
+ "devDependencies": {
30
+ "@react-native-community/eslint-config": "3.2.0",
31
+ "@types/react": "^18.2.12",
32
+ "react-native": "^0.71.10",
33
+ "tslib": "^2.5.3",
34
+ "typescript": "^5.1.3"
35
+ },
36
+ "files": [
37
+ "src",
38
+ "harmony",
39
+ "dist",
40
+ "index.tsx"
41
+ ],
42
+ "peerDependencies": {
43
+ "react-native": ">=0.69.0"
44
+ },
45
+ "author": "Martin Treurnicht",
46
+ "bugs": {
47
+ "url": "https://github.com/react-native-community/react-native-text-input-mask/issues"
48
+ },
49
+ "homepage": "https://github.com/react-native-community/react-native-text-input-mask"
50
+ }
@@ -0,0 +1,143 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ import type { TurboModule } from "react-native/Libraries/TurboModule/RCTExport";
8
+ import { TurboModuleRegistry} from "react-native";
9
+
10
+ export interface MaskOptions {
11
+ affineFormats?: string[]
12
+ customNotations?: Notation[]
13
+ affinityCalculationStrategy?: AffinityCalculationStrategy
14
+ /**
15
+ * autocomplete pattern while editing text
16
+ */
17
+ autocomplete?: boolean
18
+ /**
19
+ * automatically remove mask characters on backspace
20
+ */
21
+ autoskip?: boolean
22
+ rightToLeft?: boolean
23
+ }
24
+
25
+ export type AffinityCalculationStrategy =
26
+ /**
27
+ * Default strategy.
28
+ *
29
+ * Uses ```Mask``` built-in mechanism to calculate total affinity between the text and the mask format.
30
+ *
31
+ * For example:
32
+ * ```
33
+ * format: [00].[00]
34
+ *
35
+ * input1: 1234
36
+ * input2: 12.34
37
+ * input3: 1.234
38
+ *
39
+ * affinity1 = 4 (symbols) - 1 (missed dot) = 3
40
+ * affinity2 = 5 (symbols) = 5
41
+ * affinity3 = 5 (symbols) - 1 (superfluous dot) - 1 (missed dot) = 3
42
+ * ```
43
+ */
44
+ 'WHOLE_STRING' |
45
+
46
+ /**
47
+ * Finds the longest common prefix between the original text and the same text after applying the mask.
48
+ *
49
+ * For example:
50
+ * ```
51
+ * format1: +7 [000] [000]
52
+ * format2: 8 [000] [000]
53
+ *
54
+ * input: +7 12 345
55
+ * affinity1 = 5
56
+ * affinity2 = 0
57
+ *
58
+ * input: 8 12 345
59
+ * affinity1 = 0
60
+ * affinity2 = 4
61
+ * ```
62
+ */
63
+ 'PREFIX' |
64
+
65
+ /**
66
+ * Affinity is tolerance between the length of the input and the total amount of text current mask can accommodate.
67
+ *
68
+ * If current mask can't accommodate all the text, the affinity equals `Int.min`.
69
+ *
70
+ * For example:
71
+ * ```
72
+ * format1: [00]-[0]
73
+ * format2: [00]-[000]
74
+ * format3: [00]-[00000]
75
+ *
76
+ * input affinity1 affinity2 affinity3
77
+ * 1 -3 -5 -7
78
+ * 12 -2 -4 -6
79
+ * 123 -1 -3 -5
80
+ * 12-3 0 -2 -4
81
+ * 1234 0 -2 -4
82
+ * 12345 Int.MIN_VALUE -1 -3
83
+ * 123456 Int.MIN_VALUE 0 -2
84
+ * ```
85
+ *
86
+ * This affinity calculation strategy comes in handy when the mask format radically changes depending on the input
87
+ * length.
88
+ *
89
+ * N.B.: Make sure the widest mask format is the primary mask format.
90
+ */
91
+ 'CAPACITY' |
92
+
93
+ /**
94
+ * Affinity is tolerance between the length of the extracted value and the total extracted value length current mask can accommodate.
95
+ *
96
+ * If current mask can't accommodate all the text, the affinity equals `Int.min`.
97
+ *
98
+ * For example:
99
+ * ```
100
+ * format1: [00]-[0]
101
+ * format2: [00]-[000]
102
+ * format3: [00]-[00000]
103
+ *
104
+ * input affinity1 affinity2 affinity3
105
+ * 1 -2 -4 -6
106
+ * 12 -1 -3 -5
107
+ * 123 0 -2 -4
108
+ * 12-3 0 -2 -4
109
+ * 1234 Int.MIN_VALUE -1 -3
110
+ * 12345 Int.MIN_VALUE 0 -2
111
+ * 123456 Int.MIN_VALUE Int.MIN_VALUE -1
112
+ * ```
113
+ *
114
+ * This affinity calculation strategy comes in handy when the mask format radically changes depending on the value
115
+ * length.
116
+ *
117
+ * N.B.: Make sure the widest mask format is the primary mask format.
118
+ */
119
+ 'EXTRACTED_VALUE_CAPACITY'
120
+
121
+ interface Notation {
122
+ /**
123
+ * A symbol in format string.
124
+ */
125
+ character: string,
126
+ /**
127
+ * An associated character set of acceptable input characters.
128
+ */
129
+ characterSet: string,
130
+ /**
131
+ * Is it an optional symbol or mandatory?
132
+ */
133
+ isOptional: boolean
134
+ }
135
+
136
+ export interface Spec extends TurboModule {
137
+ mask (mask: string, value: string, autocomplete: boolean) :Promise<string>,
138
+ unmask (mask: string, value: string, autocomplete: boolean): Promise<string>,
139
+ setMask (reactNode: number, primaryFormat: string, options?: MaskOptions): void;
140
+ unmaskWithRightToLeft (mask: string, value: string, autocomplete: boolean, rightToLeft: boolean): Promise<string>;
141
+ }
142
+
143
+ export default TurboModuleRegistry.get<Spec>('RNTextInputMask') as Spec ;
@@ -0,0 +1,147 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ import RNNativeTextInputMask from './RNNativeTextInputMask';
8
+ export interface MaskOptions {
9
+ affineFormats?: string[];
10
+ customNotations?: Notation[];
11
+ affinityCalculationStrategy?: AffinityCalculationStrategy;
12
+ /**
13
+ * autocomplete pattern while editing text
14
+ */
15
+ autocomplete?: boolean;
16
+ /**
17
+ * automatically remove mask characters on backspace
18
+ */
19
+ autoskip?: boolean;
20
+ rightToLeft?: boolean;
21
+ }
22
+
23
+ type AffinityCalculationStrategy =
24
+ /**
25
+ * Default strategy.
26
+ *
27
+ * Uses ```Mask``` built-in mechanism to calculate total affinity between the text and the mask format.
28
+ *
29
+ * For example:
30
+ * ```
31
+ * format: [00].[00]
32
+ *
33
+ * input1: 1234
34
+ * input2: 12.34
35
+ * input3: 1.234
36
+ *
37
+ * affinity1 = 4 (symbols) - 1 (missed dot) = 3
38
+ * affinity2 = 5 (symbols) = 5
39
+ * affinity3 = 5 (symbols) - 1 (superfluous dot) - 1 (missed dot) = 3
40
+ * ```
41
+ */
42
+ 'WHOLE_STRING' |
43
+ /**
44
+ * Finds the longest common prefix between the original text and the same text after applying the mask.
45
+ *
46
+ * For example:
47
+ * ```
48
+ * format1: +7 [000] [000]
49
+ * format2: 8 [000] [000]
50
+ *
51
+ * input: +7 12 345
52
+ * affinity1 = 5
53
+ * affinity2 = 0
54
+ *
55
+ * input: 8 12 345
56
+ * affinity1 = 0
57
+ * affinity2 = 4
58
+ * ```
59
+ */
60
+ 'PREFIX' |
61
+ /**
62
+ * Affinity is tolerance between the length of the input and the total amount of text current mask can accommodate.
63
+ *
64
+ * If current mask can't accommodate all the text, the affinity equals `Int.min`.
65
+ *
66
+ * For example:
67
+ * ```
68
+ * format1: [00]-[0]
69
+ * format2: [00]-[000]
70
+ * format3: [00]-[00000]
71
+ *
72
+ * input affinity1 affinity2 affinity3
73
+ * 1 -3 -5 -7
74
+ * 12 -2 -4 -6
75
+ * 123 -1 -3 -5
76
+ * 12-3 0 -2 -4
77
+ * 1234 0 -2 -4
78
+ * 12345 Int.MIN_VALUE -1 -3
79
+ * 123456 Int.MIN_VALUE 0 -2
80
+ * ```
81
+ *
82
+ * This affinity calculation strategy comes in handy when the mask format radically changes depending on the input
83
+ * length.
84
+ *
85
+ * N.B.: Make sure the widest mask format is the primary mask format.
86
+ */
87
+ 'CAPACITY' |
88
+ /**
89
+ * Affinity is tolerance between the length of the extracted value and the total extracted value length current mask can accommodate.
90
+ *
91
+ * If current mask can't accommodate all the text, the affinity equals `Int.min`.
92
+ *
93
+ * For example:
94
+ * ```
95
+ * format1: [00]-[0]
96
+ * format2: [00]-[000]
97
+ * format3: [00]-[00000]
98
+ *
99
+ * input affinity1 affinity2 affinity3
100
+ * 1 -2 -4 -6
101
+ * 12 -1 -3 -5
102
+ * 123 0 -2 -4
103
+ * 12-3 0 -2 -4
104
+ * 1234 Int.MIN_VALUE -1 -3
105
+ * 12345 Int.MIN_VALUE 0 -2
106
+ * 123456 Int.MIN_VALUE Int.MIN_VALUE -1
107
+ * ```
108
+ *
109
+ * This affinity calculation strategy comes in handy when the mask format radically changes depending on the value
110
+ * length.
111
+ *
112
+ * N.B.: Make sure the widest mask format is the primary mask format.
113
+ */
114
+ 'EXTRACTED_VALUE_CAPACITY';
115
+ interface Notation {
116
+ /**
117
+ * A symbol in format string.
118
+ */
119
+ character: string;
120
+ /**
121
+ * An associated character set of acceptable input characters.
122
+ */
123
+ characterSet: string;
124
+ /**
125
+ * Is it an optional symbol or mandatory?
126
+ */
127
+ isOptional: boolean;
128
+ }
129
+
130
+
131
+ class HarmonyTextInputMask {
132
+ static mask(mask: string, value: string, autocomplete: boolean): Promise<string> {
133
+ return RNNativeTextInputMask.mask(mask, value, autocomplete);
134
+ }
135
+
136
+ static unmask(mask: string, value: string, autocomplete: boolean): Promise<string> {
137
+ return RNNativeTextInputMask.unmask(mask, value, autocomplete);
138
+ }
139
+ static setMask(reactNode: number, primaryFormat: string, options?: MaskOptions): void {
140
+ RNNativeTextInputMask.setMask(reactNode, primaryFormat, options)
141
+ }
142
+ static unmaskWithRightToLeft(mask: string, value: string, autocomplete: boolean, rightToLeft: boolean): Promise<string> {
143
+ return RNNativeTextInputMask.unmaskWithRightToLeft(mask, value, autocomplete, rightToLeft);
144
+ }
145
+ }
146
+ console.log("======HarmonyTextInputMask=",HarmonyTextInputMask)
147
+ export default HarmonyTextInputMask;
package/src/index.ts ADDED
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ import HarmonyTextInputMask ,{MaskOptions}from './index.harmony'
8
+ import {mask as maskA, unmask as unmaskA, setMask as setMaskA } from 'react-native-text-input-mask';
9
+ import { Platform } from 'react-native';
10
+
11
+ interface MaskOperations {
12
+ mask(mask: string, value: string, autocomplete: boolean): Promise<string> ;
13
+ unmask(mask: string, value: string, autocomplete: boolean): Promise<string>
14
+ setMask(reactNode: number, primaryFormat: string, options?: MaskOptions): void
15
+ }
16
+ const isIosAndroid = Platform.OS === 'ios' || Platform.OS === 'android';
17
+
18
+
19
+ class RNTextInputMask {
20
+ constructor(){}
21
+ static mask(mask: string, value: string, autocomplete: boolean): Promise<string> {
22
+ return maskA(mask, value, autocomplete);
23
+ }
24
+
25
+ static unmask(mask: string, value: string, autocomplete: boolean): Promise<string> {
26
+ return unmaskA(mask, value, autocomplete);
27
+ }
28
+ static setMask(reactNode: number, primaryFormat: string, options?: MaskOptions): void {
29
+ setMaskA(reactNode, primaryFormat, options)
30
+ }
31
+ }
32
+ console.log("======isIosAndroid=",isIosAndroid)
33
+ console.log("======RNTextInputMask=",RNTextInputMask)
34
+ export const exportMasker:MaskOperations= isIosAndroid ? RNTextInputMask : HarmonyTextInputMask
35
+ console.log("======exportMasker=",exportMasker)
36
+ export default exportMasker;