@react-native-ohos/react-native-text-input-mask 3.1.6-rc.4 → 3.1.6-rc.5
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 +64 -95
- package/harmony/text_input_mask/src/main/cpp/RNTextInputMask.h +10 -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,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 CARETSTRINGITERATOR_H
|
|
7
|
+
#define CARETSTRINGITERATOR_H
|
|
7
8
|
#pragma once
|
|
8
9
|
#include <string>
|
|
9
10
|
#include <memory>
|
|
@@ -20,11 +21,12 @@ protected:
|
|
|
20
21
|
|
|
21
22
|
public:
|
|
22
23
|
// 构造函数
|
|
23
|
-
CaretStringIterator(const CaretString &caretStr, int index = 0) : caretString(caretStr),
|
|
24
|
+
explicit CaretStringIterator(const CaretString &caretStr, int index = 0) : caretString(caretStr),
|
|
25
|
+
currentIndex(index) {}
|
|
24
26
|
|
|
25
27
|
// 插入是否影响光标位置
|
|
26
|
-
virtual bool insertionAffectsCaret()
|
|
27
|
-
|
|
28
|
+
virtual bool insertionAffectsCaret()
|
|
29
|
+
{
|
|
28
30
|
if (dynamic_cast<CaretString::Backward *>(caretString.caretGravity.get())) {
|
|
29
31
|
return currentIndex < caretString.getCaretPosition();
|
|
30
32
|
} else if (dynamic_cast<CaretString::Forward *>(caretString.caretGravity.get())) {
|
|
@@ -33,26 +35,23 @@ public:
|
|
|
33
35
|
}
|
|
34
36
|
return false;
|
|
35
37
|
}
|
|
36
|
-
|
|
37
38
|
// 删除是否影响光标位置
|
|
38
39
|
virtual bool deletionAffectsCaret() { return currentIndex < caretString.getCaretPosition(); }
|
|
39
|
-
|
|
40
40
|
/**
|
|
41
41
|
* 遍历 CaretString.string
|
|
42
42
|
* @postcondition: 迭代器位置移到下一个符号。
|
|
43
43
|
* @returns 当前符号。如果迭代器到达字符串末尾,返回 nullptr。
|
|
44
44
|
*/
|
|
45
|
-
virtual char next()
|
|
45
|
+
virtual char next()
|
|
46
|
+
{
|
|
46
47
|
if (currentIndex >= caretString.getString().length()) {
|
|
47
48
|
return '\0'; // 返回空指针表示到达字符串末尾
|
|
48
49
|
}
|
|
49
|
-
|
|
50
50
|
// char *charPtr = new char; // 创建一个字符指针
|
|
51
51
|
auto charPtr = caretString.getString()[currentIndex]; // 获取当前字符
|
|
52
52
|
currentIndex += 1; // 移动到下一个索引
|
|
53
53
|
return charPtr; // 返回当前字符
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
|
-
|
|
57
|
-
|
|
58
56
|
} // namespace TinpMask
|
|
57
|
+
#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 NEXT_H
|
|
7
|
+
#define NEXT_H
|
|
7
8
|
#pragma once
|
|
8
9
|
#include <memory>
|
|
9
10
|
#include "State.h"
|
|
@@ -13,13 +14,12 @@ namespace TinpMask {
|
|
|
13
14
|
class State;
|
|
14
15
|
class Next {
|
|
15
16
|
public:
|
|
16
|
-
std::shared_ptr<State> state;
|
|
17
|
-
char insert;
|
|
18
|
-
bool pass;
|
|
19
|
-
char value;
|
|
20
|
-
|
|
21
|
-
// 构造函数
|
|
17
|
+
std::shared_ptr<State> state;
|
|
18
|
+
char insert;
|
|
19
|
+
bool pass;
|
|
20
|
+
char value;
|
|
22
21
|
Next(std::shared_ptr<State> state, char insert, bool pass, char value)
|
|
23
22
|
: state(state), insert(insert), pass(pass), value(value) {}
|
|
24
23
|
};
|
|
25
|
-
}
|
|
24
|
+
}
|
|
25
|
+
#endif
|
|
@@ -3,28 +3,28 @@
|
|
|
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 NOTATION_H
|
|
7
|
+
#define NOTATION_H
|
|
7
8
|
#pragma once
|
|
8
9
|
#include <string>
|
|
9
10
|
|
|
10
11
|
namespace TinpMask {
|
|
11
|
-
|
|
12
12
|
class Notation {
|
|
13
13
|
public:
|
|
14
14
|
// 构造函数
|
|
15
15
|
Notation(const char character, const std::string &characterSet, bool isOptional)
|
|
16
|
-
: character(character), characterSet(characterSet), isOptional(isOptional)
|
|
17
|
-
|
|
16
|
+
: character(character), characterSet(characterSet), isOptional(isOptional)
|
|
17
|
+
{}
|
|
18
18
|
// 成员变量
|
|
19
19
|
char character; // 单个字符作为字符串
|
|
20
20
|
std::string characterSet; // 字符集
|
|
21
21
|
bool isOptional; // 是否可选
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return (this->character == other.character) &&
|
|
26
|
-
|
|
27
|
-
(this->isOptional == other.isOptional);
|
|
22
|
+
// 其他方法和成员可以根据需要添加
|
|
23
|
+
bool operator == (const Notation &other) const
|
|
24
|
+
{
|
|
25
|
+
return (this->character == other.character) && (this->characterSet == other.characterSet) &&
|
|
26
|
+
(this->isOptional == other.isOptional);
|
|
28
27
|
}
|
|
29
28
|
};
|
|
30
|
-
} // namespace TinpMask
|
|
29
|
+
} // namespace TinpMask
|
|
30
|
+
#endif
|
|
@@ -14,8 +14,8 @@ class RTLCaretStringIterator : public CaretStringIterator {
|
|
|
14
14
|
public:
|
|
15
15
|
RTLCaretStringIterator(const CaretString& caretString)
|
|
16
16
|
: CaretStringIterator(caretString) {}
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
bool insertionAffectsCaret()
|
|
18
|
+
{
|
|
19
19
|
return currentIndex <= caretString.caretPosition;
|
|
20
20
|
}
|
|
21
21
|
};
|
|
@@ -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
|
}
|