@react-native-ohos/react-native-keyboard-controller 1.12.8-rc.7 → 1.12.9
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 -8
- 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 +29 -0
- 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 -90
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentDescriptor.h +77 -77
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.cpp +816 -158
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.h +147 -74
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewJSIBinder.h +43 -43
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentDescriptor.h +64 -64
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.cpp +88 -88
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.h +63 -63
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaJSIBinder.h +39 -39
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.cpp +25 -25
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.h +27 -27
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardControllerPackage.cpp +43 -43
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardControllerPackage.h +56 -56
- package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.cpp +24 -24
- package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.h +28 -28
- package/harmony/keyboard_controller/src/main/cpp/ViewHierarchyNavigator.cpp +186 -0
- package/harmony/keyboard_controller/src/main/cpp/ViewHierarchyNavigator.h +112 -0
- package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.cpp +43 -43
- package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.h +56 -56
- package/harmony/keyboard_controller/src/main/ets/Logger.ts +45 -45
- package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerPackage.ets +49 -49
- package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerTurboModule.ts +405 -210
- package/harmony/keyboard_controller/src/main/ets/RNStatusBarManagerCompatTurboModule.ts +107 -98
- package/harmony/keyboard_controller/src/main/ets/Type.ts +41 -41
- 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 -8
- 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 +43 -41
- 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 +2 -0
- 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 +44 -42
- 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 +2 -0
- 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 -177
- 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 +381 -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/react-native-keyboard-controller.podspec +0 -61
|
@@ -1,210 +1,405 @@
|
|
|
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 { TurboModule } from "@rnoh/react-native-openharmony/ts";
|
|
8
|
-
import common from '@ohos.app.ability.common';
|
|
9
|
-
import window from '@ohos.window';
|
|
10
|
-
import inputMethod from '@ohos.inputMethod';
|
|
11
|
-
import Logger from './Logger';
|
|
12
|
-
import { KeyboardControllerEventName, KeyboardStatusType } from './Type';
|
|
13
|
-
import { BusinessError } from '@kit.BasicServicesKit';
|
|
14
|
-
import { JSON } from '@kit.ArkTS';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 { TurboModule } from "@rnoh/react-native-openharmony/ts";
|
|
8
|
+
import common from '@ohos.app.ability.common';
|
|
9
|
+
import window from '@ohos.window';
|
|
10
|
+
import inputMethod from '@ohos.inputMethod';
|
|
11
|
+
import Logger from './Logger';
|
|
12
|
+
import { KeyboardControllerEventName, KeyboardStatusType } from './Type';
|
|
13
|
+
import { BusinessError, deviceInfo } from '@kit.BasicServicesKit';
|
|
14
|
+
import { JSON } from '@kit.ArkTS';
|
|
15
|
+
import { ConfigurationConstant } from '@kit.AbilityKit';
|
|
16
|
+
import { KeyboardAvoidMode } from '@kit.ArkUI';
|
|
17
|
+
|
|
18
|
+
declare function px2vp(px: number): number;
|
|
19
|
+
|
|
20
|
+
const NATIVE_KEYBOARD_WILL_EVENT_MIN_API = 20;
|
|
21
|
+
const LEGACY_KEYBOARD_ANIMATION_DURATION = 150;
|
|
22
|
+
const WINDOW_SESSION_MANAGER = 'SystemCapability.Window.SessionManager';
|
|
23
|
+
|
|
24
|
+
interface RNKeyboardControllerSpec {
|
|
25
|
+
getConstants(): {};
|
|
26
|
+
|
|
27
|
+
setInputMode(mode: number): void;
|
|
28
|
+
|
|
29
|
+
setDefaultMode(): void;
|
|
30
|
+
|
|
31
|
+
dismiss(): void;
|
|
32
|
+
|
|
33
|
+
setFocusTo(direction: string): void;
|
|
34
|
+
|
|
35
|
+
addListener(eventName: string, listener: (event) => void,): void;
|
|
36
|
+
|
|
37
|
+
removeListeners(count: number): void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class RNKeyboardControllerTurboModule extends TurboModule implements RNKeyboardControllerSpec {
|
|
41
|
+
private context: common.UIAbilityContext;
|
|
42
|
+
private keyboardHeight: number = 0;
|
|
43
|
+
private keyboardStatus: KeyboardStatusType = KeyboardStatusType.HIDE;
|
|
44
|
+
private listenerCount: number = 0;
|
|
45
|
+
private currentWindow: window.Window | undefined = undefined;
|
|
46
|
+
private enabled: boolean = false;
|
|
47
|
+
private cleanUpCallbacks: (() => void)[] = [];
|
|
48
|
+
private previousKeyboardAvoidMode: KeyboardAvoidMode | undefined = undefined;
|
|
49
|
+
private keyboardAvoidModeControlled: boolean = false;
|
|
50
|
+
private supportsNativeWillEvents: boolean = false;
|
|
51
|
+
private keyboardHeightListenerRegistered: boolean = false;
|
|
52
|
+
private nativeWillShowListenerRegistered: boolean = false;
|
|
53
|
+
private nativeWillHideListenerRegistered: boolean = false;
|
|
54
|
+
private observerGeneration: number = 0;
|
|
55
|
+
private focusedInputTarget: number = -1;
|
|
56
|
+
private focusedInputKeyboardType: string = 'default';
|
|
57
|
+
private currentKeyboardAnimationDuration: number = 0;
|
|
58
|
+
|
|
59
|
+
private readonly keyboardHeightChangeHandler = (_data: number): void => {
|
|
60
|
+
if (!this.enabled || !this.currentWindow) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const keyboardAvoidArea = this.currentWindow.getWindowAvoidArea(window.AvoidAreaType.TYPE_KEYBOARD).bottomRect;
|
|
65
|
+
const height = Math.ceil(px2vp(keyboardAvoidArea.height));
|
|
66
|
+
if (this.keyboardHeight === height) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const wasVisible = this.keyboardHeight > 0;
|
|
70
|
+
const isVisible = height > 0;
|
|
71
|
+
this.keyboardStatus = height > 0 ? KeyboardStatusType.SHOW : KeyboardStatusType.HIDE;
|
|
72
|
+
this.keyboardHeight = height;
|
|
73
|
+
if (wasVisible !== isVisible) {
|
|
74
|
+
this.keyboardControllerEventHandle(this.keyboardStatus, height);
|
|
75
|
+
}
|
|
76
|
+
this.ctx.rnInstance.postMessageToCpp('keyboardHeightChange', height);
|
|
77
|
+
} catch (exception) {
|
|
78
|
+
Logger.error('Failed to handle keyboard height change. Cause: ' + JSON.stringify(exception));
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
private readonly keyboardWillShowHandler = (info: window.KeyboardInfo): void => {
|
|
83
|
+
if (!this.enabled) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const duration = this.getKeyboardDurationFromKeyboardInfo(info);
|
|
87
|
+
this.currentKeyboardAnimationDuration = duration;
|
|
88
|
+
const height = Math.ceil(px2vp(info.endRect.height));
|
|
89
|
+
this.emitKeyboardEvent(KeyboardControllerEventName.KEYBOARD_WILL_SHOW, height, duration);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
private readonly keyboardWillHideHandler = (info: window.KeyboardInfo): void => {
|
|
93
|
+
if (!this.enabled) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const duration = this.getKeyboardDurationFromKeyboardInfo(info);
|
|
97
|
+
this.currentKeyboardAnimationDuration = duration;
|
|
98
|
+
this.emitKeyboardEvent(KeyboardControllerEventName.KEYBOARD_WILL_HIDE, 0, duration);
|
|
99
|
+
};
|
|
100
|
+
constructor(ctx) {
|
|
101
|
+
super(ctx);
|
|
102
|
+
this.context = this.ctx.uiAbilityContext;
|
|
103
|
+
// 订阅 C++ 层发来的 focusDidSet 消息
|
|
104
|
+
this.cleanUpCallbacks.push(
|
|
105
|
+
this.ctx.rnInstance.cppEventEmitter.subscribe("focusDidSet", (payload: { current: number, count: number }) => {
|
|
106
|
+
Logger.info('###turboModule received focusDidSet from cpp', String(payload.current) + ',' + String(payload.count));
|
|
107
|
+
if (this.listenerCount > 0) {
|
|
108
|
+
this.ctx.rnInstance.emitDeviceEvent(KeyboardControllerEventName.FOCUS_DID_SET, {
|
|
109
|
+
current: payload.current,
|
|
110
|
+
count: payload.count
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
this.cleanUpCallbacks.push(
|
|
117
|
+
this.ctx.rnInstance.cppEventEmitter.subscribe(
|
|
118
|
+
'focusedInputChanged',
|
|
119
|
+
(payload: { target: number, type: string }) => {
|
|
120
|
+
this.focusedInputTarget = payload.target;
|
|
121
|
+
this.focusedInputKeyboardType = payload.type;
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
readonly getConstants: () => {};
|
|
128
|
+
|
|
129
|
+
// set mode
|
|
130
|
+
setInputMode(mode: number): void {
|
|
131
|
+
Logger.info('harmonyOS not support setInputMode')
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
setDefaultMode(): void {
|
|
135
|
+
Logger.info('harmonyOS not support setDefaultMode')
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @description 键盘隐藏
|
|
140
|
+
* */
|
|
141
|
+
dismiss(): void {
|
|
142
|
+
let inputMethodController = inputMethod.getController();
|
|
143
|
+
inputMethodController.stopInputSession()
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* @description 键盘隐藏
|
|
148
|
+
* */
|
|
149
|
+
private show(): void {
|
|
150
|
+
let inputMethodController = inputMethod.getController();
|
|
151
|
+
inputMethodController.showSoftKeyboard()
|
|
152
|
+
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
setFocusTo(direction: string): void {
|
|
156
|
+
this.ctx.rnInstance.postMessageToCpp('setFocusTo', direction);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* @description 添加监听键盘事件
|
|
161
|
+
*/
|
|
162
|
+
addListener(eventName: KeyboardControllerEventName) {
|
|
163
|
+
const supportEvents = this.supportListeners();
|
|
164
|
+
if (supportEvents.includes(eventName)) {
|
|
165
|
+
this.listenerCount += 1;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* @description 删除监听事件
|
|
171
|
+
* */
|
|
172
|
+
removeListeners(count: number): void {
|
|
173
|
+
if (count > 0) {
|
|
174
|
+
this.listenerCount = Math.max(0, this.listenerCount - count);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private supportListeners() {
|
|
179
|
+
return [
|
|
180
|
+
KeyboardControllerEventName.KEYBOARD_WILL_SHOW,
|
|
181
|
+
KeyboardControllerEventName.KEYBOARD_DID_SHOW,
|
|
182
|
+
KeyboardControllerEventName.KEYBOARD_WILL_HIDE,
|
|
183
|
+
KeyboardControllerEventName.KEYBOARD_DID_HIDE,
|
|
184
|
+
KeyboardControllerEventName.FOCUS_DID_SET
|
|
185
|
+
];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
private async setWindowSystemBarEnable(statusBarTranslucent: boolean, navigationBarTranslucent: boolean) {
|
|
189
|
+
|
|
190
|
+
let windowInstance: window.Window | undefined = undefined;
|
|
191
|
+
windowInstance = await window.getLastWindow(this.context);
|
|
192
|
+
let systemBarProperty = windowInstance.getWindowSystemBarProperties();
|
|
193
|
+
let newSystemBarProperty: window.SystemBarProperties = {
|
|
194
|
+
...systemBarProperty,
|
|
195
|
+
statusBarColor: statusBarTranslucent ? "#00000000" : systemBarProperty.statusBarColor,
|
|
196
|
+
navigationBarColor: navigationBarTranslucent ? "#00000000" : systemBarProperty.navigationBarColor
|
|
197
|
+
};
|
|
198
|
+
try {
|
|
199
|
+
let promise = windowInstance.setWindowSystemBarProperties(newSystemBarProperty);
|
|
200
|
+
promise.then(() => {
|
|
201
|
+
Logger.info('Succeeded in setting the system bar properties.');
|
|
202
|
+
}).catch((err: BusinessError) => {
|
|
203
|
+
Logger.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`);
|
|
204
|
+
});
|
|
205
|
+
} catch (exception) {
|
|
206
|
+
Logger.error(`Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
private keyboardControllerEventHandle(keyboardStatus: number, height: number) {
|
|
211
|
+
if (!this.enabled) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const legacyDuration = deviceInfo.sdkApiVersion < NATIVE_KEYBOARD_WILL_EVENT_MIN_API
|
|
216
|
+
? LEGACY_KEYBOARD_ANIMATION_DURATION
|
|
217
|
+
: 0;
|
|
218
|
+
const duration = this.supportsNativeWillEvents ? this.currentKeyboardAnimationDuration : legacyDuration;
|
|
219
|
+
if (keyboardStatus === KeyboardStatusType.HIDE) {
|
|
220
|
+
if (!this.supportsNativeWillEvents) {
|
|
221
|
+
this.emitKeyboardEvent(KeyboardControllerEventName.KEYBOARD_WILL_HIDE, 0, duration);
|
|
222
|
+
}
|
|
223
|
+
this.emitKeyboardEvent(KeyboardControllerEventName.KEYBOARD_DID_HIDE, 0, duration);
|
|
224
|
+
this.currentKeyboardAnimationDuration = 0;
|
|
225
|
+
}
|
|
226
|
+
if (keyboardStatus === KeyboardStatusType.SHOW) {
|
|
227
|
+
if (!this.supportsNativeWillEvents) {
|
|
228
|
+
this.emitKeyboardEvent(KeyboardControllerEventName.KEYBOARD_WILL_SHOW, height, duration);
|
|
229
|
+
}
|
|
230
|
+
this.emitKeyboardEvent(KeyboardControllerEventName.KEYBOARD_DID_SHOW, height, duration);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
private emitKeyboardEvent(eventName: KeyboardControllerEventName, height: number, duration: number): void {
|
|
235
|
+
if (!this.enabled || this.listenerCount <= 0) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
this.ctx.rnInstance.emitDeviceEvent(eventName, {
|
|
239
|
+
height,
|
|
240
|
+
tag: this.focusedInputTarget,
|
|
241
|
+
duration,
|
|
242
|
+
timestamp: new Date().getTime(),
|
|
243
|
+
target: this.focusedInputTarget,
|
|
244
|
+
type: this.focusedInputKeyboardType,
|
|
245
|
+
appearance: this.getKeyboardAppearance(),
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
private async startKeyboardObserver(
|
|
250
|
+
open: boolean,
|
|
251
|
+
disableSystemKeyboardAvoidance: boolean = false
|
|
252
|
+
): Promise<void> {
|
|
253
|
+
const generation = ++this.observerGeneration;
|
|
254
|
+
this.enabled = open;
|
|
255
|
+
if (!open) {
|
|
256
|
+
this.stopKeyboardObserver();
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
let currentWindow: window.Window;
|
|
261
|
+
try {
|
|
262
|
+
currentWindow = await window.getLastWindow(this.context);
|
|
263
|
+
} catch (exception) {
|
|
264
|
+
Logger.error('Failed to get the current window. Cause: ' + JSON.stringify(exception));
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (!this.enabled || generation !== this.observerGeneration) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
this.currentWindow = currentWindow;
|
|
272
|
+
this.setKeyboardAvoidModeEnabled(disableSystemKeyboardAvoidance);
|
|
273
|
+
this.supportsNativeWillEvents =
|
|
274
|
+
deviceInfo.sdkApiVersion >= NATIVE_KEYBOARD_WILL_EVENT_MIN_API &&
|
|
275
|
+
canIUse(WINDOW_SESSION_MANAGER);
|
|
276
|
+
this.registerKeyboardHeightListener();
|
|
277
|
+
this.registerNativeWillListeners();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
private stopKeyboardObserver(): void {
|
|
281
|
+
this.unregisterNativeWillListeners();
|
|
282
|
+
if (this.currentWindow && this.keyboardHeightListenerRegistered) {
|
|
283
|
+
try {
|
|
284
|
+
this.currentWindow.off('keyboardHeightChange', this.keyboardHeightChangeHandler);
|
|
285
|
+
} catch (exception) {
|
|
286
|
+
Logger.error('Failed to close keyboardHeightChange. Cause: ' + JSON.stringify(exception));
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
this.keyboardHeightListenerRegistered = false;
|
|
290
|
+
this.setKeyboardAvoidModeEnabled(false);
|
|
291
|
+
this.currentWindow = undefined;
|
|
292
|
+
this.keyboardHeight = 0;
|
|
293
|
+
this.keyboardStatus = KeyboardStatusType.HIDE;
|
|
294
|
+
this.currentKeyboardAnimationDuration = 0;
|
|
295
|
+
this.supportsNativeWillEvents = false;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
private registerKeyboardHeightListener(): void {
|
|
299
|
+
if (!this.currentWindow || this.keyboardHeightListenerRegistered) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
try {
|
|
303
|
+
this.currentWindow.on('keyboardHeightChange', this.keyboardHeightChangeHandler);
|
|
304
|
+
this.keyboardHeightListenerRegistered = true;
|
|
305
|
+
} catch (exception) {
|
|
306
|
+
Logger.error('Failed to enable keyboardHeightChange. Cause: ' + JSON.stringify(exception));
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
private registerNativeWillListeners(): void {
|
|
311
|
+
if (!this.currentWindow || !this.supportsNativeWillEvents ||
|
|
312
|
+
this.nativeWillShowListenerRegistered || this.nativeWillHideListenerRegistered) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
try {
|
|
317
|
+
this.currentWindow.on('keyboardWillShow', this.keyboardWillShowHandler);
|
|
318
|
+
this.nativeWillShowListenerRegistered = true;
|
|
319
|
+
this.currentWindow.on('keyboardWillHide', this.keyboardWillHideHandler);
|
|
320
|
+
this.nativeWillHideListenerRegistered = true;
|
|
321
|
+
} catch (exception) {
|
|
322
|
+
this.unregisterNativeWillListeners();
|
|
323
|
+
this.supportsNativeWillEvents = false;
|
|
324
|
+
Logger.error('Native keyboard will events unavailable; using confirmed-state fallback. Cause: ' +
|
|
325
|
+
JSON.stringify(exception));
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
private unregisterNativeWillListeners(): void {
|
|
330
|
+
if (!this.currentWindow) {
|
|
331
|
+
this.nativeWillShowListenerRegistered = false;
|
|
332
|
+
this.nativeWillHideListenerRegistered = false;
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
if (this.nativeWillShowListenerRegistered) {
|
|
336
|
+
try {
|
|
337
|
+
this.currentWindow.off('keyboardWillShow', this.keyboardWillShowHandler);
|
|
338
|
+
} catch (exception) {
|
|
339
|
+
Logger.error('Failed to close keyboardWillShow. Cause: ' + JSON.stringify(exception));
|
|
340
|
+
}
|
|
341
|
+
this.nativeWillShowListenerRegistered = false;
|
|
342
|
+
}
|
|
343
|
+
if (this.nativeWillHideListenerRegistered) {
|
|
344
|
+
try {
|
|
345
|
+
this.currentWindow.off('keyboardWillHide', this.keyboardWillHideHandler);
|
|
346
|
+
} catch (exception) {
|
|
347
|
+
Logger.error('Failed to close keyboardWillHide. Cause: ' + JSON.stringify(exception));
|
|
348
|
+
}
|
|
349
|
+
this.nativeWillHideListenerRegistered = false;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
private getKeyboardDurationFromKeyboardInfo(info: window.KeyboardInfo): number {
|
|
354
|
+
if (info.animated === false) {
|
|
355
|
+
return 0;
|
|
356
|
+
}
|
|
357
|
+
const duration = info.config?.duration;
|
|
358
|
+
return typeof duration === 'number' && duration >= 0 ? duration : 0;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
__onDestroy__(): void {
|
|
362
|
+
this.enabled = false;
|
|
363
|
+
++this.observerGeneration;
|
|
364
|
+
this.stopKeyboardObserver();
|
|
365
|
+
this.cleanUpCallbacks.forEach((callback) => callback());
|
|
366
|
+
this.cleanUpCallbacks = [];
|
|
367
|
+
super.__onDestroy__();
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
private setKeyboardAvoidModeEnabled(enabled: boolean): void {
|
|
371
|
+
if (!this.currentWindow) {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
try {
|
|
375
|
+
const uiContext = this.currentWindow.getUIContext();
|
|
376
|
+
if (enabled) {
|
|
377
|
+
if (!this.keyboardAvoidModeControlled) {
|
|
378
|
+
this.previousKeyboardAvoidMode = uiContext.getKeyboardAvoidMode();
|
|
379
|
+
this.keyboardAvoidModeControlled = true;
|
|
380
|
+
}
|
|
381
|
+
uiContext.setKeyboardAvoidMode(KeyboardAvoidMode.NONE);
|
|
382
|
+
} else if (this.keyboardAvoidModeControlled) {
|
|
383
|
+
if (this.previousKeyboardAvoidMode !== undefined) {
|
|
384
|
+
uiContext.setKeyboardAvoidMode(this.previousKeyboardAvoidMode);
|
|
385
|
+
}
|
|
386
|
+
this.previousKeyboardAvoidMode = undefined;
|
|
387
|
+
this.keyboardAvoidModeControlled = false;
|
|
388
|
+
}
|
|
389
|
+
} catch (exception) {
|
|
390
|
+
Logger.error('Failed to update KeyboardAvoidMode. Cause: ' + JSON.stringify(exception));
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
private getKeyboardAppearance(): string {
|
|
395
|
+
const colorMode = this.context.config.colorMode;
|
|
396
|
+
if (colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK) {
|
|
397
|
+
return 'dark';
|
|
398
|
+
}
|
|
399
|
+
else if (colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT) {
|
|
400
|
+
return 'light';
|
|
401
|
+
}
|
|
402
|
+
return 'default';
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
}
|