@react-native-ohos/react-native-text-input-mask 3.1.6-rc.4 → 3.1.6-rc.6
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/.eslintrc +16 -0
- package/.gitattributes +1 -0
- package/.mtslconfig.json +1 -0
- package/OAT.xml +79 -0
- package/README.md +6 -8
- package/dist/index.d.ts +0 -2
- package/dist/index.js +6 -25
- package/dist/index.js.map +1 -1
- package/dist/src/RNNativeTextInputMask.d.ts +0 -1
- package/dist/src/RNNativeTextInputMask.js.map +1 -1
- package/dist/src/index.harmony.d.ts +0 -1
- package/dist/src/index.harmony.js +0 -3
- package/dist/src/index.harmony.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/harmony/text_input_mask/Index.ets +3 -1
- package/harmony/text_input_mask/oh-package.json5 +2 -2
- package/harmony/text_input_mask/src/main/cpp/RNTextInputMask.cpp +73 -96
- package/harmony/text_input_mask/src/main/cpp/RNTextInputMask.h +11 -9
- package/harmony/text_input_mask/src/main/cpp/RNTextInputMaskPackage.h +4 -2
- package/harmony/text_input_mask/src/main/cpp/common/Compiler.h +84 -81
- package/harmony/text_input_mask/src/main/cpp/common/FormatError.h +5 -5
- package/harmony/text_input_mask/src/main/cpp/common/FormatSanitizer.h +26 -28
- package/harmony/text_input_mask/src/main/cpp/common/Mask.h +48 -45
- package/harmony/text_input_mask/src/main/cpp/common/RTLMask.h +18 -20
- package/harmony/text_input_mask/src/main/cpp/common/model/AffinityCalculationStrategy.h +23 -19
- package/harmony/text_input_mask/src/main/cpp/common/model/CaretString.h +11 -13
- package/harmony/text_input_mask/src/main/cpp/common/model/CaretStringIterator.h +9 -10
- package/harmony/text_input_mask/src/main/cpp/common/model/Next.h +8 -8
- package/harmony/text_input_mask/src/main/cpp/common/model/Notation.h +11 -11
- package/harmony/text_input_mask/src/main/cpp/common/model/RTLCaretStringIterator.h +2 -2
- package/harmony/text_input_mask/src/main/cpp/common/model/State.h +43 -32
- package/harmony/text_input_mask/src/main/cpp/common/model/common.h +19 -11
- package/harmony/text_input_mask/src/main/ets/{RNTextInputMaskPackage.ts → RNTextInputMaskPackage.ets} +2 -1
- package/harmony/text_input_mask/src/main/ets/RNTextInputMaskTurboModle.ts +0 -4
- package/harmony/text_input_mask/src/ohosTest/ets/test/Ability.test.ets +41 -0
- package/harmony/text_input_mask/src/ohosTest/ets/test/List.test.ets +11 -0
- package/harmony/text_input_mask/src/ohosTest/module.json5 +13 -0
- package/harmony/text_input_mask/src/test/List.test.ets +11 -0
- package/harmony/text_input_mask/src/test/LocalUnit.test.ets +39 -0
- package/harmony/text_input_mask.har +0 -0
- package/index.tsx +5 -24
- package/package.json +17 -11
- package/src/RNNativeTextInputMask.ts +0 -1
- package/src/index.harmony.ts +0 -3
- package/tsconfig.json +43 -0
- package/README.OpenSource +0 -11
- package/dist/babel.config.d.ts +0 -7
- package/dist/babel.config.js +0 -16
- package/dist/babel.config.js.map +0 -1
- package/harmony/text_input_mask/BuildProfile.ets +0 -17
- /package/harmony/text_input_mask/{ts.ts → ts.ets} +0 -0
|
@@ -3,24 +3,19 @@
|
|
|
3
3
|
* Use of this source code is governed by a MIT license that can be
|
|
4
4
|
* found in the LICENSE file.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
#ifndef STATE_H
|
|
7
|
+
#define STATE_H
|
|
7
8
|
#pragma once
|
|
8
9
|
#include <memory>
|
|
9
10
|
#include <iostream>
|
|
10
11
|
|
|
11
12
|
namespace TinpMask {
|
|
12
|
-
|
|
13
|
-
|
|
14
13
|
class Next;
|
|
15
14
|
class State {
|
|
16
15
|
public:
|
|
17
16
|
std::shared_ptr<State> child; // 指向下一个状态的智能指针
|
|
18
|
-
|
|
19
17
|
public:
|
|
20
|
-
// 构造函数
|
|
21
18
|
explicit State(std::shared_ptr<State> child = nullptr) : child(child) {}
|
|
22
|
-
|
|
23
|
-
// 虚析构函数,以确保派生类的析构函数被正确调用
|
|
24
19
|
virtual ~State() = default;
|
|
25
20
|
|
|
26
21
|
/**
|
|
@@ -44,7 +39,8 @@ public:
|
|
|
44
39
|
* @returns Next object instance with a set of actions to complete user input. If no
|
|
45
40
|
* autocomplete available, returns nullptr.
|
|
46
41
|
*/
|
|
47
|
-
virtual std::shared_ptr<Next> autocomplete()
|
|
42
|
+
virtual std::shared_ptr<Next> autocomplete()
|
|
43
|
+
{
|
|
48
44
|
return nullptr; // 默认返回 nullptr
|
|
49
45
|
}
|
|
50
46
|
|
|
@@ -56,7 +52,8 @@ public:
|
|
|
56
52
|
*
|
|
57
53
|
* @returns State object.
|
|
58
54
|
*/
|
|
59
|
-
virtual std::shared_ptr<State> nextState()
|
|
55
|
+
virtual std::shared_ptr<State> nextState()
|
|
56
|
+
{
|
|
60
57
|
return child; // 返回下一个状态
|
|
61
58
|
}
|
|
62
59
|
|
|
@@ -67,13 +64,15 @@ public:
|
|
|
67
64
|
// EOLState 类的实现
|
|
68
65
|
class EOLState : public State {
|
|
69
66
|
public:
|
|
70
|
-
EOLState(std::shared_ptr<State> child = nullptr) : State(child) {}
|
|
67
|
+
explicit EOLState(std::shared_ptr<State> child = nullptr) : State(child) {}
|
|
71
68
|
|
|
72
|
-
std::shared_ptr<Next> accept(char character) override
|
|
69
|
+
std::shared_ptr<Next> accept(char character) override
|
|
70
|
+
{
|
|
73
71
|
return nullptr; // 该状态不接受字符
|
|
74
72
|
}
|
|
75
73
|
|
|
76
|
-
std::string toString() const override
|
|
74
|
+
std::string toString() const override
|
|
75
|
+
{
|
|
77
76
|
return "EOL"; // 返回字符串表示
|
|
78
77
|
}
|
|
79
78
|
};
|
|
@@ -83,11 +82,11 @@ public:
|
|
|
83
82
|
class FixedState : public State {
|
|
84
83
|
public:
|
|
85
84
|
char ownCharacter;
|
|
86
|
-
|
|
87
85
|
public:
|
|
88
86
|
FixedState(std::shared_ptr<State> child, char ownCharacter) : State(child), ownCharacter(ownCharacter) {}
|
|
89
87
|
|
|
90
|
-
std::shared_ptr<Next> accept(char character) override
|
|
88
|
+
std::shared_ptr<Next> accept(char character) override
|
|
89
|
+
{
|
|
91
90
|
if (this->ownCharacter == character) {
|
|
92
91
|
return std::make_shared<Next>(this->nextState(), character, true, character);
|
|
93
92
|
} else {
|
|
@@ -95,16 +94,16 @@ public:
|
|
|
95
94
|
}
|
|
96
95
|
}
|
|
97
96
|
|
|
98
|
-
std::shared_ptr<Next> autocomplete() override
|
|
97
|
+
std::shared_ptr<Next> autocomplete() override
|
|
98
|
+
{
|
|
99
99
|
return std::make_shared<Next>(this->nextState(), this->ownCharacter, false, this->ownCharacter);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
std::string toString() const override
|
|
102
|
+
std::string toString() const override
|
|
103
|
+
{
|
|
103
104
|
return "{" + std::string(1, this->ownCharacter) + "} -> " + (child ? child->toString() : "null");
|
|
104
105
|
}
|
|
105
106
|
};
|
|
106
|
-
|
|
107
|
-
// FreeState 类的实现
|
|
108
107
|
class FreeState : public State {
|
|
109
108
|
public:
|
|
110
109
|
char ownCharacter;
|
|
@@ -112,7 +111,8 @@ public:
|
|
|
112
111
|
public:
|
|
113
112
|
FreeState(std::shared_ptr<State> child, char ownCharacter) : State(child), ownCharacter(ownCharacter) {}
|
|
114
113
|
|
|
115
|
-
std::shared_ptr<Next> accept(char character) override
|
|
114
|
+
std::shared_ptr<Next> accept(char character) override
|
|
115
|
+
{
|
|
116
116
|
if (this->ownCharacter == character) {
|
|
117
117
|
return std::make_shared<Next>(this->nextState(), character, true, '\0');
|
|
118
118
|
} else {
|
|
@@ -120,11 +120,13 @@ public:
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
std::shared_ptr<Next> autocomplete() override
|
|
123
|
+
std::shared_ptr<Next> autocomplete() override
|
|
124
|
+
{
|
|
124
125
|
return std::make_shared<Next>(this->nextState(), this->ownCharacter, false, '\0');
|
|
125
126
|
}
|
|
126
127
|
|
|
127
|
-
std::string toString() const override
|
|
128
|
+
std::string toString() const override
|
|
129
|
+
{
|
|
128
130
|
return std::string(1, this->ownCharacter) + " -> " + (child ? child->toString() : "null");
|
|
129
131
|
}
|
|
130
132
|
};
|
|
@@ -160,7 +162,8 @@ public:
|
|
|
160
162
|
public:
|
|
161
163
|
std::shared_ptr<OptionalValueStateType> type;
|
|
162
164
|
|
|
163
|
-
bool accepts(char character)
|
|
165
|
+
bool accepts(char character)
|
|
166
|
+
{
|
|
164
167
|
if (dynamic_cast<Numeric *>(type.get())) {
|
|
165
168
|
return std::isdigit(character);
|
|
166
169
|
} else if (dynamic_cast<Literal *>(type.get())) {
|
|
@@ -179,7 +182,8 @@ public:
|
|
|
179
182
|
OptionalValueState(std::shared_ptr<State> child, std::shared_ptr<OptionalValueStateType> &type)
|
|
180
183
|
: State(child), type(type) {}
|
|
181
184
|
|
|
182
|
-
std::shared_ptr<Next> accept(char character) override
|
|
185
|
+
std::shared_ptr<Next> accept(char character) override
|
|
186
|
+
{
|
|
183
187
|
if (this->accepts(character)) {
|
|
184
188
|
return std::make_shared<Next>(this->nextState(), character, true, character);
|
|
185
189
|
} else {
|
|
@@ -187,7 +191,8 @@ public:
|
|
|
187
191
|
}
|
|
188
192
|
}
|
|
189
193
|
|
|
190
|
-
std::string toString() const override
|
|
194
|
+
std::string toString() const override
|
|
195
|
+
{
|
|
191
196
|
if (dynamic_cast<Literal *>(type.get())) {
|
|
192
197
|
return "[a] -> " + (child ? child->toString() : "null");
|
|
193
198
|
} else if (dynamic_cast<Numeric *>(type.get())) {
|
|
@@ -228,17 +233,18 @@ public:
|
|
|
228
233
|
StateTypeName getName() override { return StateTypeName::Custom; }
|
|
229
234
|
};
|
|
230
235
|
class Custom : public ValueStateType {
|
|
231
|
-
|
|
232
236
|
public:
|
|
233
237
|
char character;
|
|
234
238
|
std::string characterSet;
|
|
235
|
-
Custom(char character,
|
|
239
|
+
Custom(char character,
|
|
240
|
+
const std::string &characterSet) : character(character), characterSet(characterSet) {}
|
|
236
241
|
StateTypeName getName() override { return StateTypeName::Custom; }
|
|
237
242
|
};
|
|
238
243
|
|
|
239
244
|
public:
|
|
240
245
|
std::shared_ptr<ValueStateType> type;
|
|
241
|
-
bool accepts(char character)
|
|
246
|
+
bool accepts(char character)
|
|
247
|
+
{
|
|
242
248
|
if (dynamic_cast<Numeric *>(type.get())) {
|
|
243
249
|
return std::isdigit(character);
|
|
244
250
|
} else if (dynamic_cast<Literal *>(type.get())) {
|
|
@@ -253,7 +259,8 @@ public:
|
|
|
253
259
|
return false;
|
|
254
260
|
}
|
|
255
261
|
|
|
256
|
-
bool acceptsWithInheritedType(std::shared_ptr<ValueStateType> inheritedType, char character)
|
|
262
|
+
bool acceptsWithInheritedType(std::shared_ptr<ValueStateType> inheritedType, char character)
|
|
263
|
+
{
|
|
257
264
|
if (dynamic_cast<Numeric *>(inheritedType.get())) {
|
|
258
265
|
return std::isdigit(character);
|
|
259
266
|
} else if (dynamic_cast<Literal *>(inheritedType.get())) {
|
|
@@ -268,14 +275,16 @@ public:
|
|
|
268
275
|
|
|
269
276
|
public:
|
|
270
277
|
// 构造函数用于创建 Ellipsis 类型的 ValueState
|
|
271
|
-
ValueState(std::shared_ptr<ValueStateType> inheritedType)
|
|
278
|
+
explicit ValueState(std::shared_ptr<ValueStateType> inheritedType)
|
|
272
279
|
: State(nullptr), type(std::make_shared<Ellipsis>(inheritedType)) {}
|
|
273
280
|
|
|
274
281
|
ValueState(std::shared_ptr<State> child, std::shared_ptr<ValueStateType> type) : State(child), type(type) {}
|
|
275
282
|
|
|
276
|
-
std::shared_ptr<Next> accept(char character) override
|
|
277
|
-
|
|
283
|
+
std::shared_ptr<Next> accept(char character) override
|
|
284
|
+
{
|
|
285
|
+
if (!accepts(character)) {
|
|
278
286
|
return nullptr;
|
|
287
|
+
}
|
|
279
288
|
return std::make_shared<Next>(nextState(), character, true, character);
|
|
280
289
|
}
|
|
281
290
|
|
|
@@ -283,7 +292,8 @@ public:
|
|
|
283
292
|
|
|
284
293
|
std::shared_ptr<State> nextState() override { return isElliptical() ? shared_from_this() : State::nextState(); }
|
|
285
294
|
|
|
286
|
-
std::string toString() const override
|
|
295
|
+
std::string toString() const override
|
|
296
|
+
{
|
|
287
297
|
if (dynamic_cast<Literal *>(type.get())) {
|
|
288
298
|
return "[A] -> " + (child ? child->toString() : "null");
|
|
289
299
|
} else if (dynamic_cast<Numeric *>(type.get())) {
|
|
@@ -300,3 +310,4 @@ public:
|
|
|
300
310
|
};
|
|
301
311
|
|
|
302
312
|
}
|
|
313
|
+
#endif
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* Use of this source code is governed by a MIT license that can be
|
|
4
4
|
* found in the LICENSE file.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
#ifndef COMMON_H
|
|
7
|
+
#define COMMON_H
|
|
7
8
|
#pragma once
|
|
8
9
|
#include "CaretString.h"
|
|
9
10
|
#include <string>
|
|
@@ -23,15 +24,17 @@ public:
|
|
|
23
24
|
std::string tailPlaceholder;
|
|
24
25
|
|
|
25
26
|
// 构造函数
|
|
26
|
-
Result(const CaretString &formattedText,
|
|
27
|
-
|
|
27
|
+
Result(const CaretString &formattedText,
|
|
28
|
+
const std::string &extractedValue, int affinity, bool complete,
|
|
29
|
+
const std::string &tailPlaceholder)
|
|
28
30
|
: formattedText(formattedText), extractedValue(extractedValue), affinity(affinity), complete(complete),
|
|
29
|
-
|
|
31
|
+
tailPlaceholder(tailPlaceholder) {}
|
|
30
32
|
|
|
31
33
|
// reversed 方法
|
|
32
|
-
Result reversed() const
|
|
34
|
+
Result reversed() const
|
|
35
|
+
{
|
|
33
36
|
return Result(this->formattedText.reversed(), reverseString(this->extractedValue), this->affinity,
|
|
34
|
-
|
|
37
|
+
this->complete, reverseString(this->tailPlaceholder));
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
private:
|
|
@@ -53,7 +56,8 @@ private:
|
|
|
53
56
|
|
|
54
57
|
public:
|
|
55
58
|
// Push 方法
|
|
56
|
-
std::optional<Next> push(const std::optional<Next> &item)
|
|
59
|
+
std::optional<Next> push(const std::optional<Next> &item)
|
|
60
|
+
{
|
|
57
61
|
if (item.has_value()) {
|
|
58
62
|
stack.push_back(item.value());
|
|
59
63
|
return item;
|
|
@@ -67,12 +71,14 @@ public:
|
|
|
67
71
|
void clear() { stack.clear(); }
|
|
68
72
|
|
|
69
73
|
// Optional: 获取栈的元素(用于检查或调试)
|
|
70
|
-
std::vector<Next> getStack() const
|
|
74
|
+
std::vector<Next> getStack() const
|
|
75
|
+
{
|
|
71
76
|
return stack; // 返回当前栈的拷贝
|
|
72
77
|
}
|
|
73
78
|
|
|
74
79
|
// Optional: 从栈中弹出一个元素
|
|
75
|
-
std::optional<Next> pop()
|
|
80
|
+
std::optional<Next> pop()
|
|
81
|
+
{
|
|
76
82
|
if (stack.empty()) {
|
|
77
83
|
return std::nullopt; // 栈为空时返回 std::nullopt
|
|
78
84
|
}
|
|
@@ -85,11 +91,13 @@ public:
|
|
|
85
91
|
bool isEmpty() const { return stack.empty(); }
|
|
86
92
|
|
|
87
93
|
// Optional: 获取栈顶元素而不移除它
|
|
88
|
-
std::optional<Next> peek() const
|
|
94
|
+
std::optional<Next> peek() const
|
|
95
|
+
{
|
|
89
96
|
if (stack.empty()) {
|
|
90
97
|
return std::nullopt; // 栈为空时返回 std::nullopt
|
|
91
98
|
}
|
|
92
99
|
return stack.back();
|
|
93
100
|
}
|
|
94
101
|
};
|
|
95
|
-
} // namespace TinpMask
|
|
102
|
+
} // namespace TinpMask
|
|
103
|
+
#endif
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts';
|
|
8
|
+
import { RNOHPackage } from "@rnoh/react-native-openharmony";
|
|
8
9
|
import type { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
|
|
9
10
|
import { RNTextInputMaskTurboModule } from './RNTextInputMaskTurboModle';
|
|
10
11
|
|
|
@@ -22,7 +23,7 @@ class RNTextInputMaskTurboModuleFactory extends TurboModulesFactory {
|
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
export class RNTextInputMaskPackage extends
|
|
26
|
+
export class RNTextInputMaskPackage extends RNOHPackage {
|
|
26
27
|
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
|
|
27
28
|
return new RNTextInputMaskTurboModuleFactory(ctx);
|
|
28
29
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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 { hilog } from '@kit.PerformanceAnalysisKit';
|
|
8
|
+
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
|
|
9
|
+
|
|
10
|
+
export default function abilityTest() {
|
|
11
|
+
describe('ActsAbilityTest', () => {
|
|
12
|
+
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
|
|
13
|
+
beforeAll(() => {
|
|
14
|
+
// Presets an action, which is performed only once before all test cases of the test suite start.
|
|
15
|
+
// This API supports only one parameter: preset action function.
|
|
16
|
+
})
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
// Presets an action, which is performed before each unit test case starts.
|
|
19
|
+
// The number of execution times is the same as the number of test cases defined by **it**.
|
|
20
|
+
// This API supports only one parameter: preset action function.
|
|
21
|
+
})
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
// Presets a clear action, which is performed after each unit test case ends.
|
|
24
|
+
// The number of execution times is the same as the number of test cases defined by **it**.
|
|
25
|
+
// This API supports only one parameter: clear action function.
|
|
26
|
+
})
|
|
27
|
+
afterAll(() => {
|
|
28
|
+
// Presets a clear action, which is performed after all test cases of the test suite end.
|
|
29
|
+
// This API supports only one parameter: clear action function.
|
|
30
|
+
})
|
|
31
|
+
it('assertContain', 0, () => {
|
|
32
|
+
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
|
|
33
|
+
hilog.info(0x0000, 'testTag', '%{public}s', 'it begin');
|
|
34
|
+
let a = 'abc';
|
|
35
|
+
let b = 'b';
|
|
36
|
+
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
|
|
37
|
+
expect(a).assertContain(b);
|
|
38
|
+
expect(a).assertEqual(a);
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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 abilityTest from './Ability.test';
|
|
8
|
+
|
|
9
|
+
export default function testsuite() {
|
|
10
|
+
abilityTest();
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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 localUnitTest from './LocalUnit.test';
|
|
8
|
+
|
|
9
|
+
export default function testsuite() {
|
|
10
|
+
localUnitTest();
|
|
11
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
|
|
8
|
+
|
|
9
|
+
export default function localUnitTest() {
|
|
10
|
+
describe('localUnitTest', () => {
|
|
11
|
+
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
|
|
12
|
+
beforeAll(() => {
|
|
13
|
+
// Presets an action, which is performed only once before all test cases of the test suite start.
|
|
14
|
+
// This API supports only one parameter: preset action function.
|
|
15
|
+
});
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
// Presets an action, which is performed before each unit test case starts.
|
|
18
|
+
// The number of execution times is the same as the number of test cases defined by **it**.
|
|
19
|
+
// This API supports only one parameter: preset action function.
|
|
20
|
+
});
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
// Presets a clear action, which is performed after each unit test case ends.
|
|
23
|
+
// The number of execution times is the same as the number of test cases defined by **it**.
|
|
24
|
+
// This API supports only one parameter: clear action function.
|
|
25
|
+
});
|
|
26
|
+
afterAll(() => {
|
|
27
|
+
// Presets a clear action, which is performed after all test cases of the test suite end.
|
|
28
|
+
// This API supports only one parameter: clear action function.
|
|
29
|
+
});
|
|
30
|
+
it('assertContain', 0, () => {
|
|
31
|
+
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
|
|
32
|
+
let a = 'abc';
|
|
33
|
+
let b = 'b';
|
|
34
|
+
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
|
|
35
|
+
expect(a).assertContain(b);
|
|
36
|
+
expect(a).assertEqual(a);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
Binary file
|
package/index.tsx
CHANGED
|
@@ -15,12 +15,9 @@ import React, {
|
|
|
15
15
|
|
|
16
16
|
import { findNodeHandle, Platform, TextInput, TextInputProps } from 'react-native'
|
|
17
17
|
import exportMasker from './src/index'
|
|
18
|
-
import HarmonyTextInputMask from './src/index.harmony'
|
|
19
|
-
const isIosAndroid = Platform.OS === 'ios' || Platform.OS === 'android';
|
|
20
18
|
export const mask = exportMasker.mask
|
|
21
19
|
export const unmask = exportMasker.unmask
|
|
22
20
|
export const setMask = exportMasker.setMask
|
|
23
|
-
export const unmaskWithRightToLeft = HarmonyTextInputMask.unmaskWithRightToLeft
|
|
24
21
|
const TextInputMask = forwardRef<Handles, TextInputMaskProps>(({
|
|
25
22
|
mask: primaryFormat,
|
|
26
23
|
defaultValue,
|
|
@@ -37,14 +34,6 @@ const TextInputMask = forwardRef<Handles, TextInputMaskProps>(({
|
|
|
37
34
|
}, ref) => {
|
|
38
35
|
const input = useRef<TextInput>(null)
|
|
39
36
|
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
37
|
|
|
49
38
|
useEffectAsync(async () => {
|
|
50
39
|
const initialValue = value ?? defaultValue
|
|
@@ -68,11 +57,9 @@ const TextInputMask = forwardRef<Handles, TextInputMaskProps>(({
|
|
|
68
57
|
}, [value])
|
|
69
58
|
|
|
70
59
|
useEffect(() => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
setMask(nodeId, primaryFormat, { affineFormats, affinityCalculationStrategy, customNotations, autocomplete, autoskip, rightToLeft })
|
|
75
|
-
}
|
|
60
|
+
const nodeId = findNodeHandle(input.current)
|
|
61
|
+
if (primaryFormat && nodeId) {
|
|
62
|
+
setMask(nodeId, primaryFormat, { affineFormats, affinityCalculationStrategy, customNotations, autocomplete, autoskip, rightToLeft })
|
|
76
63
|
}
|
|
77
64
|
}, [primaryFormat])
|
|
78
65
|
|
|
@@ -91,17 +78,11 @@ const TextInputMask = forwardRef<Handles, TextInputMaskProps>(({
|
|
|
91
78
|
ref={input}
|
|
92
79
|
value={maskedValue}
|
|
93
80
|
multiline={primaryFormat && Platform.OS === 'ios' ? false : multiline}
|
|
94
|
-
onLayout={handleLayout}
|
|
95
81
|
onChangeText={async (masked) => {
|
|
96
82
|
setMaskedValue(masked)
|
|
97
83
|
if (primaryFormat) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
onChangeText?.(masked, unmasked)
|
|
101
|
-
} else {
|
|
102
|
-
const unmasked = await unmaskWithRightToLeft(primaryFormat, masked, true, rightToLeft === undefined ? false : rightToLeft)
|
|
103
|
-
onChangeText?.(masked, unmasked)
|
|
104
|
-
}
|
|
84
|
+
const unmasked = await unmask(primaryFormat, masked, true)
|
|
85
|
+
onChangeText?.(masked, unmasked)
|
|
105
86
|
} else {
|
|
106
87
|
onChangeText?.(masked)
|
|
107
88
|
}
|
package/package.json
CHANGED
|
@@ -1,22 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native-ohos/react-native-text-input-mask",
|
|
3
|
-
"version": "3.1.6-rc.
|
|
3
|
+
"version": "3.1.6-rc.6",
|
|
4
4
|
"description": "Text input mask for React Native.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://gitcode.com/openharmony-sig/rntpc_react-native-text-input-mask
|
|
9
|
+
"url": "https://gitcode.com/openharmony-sig/rntpc_react-native-text-input-mask"
|
|
10
10
|
},
|
|
11
11
|
"keywords": [
|
|
12
12
|
"react",
|
|
13
13
|
"native",
|
|
14
14
|
"mask",
|
|
15
15
|
"text input",
|
|
16
|
+
"android",
|
|
17
|
+
"ios",
|
|
16
18
|
"harmony"
|
|
17
19
|
],
|
|
18
20
|
"harmony": {
|
|
19
|
-
"alias":"react-native-text-input-mask"
|
|
21
|
+
"alias":"react-native-text-input-mask",
|
|
22
|
+
"autolinking": {
|
|
23
|
+
"etsPackageClassName":"RNTextInputMaskPackage",
|
|
24
|
+
"cppPackageClassName":"RNTextInputMaskPackage",
|
|
25
|
+
"cmakeLibraryTargetName": "text_input_mask",
|
|
26
|
+
"ohPackageName": "@react-native-ohos/react-native-text-input-mask"
|
|
27
|
+
}
|
|
20
28
|
},
|
|
21
29
|
"scripts": {
|
|
22
30
|
"prepublish": "npx tsc"
|
|
@@ -27,22 +35,20 @@
|
|
|
27
35
|
"devDependencies": {
|
|
28
36
|
"@react-native-community/eslint-config": "3.2.0",
|
|
29
37
|
"@types/react": "^18.2.12",
|
|
30
|
-
"react-native": "^0.
|
|
38
|
+
"react-native": "^0.71.10",
|
|
31
39
|
"tslib": "^2.5.3",
|
|
32
40
|
"typescript": "^5.1.3"
|
|
33
41
|
},
|
|
34
|
-
"files": [
|
|
35
|
-
"src",
|
|
36
|
-
"harmony",
|
|
37
|
-
"dist",
|
|
38
|
-
"index.tsx"
|
|
39
|
-
],
|
|
40
42
|
"peerDependencies": {
|
|
41
43
|
"react-native": ">=0.69.0"
|
|
42
44
|
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"registry": "https://registry.npmjs.org/",
|
|
47
|
+
"access": "public"
|
|
48
|
+
},
|
|
43
49
|
"author": "Martin Treurnicht",
|
|
44
50
|
"bugs": {
|
|
45
51
|
"url": "https://gitcode.com/openharmony-sig/rntpc_react-native-text-input-mask/issues"
|
|
46
52
|
},
|
|
47
|
-
"homepage": "https://gitcode.com/openharmony-sig/rntpc_react-native-text-input-mask
|
|
53
|
+
"homepage": "https://gitcode.com/openharmony-sig/rntpc_react-native-text-input-mask"
|
|
48
54
|
}
|
|
@@ -137,7 +137,6 @@ export interface Spec extends TurboModule {
|
|
|
137
137
|
mask (mask: string, value: string, autocomplete: boolean) :Promise<string>,
|
|
138
138
|
unmask (mask: string, value: string, autocomplete: boolean): Promise<string>,
|
|
139
139
|
setMask (reactNode: number, primaryFormat: string, options?: MaskOptions): void;
|
|
140
|
-
unmaskWithRightToLeft (mask: string, value: string, autocomplete: boolean, rightToLeft: boolean): Promise<string>;
|
|
141
140
|
}
|
|
142
141
|
|
|
143
142
|
export default TurboModuleRegistry.get<Spec>('RNTextInputMask') as Spec ;
|
package/src/index.harmony.ts
CHANGED
|
@@ -139,9 +139,6 @@ class HarmonyTextInputMask {
|
|
|
139
139
|
static setMask(reactNode: number, primaryFormat: string, options?: MaskOptions): void {
|
|
140
140
|
RNNativeTextInputMask.setMask(reactNode, primaryFormat, options)
|
|
141
141
|
}
|
|
142
|
-
static unmaskWithRightToLeft(mask: string, value: string, autocomplete: boolean, rightToLeft: boolean): Promise<string> {
|
|
143
|
-
return RNNativeTextInputMask.unmaskWithRightToLeft(mask, value, autocomplete, rightToLeft);
|
|
144
|
-
}
|
|
145
142
|
}
|
|
146
143
|
console.log("======HarmonyTextInputMask=",HarmonyTextInputMask)
|
|
147
144
|
export default HarmonyTextInputMask;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Basic Options */
|
|
4
|
+
"incremental": true /* Enable incremental compilation */,
|
|
5
|
+
"target": "ES6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
|
|
6
|
+
// "module": "es2015", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
|
7
|
+
"lib": [
|
|
8
|
+
"esnext"
|
|
9
|
+
] /* Specify library files to be included in the compilation. */,
|
|
10
|
+
"allowJs": true /* Allow javascript files to be compiled. */,
|
|
11
|
+
"jsx": "react-native" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */,
|
|
12
|
+
"declaration": true /* Generates corresponding '.d.ts' file. */,
|
|
13
|
+
"sourceMap": true /* Generates corresponding '.map' file. */,
|
|
14
|
+
"importHelpers": true /* Import emit helpers from 'tslib'. */,
|
|
15
|
+
"outDir": "dist",
|
|
16
|
+
/* Strict Type-Checking Options */
|
|
17
|
+
"strict": true /* Enable all strict type-checking options. */,
|
|
18
|
+
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
|
|
19
|
+
|
|
20
|
+
/* Additional Checks */
|
|
21
|
+
"noUnusedLocals": true /* Report errors on unused locals. */,
|
|
22
|
+
"noUnusedParameters": true /* Report errors on unused parameters. */,
|
|
23
|
+
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
|
|
24
|
+
"noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,
|
|
25
|
+
|
|
26
|
+
/* Module Resolution Options */
|
|
27
|
+
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
|
|
28
|
+
"allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
|
|
29
|
+
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
|
30
|
+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
31
|
+
|
|
32
|
+
/* Experimental Options */
|
|
33
|
+
"experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
|
|
34
|
+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
35
|
+
|
|
36
|
+
/* Other Options */
|
|
37
|
+
"allowUnreachableCode": false /* Do not report errors on unreachable code. */,
|
|
38
|
+
"skipLibCheck": true /* https://github.com/DefinitelyTyped/DefinitelyTyped/issues/24573 */
|
|
39
|
+
|
|
40
|
+
},
|
|
41
|
+
// "included":["src/"],
|
|
42
|
+
"exclude":["node_modules","harmony"]
|
|
43
|
+
}
|
package/README.OpenSource
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"Name": "react-native-text-input-mask",
|
|
4
|
-
"License": "MIT License",
|
|
5
|
-
"License File": " LICENSE ",
|
|
6
|
-
"Version Number": "3.1.5",
|
|
7
|
-
"Owner" : "xiafeng@huawei.com",
|
|
8
|
-
"Upstream URL": "https://github.com/react-native-text-input-mask/react-native-text-input-mask",
|
|
9
|
-
"Description": "Text input mask for React Native on iOS and Android."
|
|
10
|
-
}
|
|
11
|
-
]
|