@ionic-native-ohos/keyboard 5.36.0

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 ADDED
@@ -0,0 +1,23 @@
1
+ Copyright 2020-present Ionic
2
+ https://ionic.io
3
+
4
+ MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/OAT.xml ADDED
@@ -0,0 +1,75 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ The MIT License (MIT)
4
+ Copyright (C) 2026 Huawei Device Co., Ltd and iSoftStone Information Technology(Group)Co.,Ltd.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+ -->
16
+
17
+ <configuration>
18
+ <oatconfig>
19
+ <licensefile></licensefile>
20
+ <policylist>
21
+ <policy name="projectPolicy" desc="">
22
+ <!--policyitem type="compatibility" name="GPL-2.0+" path="abc/.*" desc="Process that runs independently, invoked by the X process."/-->
23
+ <policyitem type="license" name="MIT" path=".*" desc="MIT"/>
24
+ <policyitem type="copyright" name="Copyright (C) 2026 Huawei Device Co., Ltd and iSoftStone Information Technology(Group)Co.,Ltd."
25
+ path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter"
26
+ desc="Copyright (C) 2026 Huawei Device Co., Ltd and iSoftStone Information Technology(Group)Co.,Ltd."/>
27
+ </policy>
28
+ </policylist>
29
+ <filefilterlist>
30
+ <filefilter name="defaultFilter" desc="Files not to check">
31
+ <!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
32
+ <!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
33
+ <!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
34
+ </filefilter>
35
+ <filefilter name="defaultPolicyFilter" desc="Filters for compatibility,license header policies">
36
+ <filteritem type="filepath" name="www/keyboard.js" desc="引用原插件代码"/>
37
+ </filefilter>
38
+ <filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies">
39
+ <filteritem type="filepath" name="www/keyboard.js" desc="引用原插件代码"/>
40
+ </filefilter>
41
+ <filefilter name="licenseFileNamePolicyFilter" desc="Filters for LICENSE file policies">
42
+ <!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
43
+ <!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
44
+ <!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
45
+ </filefilter>
46
+ <filefilter name="readmeFileNamePolicyFilter" desc="Filters for README file policies">
47
+ <!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
48
+ <!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
49
+ <!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
50
+ </filefilter>
51
+ <filefilter name="readmeOpenSourcefileNamePolicyFilter" desc="Filters for README.OpenSource file policies">
52
+ <!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
53
+ <!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
54
+ <!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
55
+ </filefilter>
56
+ <filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies">
57
+ <!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
58
+ <!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
59
+ <!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
60
+ </filefilter>
61
+
62
+ </filefilterlist>
63
+ <licensematcherlist>
64
+ <!--licensematcher name="uvwxyz License" desc="If the scanning result is InvalidLicense, you can define matching rules here. Note that quotation marks must be escaped.">
65
+ <licensetext name="
66
+ uvwxyz license textA xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
67
+ " desc=""/>
68
+ <licensetext name="
69
+ uvwxyz license textB xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
70
+ " desc=""/>
71
+ </licensematcher-->
72
+ </licensematcherlist>
73
+ </oatconfig>
74
+ </configuration>
75
+
package/README.en.md ADDED
@@ -0,0 +1,257 @@
1
+ # <center>@ionic-native/keyboard</center>
2
+ [![zh-CN](https://img.shields.io/badge/lang-中文-blue.svg)](README.md)
3
+ [![en](https://img.shields.io/badge/lang-English-blue.svg)](README.en.md)
4
+
5
+ This project is developed based on [@ionic-native/keyboard@5.36.0](https://www.npmjs.com/package/@ionic-native/keyboard/v/5.36.0).
6
+
7
+ ## Introduction
8
+
9
+ `@ionic-native/keyboard` is a core plugin in the OpenHarmony Cordova ecosystem. It provides keyboard display and visibility control, and supports listening to events when the keyboard shows and hides, offering device-differentiated adaptation for cross-platform app development. It is compatible with Android, iOS, and OpenHarmony platforms, providing unified keyboard control capabilities for cross-platform development. This document mainly describes usage on the OpenHarmony system.
10
+
11
+ The `@ionic-native/keyboard` API provides keyboard show/hide capabilities and supports listening to keyboard events.
12
+
13
+ ## Supported Platforms
14
+
15
+ - **OpenHarmony**: 5.0+
16
+
17
+ ## Installation
18
+
19
+ You can quickly install the plugin through command-line installation or manual integration. Installation from the npm repository is supported.
20
+
21
+ ### Command-line Installation (Recommended)
22
+
23
+ Install hionic CLI:
24
+
25
+ ```bash
26
+ npm install -g hionic
27
+ ```
28
+
29
+ Choose **one of the following two methods** only.
30
+
31
+ npm installation:
32
+
33
+ ```bash
34
+ # Install plugin
35
+ npm install @ionic-native/keyboard
36
+
37
+ # Sync plugin
38
+ hionic sync
39
+ ```
40
+
41
+ hionic CLI installation:
42
+
43
+ ```bash
44
+ hionic plugin add @ionic-native/keyboard
45
+ ```
46
+
47
+ ### Manual Integration
48
+
49
+ #### 1. Add Plugin Configuration
50
+
51
+ According to the `config-json` item in `plugin.xml`, locate the `config.xml` file in the `entry` module and add configuration according to the `param` tag:
52
+
53
+ ```xml
54
+ <feature name="Keyboard">
55
+ <param name="harmony-package" value="Keyboard" />
56
+ <param name="onload" value="true" />
57
+ </feature>
58
+ ```
59
+
60
+ #### 2. Update CMake Configuration
61
+
62
+ According to the `CMakeLists` item in `plugin.xml`, locate module `cordova`. The path is the `CMakeLists.txt` file specified by the `target` field. Add `add_library`:
63
+
64
+ ```
65
+ add_library(cordova SHARED
66
+ // ...
67
+ Keyboard/CDVIonicKeyboard.cpp
68
+ // ...
69
+ )
70
+ ```
71
+
72
+ #### 3. Copy Source Files
73
+
74
+ According to the `source-file` item in `plugin.xml`, copy source code from the `src` path into the directory specified by `target-dir` in the `cordova` module:
75
+
76
+ Copy `CDVIonicKeyboard.h` and `CDVIonicKeyboard.cpp` from `src/main/cpp/Keyboard` in the source code to `src/main/cpp/Keyboard` in the cordova module.
77
+
78
+ Copy `KeyboardAction.ets` from `src/main/ets/components/Keyboard` in the source code to `src/main/ets/components/Keyboard` in the cordova module.
79
+
80
+ #### 4. Add ArkTS Configuration
81
+
82
+ In the `build-profile.json5` file of the `cordova` module, add the ets path copied in step 3 to the `buildOption/arkOptions/runtimeOnly/sources` configuration array:
83
+
84
+ ```
85
+ "buildOption":{
86
+ "arkOptions": {
87
+ "runtimeOnly": {
88
+ "sources": [
89
+ // ...
90
+ "./src/main/ets/components/Keyboard/KeyboardAction.ets"
91
+ // ...
92
+ ]
93
+ }
94
+ }
95
+ }
96
+ ```
97
+
98
+ ## Uninstallation
99
+
100
+ ```bash
101
+ # Uninstall via hionic CLI
102
+ hionic plugin remove @ionic-native/keyboard
103
+ ```
104
+
105
+ ## Constraints and Limitations
106
+
107
+ ### Compatibility
108
+
109
+ Tested successfully on the following version:
110
+
111
+ 1. SDK: 5.0.5(17); IDE: DevEco Studio: 6.0.0; ROM: 5.1.0.150;
112
+
113
+ ## Usage Examples
114
+
115
+ ### Example 1: Show keyboard
116
+
117
+ Implements keyboard show functionality.
118
+
119
+ ```javascript
120
+ import { Keyboard } from '@ionic-native/keyboard';
121
+
122
+ await Keyboard.show();
123
+ ```
124
+
125
+ ### Example 2: Hide keyboard
126
+
127
+ Implements keyboard hide functionality.
128
+
129
+ ```javascript
130
+ await Keyboard.hide();
131
+ ```
132
+
133
+ ### Example 3: Listen for keyboard-will-show event
134
+
135
+ Listen for keyboard about-to-show event. Supported from API20.
136
+
137
+ ```javascript
138
+ await Keyboard.addListener('keyboardWillShow', (info) => {
139
+ console.log('Keyboard height:', info.keyboardHeight);
140
+ });
141
+ ```
142
+
143
+ ### Example 4: Listen for keyboard-did-show event
144
+
145
+ Listen for keyboard shown event. Supported from API18.
146
+
147
+ ```javascript
148
+ await Keyboard.addListener('keyboardDidShow', (info) => {
149
+ console.log('Keyboard height:', info.keyboardHeight);
150
+ });
151
+ ```
152
+
153
+ ### Example 5: Listen for keyboard-will-hide event
154
+
155
+ Listen for keyboard about-to-hide event. Supported from API20.
156
+
157
+ ```javascript
158
+ await Keyboard.addListener('keyboardWillHide', () => {
159
+ console.log('Keyboard will hide');
160
+ });
161
+ ```
162
+
163
+ ### Example 6: Listen for keyboard-did-hide event
164
+
165
+ Listen for keyboard hidden event. Supported from API18.
166
+
167
+ ```javascript
168
+ await Keyboard.addListener('keyboardDidHide', () => {
169
+ console.log('Keyboard hidden');
170
+ });
171
+ ```
172
+
173
+ ### Example 7: Remove all listeners
174
+
175
+ Remove all native listeners for this plugin.
176
+
177
+ ```javascript
178
+ await Keyboard.removeAllListeners();
179
+ ```
180
+
181
+ ## Usage Guide
182
+
183
+ ### API Methods
184
+
185
+ | Method Name | Request Parameters | Return Type | Description | Notes |
186
+ |-------|---------|---------|------|------|
187
+ | `show()` | None | `Promise<void>` | Show keyboard | |
188
+ | `hide()` | None | `Promise<void>` | Hide keyboard | |
189
+ | `addListener(eventName: 'keyboardWillShow', ...)` | eventName: string, listenerFunc: (info: KeyboardInfo) => void | Promise&lt;[PluginListenerHandle](#pluginlistenerhandle)&gt; | Listen for keyboard-will-show event | Supported from API20 |
190
+ | `addListener(eventName: 'keyboardDidShow', ...)` | eventName: string, listenerFunc: (info: KeyboardInfo) => void | Promise&lt;[PluginListenerHandle](#pluginlistenerhandle)&gt; | Listen for keyboard-did-show event | Supported from API18 |
191
+ | `addListener(eventName: 'keyboardWillHide', ...)` | eventName: string, listenerFunc: () => void | Promise&lt;[PluginListenerHandle](#pluginlistenerhandle)&gt; | Listen for keyboard-will-hide event | Supported from API20 |
192
+ | `addListener(eventName: 'keyboardDidHide', ...)` | eventName: string, listenerFunc: () => void | Promise&lt;[PluginListenerHandle](#pluginlistenerhandle)&gt; | Listen for keyboard-did-hide event | Supported from API18 |
193
+ | `removeAllListeners()` | None | `Promise<void>` | Remove all native listeners for this plugin | |
194
+
195
+ ### Data Structures
196
+
197
+ #### PluginListenerHandle
198
+
199
+ | Prop | Type |
200
+ |------|------|
201
+ | **`remove`** | `() => Promise<void>` |
202
+
203
+ #### KeyboardInfo
204
+
205
+ | Prop | Type | Description |
206
+ |------|------|-------------|
207
+ | **`keyboardHeight`** | `number` | Keyboard height |
208
+
209
+ ### Method Parameter Description
210
+
211
+ #### 1. Show keyboard
212
+
213
+ ```javascript
214
+ Keyboard.show(): Promise<void>;
215
+ ```
216
+
217
+ #### 2. Hide keyboard
218
+
219
+ ```javascript
220
+ Keyboard.hide(): Promise<void>;
221
+ ```
222
+
223
+ #### 3. Add event listener
224
+
225
+ ```javascript
226
+ Keyboard.addListener(
227
+ eventName: string, // Event name: 'keyboardWillShow' | 'keyboardDidShow' | 'keyboardWillHide' | 'keyboardDidHide'
228
+ listenerFunc: (info?: KeyboardInfo) => void // Listener callback
229
+ ): Promise<PluginListenerHandle>;
230
+ ```
231
+
232
+ #### 4. Remove all listeners
233
+
234
+ ```javascript
235
+ Keyboard.removeAllListeners(): Promise<void>;
236
+ ```
237
+
238
+ ## Directory Structure
239
+
240
+ ```
241
+ |---- Directory
242
+ | |---- src/main # Plugin implementation code
243
+ | |---- cpp # C++ code
244
+ | |---- ets # ArkTS code
245
+ | |---- www # Web-side code
246
+ | |---- README.md # Documentation
247
+ | |---- package.json # Configuration file
248
+ | |---- plugin.xml # Plugin configuration file
249
+ ```
250
+
251
+ ## Contributing
252
+
253
+ If you find any issues during usage, you can submit an [Issue](https://gitcode.com/CPF-Ionic/ionic-native-keyboard/issues). You are also very welcome to submit a [PR](https://gitcode.com/CPF-Ionic/ionic-native-keyboard/pulls) for co-development.
254
+
255
+ ## License
256
+
257
+ This plugin is open-sourced under the **Apache License 2.0**. See the [LICENSE](./LICENSE) file for details.
package/README.md ADDED
@@ -0,0 +1,254 @@
1
+ # <center>@ionic-native/keyboard</center>
2
+ [![zh-CN](https://img.shields.io/badge/lang-中文-blue.svg)](README.md)
3
+ [![en](https://img.shields.io/badge/lang-English-blue.svg)](README.en.md)
4
+
5
+ 本项目基于[@ionic-native/keyboard@5.36.0](https://www.npmjs.com/package/@ionic-native/keyboard/v/5.36.0)开发。
6
+
7
+ ## 简介
8
+
9
+ `@ionic-native/keyboard`是OpenHarmony Cordova生态系统中的核心插件,提供键盘的显示与可见性控制功能,同时支持监听键盘弹出和收起时的事件,为跨平台应用开发提供设备差异化适配能力。兼容Android、iOS 和OpenHarmony平台,为跨平台应用开发提供统一的键盘控制能力。本文档主要说明在OpenHarmony系统中的应用。
10
+
11
+ `@ionic-native/keyboard`API提供键盘的显示与隐藏功能,同时支持监听键盘事件。
12
+
13
+ ## 支持平台
14
+
15
+ - **OpenHarmony**:5.0+
16
+
17
+ ## 下载安装
18
+
19
+ 通过命令行或手动引入即可快速安装插件,支持从npm仓库获取。
20
+
21
+ ### 命令行安装(推荐)
22
+
23
+ 安装hionic CLI:
24
+
25
+ ```bash
26
+ npm install -g hionic
27
+ ```
28
+
29
+ 以下两种方式中**任选其一**即可,无需重复操作:
30
+
31
+ npm安装:
32
+
33
+ ```bash
34
+ # 安装插件
35
+ npm install @ionic-native/keyboard
36
+
37
+ # 同步插件
38
+ hionic sync
39
+ ```
40
+
41
+ hionic CLI安装:
42
+
43
+ ```bash
44
+ hionic plugin add @ionic-native/keyboard
45
+ ```
46
+
47
+ ### 手动引入安装
48
+
49
+ #### 1.添加插件配置
50
+
51
+ 根据 `plugin.xml` 的 `config-json` 项,找到 `entry` 模块中 `config.xml` 文件,并根据 `param` 标签添加配置
52
+ ```xml
53
+ <feature name="Keyboard">
54
+ <param name="harmony-package" value="Keyboard" />
55
+ <param name="onload" value="true" />
56
+ </feature>
57
+ ```
58
+
59
+ #### 2.修改CMake配置
60
+
61
+ 根据 `plugin.xml` 的 `CMakeLists` 项,找到 `cordova` 模块,路径为 `target` 字段的文件 `CMakeLists.txt`,添加 `add_library`
62
+ ```
63
+ add_library(cordova SHARED
64
+ // ...
65
+ Keyboard/CDVIonicKeyboard.cpp
66
+ // ...
67
+ )
68
+ ```
69
+
70
+ #### 3.复制源码文件
71
+
72
+ 根据 `plugin.xml` 的 `source-file` 项,将 `src` 字段的路径代码复制到 `cordova` 模块中 `target-dir` 字段的目录中:
73
+
74
+ 将源码中src/main/cpp/Keyboard目录下的CDVIonicKeyboard.h、CDVIonicKeyboard.cpp文件引入到 cordova模块中src/main/cpp/Keyboard目录下。
75
+
76
+ 将源码中src/main/ets/components/Keyboard目录下的KeyboardAction.ets文件引入到cordova模块中src/main/ets/components/Keyboard目录下。
77
+
78
+ #### 4.添加ArkTS配置
79
+
80
+ 在 `cordova` 模块的 `build-profile.json5` 文件中,`buildOption/arkOptions/runtimeOnly/sources` 配置项数组中加入步骤3中拷贝的ets文件路径:
81
+ ```
82
+ "buildOption":{
83
+ "arkOptions": {
84
+ "runtimeOnly": {
85
+ "sources": [
86
+ // ...
87
+ "./src/main/ets/components/Keyboard/KeyboardAction.ets"
88
+ // ...
89
+ ]
90
+ }
91
+ }
92
+ }
93
+ ```
94
+
95
+ ## 卸载
96
+
97
+ ```bash
98
+ # hionic CLI 卸载
99
+ hionic plugin remove @ionic-native/keyboard
100
+ ```
101
+
102
+ ## 约束与限制
103
+
104
+ ### 兼容性
105
+
106
+ 在以下版本中已测试通过:
107
+
108
+ 1. SDK: 5.0.5(17); IDE: DevEco Studio: 6.0.0; ROM: 5.1.0.150;
109
+
110
+ ## 使用示例
111
+
112
+ ### 示例1:显示键盘
113
+
114
+ 实现显示键盘功能。
115
+
116
+ ```javascript
117
+ import { Keyboard } from '@ionic-native/keyboard';
118
+
119
+ await Keyboard.show();
120
+ ```
121
+
122
+ ### 示例2:隐藏键盘
123
+
124
+ 实现隐藏键盘功能。
125
+
126
+ ```javascript
127
+ await Keyboard.hide();
128
+ ```
129
+
130
+ ### 示例3:监听键盘即将弹出事件
131
+
132
+ 监听键盘即将弹出的事件,从API20之后开始支持。
133
+
134
+ ```javascript
135
+ await Keyboard.addListener('keyboardWillShow', (info) => {
136
+ console.log('键盘高度:', info.keyboardHeight);
137
+ });
138
+ ```
139
+
140
+ ### 示例4:监听键盘弹出事件
141
+
142
+ 监听键盘弹出的事件,从API18之后开始支持。
143
+
144
+ ```javascript
145
+ await Keyboard.addListener('keyboardDidShow', (info) => {
146
+ console.log('键盘高度:', info.keyboardHeight);
147
+ });
148
+ ```
149
+
150
+ ### 示例5:监听键盘即将隐藏事件
151
+
152
+ 监听键盘即将隐藏的事件,从API20之后开始支持。
153
+
154
+ ```javascript
155
+ await Keyboard.addListener('keyboardWillHide', () => {
156
+ console.log('键盘即将隐藏');
157
+ });
158
+ ```
159
+
160
+ ### 示例6:监听键盘隐藏事件
161
+
162
+ 监听键盘隐藏的事件,从API18之后开始支持。
163
+
164
+ ```javascript
165
+ await Keyboard.addListener('keyboardDidHide', () => {
166
+ console.log('键盘已隐藏');
167
+ });
168
+ ```
169
+
170
+ ### 示例7:移除所有监听器
171
+
172
+ 移除该插件的所有原生监听器。
173
+
174
+ ```javascript
175
+ await Keyboard.removeAllListeners();
176
+ ```
177
+
178
+ ## 使用说明
179
+
180
+ ### 接口方法
181
+
182
+ | 方法名 | 请求参数 | 返回类型 | 描述 | 备注 |
183
+ |-------|---------|---------|------|------|
184
+ | `show()` | 无 | `Promise<void>` | 显示键盘 | |
185
+ | `hide()` | 无 | `Promise<void>` | 隐藏键盘 | |
186
+ | `addListener(eventName: 'keyboardWillShow', ...)` | eventName: string, listenerFunc: (info: KeyboardInfo) => void | Promise&lt;[PluginListenerHandle](#pluginlistenerhandle)&gt; | 监听键盘即将弹出的事件 | 从API20之后开始支持 |
187
+ | `addListener(eventName: 'keyboardDidShow', ...)` | eventName: string, listenerFunc: (info: KeyboardInfo) => void | Promise&lt;[PluginListenerHandle](#pluginlistenerhandle)&gt; | 监听键盘弹出的事件 | 从API18之后开始支持 |
188
+ | `addListener(eventName: 'keyboardWillHide', ...)` | eventName: string, listenerFunc: () => void | Promise&lt;[PluginListenerHandle](#pluginlistenerhandle)&gt; | 监听键盘即将隐藏的事件 | 从API20之后开始支持 |
189
+ | `addListener(eventName: 'keyboardDidHide', ...)` | eventName: string, listenerFunc: () => void | Promise&lt;[PluginListenerHandle](#pluginlistenerhandle)&gt; | 监听键盘隐藏的事件 | 从API18之后开始支持 |
190
+ | `removeAllListeners()` | 无 | `Promise<void>` | 移除该插件的所有原生监听器 | |
191
+
192
+ ### 数据结构
193
+
194
+ #### PluginListenerHandle
195
+
196
+ | Prop | Type |
197
+ |------|------|
198
+ | **`remove`** | `() => Promise<void>` |
199
+
200
+ #### KeyboardInfo
201
+
202
+ | Prop | Type | Description |
203
+ |------|------|-------------|
204
+ | **`keyboardHeight`** | `number` | 键盘的高度 |
205
+
206
+ ### 方法参数说明
207
+
208
+ #### 1. 显示键盘
209
+
210
+ ```javascript
211
+ Keyboard.show(): Promise<void>;
212
+ ```
213
+
214
+ #### 2. 隐藏键盘
215
+
216
+ ```javascript
217
+ Keyboard.hide(): Promise<void>;
218
+ ```
219
+
220
+ #### 3. 添加事件监听器
221
+
222
+ ```javascript
223
+ Keyboard.addListener(
224
+ eventName: string, // 事件名称:'keyboardWillShow' | 'keyboardDidShow' | 'keyboardWillHide' | 'keyboardDidHide'
225
+ listenerFunc: (info?: KeyboardInfo) => void // 监听回调函数
226
+ ): Promise<PluginListenerHandle>;
227
+ ```
228
+
229
+ #### 4. 移除所有监听器
230
+
231
+ ```javascript
232
+ Keyboard.removeAllListeners(): Promise<void>;
233
+ ```
234
+
235
+ ## 目录结构
236
+
237
+ ```
238
+ |---- 目录
239
+ | |---- src/main # 插件的实现代码
240
+ | |---- cpp # C++ 代码
241
+ | |---- ets # ArkTS 代码
242
+ | |---- www # Web 侧代码
243
+ | |---- README.md # 说明文档
244
+ | |---- package.json # 配置文件
245
+ | |---- plugin.xml # 插件配置文件
246
+ ```
247
+
248
+ ## 贡献代码
249
+
250
+ 使用过程中发现任何问题都可以提[Issue](https://gitcode.com/CPF-Ionic/ionic-native-keyboard/issues),当然,也非常欢迎发[PR](https://gitcode.com/CPF-Ionic/ionic-native-keyboard/pulls)共建。
251
+
252
+ ## 许可证
253
+
254
+ 本插件基于**Apache License 2.0**开源,详见[LICENSE](./LICENSE)文件。
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@ionic-native-ohos/keyboard",
3
+ "version": "5.36.0",
4
+ "description": "Ionic Native - Native plugins for ionic apps",
5
+ "cordova": {
6
+ "id": "cordova-keyboard",
7
+ "platforms": [
8
+ "ohos"
9
+ ]
10
+ },
11
+ "repository": "gitcode:CPF-Ionic/ionic-native-keyboard",
12
+ "bugs": "https://gitcode.com/CPF-Ionic/ionic-native-keyboard/issues",
13
+ "keywords": [
14
+ "cordova",
15
+ "keyboard",
16
+ "ecosystem:cordova",
17
+ "cordova-openharmony"
18
+ ],
19
+ "author": " Huawei Device Co., Ltd and iSoftStone Information Technology(Group)Co.,Ltd.",
20
+ "license": "MIT"
21
+ }
package/plugin.xml ADDED
@@ -0,0 +1,50 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ The MIT License (MIT)
4
+ Copyright (C) 2026 Huawei Device Co., Ltd and iSoftStone Information Technology(Group)Co.,Ltd.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+ -->
16
+ <plugin
17
+ id="cordova-keyboard"
18
+ version="5.36.0">
19
+ <name>@ionic-native/keyboard</name>
20
+ <description>Cordova Keyboard Plugin</description>
21
+ <license>MIT</license>
22
+ <keywords>cordova,insomnia</keywords>
23
+ <repo>https://gitcode.com/CPF-Ionic/ionic-native-keyboard.git</repo>
24
+ <issue>https://gitcode.com/CPF-Ionic/ionic-native-keyboard/issues</issue>
25
+
26
+ <engines>
27
+ <engine name="@cordova-ohos/ohos" version=">=2.0.0" />
28
+ </engines>
29
+
30
+ <platform name="ohos">
31
+ <config-file target="src/main/resources/rawfile/config.xml" parent="/*" modules-targets-name="default">
32
+ <feature name="Keyboard">
33
+ <param name="harmony-package" value="Keyboard" />
34
+ <param name="onload" value="true" />
35
+ </feature>
36
+ </config-file>
37
+
38
+ <CMakeLists target="src/main/cpp/CMakeLists.txt" modules-name="cordova">
39
+ <param target="add_library" value="Keyboard/CDVIonicKeyboard.cpp"/>
40
+ </CMakeLists>
41
+
42
+ <source-file type="h" src="src/main/cpp/Keyboard/CDVIonicKeyboard.h" target-dir="src/main/cpp/Keyboard" modules-name="cordova"/>
43
+ <source-file type="cpp" src="src/main/cpp/Keyboard/CDVIonicKeyboard.cpp" target-dir="src/main/cpp/Keyboard" modules-name="cordova"/>
44
+ <source-file type="ets" src="src/main/ets/components/Keyboard/KeyboardAction.ets" target-dir="src/main/ets/components/Keyboard" modules-name="cordova" runtimeOnly="true"/>
45
+
46
+ <js-module src="www/keyboard.js" name="Keyboard" modules-targets-name="default">
47
+ <clobbers target="cordova.plugins.keyboard" />
48
+ </js-module>
49
+ </platform>
50
+ </plugin>
@@ -0,0 +1,56 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ * Copyright (C) 2026 Huawei Device Co., Ltd and iSoftStone Information Technology(Group)Co.,Ltd.
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ */
15
+
16
+ #include "CDVIonicKeyboard.h"
17
+
18
+ const int CODE_INDEX = 2;
19
+ REGISTER_PLUGIN_CLASS(CDVIonicKeyboard)
20
+ bool CDVIonicKeyboard::execute(const std::string &action, cJSON *args, CallbackContext cbc)
21
+ {
22
+ if (action == "hide") {
23
+ executeArkTs("./Keyboard/KeyboardAction/ShowKeyboard", 0, "", "CDVIonicKeyboard", cbc);
24
+ } else if (action == "show") {
25
+ executeArkTs("./Keyboard/KeyboardAction/ShowKeyboard", 1, "", "CDVIonicKeyboard", cbc);
26
+ } else if (action == "init") {
27
+ m_cbc = cbc;
28
+ executeArkTs("./Keyboard/KeyboardAction/ShowKeyboard", CODE_INDEX, "", "CDVIonicKeyboard", cbc);
29
+ } else if (action == "onArKTsResult") {
30
+ return onArKTsResult(args);
31
+ }
32
+ return true;
33
+ }
34
+
35
+ bool CDVIonicKeyboard::onArKTsResult(cJSON *args)
36
+ {
37
+ cJSON *content = cJSON_GetObjectItem(args, "content");
38
+ std::string action = "";
39
+ if (content != NULL) {
40
+ action = content->valuestring;
41
+ }
42
+
43
+ if (action == "keyboardHeightChange") {
44
+ cJSON *json = cJSON_GetObjectItem(args, "result");
45
+ if (json != NULL && json->type == cJSON_Array) {
46
+ int32_t count = cJSON_GetArraySize(json);
47
+ if (count > 0) {
48
+ std::string ret = cJSON_GetArrayItem(json, 0)->valuestring;
49
+ PluginResult pluginResult(PluginResult::OK, ret);
50
+ pluginResult.setKeepCallback(true);
51
+ m_cbc.sendPluginResult(pluginResult);
52
+ }
53
+ }
54
+ }
55
+ return true;
56
+ }
@@ -0,0 +1,30 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ * Copyright (C) 2026 Huawei Device Co., Ltd and iSoftStone Information Technology(Group)Co.,Ltd.
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ */
15
+
16
+ #ifndef MYAPPLICATION_CDVIONICKEYBOARD_H
17
+ #define MYAPPLICATION_CDVIONICKEYBOARD_H
18
+
19
+ #include "CordovaPlugin.h"
20
+ class CDVIonicKeyboard : public CordovaPlugin {
21
+ CallbackContext m_cbc;
22
+
23
+ public:
24
+ CDVIonicKeyboard() {}
25
+ ~CDVIonicKeyboard() {}
26
+ bool execute(const std::string &action, cJSON *args, CallbackContext cbc) override;
27
+ bool onArKTsResult(cJSON *args);
28
+ };
29
+
30
+ #endif // MYAPPLICATION_CDVIONICKEYBOARD_H
@@ -0,0 +1,62 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ * Copyright (C) 2026 Huawei Device Co., Ltd and iSoftStone Information Technology(Group)Co.,Ltd.
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ */
15
+
16
+ import { ArkTsAttribute, NativeAttribute } from "../PluginGlobal";
17
+ import { inputMethod } from "@kit.IMEKit";
18
+ import { BusinessError } from "@kit.BasicServicesKit";
19
+ import { window } from "@kit.ArkUI";
20
+ import cordova from 'libcordova.so';
21
+
22
+ export function ShowKeyboard(pageIndex: NativeAttribute) {
23
+ if (pageIndex.pageValue == 1) {
24
+ try {
25
+ let textConfig: inputMethod.TextConfig = {
26
+ inputAttribute: {
27
+ textInputType: 0,
28
+ enterKeyType: 1
29
+ }
30
+ };
31
+ inputMethod.getController().attach(true, textConfig, (err: BusinessError) => {
32
+ if (err) {
33
+ console.error(`Failed to attach: ${JSON.stringify(err)}`);
34
+ return;
35
+ }
36
+ console.info('Succeeded in attaching the inputMethod.');
37
+ inputMethod.getController().showTextInput();
38
+ });
39
+ } catch (err) {
40
+ console.error(`Failed to attach: ${JSON.stringify(err)}`);
41
+ }
42
+ }
43
+
44
+ if (pageIndex.pageValue == 0) {
45
+ inputMethod.getController().hideTextInput();
46
+ }
47
+
48
+ if (pageIndex.pageValue == 2) {
49
+ window.getLastWindow(getContext()).then(currentWindow => {
50
+ currentWindow.on('keyboardHeightChange', (height: number) => {
51
+ let keyboardHeight = height;
52
+ if (height > 0) { //键盘显示
53
+ let result: ArkTsAttribute = { content: "keyboardHeightChange", result: ["S" + keyboardHeight] };
54
+ cordova.onArkTsResult(JSON.stringify(result), pageIndex.pageObject, pageIndex.pageWebTag);
55
+ } else { //键盘隐藏
56
+ let result: ArkTsAttribute = { content: "keyboardHeightChange", result: ["H"] };
57
+ cordova.onArkTsResult(JSON.stringify(result), pageIndex.pageObject, pageIndex.pageWebTag);
58
+ }
59
+ });
60
+ });
61
+ }
62
+ }
@@ -0,0 +1,87 @@
1
+ cordova.define("cordova-plugin-ionic-keyboard.keyboard", function(require, exports, module) {
2
+ var argscheck = require('cordova/argscheck'),
3
+ utils = require('cordova/utils'),
4
+ exec = require('cordova/exec'),
5
+ channel = require('cordova/channel');
6
+
7
+ var Keyboard = function () {};
8
+
9
+ Keyboard.fireOnShow = function (height) {
10
+ Keyboard.isVisible = true;
11
+ cordova.fireWindowEvent('keyboardDidShow', {
12
+ 'keyboardHeight': height
13
+ });
14
+
15
+ // To support the keyboardAttach directive listening events
16
+ // inside Ionic's main bundle
17
+ cordova.fireWindowEvent('native.keyboardshow', {
18
+ 'keyboardHeight': height
19
+ });
20
+ };
21
+
22
+ Keyboard.fireOnHide = function () {
23
+ Keyboard.isVisible = false;
24
+ cordova.fireWindowEvent('keyboardDidHide');
25
+
26
+ // To support the keyboardAttach directive listening events
27
+ // inside Ionic's main bundle
28
+ cordova.fireWindowEvent('native.keyboardhide');
29
+ };
30
+
31
+ Keyboard.fireOnHiding = function () {
32
+ cordova.fireWindowEvent('keyboardWillHide');
33
+ };
34
+
35
+ Keyboard.fireOnShowing = function (height) {
36
+ cordova.fireWindowEvent('keyboardWillShow', {
37
+ 'keyboardHeight': height
38
+ });
39
+ };
40
+
41
+ Keyboard.hideFormAccessoryBar = Keyboard.hideKeyboardAccessoryBar = function (hide) {
42
+ console.warn("Keyboard.hideKeyboardAccessoryBar() not supported in Android");
43
+ };
44
+
45
+ Keyboard.hide = function () {
46
+ exec(null, null, "CDVIonicKeyboard", "hide", []);
47
+ };
48
+
49
+ Keyboard.show = function () {
50
+ exec(null, null, "CDVIonicKeyboard", "show", []);
51
+ };
52
+
53
+ Keyboard.disableScroll = function (disable) {
54
+ console.warn("Keyboard.disableScroll() not supported in Android");
55
+ };
56
+
57
+ Keyboard.setResizeMode = function (mode) {
58
+ console.warn("Keyboard.setResizeMode() not supported in Android");
59
+ }
60
+
61
+ Keyboard.setKeyboardStyle = function(style) {
62
+ console.warn("Keyboard.setKeyboardStyle() not supported in Android");
63
+ };
64
+
65
+ channel.onCordovaReady.subscribe(function () {
66
+ exec(success, null, 'CDVIonicKeyboard', 'init', []);
67
+
68
+ function success(msg) {
69
+ var action = msg.charAt(0);
70
+ if (action === 'S') {
71
+ var keyboardHeight = parseInt(msg.substr(1));
72
+ Keyboard.fireOnShowing(keyboardHeight);
73
+ Keyboard.fireOnShow(keyboardHeight);
74
+
75
+ } else if (action === 'H') {
76
+ Keyboard.fireOnHiding();
77
+ Keyboard.fireOnHide();
78
+ }
79
+ }
80
+ });
81
+
82
+
83
+ Keyboard.isVisible = false;
84
+
85
+ module.exports = Keyboard;
86
+
87
+ });