@moodlehq/cordova-plugin-ionic-keyboard 2.2.0-moodle.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/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+
3
+
4
+ ## [2.2.0](https://github.com/ionic-team/cordova-plugin-ionic-keyboard/compare/2.1.3...v2.2.0) (2019-09-03)
5
+
6
+
7
+ ### Features
8
+
9
+ * **android:** add resizeOnFullScreen preference for Android ([#106](https://github.com/ionic-team/cordova-plugin-ionic-keyboard/issues/106)) ([169c73c](https://github.com/ionic-team/cordova-plugin-ionic-keyboard/commit/169c73c227ebb336af6bb3edb3ccfde536913338))
10
+ * **ios:** Added Keyboard.setKeyboardStyle method ([#79](https://github.com/ionic-team/cordova-plugin-ionic-keyboard/issues/79)) ([4c03a7e](https://github.com/ionic-team/cordova-plugin-ionic-keyboard/commit/4c03a7e0ca6821fa823128cc5e7544437932d67c))
11
+ * **ios:** reimplement disableScroll method ([#102](https://github.com/ionic-team/cordova-plugin-ionic-keyboard/issues/102)) ([b33e7a2](https://github.com/ionic-team/cordova-plugin-ionic-keyboard/commit/b33e7a29909e51c7bff95851925f97edd5164cb7))
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * **android:** Avoid conflicts when ionic-plugin-keyboard is installed ([#104](https://github.com/ionic-team/cordova-plugin-ionic-keyboard/issues/104)) ([893dc8e](https://github.com/ionic-team/cordova-plugin-ionic-keyboard/commit/893dc8e230a792b1b7a6d433e5db74a3e1022486))
17
+ * **ios:** respect KeyboardAppearanceDark preference from webview plugin ([#101](https://github.com/ionic-team/cordova-plugin-ionic-keyboard/issues/101)) ([b00e3a9](https://github.com/ionic-team/cordova-plugin-ionic-keyboard/commit/b00e3a92b3f8ecb31e9914d4abda503a332249d0))
18
+ * **ios:** Delay resize until keyboard animation finish ([#81](https://github.com/ionic-team/cordova-plugin-ionic-keyboard/issues/81)) ([d729cbf](https://github.com/ionic-team/cordova-plugin-ionic-keyboard/commit/d729cbf314eba47cb3fdfb56bc2df27305828738))
19
+ * **ios:** Avoid duplicate hide event when user changes field ([#68](https://github.com/ionic-team/cordova-plugin-ionic-keyboard/issues/68)) ([4a0e018](https://github.com/ionic-team/cordova-plugin-ionic-keyboard/commit/4a0e0182822253427e1df12246252798dbe0a496))
20
+
21
+
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # cordova-plugin-ionic-keyboard (fork)
2
+
3
+ This is a fork of `cordova-plugin-ionic-keyboard` by [Moodle HQ](https://moodle.com/). If you are looking for the documentation, you can read the original at [ionic-team/cordova-plugin-ionic-keyboard](hhttps://github.com/ionic-team/cordova-plugin-ionic-keyboard).
4
+
5
+ ## Modifications from the original
6
+
7
+ We created this fork because we needed to include the following modifications in [our mobile application](https://github.com/moodlehq/moodleapp):
8
+
9
+ | PR | Description |
10
+ | -- | ----------- |
11
+ | [#883](https://github.com/ionic-team/cordova-plugin-ionic-keyboard/pull/181) | Fix ion-footer hidden behind keyboard on iOS |
12
+ | - | Port Android implementation from Capacitor plugin |
13
+ | - | Set a CSS variable with the height of the keyboard on iOS |
14
+
15
+ You can see all the changes here: [master...moodlemobile:master](https://github.com/ionic-team/cordova-plugin-ionic-keyboard/compare/master...moodlemobile:master)
16
+
17
+ ## Installation
18
+
19
+ You can install this package using the [original installation instructions](https://github.com/ionic-team/cordova-plugin-ionic-keyboard#installation), but installing this package instead:
20
+
21
+ ```sh
22
+ cordova plugin add @moodlehq/cordova-plugin-ionic-keyboard@2.2.0-moodle.1
23
+ ```
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@moodlehq/cordova-plugin-ionic-keyboard",
3
+ "version": "2.2.0-moodle.1",
4
+ "description": "Moodle's fork of Ionic Keyboard Plugin",
5
+ "scripts": {
6
+ "release": "standard-version -a",
7
+ "pre-release": "standard-version -a -p --skip.changelog=true --skip.tag=true"
8
+ },
9
+ "standard-version": {
10
+ "scripts": {
11
+ "postbump": "sync-cordova-xml2 package.json plugin.xml --output=plugin.xml && git add plugin.xml"
12
+ }
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/moodlemobile/cordova-plugin-ionic-keyboard.git"
17
+ },
18
+ "keywords": [
19
+ "cordova",
20
+ "keyboard",
21
+ "ecosystem:cordova",
22
+ "cordova-ios",
23
+ "cordova-android"
24
+ ],
25
+ "author": "Apache Software Foundation",
26
+ "license": "Apache 2.0",
27
+ "bugs": {
28
+ "url": "https://github.com/moodlemobile/cordova-plugin-ionic-keyboard/issues"
29
+ },
30
+ "homepage": "https://github.com/moodlemobile/cordova-plugin-ionic-keyboard#readme",
31
+ "devDependencies": {
32
+ "standard-version": "^7.0.0",
33
+ "sync-cordova-xml2": "0.0.3"
34
+ }
35
+ }
package/plugin.xml ADDED
@@ -0,0 +1,48 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+
3
+ <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:rim="http://www.blackberry.com/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" id="@moodlehq/cordova-plugin-ionic-keyboard" version="2.2.0-moodle.1">
4
+ <name>cordova-plugin-ionic-keyboard</name>
5
+ <description>Ionic Keyboard Plugin</description>
6
+ <license>Apache 2.0</license>
7
+ <keywords>cordova,keyboard,ecosystem:cordova,cordova-ios,cordova-android</keywords>
8
+ <repo>https://github.com/moodlemobile/cordova-plugin-ionic-keyboard.git</repo>
9
+ <issue>https://github.com/moodlemobile/cordova-plugin-ionic-keyboard/issues</issue>
10
+ <author>Apache Software Foundation</author>
11
+
12
+ <engines>
13
+ <engine name="cordova" version=">=3.2.0"/>
14
+ </engines>
15
+
16
+ <!-- ios -->
17
+ <platform name="ios">
18
+
19
+ <js-module src="www/ios/keyboard.js" name="keyboard">
20
+ <clobbers target="window.Keyboard"/>
21
+ </js-module>
22
+
23
+ <config-file target="config.xml" parent="/*">
24
+ <feature name="CDVIonicKeyboard">
25
+ <param name="ios-package" value="CDVIonicKeyboard" onload="true"/>
26
+ </feature>
27
+ </config-file>
28
+
29
+ <header-file src="src/ios/CDVIonicKeyboard.h"/>
30
+ <source-file src="src/ios/CDVIonicKeyboard.m"/>
31
+ </platform>
32
+
33
+ <!-- android -->
34
+ <platform name="android">
35
+ <js-module src="www/android/keyboard.js" name="keyboard">
36
+ <clobbers target="window.Keyboard"/>
37
+ </js-module>
38
+ <config-file target="config.xml" parent="/*">
39
+ <feature name="CDVIonicKeyboard">
40
+ <param name="android-package" value="io.ionic.keyboard.CDVIonicKeyboard" onload="true"/>
41
+ </feature>
42
+ </config-file>
43
+
44
+ <source-file src="src/android/CDVIonicKeyboard.java" target-dir="src/io/ionic/keyboard"/>
45
+ <source-file src="src/android/Keyboard.java" target-dir="src/io/ionic/keyboard"/>
46
+ </platform>
47
+
48
+ </plugin>
@@ -0,0 +1,92 @@
1
+ package io.ionic.keyboard;
2
+
3
+ import org.apache.cordova.CallbackContext;
4
+ import org.apache.cordova.CordovaInterface;
5
+ import org.apache.cordova.CordovaPlugin;
6
+ import org.apache.cordova.CordovaWebView;
7
+ import org.apache.cordova.PluginResult;
8
+ import org.apache.cordova.PluginResult.Status;
9
+ import org.json.JSONArray;
10
+ import org.json.JSONException;
11
+
12
+ import android.os.Handler;
13
+ import android.os.Looper;
14
+
15
+ public class CDVIonicKeyboard extends CordovaPlugin {
16
+ private Keyboard implementation;
17
+
18
+ public void initialize(CordovaInterface cordova, CordovaWebView webView) {
19
+ super.initialize(cordova, webView);
20
+ }
21
+
22
+ public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
23
+ if ("hide".equals(action)) {
24
+ cordova.getThreadPool().execute(
25
+ () -> {
26
+ if (!implementation.hide()) {
27
+ callbackContext.error("Can't close keyboard, not currently focused");
28
+ } else {
29
+ callbackContext.success(); // Thread-safe.
30
+ }
31
+ }
32
+ );
33
+ return true;
34
+ }
35
+ if ("show".equals(action)) {
36
+ cordova.getThreadPool().execute(
37
+ () ->
38
+ new Handler(Looper.getMainLooper())
39
+ .postDelayed(
40
+ () -> {
41
+ implementation.show();
42
+ callbackContext.success(); // Thread-safe.
43
+ },
44
+ 350
45
+ )
46
+ );
47
+ return true;
48
+ }
49
+ if ("init".equals(action)) {
50
+ cordova.getThreadPool().execute(
51
+ () -> {
52
+ boolean resizeOnFullScreen = preferences.getBoolean("resizeOnFullScreen", false);
53
+ implementation = new Keyboard(cordova.getActivity(), resizeOnFullScreen);
54
+ implementation.setKeyboardEventListener(
55
+ (String event, int size) -> {
56
+ PluginResult result;
57
+ String msg;
58
+ switch (event) {
59
+ case Keyboard.EVENT_KB_WILL_SHOW:
60
+ case Keyboard.EVENT_KB_DID_SHOW:
61
+ msg = "S" + Integer.toString(size);
62
+ result = new PluginResult(PluginResult.Status.OK, msg);
63
+ result.setKeepCallback(true);
64
+ callbackContext.sendPluginResult(result);
65
+ break;
66
+ case Keyboard.EVENT_KB_WILL_HIDE:
67
+ case Keyboard.EVENT_KB_DID_HIDE:
68
+ msg = "H";
69
+ result = new PluginResult(PluginResult.Status.OK, msg);
70
+ result.setKeepCallback(true);
71
+ callbackContext.sendPluginResult(result);
72
+ break;
73
+ }
74
+ }
75
+ );
76
+
77
+ PluginResult dataResult = new PluginResult(PluginResult.Status.OK);
78
+ dataResult.setKeepCallback(true);
79
+ callbackContext.sendPluginResult(dataResult);
80
+ }
81
+ );
82
+ return true;
83
+ }
84
+ return false; // Returning false results in a "MethodNotFound" error.
85
+ }
86
+
87
+ @Override
88
+ public void onDestroy() {
89
+ implementation.setKeyboardEventListener(null);
90
+ }
91
+
92
+ }
@@ -0,0 +1,172 @@
1
+ package io.ionic.keyboard;
2
+
3
+ import android.content.Context;
4
+ import android.graphics.Rect;
5
+ import android.os.Build;
6
+ import android.util.DisplayMetrics;
7
+ import android.util.TypedValue;
8
+ import android.view.View;
9
+ import android.view.Window;
10
+ import android.view.inputmethod.InputMethodManager;
11
+ import android.widget.FrameLayout;
12
+ import androidx.annotation.NonNull;
13
+ import androidx.annotation.Nullable;
14
+ import androidx.appcompat.app.AppCompatActivity;
15
+ import androidx.core.view.ViewCompat;
16
+ import androidx.core.view.WindowInsetsAnimationCompat;
17
+ import androidx.core.view.WindowInsetsCompat;
18
+ import java.util.List;
19
+
20
+ public class Keyboard {
21
+
22
+ interface KeyboardEventListener {
23
+ void onKeyboardEvent(String event, int size);
24
+ }
25
+
26
+ private AppCompatActivity activity;
27
+ private View rootView;
28
+ private int usableHeightPrevious;
29
+ private FrameLayout.LayoutParams frameLayoutParams;
30
+ private View mChildOfContent;
31
+
32
+ public void setKeyboardEventListener(@Nullable KeyboardEventListener keyboardEventListener) {
33
+ this.keyboardEventListener = keyboardEventListener;
34
+ }
35
+
36
+ @Nullable
37
+ private KeyboardEventListener keyboardEventListener;
38
+
39
+ static final String EVENT_KB_WILL_SHOW = "keyboardWillShow";
40
+ static final String EVENT_KB_DID_SHOW = "keyboardDidShow";
41
+ static final String EVENT_KB_WILL_HIDE = "keyboardWillHide";
42
+ static final String EVENT_KB_DID_HIDE = "keyboardDidHide";
43
+
44
+ public Keyboard(AppCompatActivity activity, boolean resizeOnFullScreen) {
45
+ this.activity = activity;
46
+
47
+ //http://stackoverflow.com/a/4737265/1091751 detect if keyboard is showing
48
+ FrameLayout content = activity.getWindow().getDecorView().findViewById(android.R.id.content);
49
+ rootView = content.getRootView();
50
+
51
+ ViewCompat.setWindowInsetsAnimationCallback(
52
+ rootView,
53
+ new WindowInsetsAnimationCompat.Callback(WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_STOP) {
54
+ @NonNull
55
+ @Override
56
+ public WindowInsetsCompat onProgress(
57
+ @NonNull WindowInsetsCompat insets,
58
+ @NonNull List<WindowInsetsAnimationCompat> runningAnimations
59
+ ) {
60
+ return insets;
61
+ }
62
+
63
+ @NonNull
64
+ @Override
65
+ public WindowInsetsAnimationCompat.BoundsCompat onStart(
66
+ @NonNull WindowInsetsAnimationCompat animation,
67
+ @NonNull WindowInsetsAnimationCompat.BoundsCompat bounds
68
+ ) {
69
+ boolean showingKeyboard = ViewCompat.getRootWindowInsets(rootView).isVisible(WindowInsetsCompat.Type.ime());
70
+ WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(rootView);
71
+ int imeHeight = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom;
72
+ DisplayMetrics dm = activity.getResources().getDisplayMetrics();
73
+ final float density = dm.density;
74
+
75
+ if (resizeOnFullScreen) {
76
+ possiblyResizeChildOfContent(showingKeyboard);
77
+ }
78
+
79
+ if (showingKeyboard) {
80
+ keyboardEventListener.onKeyboardEvent(EVENT_KB_WILL_SHOW, Math.round(imeHeight / density));
81
+ } else {
82
+ keyboardEventListener.onKeyboardEvent(EVENT_KB_WILL_HIDE, 0);
83
+ }
84
+ return super.onStart(animation, bounds);
85
+ }
86
+
87
+ @Override
88
+ public void onEnd(@NonNull WindowInsetsAnimationCompat animation) {
89
+ super.onEnd(animation);
90
+ boolean showingKeyboard = ViewCompat.getRootWindowInsets(rootView).isVisible(WindowInsetsCompat.Type.ime());
91
+ WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(rootView);
92
+ int imeHeight = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom;
93
+ DisplayMetrics dm = activity.getResources().getDisplayMetrics();
94
+ final float density = dm.density;
95
+
96
+ if (showingKeyboard) {
97
+ keyboardEventListener.onKeyboardEvent(EVENT_KB_DID_SHOW, Math.round(imeHeight / density));
98
+ } else {
99
+ keyboardEventListener.onKeyboardEvent(EVENT_KB_DID_HIDE, 0);
100
+ }
101
+ }
102
+ }
103
+ );
104
+
105
+ mChildOfContent = content.getChildAt(0);
106
+ frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
107
+ }
108
+
109
+ public void show() {
110
+ ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(activity.getCurrentFocus(), 0);
111
+ }
112
+
113
+ public boolean hide() {
114
+ InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
115
+ View v = activity.getCurrentFocus();
116
+ if (v == null) {
117
+ return false;
118
+ } else {
119
+ inputManager.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
120
+ return true;
121
+ }
122
+ }
123
+
124
+ private void possiblyResizeChildOfContent(boolean keyboardShown) {
125
+ int usableHeightNow = keyboardShown ? computeUsableHeight() : -1;
126
+ if (usableHeightPrevious != usableHeightNow) {
127
+ frameLayoutParams.height = usableHeightNow;
128
+ mChildOfContent.requestLayout();
129
+ usableHeightPrevious = usableHeightNow;
130
+ }
131
+ }
132
+
133
+ private int computeUsableHeight() {
134
+ Rect r = new Rect();
135
+ mChildOfContent.getWindowVisibleDisplayFrame(r);
136
+ if (shouldApplyEdgeToEdgeAdjustments()) {
137
+ WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(rootView);
138
+ if (insets != null) {
139
+ int systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom;
140
+ if (systemBars > 0) {
141
+ return r.bottom + systemBars;
142
+ }
143
+ }
144
+ }
145
+
146
+ return isOverlays() ? r.bottom : r.height();
147
+ }
148
+
149
+ private boolean shouldApplyEdgeToEdgeAdjustments() {
150
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) { // Check the app's edge-to-edge preference
151
+ TypedValue value = new TypedValue();
152
+ boolean optOutAttributeExists = activity
153
+ .getTheme()
154
+ .resolveAttribute(android.R.attr.windowOptOutEdgeToEdgeEnforcement, value, true);
155
+
156
+ if (!optOutAttributeExists) { // Default is to apply edge to edge
157
+ return true;
158
+ } else {
159
+ return value.data == 0;
160
+ }
161
+ }
162
+ return false;
163
+ }
164
+
165
+ @SuppressWarnings("deprecation")
166
+ private boolean isOverlays() {
167
+ final Window window = activity.getWindow();
168
+ return (
169
+ (window.getDecorView().getSystemUiVisibility() & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) == View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
170
+ );
171
+ }
172
+ }
@@ -0,0 +1,24 @@
1
+ /*
2
+ Licensed to the Apache Software Foundation (ASF) under one
3
+ or more contributor license agreements. See the NOTICE file
4
+ distributed with this work for additional information
5
+ regarding copyright ownership. The ASF licenses this file
6
+ to you under the Apache License, Version 2.0 (the
7
+ "License"); you may not use this file except in compliance
8
+ with the License. You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing,
13
+ software distributed under the License is distributed on an
14
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ KIND, either express or implied. See the License for the
16
+ specific language governing permissions and limitations
17
+ under the License.
18
+ */
19
+
20
+ #import <Cordova/CDVPlugin.h>
21
+
22
+ @interface CDVIonicKeyboard : CDVPlugin
23
+
24
+ @end
@@ -0,0 +1,411 @@
1
+ /*
2
+ Licensed to the Apache Software Foundation (ASF) under one
3
+ or more contributor license agreements. See the NOTICE file
4
+ distributed with this work for additional information
5
+ regarding copyright ownership. The ASF licenses this file
6
+ to you under the Apache License, Version 2.0 (the
7
+ "License"); you may not use this file except in compliance
8
+ with the License. You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing,
13
+ software distributed under the License is distributed on an
14
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ KIND, either express or implied. See the License for the
16
+ specific language governing permissions and limitations
17
+ under the License.
18
+ */
19
+
20
+ #import "CDVIonicKeyboard.h"
21
+ #import <Cordova/CDVAvailability.h>
22
+ #import <Cordova/NSDictionary+CordovaPreferences.h>
23
+ #import <objc/runtime.h>
24
+
25
+ typedef enum : NSUInteger {
26
+ ResizeNone,
27
+ ResizeNative,
28
+ ResizeBody,
29
+ ResizeIonic,
30
+ } ResizePolicy;
31
+
32
+ #ifndef __CORDOVA_3_2_0
33
+ #warning "The keyboard plugin is only supported in Cordova 3.2 or greater, it may not work properly in an older version. If you do use this plugin in an older version, make sure the HideKeyboardFormAccessoryBar and KeyboardShrinksView preference values are false."
34
+ #endif
35
+
36
+ @interface CDVIonicKeyboard () <UIScrollViewDelegate>
37
+
38
+ @property (readwrite, assign, nonatomic) BOOL disableScroll;
39
+ @property (readwrite, assign, nonatomic) BOOL hideFormAccessoryBar;
40
+ @property (readwrite, assign, nonatomic) BOOL keyboardIsVisible;
41
+ @property (nonatomic, readwrite) ResizePolicy keyboardResizes;
42
+ @property (readwrite, assign, nonatomic) NSString* keyboardStyle;
43
+ @property (nonatomic, readwrite) BOOL isWK;
44
+ @property (nonatomic, readwrite) int paddingBottom;
45
+
46
+ @end
47
+
48
+ @implementation CDVIonicKeyboard
49
+
50
+ NSTimer *hideTimer;
51
+
52
+ - (id)settingForKey:(NSString *)key
53
+ {
54
+ return [self.commandDelegate.settings objectForKey:[key lowercaseString]];
55
+ }
56
+
57
+ #pragma mark Initialize
58
+
59
+ NSString* UIClassString;
60
+ NSString* WKClassString;
61
+ NSString* UITraitsClassString;
62
+
63
+ - (void)pluginInitialize
64
+ {
65
+ UIClassString = [@[@"UI", @"Web", @"Browser", @"View"] componentsJoinedByString:@""];
66
+ WKClassString = [@[@"WK", @"Content", @"View"] componentsJoinedByString:@""];
67
+ UITraitsClassString = [@[@"UI", @"Text", @"Input", @"Traits"] componentsJoinedByString:@""];
68
+
69
+ NSDictionary *settings = self.commandDelegate.settings;
70
+
71
+ self.disableScroll = ![settings cordovaBoolSettingForKey:@"ScrollEnabled" defaultValue:NO];
72
+
73
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarDidChangeFrame:) name: UIApplicationDidChangeStatusBarFrameNotification object:nil];
74
+
75
+ self.keyboardResizes = ResizeNative;
76
+ BOOL doesResize = [settings cordovaBoolSettingForKey:@"KeyboardResize" defaultValue:YES];
77
+ if (!doesResize) {
78
+ self.keyboardResizes = ResizeNone;
79
+ NSLog(@"CDVIonicKeyboard: no resize");
80
+
81
+ } else {
82
+ NSString *resizeMode = [settings cordovaSettingForKey:@"KeyboardResizeMode"];
83
+ if (resizeMode) {
84
+ if ([resizeMode isEqualToString:@"ionic"]) {
85
+ self.keyboardResizes = ResizeIonic;
86
+ } else if ([resizeMode isEqualToString:@"body"]) {
87
+ self.keyboardResizes = ResizeBody;
88
+ }
89
+ }
90
+ NSLog(@"CDVIonicKeyboard: resize mode %lu", (unsigned long)self.keyboardResizes);
91
+ }
92
+ self.hideFormAccessoryBar = [settings cordovaBoolSettingForKey:@"HideKeyboardFormAccessoryBar" defaultValue:YES];
93
+
94
+ NSString *keyboardStyle = [settings cordovaSettingForKey:@"KeyboardStyle"];
95
+ if (keyboardStyle) {
96
+ [self setKeyboardStyle:keyboardStyle];
97
+ }
98
+
99
+ if ([settings cordovaBoolSettingForKey:@"KeyboardAppearanceDark" defaultValue:NO]) {
100
+ [self setKeyboardStyle:@"dark"];
101
+ }
102
+
103
+ NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
104
+
105
+ [nc addObserver:self selector:@selector(onKeyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
106
+ [nc addObserver:self selector:@selector(onKeyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
107
+ [nc addObserver:self selector:@selector(onKeyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
108
+ [nc addObserver:self selector:@selector(onKeyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
109
+
110
+ // Prevent WKWebView to resize window
111
+ BOOL isWK = self.isWK = [self.webView isKindOfClass:NSClassFromString(@"WKWebView")];
112
+ if (!isWK) {
113
+ NSLog(@"CDVIonicKeyboard: WARNING!!: Keyboard plugin works better with WK");
114
+ }
115
+
116
+ if (isWK) {
117
+ [nc removeObserver:self.webView name:UIKeyboardWillHideNotification object:nil];
118
+ [nc removeObserver:self.webView name:UIKeyboardWillShowNotification object:nil];
119
+ [nc removeObserver:self.webView name:UIKeyboardWillChangeFrameNotification object:nil];
120
+ [nc removeObserver:self.webView name:UIKeyboardDidChangeFrameNotification object:nil];
121
+ }
122
+ }
123
+
124
+ -(void)statusBarDidChangeFrame:(NSNotification*)notification
125
+ {
126
+ [self _updateFrame];
127
+ }
128
+
129
+
130
+ #pragma mark Keyboard events
131
+
132
+ - (void)resetScrollView
133
+ {
134
+ UIScrollView *scrollView = [self.webView scrollView];
135
+ [scrollView setContentInset:UIEdgeInsetsZero];
136
+ }
137
+
138
+ - (void)onKeyboardWillHide:(NSNotification *)sender
139
+ {
140
+ if (self.isWK) {
141
+ [self setKeyboardHeight:0 delay:0.01];
142
+ [self resetScrollView];
143
+ }
144
+ hideTimer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(fireOnHiding) userInfo:nil repeats:NO];
145
+ }
146
+
147
+ - (void)fireOnHiding {
148
+ [self.commandDelegate evalJs:@"Keyboard.fireOnHiding();"];
149
+ }
150
+
151
+ - (void)onKeyboardWillShow:(NSNotification *)note
152
+ {
153
+ if (hideTimer != nil) {
154
+ [hideTimer invalidate];
155
+ }
156
+ CGRect rect = [[note.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
157
+ double height = rect.size.height;
158
+
159
+ if (self.isWK) {
160
+ double duration = [[note.userInfo valueForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
161
+ [self setKeyboardHeight:height delay:duration+0.2];
162
+ [self resetScrollView];
163
+ }
164
+
165
+ [self setKeyboardStyle:self.keyboardStyle];
166
+
167
+ NSString *js = [NSString stringWithFormat:@"Keyboard.fireOnShowing(%d);", (int)height];
168
+ [self.commandDelegate evalJs:js];
169
+ }
170
+
171
+ - (void)onKeyboardDidShow:(NSNotification *)note
172
+ {
173
+ CGRect rect = [[note.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
174
+ double height = rect.size.height;
175
+
176
+ if (self.isWK) {
177
+ [self resetScrollView];
178
+ }
179
+
180
+ NSString *js = [NSString stringWithFormat:@"Keyboard.fireOnShow(%d);", (int)height];
181
+ [self.commandDelegate evalJs:js];
182
+ }
183
+
184
+ - (void)onKeyboardDidHide:(NSNotification *)sender
185
+ {
186
+ [self.commandDelegate evalJs:@"Keyboard.fireOnHide();"];
187
+ [self resetScrollView];
188
+ }
189
+
190
+ - (void)setKeyboardHeight:(int)height delay:(NSTimeInterval)delay
191
+ {
192
+ if (self.keyboardResizes != ResizeNone) {
193
+ [self setPaddingBottom: height delay:delay];
194
+ }
195
+ }
196
+
197
+ - (void)setPaddingBottom:(int)paddingBottom delay:(NSTimeInterval)delay
198
+ {
199
+ if (self.paddingBottom == paddingBottom) {
200
+ return;
201
+ }
202
+
203
+ self.paddingBottom = paddingBottom;
204
+
205
+ __weak CDVIonicKeyboard* weakSelf = self;
206
+ SEL action = @selector(_updateFrame);
207
+ [NSObject cancelPreviousPerformRequestsWithTarget:weakSelf selector:action object:nil];
208
+ if (delay == 0) {
209
+ [self _updateFrame];
210
+ } else {
211
+ [weakSelf performSelector:action withObject:nil afterDelay:delay];
212
+ }
213
+ }
214
+
215
+ - (void)_updateFrame
216
+ {
217
+ CGSize statusBarSize = [[UIApplication sharedApplication] statusBarFrame].size;
218
+ int statusBarHeight = MIN(statusBarSize.width, statusBarSize.height);
219
+
220
+ int _paddingBottom = (int)self.paddingBottom;
221
+
222
+ if (statusBarHeight == 40) {
223
+ _paddingBottom = _paddingBottom + 20;
224
+ }
225
+ NSLog(@"CDVIonicKeyboard: updating frame");
226
+ // NOTE: to handle split screen correctly, the application's window bounds must be used as opposed to the screen's bounds.
227
+ CGRect f = [[[[UIApplication sharedApplication] delegate] window] bounds];
228
+ CGRect wf = self.webView.frame;
229
+ switch (self.keyboardResizes) {
230
+ case ResizeBody:
231
+ {
232
+ NSString *js = [NSString stringWithFormat:@"Keyboard.fireOnResize(%d, %d, document.body);",
233
+ _paddingBottom, (int)(f.size.height - wf.origin.y)];
234
+ [self.commandDelegate evalJs:js];
235
+ break;
236
+ }
237
+ case ResizeIonic:
238
+ {
239
+ NSString *js = [NSString stringWithFormat:@"Keyboard.fireOnResize(%d, %d, document.querySelector('ion-app'));",
240
+ _paddingBottom, (int)(f.size.height - wf.origin.y)];
241
+ [self.commandDelegate evalJs:js];
242
+ break;
243
+ }
244
+ case ResizeNative:
245
+ {
246
+ [self.webView setFrame:CGRectMake(wf.origin.x, wf.origin.y, f.size.width - wf.origin.x, f.size.height - wf.origin.y - self.paddingBottom)];
247
+ break;
248
+ }
249
+ default:
250
+ break;
251
+ }
252
+ [self resetScrollView];
253
+ }
254
+
255
+ #pragma mark Keyboard Style
256
+
257
+ - (void)setKeyboardStyle:(NSString*)style
258
+ {
259
+ IMP newImp = [style isEqualToString:@"dark"] ? imp_implementationWithBlock(^(id _s) {
260
+ return UIKeyboardAppearanceDark;
261
+ }) : imp_implementationWithBlock(^(id _s) {
262
+ return UIKeyboardAppearanceLight;
263
+ });
264
+
265
+ if (self.isWK) {
266
+ for (NSString* classString in @[WKClassString, UITraitsClassString]) {
267
+ Class c = NSClassFromString(classString);
268
+ Method m = class_getInstanceMethod(c, @selector(keyboardAppearance));
269
+
270
+ if (m != NULL) {
271
+ method_setImplementation(m, newImp);
272
+ } else {
273
+ class_addMethod(c, @selector(keyboardAppearance), newImp, "l@:");
274
+ }
275
+ }
276
+ }
277
+ else {
278
+ for (NSString* classString in @[UIClassString, UITraitsClassString]) {
279
+ Class c = NSClassFromString(classString);
280
+ Method m = class_getInstanceMethod(c, @selector(keyboardAppearance));
281
+
282
+ if (m != NULL) {
283
+ method_setImplementation(m, newImp);
284
+ } else {
285
+ class_addMethod(c, @selector(keyboardAppearance), newImp, "l@:");
286
+ }
287
+ }
288
+ }
289
+
290
+ _keyboardStyle = style;
291
+ }
292
+
293
+ #pragma mark HideFormAccessoryBar
294
+
295
+ static IMP UIOriginalImp;
296
+ static IMP WKOriginalImp;
297
+
298
+ - (void)setHideFormAccessoryBar:(BOOL)hideFormAccessoryBar
299
+ {
300
+ if (hideFormAccessoryBar == _hideFormAccessoryBar) {
301
+ return;
302
+ }
303
+
304
+ Method UIMethod = class_getInstanceMethod(NSClassFromString(UIClassString), @selector(inputAccessoryView));
305
+ Method WKMethod = class_getInstanceMethod(NSClassFromString(WKClassString), @selector(inputAccessoryView));
306
+
307
+ if (hideFormAccessoryBar) {
308
+ UIOriginalImp = method_getImplementation(UIMethod);
309
+ WKOriginalImp = method_getImplementation(WKMethod);
310
+
311
+ IMP newImp = imp_implementationWithBlock(^(id _s) {
312
+ return nil;
313
+ });
314
+
315
+ method_setImplementation(UIMethod, newImp);
316
+ method_setImplementation(WKMethod, newImp);
317
+ } else {
318
+ method_setImplementation(UIMethod, UIOriginalImp);
319
+ method_setImplementation(WKMethod, WKOriginalImp);
320
+ }
321
+
322
+ _hideFormAccessoryBar = hideFormAccessoryBar;
323
+ }
324
+
325
+ #pragma mark scroll
326
+
327
+ - (void)setDisableScroll:(BOOL)disableScroll {
328
+ if (disableScroll == _disableScroll) {
329
+ return;
330
+ }
331
+ if (disableScroll) {
332
+ self.webView.scrollView.scrollEnabled = NO;
333
+ self.webView.scrollView.delegate = self;
334
+ }
335
+ else {
336
+ self.webView.scrollView.scrollEnabled = YES;
337
+ self.webView.scrollView.delegate = nil;
338
+ }
339
+ _disableScroll = disableScroll;
340
+ }
341
+
342
+ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
343
+ [scrollView setContentOffset: CGPointZero];
344
+ }
345
+
346
+ #pragma mark Plugin interface
347
+
348
+ - (void)hideFormAccessoryBar:(CDVInvokedUrlCommand *)command
349
+ {
350
+ if (command.arguments.count > 0) {
351
+ id value = [command.arguments objectAtIndex:0];
352
+ if (!([value isKindOfClass:[NSNumber class]])) {
353
+ value = [NSNumber numberWithBool:NO];
354
+ }
355
+
356
+ self.hideFormAccessoryBar = [value boolValue];
357
+ }
358
+
359
+ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:self.hideFormAccessoryBar]
360
+ callbackId:command.callbackId];
361
+ }
362
+
363
+ - (void)hide:(CDVInvokedUrlCommand *)command
364
+ {
365
+ [self.webView endEditing:YES];
366
+ }
367
+
368
+ - (void)setResizeMode:(CDVInvokedUrlCommand *)command
369
+ {
370
+ NSString * mode = [command.arguments objectAtIndex:0];
371
+ if ([mode isEqualToString:@"ionic"]) {
372
+ self.keyboardResizes = ResizeIonic;
373
+ } else if ([mode isEqualToString:@"body"]) {
374
+ self.keyboardResizes = ResizeBody;
375
+ } else if ([mode isEqualToString:@"native"]) {
376
+ self.keyboardResizes = ResizeNative;
377
+ } else {
378
+ self.keyboardResizes = ResizeNone;
379
+ }
380
+ }
381
+
382
+ - (void)keyboardStyle:(CDVInvokedUrlCommand*)command
383
+ {
384
+ id value = [command.arguments objectAtIndex:0];
385
+ if ([value isKindOfClass:[NSString class]]) {
386
+ value = [(NSString*)value lowercaseString];
387
+ } else {
388
+ value = @"light";
389
+ }
390
+
391
+ self.keyboardStyle = value;
392
+ }
393
+
394
+ - (void)disableScroll:(CDVInvokedUrlCommand*)command {
395
+ if (!command.arguments || ![command.arguments count]){
396
+ return;
397
+ }
398
+ id value = [command.arguments objectAtIndex:0];
399
+ if (value != [NSNull null]) {
400
+ self.disableScroll = [value boolValue];
401
+ }
402
+ }
403
+
404
+ #pragma mark dealloc
405
+
406
+ - (void)dealloc
407
+ {
408
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
409
+ }
410
+
411
+ @end
@@ -0,0 +1,84 @@
1
+ var argscheck = require('cordova/argscheck'),
2
+ utils = require('cordova/utils'),
3
+ exec = require('cordova/exec'),
4
+ channel = require('cordova/channel');
5
+
6
+ var Keyboard = function () {};
7
+
8
+ Keyboard.fireOnShow = function (height) {
9
+ Keyboard.isVisible = true;
10
+ cordova.fireWindowEvent('keyboardDidShow', {
11
+ 'keyboardHeight': height
12
+ });
13
+
14
+ // To support the keyboardAttach directive listening events
15
+ // inside Ionic's main bundle
16
+ cordova.fireWindowEvent('native.keyboardshow', {
17
+ 'keyboardHeight': height
18
+ });
19
+ };
20
+
21
+ Keyboard.fireOnHide = function () {
22
+ Keyboard.isVisible = false;
23
+ cordova.fireWindowEvent('keyboardDidHide');
24
+
25
+ // To support the keyboardAttach directive listening events
26
+ // inside Ionic's main bundle
27
+ cordova.fireWindowEvent('native.keyboardhide');
28
+ };
29
+
30
+ Keyboard.fireOnHiding = function () {
31
+ cordova.fireWindowEvent('keyboardWillHide');
32
+ };
33
+
34
+ Keyboard.fireOnShowing = function (height) {
35
+ cordova.fireWindowEvent('keyboardWillShow', {
36
+ 'keyboardHeight': height
37
+ });
38
+ };
39
+
40
+ Keyboard.hideFormAccessoryBar = Keyboard.hideKeyboardAccessoryBar = function (hide) {
41
+ console.warn("Keyboard.hideKeyboardAccessoryBar() not supported in Android");
42
+ };
43
+
44
+ Keyboard.hide = function () {
45
+ exec(null, null, "CDVIonicKeyboard", "hide", []);
46
+ };
47
+
48
+ Keyboard.show = function () {
49
+ exec(null, null, "CDVIonicKeyboard", "show", []);
50
+ };
51
+
52
+ Keyboard.disableScroll = function (disable) {
53
+ console.warn("Keyboard.disableScroll() not supported in Android");
54
+ };
55
+
56
+ Keyboard.setResizeMode = function (mode) {
57
+ console.warn("Keyboard.setResizeMode() not supported in Android");
58
+ }
59
+
60
+ Keyboard.setKeyboardStyle = function(style) {
61
+ console.warn("Keyboard.setKeyboardStyle() not supported in Android");
62
+ };
63
+
64
+ channel.onCordovaReady.subscribe(function () {
65
+ exec(success, null, 'CDVIonicKeyboard', 'init', []);
66
+
67
+ function success(msg) {
68
+ var action = msg.charAt(0);
69
+ if (action === 'S') {
70
+ var keyboardHeight = parseInt(msg.substr(1));
71
+ Keyboard.fireOnShowing(keyboardHeight);
72
+ Keyboard.fireOnShow(keyboardHeight);
73
+
74
+ } else if (action === 'H') {
75
+ Keyboard.fireOnHiding();
76
+ Keyboard.fireOnHide();
77
+ }
78
+ }
79
+ });
80
+
81
+
82
+ Keyboard.isVisible = false;
83
+
84
+ module.exports = Keyboard;
@@ -0,0 +1,106 @@
1
+ /*
2
+ *
3
+ * Licensed to the Apache Software Foundation (ASF) under one
4
+ * or more contributor license agreements. See the NOTICE file
5
+ * distributed with this work for additional information
6
+ * regarding copyright ownership. The ASF licenses this file
7
+ * to you under the Apache License, Version 2.0 (the
8
+ * "License"); you may not use this file except in compliance
9
+ * with the License. You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing,
14
+ * software distributed under the License is distributed on an
15
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ * KIND, either express or implied. See the License for the
17
+ * specific language governing permissions and limitations
18
+ * under the License.
19
+ *
20
+ */
21
+
22
+ var argscheck = require('cordova/argscheck'),
23
+ utils = require('cordova/utils'),
24
+ exec = require('cordova/exec');
25
+
26
+ var Keyboard = function () {};
27
+
28
+ Keyboard.fireOnShow = function (height) {
29
+ Keyboard.isVisible = true;
30
+ cordova.fireWindowEvent('keyboardDidShow', {
31
+ 'keyboardHeight': height
32
+ });
33
+
34
+ // To support the keyboardAttach directive listening events
35
+ // inside Ionic's main bundle
36
+ cordova.fireWindowEvent('native.keyboardshow', {
37
+ 'keyboardHeight': height
38
+ });
39
+ };
40
+
41
+ Keyboard.fireOnHide = function () {
42
+ Keyboard.isVisible = false;
43
+ cordova.fireWindowEvent('keyboardDidHide');
44
+
45
+ // To support the keyboardAttach directive listening events
46
+ // inside Ionic's main bundle
47
+ cordova.fireWindowEvent('native.keyboardhide');
48
+ };
49
+
50
+ Keyboard.fireOnHiding = function () {
51
+ cordova.fireWindowEvent('keyboardWillHide');
52
+ };
53
+
54
+ Keyboard.fireOnShowing = function (height) {
55
+ cordova.fireWindowEvent('keyboardWillShow', {
56
+ 'keyboardHeight': height
57
+ });
58
+ };
59
+
60
+ Keyboard.fireOnResize = function (height, screenHeight, ele) {
61
+ if (!ele) {
62
+ return;
63
+ }
64
+ if (height === 0) {
65
+ ele.style.height = null;
66
+ } else {
67
+ ele.style.height = (screenHeight - height) + 'px';
68
+ }
69
+
70
+ // Update the CSS variable with the height of keyboard.
71
+ document.documentElement.style.setProperty('--keyboard-height', height > 0 ? `${height}px` : null);
72
+ };
73
+
74
+ Keyboard.hideFormAccessoryBar = function (hide, success) {
75
+ if (hide !== null && hide !== undefined) {
76
+ exec(success, null, "CDVIonicKeyboard", "hideFormAccessoryBar", [hide]);
77
+ } else {
78
+ exec(success, null, "CDVIonicKeyboard", "hideFormAccessoryBar", []);
79
+ }
80
+ };
81
+
82
+ Keyboard.hide = function () {
83
+ exec(null, null, "CDVIonicKeyboard", "hide", []);
84
+ };
85
+
86
+ Keyboard.show = function () {
87
+ console.warn('Showing keyboard not supported in iOS due to platform limitations.');
88
+ console.warn('Instead, use input.focus(), and ensure that you have the following setting in your config.xml: \n');
89
+ console.warn(' <preference name="KeyboardDisplayRequiresUserAction" value="false"/>\n');
90
+ };
91
+
92
+ Keyboard.disableScroll = function (disable) {
93
+ exec(null, null, "CDVIonicKeyboard", "disableScroll", [disable]);
94
+ };
95
+
96
+ Keyboard.setResizeMode = function (mode) {
97
+ exec(null, null, "CDVIonicKeyboard", "setResizeMode", [mode]);
98
+ }
99
+
100
+ Keyboard.setKeyboardStyle = function(style) {
101
+ exec(null, null, "CDVIonicKeyboard", "keyboardStyle", [style]);
102
+ };
103
+
104
+ Keyboard.isVisible = false;
105
+
106
+ module.exports = Keyboard;