From 4290523410d839ee6f5896325bb4467590aeb3b7 Mon Sep 17 00:00:00 2001 From: Omar Mefire Date: Tue, 31 Mar 2015 13:57:49 +0300 Subject: [PATCH 1/2] Adds support for windows platform --- README.md | 12 +++++----- plugin.xml | 7 ++++++ src/windows/KeyboardProxy.js | 43 ++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 src/windows/KeyboardProxy.js diff --git a/README.md b/README.md index 63f7001..836cf6d 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Close the keyboard if it is open. Supported Platforms ------------------- -- iOS, Android, Blackberry 10 +- iOS, Android, Blackberry 10, Windows (_Windows Phone devices only_) Keyboard.disableScroll @@ -65,18 +65,18 @@ Disable native scrolling, useful if you are using JavaScript to scroll Supported Platforms ------------------- -- iOS +- iOS, Windows Keyboard.show ================= -Force keyboard to be shown on Android. This typically helps if autofocus on a text element does not pop up the keyboard automatically +Force keyboard to be shown. This typically helps if autofocus on a text element does not pop up the keyboard automatically cordova.plugins.Keyboard.show(); Supported Platforms -- Android, Blackberry 10 +- Android, Blackberry 10, Windows (_Windows Phone devices only_) native.keyboardshow ================= @@ -98,7 +98,7 @@ keyboardHeight: the height of the keyboard in pixels Supported Platforms ------------------- -- iOS, Android, Blackberry 10 +- iOS, Android, Blackberry 10, Windows native.keyboardhide @@ -120,4 +120,4 @@ None Supported Platforms ------------------- -- iOS, Android, Blackberry 10 +- iOS, Android, Blackberry 10, Windows diff --git a/plugin.xml b/plugin.xml index 0668891..0880c08 100644 --- a/plugin.xml +++ b/plugin.xml @@ -52,4 +52,11 @@ + + + + + + + diff --git a/src/windows/KeyboardProxy.js b/src/windows/KeyboardProxy.js new file mode 100644 index 0000000..8d38582 --- /dev/null +++ b/src/windows/KeyboardProxy.js @@ -0,0 +1,43 @@ + +/*global Windows, WinJS, cordova, module, require*/ + +var inputPane = Windows.UI.ViewManagement.InputPane.getForCurrentView(); +var isPhone = cordova.platformId === 'windows' && WinJS.Utilities.isPhone; +var keyboardScrollDisabled = false; + +inputPane.addEventListener('hiding', function() { + cordova.fireDocumentEvent('native.keyboardhide'); + cordova.plugins.Keyboard.isVisible = false; +}); + +inputPane.addEventListener('showing', function(e) { + if (keyboardScrollDisabled) { + // this disables automatic scrolling of view contents to show focused control + e.ensuredFocusedElementInView = true; + } + cordova.fireDocumentEvent('native.keyboardshow', { keyboardHeight: e.occludedRect.height }); + cordova.plugins.Keyboard.isVisible = true; +}); + +module.exports.disableScroll = function (win, fail, args) { + var disable = args[0]; + keyboardScrollDisabled = disable; +}; + +module.exports.show = function () { + // Due to https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.viewmanagement.inputpane.tryshow.aspx + // this action available on Windows Phone devices only + if (isPhone) { + inputPane.tryShow(); + } +}; + +module.exports.close = function () { + // Due to https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.viewmanagement.inputpane.tryhide.aspx + // this action available on Windows Phone devices only + if (isPhone) { + inputPane.tryHide(); + } +}; + +require("cordova/exec/proxy").add("Keyboard", module.exports); From 7cf18baa1a26bc93fd0323462f2267547a1afa3c Mon Sep 17 00:00:00 2001 From: Omar Mefire Date: Tue, 30 Jun 2015 16:18:00 -0700 Subject: [PATCH 2/2] Windows support: Remove Windows Phone only limitation --- README.md | 4 ++-- src/windows/KeyboardProxy.js | 9 ++------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 836cf6d..04b57c6 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Close the keyboard if it is open. Supported Platforms ------------------- -- iOS, Android, Blackberry 10, Windows (_Windows Phone devices only_) +- iOS, Android, Blackberry 10, Windows Keyboard.disableScroll @@ -76,7 +76,7 @@ Force keyboard to be shown. This typically helps if autofocus on a text element Supported Platforms -- Android, Blackberry 10, Windows (_Windows Phone devices only_) +- Android, Blackberry 10, Windows native.keyboardshow ================= diff --git a/src/windows/KeyboardProxy.js b/src/windows/KeyboardProxy.js index 8d38582..c5f6fd0 100644 --- a/src/windows/KeyboardProxy.js +++ b/src/windows/KeyboardProxy.js @@ -2,7 +2,6 @@ /*global Windows, WinJS, cordova, module, require*/ var inputPane = Windows.UI.ViewManagement.InputPane.getForCurrentView(); -var isPhone = cordova.platformId === 'windows' && WinJS.Utilities.isPhone; var keyboardScrollDisabled = false; inputPane.addEventListener('hiding', function() { @@ -25,17 +24,13 @@ module.exports.disableScroll = function (win, fail, args) { }; module.exports.show = function () { - // Due to https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.viewmanagement.inputpane.tryshow.aspx - // this action available on Windows Phone devices only - if (isPhone) { + if (typeof inputPane.tryShow === 'function') { inputPane.tryShow(); } }; module.exports.close = function () { - // Due to https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.viewmanagement.inputpane.tryhide.aspx - // this action available on Windows Phone devices only - if (isPhone) { + if (typeof inputPane.tryShow === 'function') { inputPane.tryHide(); } };