@react-native-ohos/react-native-keyboard-controller 1.12.8 → 1.12.10-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.
- package/LICENSE +21 -21
- package/README.OpenSource +10 -10
- package/README.md +603 -19
- package/harmony/keyboard_controller/BuildProfile.ets +16 -16
- package/harmony/keyboard_controller/Index.ets +8 -29
- package/harmony/keyboard_controller/ResourceTable.txt +8 -8
- package/harmony/keyboard_controller/build-profile.json5 +31 -31
- package/harmony/keyboard_controller/hvigorfile.ts +6 -6
- package/harmony/keyboard_controller/obfuscation-rules.txt +17 -17
- package/harmony/keyboard_controller/oh-package-lock.json5 +28 -18
- package/harmony/keyboard_controller/oh-package.json5 +11 -11
- package/harmony/keyboard_controller/src/main/cpp/CMakeLists.txt +7 -7
- package/harmony/keyboard_controller/src/main/cpp/EventEmitters.cpp +119 -96
- package/harmony/keyboard_controller/src/main/cpp/EventEmitters.h +90 -111
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentDescriptor.h +77 -98
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.cpp +837 -274
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.h +152 -101
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewJSIBinder.h +43 -64
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentDescriptor.h +64 -85
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.cpp +88 -109
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.h +63 -84
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaJSIBinder.h +39 -60
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.cpp +25 -46
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.h +27 -48
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardControllerPackage.cpp +43 -64
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardControllerPackage.h +56 -77
- package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.cpp +24 -45
- package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.h +28 -49
- package/harmony/keyboard_controller/src/main/cpp/ViewHierarchyNavigator.cpp +186 -186
- package/harmony/keyboard_controller/src/main/cpp/ViewHierarchyNavigator.h +112 -112
- package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.cpp +43 -64
- package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.h +56 -77
- package/harmony/keyboard_controller/src/main/ets/Logger.ts +45 -66
- package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerPackage.ets +49 -70
- package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerTurboModule.ts +405 -245
- package/harmony/keyboard_controller/src/main/ets/RNStatusBarManagerCompatTurboModule.ts +107 -119
- package/harmony/keyboard_controller/src/main/ets/Type.ts +41 -62
- package/harmony/keyboard_controller/src/main/module.json +29 -29
- package/harmony/keyboard_controller/src/main/module.json5 +11 -11
- package/harmony/keyboard_controller/src/main/resources/base/element/string.json +8 -8
- package/harmony/keyboard_controller/src/main/resources/en_US/element/string.json +8 -8
- package/harmony/keyboard_controller/src/main/resources/zh_CN/element/string.json +8 -8
- package/harmony/keyboard_controller/ts.ets +8 -29
- package/harmony/keyboard_controller.har +0 -0
- package/lib/commonjs/animated.js +4 -16
- package/lib/commonjs/animated.js.map +1 -1
- package/lib/commonjs/bindings.js +3 -3
- package/lib/commonjs/bindings.js.map +1 -1
- package/lib/commonjs/bindings.native.js +3 -3
- package/lib/commonjs/bindings.native.js.map +1 -1
- package/lib/commonjs/components/KeyboardAvoidingView/hooks.js.map +1 -1
- package/lib/commonjs/components/KeyboardAvoidingView/index.js +3 -3
- package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js +39 -39
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +3 -3
- package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/utils.js.map +1 -1
- package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/Arrow.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/Button.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/colors.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/colors.native.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/index.js +3 -3
- package/lib/commonjs/components/KeyboardToolbar/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/types.js.map +1 -1
- package/lib/commonjs/components/hooks/useColorScheme.js.map +1 -1
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/constants.js.map +1 -1
- package/lib/commonjs/context.js.map +1 -1
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/hooks/useWindowDimensions/index.android.js.map +1 -1
- package/lib/commonjs/hooks/useWindowDimensions/index.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internal.js +18 -18
- package/lib/commonjs/internal.js.map +1 -1
- package/lib/commonjs/monkey-patch.android.js +4 -4
- package/lib/commonjs/monkey-patch.android.js.map +1 -1
- package/lib/commonjs/monkey-patch.js.map +1 -1
- package/lib/commonjs/reanimated.js.map +1 -1
- package/lib/commonjs/reanimated.native.js.map +1 -1
- package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/NativeKeyboardController.js.map +1 -1
- package/lib/commonjs/specs/NativeStatusBarManagerCompat.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/module/animated.js +5 -17
- package/lib/module/animated.js.map +1 -1
- package/lib/module/bindings.js +3 -3
- package/lib/module/bindings.js.map +1 -1
- package/lib/module/bindings.native.js +3 -3
- package/lib/module/bindings.native.js.map +1 -1
- package/lib/module/components/KeyboardAvoidingView/hooks.js.map +1 -1
- package/lib/module/components/KeyboardAvoidingView/index.js +3 -3
- package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/index.js +39 -39
- package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +3 -3
- package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/utils.js.map +1 -1
- package/lib/module/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/Arrow.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/Button.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/colors.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/colors.native.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/index.js +3 -3
- package/lib/module/components/KeyboardToolbar/index.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/types.js.map +1 -1
- package/lib/module/components/hooks/useColorScheme.js.map +1 -1
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/constants.js.map +1 -1
- package/lib/module/context.js.map +1 -1
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/useWindowDimensions/index.android.js.map +1 -1
- package/lib/module/hooks/useWindowDimensions/index.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal.js +18 -18
- package/lib/module/internal.js.map +1 -1
- package/lib/module/monkey-patch.android.js +4 -4
- package/lib/module/monkey-patch.android.js.map +1 -1
- package/lib/module/monkey-patch.js.map +1 -1
- package/lib/module/reanimated.js.map +1 -1
- package/lib/module/reanimated.native.js.map +1 -1
- package/lib/module/specs/KeyboardControllerViewNativeComponent.js.map +1 -1
- package/lib/module/specs/KeyboardGestureAreaNativeComponent.js.map +1 -1
- package/lib/module/specs/NativeKeyboardController.js.map +1 -1
- package/lib/module/specs/NativeStatusBarManagerCompat.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils.js.map +1 -1
- package/lib/typescript/types.d.ts +1 -0
- package/package.json +181 -178
- package/src/animated.tsx +246 -253
- package/src/bindings.native.ts +57 -57
- package/src/bindings.ts +38 -38
- package/src/components/KeyboardAvoidingView/hooks.ts +58 -58
- package/src/components/KeyboardAvoidingView/index.tsx +156 -156
- package/src/components/KeyboardAwareScrollView/index.tsx +373 -373
- package/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +133 -133
- package/src/components/KeyboardAwareScrollView/utils.ts +41 -41
- package/src/components/KeyboardStickyView/index.tsx +57 -57
- package/src/components/KeyboardToolbar/Arrow.tsx +80 -80
- package/src/components/KeyboardToolbar/Button.tsx +98 -98
- package/src/components/KeyboardToolbar/colors.native.ts +37 -37
- package/src/components/KeyboardToolbar/colors.ts +16 -16
- package/src/components/KeyboardToolbar/index.tsx +211 -211
- package/src/components/KeyboardToolbar/types.ts +40 -40
- package/src/components/hooks/useColorScheme.ts +5 -5
- package/src/components/index.ts +11 -11
- package/src/constants.ts +19 -19
- package/src/context.ts +65 -65
- package/src/hooks/index.ts +90 -90
- package/src/hooks/useWindowDimensions/index.android.ts +33 -33
- package/src/hooks/useWindowDimensions/index.ts +1 -1
- package/src/index.ts +21 -21
- package/src/internal.ts +84 -84
- package/src/monkey-patch.android.ts +44 -44
- package/src/monkey-patch.ts +4 -4
- package/src/reanimated.native.ts +132 -132
- package/src/reanimated.ts +29 -29
- package/src/specs/KeyboardControllerViewNativeComponent.ts +70 -70
- package/src/specs/KeyboardGestureAreaNativeComponent.ts +15 -15
- package/src/specs/NativeKeyboardController.ts +19 -19
- package/src/specs/NativeStatusBarManagerCompat.ts +14 -14
- package/src/types.ts +212 -211
- package/src/utils.ts +1 -1
package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.cpp
CHANGED
|
@@ -1,274 +1,837 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Huawei
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
KeyboardControllerViewComponentInstance
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
void KeyboardControllerViewComponentInstance::
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
|
|
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
|
+
#include "KeyboardControllerViewComponentInstance.h"
|
|
8
|
+
#include <algorithm>
|
|
9
|
+
#include <cmath>
|
|
10
|
+
#include <functional>
|
|
11
|
+
#include <folly/dynamic.h>
|
|
12
|
+
#include <iostream>
|
|
13
|
+
#include <unordered_map>
|
|
14
|
+
#include <arkui/native_interface_focus.h>
|
|
15
|
+
#include "RNOH/RNInstance.h"
|
|
16
|
+
#include "react/renderer/components/textinput/TextInputProps.h"
|
|
17
|
+
|
|
18
|
+
namespace rnoh {
|
|
19
|
+
using KeyboardControllerStatus = rnoh::KeyboardControllerStatus;
|
|
20
|
+
|
|
21
|
+
namespace {
|
|
22
|
+
constexpr int KBC_FOCUSED_INPUT_AREA_CHANGE_TARGET_ID = 0x4B4243;
|
|
23
|
+
struct InputObserver {
|
|
24
|
+
using Instance = std::shared_ptr<KeyboardControllerViewComponentInstance>;
|
|
25
|
+
|
|
26
|
+
std::weak_ptr<TextInputComponentInstance> input;
|
|
27
|
+
bool areaEventRegistered = false;
|
|
28
|
+
std::unordered_map<KeyboardControllerViewComponentInstance *,
|
|
29
|
+
std::weak_ptr<KeyboardControllerViewComponentInstance>> instances;
|
|
30
|
+
|
|
31
|
+
void addInstance(Instance const &target) {
|
|
32
|
+
instances[target.get()] = target;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
void removeInstance(KeyboardControllerViewComponentInstance *target) {
|
|
36
|
+
instances.erase(target);
|
|
37
|
+
for (auto it = instances.begin(); it != instances.end();) {
|
|
38
|
+
if (it->second.expired()) {
|
|
39
|
+
it = instances.erase(it);
|
|
40
|
+
} else {
|
|
41
|
+
++it;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
std::vector<Instance> lockInstances() {
|
|
47
|
+
std::vector<Instance> result;
|
|
48
|
+
for (auto it = instances.begin(); it != instances.end();) {
|
|
49
|
+
auto instance = it->second.lock();
|
|
50
|
+
if (instance) {
|
|
51
|
+
result.push_back(instance);
|
|
52
|
+
++it;
|
|
53
|
+
} else {
|
|
54
|
+
it = instances.erase(it);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
std::unordered_map<ArkUI_NodeHandle, InputObserver> g_inputObservers;
|
|
61
|
+
|
|
62
|
+
static std::string keyboardTypeToString(facebook::react::KeyboardType type) {
|
|
63
|
+
switch (type) {
|
|
64
|
+
case facebook::react::KeyboardType::Default: return "default";
|
|
65
|
+
case facebook::react::KeyboardType::EmailAddress: return "email-address";
|
|
66
|
+
case facebook::react::KeyboardType::Numeric: return "numeric";
|
|
67
|
+
case facebook::react::KeyboardType::PhonePad: return "phone-pad";
|
|
68
|
+
case facebook::react::KeyboardType::NumberPad: return "number-pad";
|
|
69
|
+
case facebook::react::KeyboardType::DecimalPad: return "decimal-pad";
|
|
70
|
+
case facebook::react::KeyboardType::ASCIICapable: return "ascii-capable";
|
|
71
|
+
case facebook::react::KeyboardType::NumbersAndPunctuation: return "numbers-and-punctuation";
|
|
72
|
+
case facebook::react::KeyboardType::URL: return "url";
|
|
73
|
+
case facebook::react::KeyboardType::NamePhonePad: return "name-phone-pad";
|
|
74
|
+
case facebook::react::KeyboardType::Twitter: return "twitter";
|
|
75
|
+
case facebook::react::KeyboardType::WebSearch: return "web-search";
|
|
76
|
+
case facebook::react::KeyboardType::ASCIICapableNumberPad: return "ascii-capable-number-pad";
|
|
77
|
+
case facebook::react::KeyboardType::VisiblePassword: return "visible-password";
|
|
78
|
+
}
|
|
79
|
+
return "default";
|
|
80
|
+
}
|
|
81
|
+
} // namespace
|
|
82
|
+
|
|
83
|
+
KeyboardControllerViewComponentInstance::KeyboardControllerViewComponentInstance(Context context)
|
|
84
|
+
: CppComponentInstance(std::move(context)), ArkTSMessageHub::Observer(m_deps->arkTSMessageHub) {
|
|
85
|
+
DLOG(INFO) << "KeyboardControllerViewComponentInstance";
|
|
86
|
+
|
|
87
|
+
m_keyboardVsyncListener = std::make_shared<VSyncListener>("KeyboardControllerAnimation");
|
|
88
|
+
m_customNode.setCustomNodeDelegate(this);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
KeyboardControllerViewComponentInstance::~KeyboardControllerViewComponentInstance() {
|
|
92
|
+
cancelKeyboardAnimation();
|
|
93
|
+
m_keyboardVsyncListener.reset();
|
|
94
|
+
clearFocusedInputLayoutObserver();
|
|
95
|
+
for (const auto &child : getChildren()) {
|
|
96
|
+
clearTextInputDelegates(child);
|
|
97
|
+
}
|
|
98
|
+
for (auto it = g_inputObservers.begin(); it != g_inputObservers.end();) {
|
|
99
|
+
auto handle = (it++)->first;
|
|
100
|
+
removeInputObserver(handle);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
void KeyboardControllerViewComponentInstance::onChildInserted(ComponentInstance::Shared const &childComponentInstance,
|
|
104
|
+
std::size_t index) {
|
|
105
|
+
CppComponentInstance::onChildInserted(childComponentInstance, index);
|
|
106
|
+
m_customNode.insertChild(childComponentInstance->getLocalRootArkUINode(), index + 1);
|
|
107
|
+
DLOG(INFO) << "###111" << childComponentInstance->getComponentName();
|
|
108
|
+
findTextInputComponents(childComponentInstance);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
void KeyboardControllerViewComponentInstance::onChildRemoved(ComponentInstance::Shared const &childComponentInstance) {
|
|
112
|
+
clearTextInputDelegates(childComponentInstance);
|
|
113
|
+
if (childComponentInstance->getLocalRootArkUINode().getArkUINodeHandle() == m_observedFocusedInputHandle) {
|
|
114
|
+
clearFocusedInputLayoutObserver();
|
|
115
|
+
}
|
|
116
|
+
CppComponentInstance::onChildRemoved(childComponentInstance);
|
|
117
|
+
m_customNode.removeChild(childComponentInstance->getLocalRootArkUINode());
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
void KeyboardControllerViewComponentInstance::onPropsChanged(SharedConcreteProps const &props) {
|
|
121
|
+
DLOG(INFO) << "###onPropsChanged" << props->enabled << props->statusBarTranslucent
|
|
122
|
+
<< props->navigationBarTranslucent;
|
|
123
|
+
CppComponentInstance::onPropsChanged(props);
|
|
124
|
+
if (this->enabled != props->enabled) {
|
|
125
|
+
this->enabled = props->enabled;
|
|
126
|
+
this->startKeyboardObserver();
|
|
127
|
+
}
|
|
128
|
+
if (this->navigationBarTranslucent != props->navigationBarTranslucent) {
|
|
129
|
+
this->navigationBarTranslucent = props->navigationBarTranslucent;
|
|
130
|
+
this->setWindowSystemBarEnable();
|
|
131
|
+
}
|
|
132
|
+
if (this->statusBarTranslucent != props->statusBarTranslucent) {
|
|
133
|
+
this->statusBarTranslucent = props->statusBarTranslucent;
|
|
134
|
+
this->setWindowSystemBarEnable();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
void KeyboardControllerViewComponentInstance::onCommandReceived(std::string const &commandName,
|
|
139
|
+
folly::dynamic const &args) {
|
|
140
|
+
CppComponentInstance::onCommandReceived(commandName, args);
|
|
141
|
+
if (commandName == "synchronizeFocusedInputLayout") {
|
|
142
|
+
syncUpLayout();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
ArkUINode &KeyboardControllerViewComponentInstance::getLocalRootArkUINode() { return m_customNode; }
|
|
147
|
+
void KeyboardControllerViewComponentInstance::onClick() {}
|
|
148
|
+
void KeyboardControllerViewComponentInstance::onMessageReceived(ArkTSMessage const &message) {
|
|
149
|
+
DLOG(INFO) << "onMessageReceived";
|
|
150
|
+
if (message.name == "keyboardHeightChange") {
|
|
151
|
+
double height = message.payload.getDouble();
|
|
152
|
+
double previousKeyboardHeight = this->keyboardHeight;
|
|
153
|
+
DLOG(INFO) << "keyboardHeightChange: " << height;
|
|
154
|
+
if (height > 0) {
|
|
155
|
+
this->keyboardStatus = KeyboardControllerStatus::SHOW;
|
|
156
|
+
this->keyboardHeight = height;
|
|
157
|
+
this->textInputVector.clear();
|
|
158
|
+
this->focusDidSet();
|
|
159
|
+
auto textInputVectorTemp = ViewHierarchyNavigator::getAllInputFields(this->shared_from_this());
|
|
160
|
+
for (size_t i = 0; i < textInputVectorTemp.size(); ++i) {
|
|
161
|
+
auto &input = textInputVectorTemp[i];
|
|
162
|
+
findTextInputComponents(input);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (height == 0) {
|
|
166
|
+
this->keyboardStatus = KeyboardControllerStatus::HIDE;
|
|
167
|
+
this->keyboardHeight = previousKeyboardHeight > 0 ? previousKeyboardHeight : 0;
|
|
168
|
+
m_lastKeyboardEventTarget = -1;
|
|
169
|
+
}
|
|
170
|
+
m_isHandlingKeyboardHeightChange = true;
|
|
171
|
+
if (this->enabled) {
|
|
172
|
+
syncUpLayout();
|
|
173
|
+
}
|
|
174
|
+
this->keyboardHeightChangeHandle(previousKeyboardHeight);
|
|
175
|
+
m_isHandlingKeyboardHeightChange = false;
|
|
176
|
+
if (height == 0) {
|
|
177
|
+
this->keyboardHeight = 0;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (message.name == "setFocusTo") {
|
|
181
|
+
std::string direction = message.payload.getString();
|
|
182
|
+
this->setFocusTo(direction);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
void KeyboardControllerViewComponentInstance::setWindowSystemBarEnable() {
|
|
186
|
+
auto rnInstancePtr = this->m_deps->rnInstance.lock();
|
|
187
|
+
if (rnInstancePtr != nullptr) {
|
|
188
|
+
auto turboModule = rnInstancePtr->getTurboModule("KeyboardController");
|
|
189
|
+
auto arkTsTurboModule = std::dynamic_pointer_cast<rnoh::ArkTSTurboModule>(turboModule);
|
|
190
|
+
arkTsTurboModule->callSync("setWindowSystemBarEnable", {this->statusBarTranslucent, this->navigationBarTranslucent});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
void KeyboardControllerViewComponentInstance::startKeyboardObserver() {
|
|
195
|
+
auto rnInstancePtr = this->m_deps->rnInstance.lock();
|
|
196
|
+
if (rnInstancePtr != nullptr) {
|
|
197
|
+
auto turboModule = rnInstancePtr->getTurboModule("KeyboardController");
|
|
198
|
+
auto arkTsTurboModule = std::dynamic_pointer_cast<rnoh::ArkTSTurboModule>(turboModule);
|
|
199
|
+
arkTsTurboModule->callSync("startKeyboardObserver", {this->enabled, true});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
void KeyboardControllerViewComponentInstance::keyboardHeightChangeHandle(double previousKeyboardHeight) {
|
|
204
|
+
auto rnInstancePtr = this->m_deps->rnInstance.lock();
|
|
205
|
+
if (rnInstancePtr != nullptr && this->enabled) {
|
|
206
|
+
int target = m_tag;
|
|
207
|
+
auto focusedInput = findFocusedTextInput();
|
|
208
|
+
if (focusedInput) {
|
|
209
|
+
target = static_cast<int>(focusedInput->getTag());
|
|
210
|
+
m_lastFocusedInputTag = target;
|
|
211
|
+
} else if (this->keyboardStatus == KeyboardControllerStatus::HIDE &&
|
|
212
|
+
m_lastFocusedInputTag != -1) {
|
|
213
|
+
// On Harmony, NODE_ON_BLUR fires before the keyboard height change,
|
|
214
|
+
// so findFocusedTextInput() returns nullptr during keyboard hide.
|
|
215
|
+
// Use the cached tag so the JS layer receives the focused input's
|
|
216
|
+
// tag (e.g. 606) instead of m_tag (e.g. 8).
|
|
217
|
+
target = m_lastFocusedInputTag;
|
|
218
|
+
}
|
|
219
|
+
m_lastKeyboardEventTarget = target;
|
|
220
|
+
const bool willHide = this->keyboardStatus == KeyboardControllerStatus::HIDE;
|
|
221
|
+
startKeyboardAnimation(previousKeyboardHeight, willHide ? 0 : this->keyboardHeight, target);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
TaskExecutor::Shared KeyboardControllerViewComponentInstance::getTaskExecutor() const {
|
|
226
|
+
auto rnInstance = m_deps->rnInstance.lock();
|
|
227
|
+
auto internalInstance = std::dynamic_pointer_cast<RNInstanceInternal>(rnInstance);
|
|
228
|
+
return internalInstance ? internalInstance->getTaskExecutor() : nullptr;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
void KeyboardControllerViewComponentInstance::cancelKeyboardAnimation() {
|
|
232
|
+
++m_keyboardAnimationGeneration;
|
|
233
|
+
auto taskExecutor = getTaskExecutor();
|
|
234
|
+
if (m_keyboardAnimationTask.has_value() && taskExecutor) {
|
|
235
|
+
taskExecutor->cancelDelayedTask(m_keyboardAnimationTask.value());
|
|
236
|
+
}
|
|
237
|
+
m_keyboardAnimationTask.reset();
|
|
238
|
+
m_keyboardAnimationStartTimestampNs.reset();
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
void KeyboardControllerViewComponentInstance::startKeyboardAnimation(double fromHeight, double toHeight, int target) {
|
|
242
|
+
cancelKeyboardAnimation();
|
|
243
|
+
const uint64_t generation = m_keyboardAnimationGeneration;
|
|
244
|
+
constexpr int durationMs = 150;
|
|
245
|
+
facebook::react::KeyboardControllerViewEventEmitter::MoveEvent start = {
|
|
246
|
+
toHeight > 0 ? toHeight : 0,
|
|
247
|
+
toHeight > 0 ? 1.0 : 0.0,
|
|
248
|
+
durationMs,
|
|
249
|
+
target};
|
|
250
|
+
m_eventEmitter->onKeyboardMoveStart(start);
|
|
251
|
+
requestKeyboardAnimationFrame(generation, fromHeight, toHeight, target);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
void KeyboardControllerViewComponentInstance::requestKeyboardAnimationFrame(
|
|
255
|
+
uint64_t generation,
|
|
256
|
+
double fromHeight,
|
|
257
|
+
double toHeight,
|
|
258
|
+
int target) {
|
|
259
|
+
if (!m_keyboardVsyncListener || !m_eventEmitter || !this->enabled) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
auto weakSelf = std::weak_ptr<KeyboardControllerViewComponentInstance>(
|
|
263
|
+
std::static_pointer_cast<KeyboardControllerViewComponentInstance>(shared_from_this()));
|
|
264
|
+
m_keyboardVsyncListener->requestFrame(
|
|
265
|
+
[weakSelf, generation, fromHeight, toHeight, target](long long timestampNs) {
|
|
266
|
+
auto self = weakSelf.lock();
|
|
267
|
+
if (!self || generation != self->m_keyboardAnimationGeneration) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
auto taskExecutor = self->getTaskExecutor();
|
|
271
|
+
if (!taskExecutor) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
auto frameTask = [weakSelf, generation, fromHeight, toHeight, target, timestampNs] {
|
|
275
|
+
auto self = weakSelf.lock();
|
|
276
|
+
if (!self) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
self->handleKeyboardAnimationFrame(
|
|
280
|
+
generation, fromHeight, toHeight, target, static_cast<int64_t>(timestampNs));
|
|
281
|
+
};
|
|
282
|
+
if (taskExecutor->isOnTaskThread(TaskThread::MAIN)) {
|
|
283
|
+
frameTask();
|
|
284
|
+
} else {
|
|
285
|
+
taskExecutor->runTask(TaskThread::MAIN, std::move(frameTask));
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
void KeyboardControllerViewComponentInstance::handleKeyboardAnimationFrame(
|
|
291
|
+
uint64_t generation,
|
|
292
|
+
double fromHeight,
|
|
293
|
+
double toHeight,
|
|
294
|
+
int target,
|
|
295
|
+
int64_t timestampNs) {
|
|
296
|
+
if (generation != m_keyboardAnimationGeneration || !m_eventEmitter || !this->enabled) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (!m_keyboardAnimationStartTimestampNs.has_value()) {
|
|
301
|
+
m_keyboardAnimationStartTimestampNs = timestampNs;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
constexpr int durationMs = 150;
|
|
305
|
+
constexpr int64_t nanosecondsPerMillisecond = 1000000;
|
|
306
|
+
constexpr int64_t durationNs = durationMs * nanosecondsPerMillisecond;
|
|
307
|
+
const int64_t elapsedNs = std::max<int64_t>(0, timestampNs - m_keyboardAnimationStartTimestampNs.value());
|
|
308
|
+
const double animationFraction = std::clamp(
|
|
309
|
+
static_cast<double>(elapsedNs) / static_cast<double>(durationNs),
|
|
310
|
+
0.0,
|
|
311
|
+
1.0);
|
|
312
|
+
const double height = fromHeight + (toHeight - fromHeight) * animationFraction;
|
|
313
|
+
const double denominator = std::max(fromHeight, toHeight);
|
|
314
|
+
facebook::react::KeyboardControllerViewEventEmitter::MoveEvent move = {
|
|
315
|
+
height,
|
|
316
|
+
denominator > 0 ? std::abs(height / denominator) : 0.0,
|
|
317
|
+
durationMs,
|
|
318
|
+
target};
|
|
319
|
+
m_eventEmitter->onKeyboardMove(move);
|
|
320
|
+
|
|
321
|
+
if (animationFraction < 1.0) {
|
|
322
|
+
requestKeyboardAnimationFrame(generation, fromHeight, toHeight, target);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
constexpr int scrollSettleDelayMs = 16;
|
|
327
|
+
auto taskExecutor = getTaskExecutor();
|
|
328
|
+
if (!taskExecutor) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
auto weakSelf = std::weak_ptr<KeyboardControllerViewComponentInstance>(
|
|
332
|
+
std::static_pointer_cast<KeyboardControllerViewComponentInstance>(shared_from_this()));
|
|
333
|
+
m_keyboardAnimationTask = taskExecutor->runDelayedTask(
|
|
334
|
+
TaskThread::MAIN,
|
|
335
|
+
[weakSelf, generation, toHeight, target] {
|
|
336
|
+
auto self = weakSelf.lock();
|
|
337
|
+
if (!self || generation != self->m_keyboardAnimationGeneration ||
|
|
338
|
+
!self->m_eventEmitter || !self->enabled) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
constexpr int durationMs = 150;
|
|
342
|
+
facebook::react::KeyboardControllerViewEventEmitter::MoveEvent end = {
|
|
343
|
+
toHeight, toHeight > 0 ? 1.0 : 0.0, durationMs, target};
|
|
344
|
+
self->m_eventEmitter->onKeyboardMoveEnd(end);
|
|
345
|
+
self->m_keyboardAnimationTask.reset();
|
|
346
|
+
self->m_keyboardAnimationStartTimestampNs.reset();
|
|
347
|
+
},
|
|
348
|
+
scrollSettleDelayMs);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* 遍历查找TextInput
|
|
353
|
+
* */
|
|
354
|
+
void KeyboardControllerViewComponentInstance::findTextInputComponents(
|
|
355
|
+
ComponentInstance::Shared const &childComponentInstance) {
|
|
356
|
+
std::string name = childComponentInstance->getComponentName();
|
|
357
|
+
if (name.find("TextInput") != std::string::npos || name.find("TextArea") != std::string::npos) {
|
|
358
|
+
auto input = std::dynamic_pointer_cast<TextInputComponentInstance>(childComponentInstance);
|
|
359
|
+
if (!input) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
ArkUINode &node = input->getLocalRootArkUINode();
|
|
363
|
+
auto handle = node.getArkUINodeHandle();
|
|
364
|
+
auto observerIt = g_inputObservers.find(handle);
|
|
365
|
+
if (observerIt != g_inputObservers.end() && observerIt->second.input.expired()) {
|
|
366
|
+
g_inputObservers.erase(observerIt);
|
|
367
|
+
observerIt = g_inputObservers.end();
|
|
368
|
+
}
|
|
369
|
+
if (handle && observerIt == g_inputObservers.end()) {
|
|
370
|
+
auto result = NativeNodeApi::getInstance()->addNodeEventReceiver(
|
|
371
|
+
handle, KeyboardControllerViewComponentInstance::textSelectionEventReceiver);
|
|
372
|
+
if (result == ARKUI_ERROR_CODE_NO_ERROR) {
|
|
373
|
+
InputObserver observer;
|
|
374
|
+
observer.input = input;
|
|
375
|
+
g_inputObservers.emplace(handle, std::move(observer));
|
|
376
|
+
observerIt = g_inputObservers.find(handle);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (observerIt != g_inputObservers.end()) {
|
|
380
|
+
observerIt->second.input = input;
|
|
381
|
+
observerIt->second.addInstance(
|
|
382
|
+
std::dynamic_pointer_cast<KeyboardControllerViewComponentInstance>(shared_from_this()));
|
|
383
|
+
}
|
|
384
|
+
this->textInputVector.push_back(input);
|
|
385
|
+
}
|
|
386
|
+
auto childrenComponentInstances = childComponentInstance->getChildren();
|
|
387
|
+
if (childrenComponentInstances.empty()) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
std::vector<ComponentInstance::Shared>::iterator it1;
|
|
392
|
+
for (it1 = childrenComponentInstances.begin(); it1 != childrenComponentInstances.end(); ++it1) {
|
|
393
|
+
ComponentInstance::Shared const &t = *it1;
|
|
394
|
+
findTextInputComponents(t);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
void KeyboardControllerViewComponentInstance::clearTextInputDelegates(
|
|
399
|
+
ComponentInstance::Shared const &component) {
|
|
400
|
+
if (!component) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
ArkUINode &node = component->getLocalRootArkUINode();
|
|
404
|
+
if (node.getArkUINodeHandle() == m_observedFocusedInputHandle) {
|
|
405
|
+
clearFocusedInputLayoutObserver();
|
|
406
|
+
}
|
|
407
|
+
removeInputObserver(node.getArkUINodeHandle());
|
|
408
|
+
for (const auto &child : component->getChildren()) {
|
|
409
|
+
clearTextInputDelegates(child);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
void KeyboardControllerViewComponentInstance::removeInputObserver(ArkUI_NodeHandle handle) {
|
|
414
|
+
auto observerIt = g_inputObservers.find(handle);
|
|
415
|
+
if (observerIt == g_inputObservers.end()) {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
observerIt->second.removeInstance(this);
|
|
419
|
+
if (!observerIt->second.instances.empty()) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
if (observerIt->second.input.lock()) {
|
|
423
|
+
if (observerIt->second.areaEventRegistered) {
|
|
424
|
+
NativeNodeApi::getInstance()->unregisterNodeEvent(handle, NODE_EVENT_ON_AREA_CHANGE);
|
|
425
|
+
}
|
|
426
|
+
NativeNodeApi::getInstance()->removeNodeEventReceiver(
|
|
427
|
+
handle, KeyboardControllerViewComponentInstance::textSelectionEventReceiver);
|
|
428
|
+
}
|
|
429
|
+
g_inputObservers.erase(observerIt);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
void KeyboardControllerViewComponentInstance::onChange(std::string text) {
|
|
433
|
+
onChange(std::move(text), findFocusedTextInput());
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
void KeyboardControllerViewComponentInstance::onChange(
|
|
437
|
+
std::string text,
|
|
438
|
+
TextInputComponentInstance::Shared const &focusedInput) {
|
|
439
|
+
facebook::react::KeyboardControllerViewEventEmitter::TextChangeEvent event = {text};
|
|
440
|
+
if (this->enabled && m_eventEmitter) {
|
|
441
|
+
syncUpLayout(focusedInput);
|
|
442
|
+
m_eventEmitter->onFocusedInputTextChanged(event);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
void KeyboardControllerViewComponentInstance::onChange(std::string text, std::string extendStr) {
|
|
447
|
+
onChange(std::move(text));
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
void KeyboardControllerViewComponentInstance::onTextSelectionChange(int32_t location, int32_t length) {
|
|
451
|
+
if (!this->enabled) {
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
auto focusedInput = findFocusedTextInput();
|
|
455
|
+
if (!focusedInput) {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
syncUpLayout();
|
|
459
|
+
dispatchSelectionToJS(
|
|
460
|
+
static_cast<int>(focusedInput->getTag()),
|
|
461
|
+
location,
|
|
462
|
+
location + length);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
void KeyboardControllerViewComponentInstance::dispatchSelectionToJS(
|
|
466
|
+
int target, int32_t startPos, int32_t endPos) {
|
|
467
|
+
if (!m_eventEmitter || !this->enabled) {
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
facebook::react::KeyboardControllerViewEventEmitter::InputSectionEvent event = {};
|
|
471
|
+
event.target = target;
|
|
472
|
+
event.selection.start.x = 0;
|
|
473
|
+
event.selection.start.y = 0;
|
|
474
|
+
event.selection.start.position = startPos;
|
|
475
|
+
event.selection.end.x = 0;
|
|
476
|
+
event.selection.end.y = 0;
|
|
477
|
+
event.selection.end.position = endPos;
|
|
478
|
+
m_eventEmitter->onFocusedInputSelectionChanged(event);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
void KeyboardControllerViewComponentInstance::focusDidSet() {
|
|
482
|
+
auto focused = findFocusedTextInput();
|
|
483
|
+
if (!focused || !this->enabled) {
|
|
484
|
+
this->textInputVector.clear();
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
this->textInputVector = ViewHierarchyNavigator::getAllInputFields(this->shared_from_this());
|
|
488
|
+
int count = static_cast<int>(this->textInputVector.size());
|
|
489
|
+
int currentIndex = -1;
|
|
490
|
+
for (size_t i = 0; i < this->textInputVector.size(); ++i) {
|
|
491
|
+
auto& input = this->textInputVector[i];
|
|
492
|
+
if (input && input->getTag() == focused->getTag()) {
|
|
493
|
+
currentIndex = static_cast<int>(i);
|
|
494
|
+
break;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
this->textInputVector.clear();
|
|
498
|
+
// 发送 focusDidSet 事件到 JS 层
|
|
499
|
+
if (currentIndex >= 0) {
|
|
500
|
+
auto rnInstancePtr = this->m_deps->rnInstance.lock();
|
|
501
|
+
if (rnInstancePtr != nullptr) {
|
|
502
|
+
folly::dynamic payload = folly::dynamic::object
|
|
503
|
+
("current", currentIndex)
|
|
504
|
+
("count", count);
|
|
505
|
+
rnInstancePtr->postMessageToArkTS("focusDidSet", payload);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
void KeyboardControllerViewComponentInstance::onFocus() {
|
|
511
|
+
postFocusedInputChanged();
|
|
512
|
+
this->focusDidSet();
|
|
513
|
+
syncUpLayout();
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
void KeyboardControllerViewComponentInstance::onBlur() {
|
|
517
|
+
// Cache the tag of the input that is losing focus. On Harmony, NODE_ON_BLUR
|
|
518
|
+
// fires before the keyboard height change arrives, so findFocusedTextInput()
|
|
519
|
+
// will return nullptr when keyboardHeightChangeHandle runs. This cache lets
|
|
520
|
+
// us send the correct target (the focused input's tag, not m_tag) during
|
|
521
|
+
// keyboard hide.
|
|
522
|
+
auto focusedInput = findFocusedTextInput();
|
|
523
|
+
if (focusedInput) {
|
|
524
|
+
m_lastFocusedInputTag = static_cast<int>(focusedInput->getTag());
|
|
525
|
+
}
|
|
526
|
+
clearFocusedInputLayoutObserver();
|
|
527
|
+
m_lastLayoutEvent = FocusedInputLayoutData{};
|
|
528
|
+
if (m_eventEmitter && this->enabled) {
|
|
529
|
+
facebook::react::KeyboardControllerViewEventEmitter::InputLayoutEvent payload = {};
|
|
530
|
+
payload.target = -1;
|
|
531
|
+
payload.parentScrollViewTarget = -1;
|
|
532
|
+
m_eventEmitter->onFocusedInputLayoutChanged(payload);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* 设置焦点到指定方向的输入框
|
|
538
|
+
* 实现逻辑仿照 iOS ViewHierarchyNavigator.swift
|
|
539
|
+
* @param direction "next" | "prev"
|
|
540
|
+
*/
|
|
541
|
+
void KeyboardControllerViewComponentInstance::setFocusTo(const std::string& direction) {
|
|
542
|
+
if (direction != "next" && direction != "prev") {
|
|
543
|
+
DLOG(WARNING) << "setFocusTo: invalid direction, must be 'next' or 'prev'";
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
auto currentFocus = this->findFocusedTextInput();
|
|
547
|
+
if (!currentFocus) {
|
|
548
|
+
DLOG(INFO) << "no current focus available";
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
// 使用 ViewHierarchyNavigator 查找目标输入框
|
|
552
|
+
auto targetInput = ViewHierarchyNavigator::setFocusTo(direction, currentFocus);
|
|
553
|
+
if (targetInput) {
|
|
554
|
+
DLOG(INFO) << "setFocusTo: found target, requesting focus, tag=" << targetInput->getTag();
|
|
555
|
+
// 获取 ArkUI_NodeHandle 并请求焦点
|
|
556
|
+
ArkUINode& node = targetInput->getLocalRootArkUINode();
|
|
557
|
+
ArkUI_NodeHandle nodeHandle = node.getArkUINodeHandle();
|
|
558
|
+
ArkUI_ErrorCode result = ARKUI_ERROR_CODE_NO_ERROR;
|
|
559
|
+
high_lib_handle = dlopen("libace_ndk.z.so", RTLD_LAZY);
|
|
560
|
+
if (high_lib_handle == NULL) {
|
|
561
|
+
DLOG(INFO) << "libace_ndk.z.so not existed";
|
|
562
|
+
} else {
|
|
563
|
+
focusRequestMethod = (ArkUI_ErrorCode(*)(ArkUI_NodeHandle node))dlsym(high_lib_handle, "OH_ArkUI_FocusRequest");
|
|
564
|
+
bool isFocusRequestMethodExisted = focusRequestMethod != NULL;
|
|
565
|
+
if (isFocusRequestMethodExisted) {
|
|
566
|
+
DLOG(INFO) << "OH_ArkUI_FocusRequest method existed";
|
|
567
|
+
result = focusRequestMethod(nodeHandle);
|
|
568
|
+
} else {
|
|
569
|
+
DLOG(INFO) << "OH_ArkUI_FocusRequest method not existed";
|
|
570
|
+
}
|
|
571
|
+
dlclose(high_lib_handle);
|
|
572
|
+
}
|
|
573
|
+
if (!(result == ARKUI_ERROR_CODE_NO_ERROR)) {
|
|
574
|
+
DLOG(WARNING) << "setFocusTo: focus request failed with error code: " << result;
|
|
575
|
+
}
|
|
576
|
+
} else {
|
|
577
|
+
DLOG(INFO) << "setFocusTo: no target input found in direction " << direction;
|
|
578
|
+
}
|
|
579
|
+
this->textInputVector.clear();
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
TextInputComponentInstance::Shared KeyboardControllerViewComponentInstance::findFocusedTextInput() {
|
|
583
|
+
std::function<TextInputComponentInstance::Shared(ComponentInstance::Shared)> findFocused;
|
|
584
|
+
findFocused = [&](ComponentInstance::Shared component) -> TextInputComponentInstance::Shared {
|
|
585
|
+
if (!component) {
|
|
586
|
+
return nullptr;
|
|
587
|
+
}
|
|
588
|
+
if (auto input = std::dynamic_pointer_cast<TextInputComponentInstance>(component)) {
|
|
589
|
+
if (input->getLocalRootArkUINode().isFocused()) {
|
|
590
|
+
return input;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
for (const auto &child : component->getChildren()) {
|
|
594
|
+
if (auto input = findFocused(child)) {
|
|
595
|
+
return input;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
return nullptr;
|
|
599
|
+
};
|
|
600
|
+
return findFocused(this->shared_from_this());
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
int KeyboardControllerViewComponentInstance::findParentScrollViewTarget(ComponentInstance::Shared const &input) {
|
|
604
|
+
auto parent = input->getParent().lock();
|
|
605
|
+
while (parent != nullptr) {
|
|
606
|
+
if (parent->getComponentName().find("ScrollView") != std::string::npos) {
|
|
607
|
+
return static_cast<int>(parent->getTag());
|
|
608
|
+
}
|
|
609
|
+
parent = parent->getParent().lock();
|
|
610
|
+
}
|
|
611
|
+
return -1;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
double KeyboardControllerViewComponentInstance::pxToVp(double px) const {
|
|
615
|
+
auto pointScaleFactor = this->getLayoutMetrics().pointScaleFactor;
|
|
616
|
+
return pointScaleFactor == 0.0 ? px : px / pointScaleFactor;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
void KeyboardControllerViewComponentInstance::textSelectionEventReceiver(ArkUI_NodeEvent *event) {
|
|
620
|
+
if (event == nullptr) {
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
auto eventType = OH_ArkUI_NodeEvent_GetEventType(event);
|
|
624
|
+
auto handle = OH_ArkUI_NodeEvent_GetNodeHandle(event);
|
|
625
|
+
auto observerIt = g_inputObservers.find(handle);
|
|
626
|
+
if (observerIt == g_inputObservers.end()) {
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
auto input = observerIt->second.input.lock();
|
|
630
|
+
if (!input) {
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
auto instances = observerIt->second.lockInstances();
|
|
634
|
+
instances.erase(
|
|
635
|
+
std::remove_if(
|
|
636
|
+
instances.begin(),
|
|
637
|
+
instances.end(),
|
|
638
|
+
[](auto const &instance) { return !instance->enabled; }),
|
|
639
|
+
instances.end());
|
|
640
|
+
|
|
641
|
+
if (eventType == NODE_EVENT_ON_AREA_CHANGE &&
|
|
642
|
+
OH_ArkUI_NodeEvent_GetTargetId(event) == KBC_FOCUSED_INPUT_AREA_CHANGE_TARGET_ID) {
|
|
643
|
+
for (auto const &instance : instances) {
|
|
644
|
+
if (instance->m_observedFocusedInputHandle == handle) {
|
|
645
|
+
instance->syncUpLayout(input);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
if (eventType == NODE_ON_BLUR) {
|
|
651
|
+
for (auto const &instance : instances) {
|
|
652
|
+
if (instance->m_observedFocusedInputHandle == nullptr ||
|
|
653
|
+
instance->m_observedFocusedInputHandle == handle) {
|
|
654
|
+
instance->onBlur();
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
if (eventType == NODE_ON_FOCUS) {
|
|
660
|
+
for (auto const &instance : instances) {
|
|
661
|
+
instance->postFocusedInputChanged();
|
|
662
|
+
instance->focusDidSet();
|
|
663
|
+
instance->syncUpLayout(input);
|
|
664
|
+
}
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
const auto *focusStatus = NativeNodeApi::getInstance()->getAttribute(handle, NODE_FOCUS_STATUS);
|
|
669
|
+
if (focusStatus == nullptr || focusStatus->value == nullptr ||
|
|
670
|
+
focusStatus->size < 1 || focusStatus->value[0].i32 == 0) {
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
if (eventType == NODE_TEXT_INPUT_ON_CHANGE ||
|
|
675
|
+
eventType == NODE_TEXT_INPUT_ON_CHANGE_WITH_PREVIEW_TEXT ||
|
|
676
|
+
eventType == NODE_TEXT_AREA_ON_CHANGE ||
|
|
677
|
+
eventType == NODE_TEXT_AREA_ON_CHANGE_WITH_PREVIEW_TEXT) {
|
|
678
|
+
auto textAttribute = eventType == NODE_TEXT_INPUT_ON_CHANGE ||
|
|
679
|
+
eventType == NODE_TEXT_INPUT_ON_CHANGE_WITH_PREVIEW_TEXT
|
|
680
|
+
? NODE_TEXT_INPUT_TEXT
|
|
681
|
+
: NODE_TEXT_AREA_TEXT;
|
|
682
|
+
const auto *text = NativeNodeApi::getInstance()->getAttribute(handle, textAttribute);
|
|
683
|
+
if (text != nullptr && text->string != nullptr) {
|
|
684
|
+
for (auto const &instance : instances) {
|
|
685
|
+
instance->onChange(std::string(text->string), input);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
if (eventType != NODE_TEXT_INPUT_ON_TEXT_SELECTION_CHANGE &&
|
|
692
|
+
eventType != NODE_TEXT_AREA_ON_TEXT_SELECTION_CHANGE) {
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
auto componentEvent = OH_ArkUI_NodeEvent_GetNodeComponentEvent(event);
|
|
696
|
+
if (componentEvent == nullptr) {
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
for (auto const &instance : instances) {
|
|
700
|
+
instance->syncUpLayout(input);
|
|
701
|
+
instance->dispatchSelectionToJS(
|
|
702
|
+
static_cast<int>(input->getTag()),
|
|
703
|
+
componentEvent->data[0].i32,
|
|
704
|
+
componentEvent->data[1].i32);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
void KeyboardControllerViewComponentInstance::clearFocusedInputLayoutObserver() {
|
|
709
|
+
m_observedFocusedInputHandle = nullptr;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
void KeyboardControllerViewComponentInstance::updateFocusedInputLayoutObserver(
|
|
713
|
+
TextInputComponentInstance::Shared const &focusedInput) {
|
|
714
|
+
ArkUI_NodeHandle handle = focusedInput
|
|
715
|
+
? focusedInput->getLocalRootArkUINode().getArkUINodeHandle()
|
|
716
|
+
: nullptr;
|
|
717
|
+
if (handle == m_observedFocusedInputHandle) {
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
clearFocusedInputLayoutObserver();
|
|
721
|
+
if (handle == nullptr) {
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
auto observerIt = g_inputObservers.find(handle);
|
|
725
|
+
if (observerIt == g_inputObservers.end()) {
|
|
726
|
+
findTextInputComponents(focusedInput);
|
|
727
|
+
observerIt = g_inputObservers.find(handle);
|
|
728
|
+
}
|
|
729
|
+
if (observerIt == g_inputObservers.end()) {
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
auto *nodeApi = NativeNodeApi::getInstance();
|
|
733
|
+
auto registerRet = observerIt->second.areaEventRegistered
|
|
734
|
+
? ARKUI_ERROR_CODE_NO_ERROR
|
|
735
|
+
: nodeApi->registerNodeEvent(
|
|
736
|
+
handle, NODE_EVENT_ON_AREA_CHANGE, KBC_FOCUSED_INPUT_AREA_CHANGE_TARGET_ID, nullptr);
|
|
737
|
+
if (registerRet != ARKUI_ERROR_CODE_NO_ERROR) {
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
observerIt->second.areaEventRegistered = true;
|
|
741
|
+
m_observedFocusedInputHandle = handle;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
void KeyboardControllerViewComponentInstance::syncUpLayout() {
|
|
745
|
+
auto focusedInput = findFocusedTextInput();
|
|
746
|
+
syncUpLayout(focusedInput);
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
void KeyboardControllerViewComponentInstance::syncUpLayout(
|
|
750
|
+
TextInputComponentInstance::Shared const &focusedInput) {
|
|
751
|
+
if (!focusedInput) {
|
|
752
|
+
clearFocusedInputLayoutObserver();
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
updateFocusedInputLayoutObserver(focusedInput);
|
|
756
|
+
ArkUI_NodeHandle handle = focusedInput->getLocalRootArkUINode().getArkUINodeHandle();
|
|
757
|
+
ArkUI_IntOffset windowOffset{};
|
|
758
|
+
ArkUI_IntOffset localOffset{};
|
|
759
|
+
ArkUI_IntSize size{};
|
|
760
|
+
if (handle == nullptr ||
|
|
761
|
+
OH_ArkUI_NodeUtils_GetLayoutPositionInWindow(handle, &windowOffset) != ARKUI_ERROR_CODE_NO_ERROR ||
|
|
762
|
+
OH_ArkUI_NodeUtils_GetLayoutPosition(handle, &localOffset) != ARKUI_ERROR_CODE_NO_ERROR ||
|
|
763
|
+
OH_ArkUI_NodeUtils_GetLayoutSize(handle, &size) != ARKUI_ERROR_CODE_NO_ERROR) {
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
FocusedInputLayoutData event;
|
|
767
|
+
event.absoluteX = pxToVp(windowOffset.x);
|
|
768
|
+
event.absoluteY = pxToVp(windowOffset.y);
|
|
769
|
+
event.x = pxToVp(localOffset.x);
|
|
770
|
+
event.y = pxToVp(localOffset.y);
|
|
771
|
+
event.width = pxToVp(size.width);
|
|
772
|
+
event.height = pxToVp(size.height);
|
|
773
|
+
event.target = static_cast<int>(focusedInput->getTag());
|
|
774
|
+
event.parentScrollViewTarget = findParentScrollViewTarget(focusedInput);
|
|
775
|
+
dispatchLayoutToJS(event);
|
|
776
|
+
dispatchKeyboardFocusChangedIfNeeded(focusedInput);
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
void KeyboardControllerViewComponentInstance::dispatchLayoutToJS(FocusedInputLayoutData const &event) {
|
|
780
|
+
if (event == m_lastLayoutEvent) {
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
m_lastLayoutEvent = event;
|
|
784
|
+
if (!m_eventEmitter || !this->enabled) {
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
facebook::react::KeyboardControllerViewEventEmitter::InputLayoutEvent payload = {};
|
|
788
|
+
payload.target = event.target;
|
|
789
|
+
payload.parentScrollViewTarget = event.parentScrollViewTarget;
|
|
790
|
+
payload.layout.absoluteX = event.absoluteX;
|
|
791
|
+
payload.layout.absoluteY = event.absoluteY;
|
|
792
|
+
payload.layout.x = event.x;
|
|
793
|
+
payload.layout.y = event.y;
|
|
794
|
+
payload.layout.width = event.width;
|
|
795
|
+
payload.layout.height = event.height;
|
|
796
|
+
m_eventEmitter->onFocusedInputLayoutChanged(payload);
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
void KeyboardControllerViewComponentInstance::dispatchKeyboardFocusChangedIfNeeded(
|
|
800
|
+
TextInputComponentInstance::Shared const &focusedInput) {
|
|
801
|
+
if (m_isHandlingKeyboardHeightChange) {
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
if (!this->enabled || !m_eventEmitter || this->keyboardHeight <= 0) {
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
int target = static_cast<int>(focusedInput->getTag());
|
|
809
|
+
if (m_lastKeyboardEventTarget == -1 || target == m_lastKeyboardEventTarget) {
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
cancelKeyboardAnimation();
|
|
813
|
+
facebook::react::KeyboardControllerViewEventEmitter::MoveEvent event = {
|
|
814
|
+
this->keyboardHeight, 1.0, 0, target};
|
|
815
|
+
m_lastKeyboardEventTarget = target;
|
|
816
|
+
m_eventEmitter->onKeyboardMoveStart(event);
|
|
817
|
+
m_eventEmitter->onKeyboardMoveEnd(event);
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
void KeyboardControllerViewComponentInstance::postFocusedInputChanged() {
|
|
821
|
+
auto focusedInput = findFocusedTextInput();
|
|
822
|
+
int target = -1;
|
|
823
|
+
std::string type = "default";
|
|
824
|
+
if (focusedInput) {
|
|
825
|
+
target = static_cast<int>(focusedInput->getTag());
|
|
826
|
+
auto props = std::dynamic_pointer_cast<const facebook::react::TextInputProps>(focusedInput->getProps());
|
|
827
|
+
if (props) {
|
|
828
|
+
type = keyboardTypeToString(props->traits.keyboardType);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
auto rnInstancePtr = this->m_deps->rnInstance.lock();
|
|
832
|
+
if (rnInstancePtr != nullptr) {
|
|
833
|
+
folly::dynamic payload = folly::dynamic::object("target", target)("type", type);
|
|
834
|
+
rnInstancePtr->postMessageToArkTS("focusedInputChanged", std::move(payload));
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
} // namespace rnoh
|