@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
|
@@ -22,9 +22,13 @@ using namespace rnoh;
|
|
|
22
22
|
using namespace react;
|
|
23
23
|
using namespace TinpMask;
|
|
24
24
|
static constexpr int AVOIDENCE = 1;
|
|
25
|
+
static constexpr int EVENT_ID_ONCHANGE = 110;
|
|
26
|
+
static constexpr int EVENT_ID_ONFOCUS = 111;
|
|
27
|
+
static constexpr int EVENT_ID_ONSELECT_CHANGE = 112;
|
|
25
28
|
std::unordered_map<std::string, std::shared_ptr<RTLMask>> TinpMask::RTLMask::cache;
|
|
26
29
|
std::unordered_map<std::string, std::shared_ptr<Mask>> TinpMask::Mask::MaskFactory::maskCache;
|
|
27
|
-
void maybeThrow(int32_t status)
|
|
30
|
+
void maybeThrow(int32_t status)
|
|
31
|
+
{
|
|
28
32
|
DLOG(INFO) << "=====text change maybeThrow status: " << status;
|
|
29
33
|
if (status != 0) {
|
|
30
34
|
auto message = std::string("ArkUINode operation failed with status: ") + std::to_string(status);
|
|
@@ -33,7 +37,8 @@ void maybeThrow(int32_t status) {
|
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
|
|
36
|
-
void myEventReceiver(ArkUI_NodeEvent *event)
|
|
40
|
+
void myEventReceiver(ArkUI_NodeEvent *event)
|
|
41
|
+
{
|
|
37
42
|
int32_t eventId = OH_ArkUI_NodeEvent_GetTargetId(event);
|
|
38
43
|
ArkUI_NodeHandle textNode = OH_ArkUI_NodeEvent_GetNodeHandle(event);
|
|
39
44
|
void *data = NativeNodeApi::getInstance()->getUserData(textNode);
|
|
@@ -41,11 +46,20 @@ void myEventReceiver(ArkUI_NodeEvent *event) {
|
|
|
41
46
|
std::string content = item->string;
|
|
42
47
|
UserData *userData = reinterpret_cast<UserData *>(data);
|
|
43
48
|
auto self = userData->instance;
|
|
44
|
-
if (self == nullptr) {
|
|
49
|
+
if (self == nullptr) {
|
|
50
|
+
return;
|
|
51
|
+
};
|
|
45
52
|
bool isDelete = userData->lastInputText.size() >= content.size();
|
|
46
53
|
bool useAutocomplete = !isDelete ? userData->maskOptions.autocomplete.value() : false;
|
|
47
54
|
bool useAutoskip = isDelete ? userData->maskOptions.autoskip.value() : false;
|
|
48
|
-
|
|
55
|
+
if (eventId == EVENT_ID_ONSELECT_CHANGE && self->lastStrPtr_) {
|
|
56
|
+
ArkUI_AttributeItem item{.string = self->lastStrPtr_.get()->c_str()};
|
|
57
|
+
userData->lastInputText = self->lastStrPtr_.get()->c_str();
|
|
58
|
+
maybeThrow(NativeNodeApi::getInstance()->setAttribute(userData->data, NODE_TEXT_INPUT_TEXT, &item));
|
|
59
|
+
if (self->lastStrPtr_->empty()) {
|
|
60
|
+
self->lastStrPtr_ = nullptr;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
49
63
|
// onChange 事件
|
|
50
64
|
if (eventId == userData->node) {
|
|
51
65
|
std::shared_ptr<CaretString::CaretGravity> caretGravity = nullptr;
|
|
@@ -65,26 +79,26 @@ void myEventReceiver(ArkUI_NodeEvent *event) {
|
|
|
65
79
|
content = resultString;
|
|
66
80
|
}
|
|
67
81
|
std::string finalString = isDelete ? content : resultString;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
maybeThrow(NativeNodeApi::getInstance()->setAttribute(userData->data, NODE_TEXT_INPUT_TEXT, &item));
|
|
71
|
-
} catch (FormatError e) {
|
|
82
|
+
self->lastStrPtr_ = std::make_shared<std::string>(finalString);
|
|
83
|
+
} catch (const FormatError &e) {
|
|
72
84
|
DLOG(ERROR) << " mask complier error " << e.what();
|
|
73
85
|
}
|
|
74
86
|
}
|
|
75
87
|
// onFocus 事件
|
|
76
|
-
if (eventId ==
|
|
88
|
+
if (eventId == EVENT_ID_ONFOCUS) {
|
|
77
89
|
if (userData->maskOptions.autocomplete.value()) {
|
|
78
90
|
std::string text = "";
|
|
79
91
|
text += content;
|
|
80
92
|
try {
|
|
81
93
|
CaretString string(text, text.length(),
|
|
82
|
-
|
|
94
|
+
std::make_shared<CaretString::Forward>(userData->maskOptions.autocomplete.value()));
|
|
83
95
|
auto maskObj = self->pickMask(string, userData->maskOptions, userData->primaryFormat);
|
|
84
96
|
std::string resultString = maskObj->apply(string).formattedText.string;
|
|
85
|
-
ArkUI_AttributeItem item{
|
|
97
|
+
ArkUI_AttributeItem item{
|
|
98
|
+
.string = resultString.c_str()
|
|
99
|
+
};
|
|
86
100
|
maybeThrow(NativeNodeApi::getInstance()->setAttribute(userData->data, NODE_TEXT_INPUT_TEXT, &item));
|
|
87
|
-
} catch (FormatError e) {
|
|
101
|
+
} catch (const FormatError &e) {
|
|
88
102
|
DLOG(ERROR) << " mask complier error " << e.what();
|
|
89
103
|
}
|
|
90
104
|
}
|
|
@@ -92,7 +106,8 @@ void myEventReceiver(ArkUI_NodeEvent *event) {
|
|
|
92
106
|
}
|
|
93
107
|
|
|
94
108
|
// 计算亲和度
|
|
95
|
-
int calculateAffinity(Mask mask, const CaretString &text, std::string affinityCalculationStrategy)
|
|
109
|
+
int calculateAffinity(Mask mask, const CaretString &text, std::string affinityCalculationStrategy)
|
|
110
|
+
{
|
|
96
111
|
AffinityCalculationStrategy strategy;
|
|
97
112
|
if (affinityCalculationStrategy == "WHOLE_STRING") {
|
|
98
113
|
strategy = AffinityCalculationStrategy::WHOLE_STRING;
|
|
@@ -109,7 +124,8 @@ int calculateAffinity(Mask mask, const CaretString &text, std::string affinityCa
|
|
|
109
124
|
}
|
|
110
125
|
// 获取或创建 Mask
|
|
111
126
|
std::shared_ptr<Mask> maskGetOrCreate(const std::string &format, const std::vector<Notation> &customNotations,
|
|
112
|
-
|
|
127
|
+
bool rightToLeft)
|
|
128
|
+
{
|
|
113
129
|
if (rightToLeft) {
|
|
114
130
|
return RTLMask::getOrCreate(format, customNotations);
|
|
115
131
|
} else {
|
|
@@ -118,13 +134,14 @@ std::shared_ptr<Mask> maskGetOrCreate(const std::string &format, const std::vect
|
|
|
118
134
|
}
|
|
119
135
|
|
|
120
136
|
std::shared_ptr<Mask> RNTextInputMask::pickMask(const CaretString &text, MaskOptions maskOptions,
|
|
121
|
-
|
|
137
|
+
std::string primaryMask)
|
|
138
|
+
{
|
|
122
139
|
// 如果 affineFormats 为空,直接返回 primaryMask
|
|
123
140
|
if (maskOptions.affineFormats->size() <= 0) {
|
|
124
141
|
auto mask = maskGetOrCreate(primaryMask, maskOptions.customNotations.value(), maskOptions.rightToLeft.value());
|
|
125
142
|
int affinity = calculateAffinity(*mask, text, maskOptions.affinityCalculationStrategy.value());
|
|
126
|
-
DLOG(INFO) << " ======= pickMask calculateAffinity value: " << affinity
|
|
127
|
-
|
|
143
|
+
DLOG(INFO) << " ======= pickMask calculateAffinity value: " << affinity <<
|
|
144
|
+
"\n affinityCalculationStrategy: " << maskOptions.affinityCalculationStrategy.value();
|
|
128
145
|
return mask;
|
|
129
146
|
}
|
|
130
147
|
// 定义 MaskAffinity 结构体,用于存储 Mask 和相应的亲和度
|
|
@@ -136,8 +153,8 @@ std::shared_ptr<Mask> RNTextInputMask::pickMask(const CaretString &text, MaskOpt
|
|
|
136
153
|
|
|
137
154
|
// 计算 primaryMask 的亲和度
|
|
138
155
|
int primaryAffinity = calculateAffinity(primaryMask, text, maskOptions.affinityCalculationStrategy.value());
|
|
139
|
-
DLOG(INFO) << " ======= pickMask calculateAffinity value: " << primaryAffinity << " \n mask: " << primaryMask
|
|
140
|
-
|
|
156
|
+
DLOG(INFO) << " ======= pickMask calculateAffinity value: " << primaryAffinity << " \n mask: " << primaryMask <<
|
|
157
|
+
"\n affinityCalculationStrategy: " << maskOptions.affinityCalculationStrategy.value();
|
|
141
158
|
// 存储所有 mask 和亲和度的列表
|
|
142
159
|
std::vector<MaskAffinity> masksAndAffinities;
|
|
143
160
|
|
|
@@ -146,14 +163,14 @@ std::shared_ptr<Mask> RNTextInputMask::pickMask(const CaretString &text, MaskOpt
|
|
|
146
163
|
std::shared_ptr<Mask> mask =
|
|
147
164
|
maskGetOrCreate(format, maskOptions.customNotations.value(), maskOptions.rightToLeft.value());
|
|
148
165
|
int affinity = calculateAffinity(*mask, text, maskOptions.affinityCalculationStrategy.value());
|
|
149
|
-
DLOG(INFO) << " ======= pickMask calculateAffinity value: " << affinity << "\n affineFormat: " << format
|
|
150
|
-
|
|
166
|
+
DLOG(INFO) << " ======= pickMask calculateAffinity value: " << affinity << "\n affineFormat: " << format <<
|
|
167
|
+
"\n affinityCalculationStrategy: " << maskOptions.affinityCalculationStrategy.value();
|
|
151
168
|
masksAndAffinities.emplace_back(*mask, affinity);
|
|
152
169
|
}
|
|
153
170
|
|
|
154
171
|
// 按亲和度降序排序
|
|
155
172
|
std::sort(masksAndAffinities.begin(), masksAndAffinities.end(),
|
|
156
|
-
|
|
173
|
+
[](const MaskAffinity &a, const MaskAffinity &b) { return a.affinity > b.affinity; });
|
|
157
174
|
|
|
158
175
|
// 寻找插入位置
|
|
159
176
|
int insertIndex = -1;
|
|
@@ -175,7 +192,8 @@ std::shared_ptr<Mask> RNTextInputMask::pickMask(const CaretString &text, MaskOpt
|
|
|
175
192
|
return std::make_shared<Mask>(masksAndAffinities.front().mask);
|
|
176
193
|
}
|
|
177
194
|
|
|
178
|
-
void RNTextInputMask::setMask(int reactNode, std::string primaryFormat, MaskOptions maskOptions)
|
|
195
|
+
void RNTextInputMask::setMask(int reactNode, std::string primaryFormat, MaskOptions maskOptions)
|
|
196
|
+
{
|
|
179
197
|
auto task = [this, reactNode, primaryFormat, maskOptions] {
|
|
180
198
|
auto weakInstance = m_ctx.instance;
|
|
181
199
|
auto instance = weakInstance.lock();
|
|
@@ -193,24 +211,26 @@ void RNTextInputMask::setMask(int reactNode, std::string primaryFormat, MaskOpti
|
|
|
193
211
|
}
|
|
194
212
|
ArkUINode &node = input->getLocalRootArkUINode();
|
|
195
213
|
TextInputNode *textInputNode = dynamic_cast<TextInputNode *>(&node);
|
|
196
|
-
UserData *userData = new UserData({
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
214
|
+
UserData *userData = new UserData({
|
|
215
|
+
.data = textInputNode->getArkUINodeHandle(),
|
|
216
|
+
.maskOptions = maskOptions,
|
|
217
|
+
.primaryFormat = primaryFormat,
|
|
218
|
+
.node = reactNode,
|
|
219
|
+
.instance = this });
|
|
201
220
|
NativeNodeApi::getInstance()->registerNodeEvent(textInputNode->getArkUINodeHandle(), NODE_TEXT_INPUT_ON_CHANGE,
|
|
202
221
|
reactNode, textInputNode);
|
|
222
|
+
NativeNodeApi::getInstance()->registerNodeEvent(textInputNode->getArkUINodeHandle(),
|
|
223
|
+
NODE_TEXT_INPUT_ON_TEXT_SELECTION_CHANGE, EVENT_ID_ONSELECT_CHANGE, textInputNode);
|
|
203
224
|
NativeNodeApi::getInstance()->registerNodeEvent(textInputNode->getArkUINodeHandle(), NODE_ON_FOCUS, 111,
|
|
204
|
-
|
|
225
|
+
textInputNode);
|
|
205
226
|
this->m_userDatas.insert(userData);
|
|
206
227
|
NativeNodeApi::getInstance()->setUserData(textInputNode->getArkUINodeHandle(), userData);
|
|
207
228
|
NativeNodeApi::getInstance()->addNodeEventReceiver(textInputNode->getArkUINodeHandle(), myEventReceiver);
|
|
208
229
|
};
|
|
209
230
|
this->m_ctx.taskExecutor->runTask(TaskThread::MAIN, std::move(task));
|
|
210
231
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
232
|
+
std::string getString(std::string maskValue, std::string value, bool autocomplete, bool isMask)
|
|
233
|
+
{
|
|
214
234
|
auto maskObj = Mask::MaskFactory::getOrCreate(maskValue, {});
|
|
215
235
|
CaretString text(value, value.length(), std::make_shared<CaretString::Forward>(autocomplete));
|
|
216
236
|
auto r = maskObj->apply(text);
|
|
@@ -222,32 +242,14 @@ std::string getString(std::string maskValue, std::string value, bool autocomplet
|
|
|
222
242
|
}
|
|
223
243
|
return result;
|
|
224
244
|
}
|
|
225
|
-
|
|
226
|
-
std::string getString(std::string maskValue, std::string value, bool autocomplete, bool isMask, bool rightToLeft) {
|
|
227
|
-
std::shared_ptr<Mask> maskObj;
|
|
228
|
-
if (rightToLeft) {
|
|
229
|
-
maskObj = RTLMask::getOrCreate(maskValue, {});
|
|
230
|
-
} else {
|
|
231
|
-
maskObj = Mask::MaskFactory::getOrCreate(maskValue, {});
|
|
232
|
-
}
|
|
233
|
-
CaretString text(value, value.length(), std::make_shared<CaretString::Forward>(autocomplete));
|
|
234
|
-
auto r = maskObj->apply(text);
|
|
235
|
-
std::string result;
|
|
236
|
-
if (isMask) {
|
|
237
|
-
result = r.formattedText.string;
|
|
238
|
-
} else {
|
|
239
|
-
result = r.extractedValue;
|
|
240
|
-
}
|
|
241
|
-
return result;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
245
|
static jsi::Value __hostFunction_RNTextInputMask_unmask(jsi::Runtime &rt, react::TurboModule &turboModule,
|
|
245
|
-
|
|
246
|
+
const jsi::Value *args, size_t count)
|
|
247
|
+
{
|
|
246
248
|
std::string maskValue = args[0].getString(rt).utf8(rt);
|
|
247
249
|
std::string value = args[1].getString(rt).utf8(rt);
|
|
248
250
|
bool autocomplete = args[2].getBool();
|
|
249
|
-
return createPromiseAsJSIValue(
|
|
250
|
-
|
|
251
|
+
return createPromiseAsJSIValue(rt,
|
|
252
|
+
[maskValue, value, autocomplete](jsi::Runtime &rt2, std::shared_ptr<facebook::react::Promise> promise) {
|
|
251
253
|
try {
|
|
252
254
|
auto start = std::chrono::high_resolution_clock::now();
|
|
253
255
|
std::string result = getString(maskValue, value, autocomplete, 0);
|
|
@@ -262,37 +264,14 @@ static jsi::Value __hostFunction_RNTextInputMask_unmask(jsi::Runtime &rt, react:
|
|
|
262
264
|
}
|
|
263
265
|
});
|
|
264
266
|
}
|
|
265
|
-
|
|
266
|
-
static jsi::Value __hostFunction_RNTextInputMask_unmaskWithRightToLeft(jsi::Runtime &rt, react::TurboModule &turboModule,
|
|
267
|
-
const jsi::Value *args, size_t count) {
|
|
268
|
-
std::string maskValue = args[0].getString(rt).utf8(rt);
|
|
269
|
-
std::string value = args[1].getString(rt).utf8(rt);
|
|
270
|
-
bool autocomplete = args[2].getBool();
|
|
271
|
-
bool rightToLeft = args[3].getBool();
|
|
272
|
-
return createPromiseAsJSIValue(
|
|
273
|
-
rt, [maskValue, value, autocomplete, rightToLeft](jsi::Runtime &rt2, std::shared_ptr<facebook::react::Promise> promise) {
|
|
274
|
-
try {
|
|
275
|
-
auto start = std::chrono::high_resolution_clock::now();
|
|
276
|
-
std::string result = getString(maskValue, value, autocomplete, 0, rightToLeft);
|
|
277
|
-
promise->resolve(jsi::String::createFromUtf8(rt2, result));
|
|
278
|
-
// 获取结束时间点
|
|
279
|
-
auto end = std::chrono::high_resolution_clock::now();
|
|
280
|
-
// 计算延迟
|
|
281
|
-
std::chrono::duration<double, std::milli> latency = end - start;
|
|
282
|
-
DLOG(INFO) << "=======unmask 响应时长: " << latency.count() << " 毫秒" << std::endl;
|
|
283
|
-
} catch (FormatError e) {
|
|
284
|
-
promise->reject(e.what());
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
|
|
289
267
|
static jsi::Value __hostFunction_RNTextInputMask_mask(jsi::Runtime &rt, react::TurboModule &turboModule,
|
|
290
|
-
|
|
268
|
+
const jsi::Value *args, size_t count)
|
|
269
|
+
{
|
|
291
270
|
std::string maskValue = args[0].getString(rt).utf8(rt);
|
|
292
271
|
std::string value = args[1].getString(rt).utf8(rt);
|
|
293
272
|
bool autocomplete = args[2].getBool();
|
|
294
|
-
return createPromiseAsJSIValue(
|
|
295
|
-
|
|
273
|
+
return createPromiseAsJSIValue(rt,
|
|
274
|
+
[maskValue, value, autocomplete](jsi::Runtime &rt2, std::shared_ptr<facebook::react::Promise> promise) {
|
|
296
275
|
try {
|
|
297
276
|
auto start = std::chrono::high_resolution_clock::now();
|
|
298
277
|
std::string result = getString(maskValue, value, autocomplete, 1);
|
|
@@ -307,10 +286,9 @@ static jsi::Value __hostFunction_RNTextInputMask_mask(jsi::Runtime &rt, react::T
|
|
|
307
286
|
}
|
|
308
287
|
});
|
|
309
288
|
}
|
|
310
|
-
|
|
311
289
|
static jsi::Value __hostFunction_RNTextInputMask_setMask(jsi::Runtime &rt, react::TurboModule &turboModule,
|
|
312
|
-
|
|
313
|
-
|
|
290
|
+
const jsi::Value *args, size_t count)
|
|
291
|
+
{
|
|
314
292
|
auto turbo = static_cast<RNTextInputMask *>(&turboModule);
|
|
315
293
|
if (turbo->grt == nullptr) {
|
|
316
294
|
turbo->grt = &rt;
|
|
@@ -330,8 +308,8 @@ static jsi::Value __hostFunction_RNTextInputMask_setMask(jsi::Runtime &rt, react
|
|
|
330
308
|
for (size_t i = 0; i < length; ++i) {
|
|
331
309
|
// 获取数组元素
|
|
332
310
|
jsi::Value value = arrayAffineFormats.getValueAtIndex(rt, i);
|
|
333
|
-
std::cout << "===affineFormats index" + std::to_string(i) << "--" << value.getString(rt).utf8(rt)
|
|
334
|
-
|
|
311
|
+
std::cout << "===affineFormats index" + std::to_string(i) << "--" << value.getString(rt).utf8(rt) <<
|
|
312
|
+
std::endl;
|
|
335
313
|
affineFormatsValues.push_back(value.getString(rt).utf8(rt));
|
|
336
314
|
}
|
|
337
315
|
} else {
|
|
@@ -369,8 +347,6 @@ static jsi::Value __hostFunction_RNTextInputMask_setMask(jsi::Runtime &rt, react
|
|
|
369
347
|
std::cerr << "====The property 'myArray' is not an array." << std::endl;
|
|
370
348
|
}
|
|
371
349
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
350
|
std::string affinityCalculationStrategy;
|
|
375
351
|
if (obj.hasProperty(rt, "affinityCalculationStrategy") &&
|
|
376
352
|
!obj.getProperty(rt, "affinityCalculationStrategy").isUndefined()) {
|
|
@@ -393,24 +369,25 @@ static jsi::Value __hostFunction_RNTextInputMask_setMask(jsi::Runtime &rt, react
|
|
|
393
369
|
}
|
|
394
370
|
|
|
395
371
|
auto maskOptions = new MaskOptions(affineFormatsValues, customNotationsValues, affinityCalculationStrategy,
|
|
396
|
-
|
|
372
|
+
autocomplete, autoskip, rightToLeft);
|
|
397
373
|
static_cast<RNTextInputMask *>(&turboModule)->setMask(reactNode, primaryFormat, *maskOptions);
|
|
398
374
|
return jsi::Value::undefined();
|
|
399
375
|
}
|
|
400
376
|
|
|
401
377
|
RNTextInputMask::RNTextInputMask(const ArkTSTurboModule::Context ctx, const std::string name)
|
|
402
|
-
: ArkTSTurboModule(ctx, name)
|
|
403
|
-
|
|
404
|
-
methodMap_["
|
|
405
|
-
methodMap_["
|
|
406
|
-
methodMap_["
|
|
378
|
+
: ArkTSTurboModule(ctx, name)
|
|
379
|
+
{
|
|
380
|
+
methodMap_["setMask"] = MethodMetadata{ 3, __hostFunction_RNTextInputMask_setMask };
|
|
381
|
+
methodMap_["mask"] = MethodMetadata{ 3, __hostFunction_RNTextInputMask_mask };
|
|
382
|
+
methodMap_["unmask"] = MethodMetadata{ 3, __hostFunction_RNTextInputMask_unmask };
|
|
407
383
|
}
|
|
408
|
-
|
|
409
|
-
|
|
384
|
+
RNTextInputMask::~RNTextInputMask()
|
|
385
|
+
{
|
|
410
386
|
for (auto userData : m_userDatas) {
|
|
411
387
|
if (userData != nullptr) {
|
|
412
388
|
NativeNodeApi::getInstance()->unregisterNodeEvent(userData->data, NODE_TEXT_INPUT_ON_CHANGE);
|
|
413
389
|
NativeNodeApi::getInstance()->unregisterNodeEvent(userData->data, NODE_ON_FOCUS);
|
|
390
|
+
NativeNodeApi::getInstance()->unregisterNodeEvent(userData->data, NODE_TEXT_INPUT_ON_TEXT_SELECTION_CHANGE);
|
|
414
391
|
NativeNodeApi::getInstance()->removeNodeEventReceiver(userData->data, myEventReceiver);
|
|
415
392
|
delete userData;
|
|
416
393
|
userData = nullptr;
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
*
|
|
13
13
|
* @generatorVersion: 1
|
|
14
14
|
*/
|
|
15
|
+
#ifndef RNTEXTINPUTMASK_H
|
|
16
|
+
#define RNTEXTINPUTMASK_H
|
|
15
17
|
#pragma once
|
|
16
18
|
|
|
17
19
|
#include "RNOH/ArkTSTurboModule.h"
|
|
@@ -37,7 +39,8 @@ struct MaskParams {
|
|
|
37
39
|
MaskParams() = default;
|
|
38
40
|
MaskParams(const std::string &m, const std::string &v, std::optional<bool> autoComplete = std::nullopt)
|
|
39
41
|
: mask(m), value(v), autocomplete(autoComplete) {} // 构造函数
|
|
40
|
-
MaskParams &operator=(const MaskParams &input)
|
|
42
|
+
MaskParams &operator=(const MaskParams &input)
|
|
43
|
+
{
|
|
41
44
|
this->mask = input.mask;
|
|
42
45
|
this->value = input.value;
|
|
43
46
|
this->autocomplete = input.autocomplete;
|
|
@@ -55,12 +58,13 @@ struct MaskOptions {
|
|
|
55
58
|
|
|
56
59
|
MaskOptions()
|
|
57
60
|
: affineFormats(std::vector<std::string>()), customNotations(std::vector<Notation>()),
|
|
58
|
-
|
|
61
|
+
affinityCalculationStrategy(std::nullopt), autocomplete(true), autoskip(false), rightToLeft(false) {}
|
|
59
62
|
MaskOptions(const std::vector<std::string> &formats, const std::vector<Notation> ¬ations,
|
|
60
|
-
|
|
63
|
+
const std::string &strategy, bool autoComp, bool autoSkip, bool rtl)
|
|
61
64
|
: affineFormats(formats), customNotations(notations),
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
affinityCalculationStrategy(strategy.empty() ?
|
|
66
|
+
std::make_optional("WHOLE_STRING") : std::make_optional(strategy)),
|
|
67
|
+
autocomplete(autoComp), autoskip(autoSkip), rightToLeft(rtl) {}
|
|
64
68
|
};
|
|
65
69
|
|
|
66
70
|
typedef struct {
|
|
@@ -78,16 +82,14 @@ public:
|
|
|
78
82
|
void setMask(int reactNode, std::string primaryFormat, MaskOptions options);
|
|
79
83
|
jsi::Value mask(std::string mask, std::string value, bool autocomplete);
|
|
80
84
|
jsi::Value unmask(std::string mask, std::string value, bool autocomplete);
|
|
81
|
-
jsi::Value unmaskWithRightToLeft(std::string mask, std::string value, bool autocomplete, bool rightToLeft);
|
|
82
85
|
jsi::Runtime *grt = nullptr;
|
|
83
86
|
std::shared_ptr<Mask> pickMask(const CaretString &text, MaskOptions maskOptions, std::string primaryMask);
|
|
84
|
-
|
|
87
|
+
std::shared_ptr<std::string> lastStrPtr_ {nullptr};
|
|
85
88
|
// 释放资源
|
|
86
89
|
~RNTextInputMask();
|
|
87
90
|
|
|
88
91
|
private:
|
|
89
92
|
std::unordered_set<UserData *> m_userDatas;
|
|
90
93
|
};
|
|
91
|
-
|
|
92
|
-
|
|
93
94
|
} // namespace rnoh
|
|
95
|
+
#endif
|
|
@@ -13,7 +13,8 @@ using namespace facebook;
|
|
|
13
13
|
namespace rnoh {
|
|
14
14
|
class RNTextInputMaskTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
|
|
15
15
|
public:
|
|
16
|
-
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override
|
|
16
|
+
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override
|
|
17
|
+
{
|
|
17
18
|
if (name == "RNTextInputMask") {
|
|
18
19
|
return std::make_shared<RNTextInputMask>(ctx, name);
|
|
19
20
|
}
|
|
@@ -24,7 +25,8 @@ public:
|
|
|
24
25
|
class RNTextInputMaskPackage : public Package {
|
|
25
26
|
public:
|
|
26
27
|
RNTextInputMaskPackage(Package::Context ctx) : Package(ctx) {}
|
|
27
|
-
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override
|
|
28
|
+
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override
|
|
29
|
+
{
|
|
28
30
|
return std::make_unique<RNTextInputMaskTurboModuleFactoryDelegate>();
|
|
29
31
|
}
|
|
30
32
|
// std::vector<ArkTSMessageHandler::Shared> createArkTSMessageHandlers() override;
|