From 9bd556a934aca931d565664d34df2194ef46fadb Mon Sep 17 00:00:00 2001 From: nyari Date: Wed, 3 Oct 2018 15:14:57 +0200 Subject: [PATCH] Base windows support --- .gitignore | 3 ++- plugin.xml | 15 ++++++++--- www/windows/keyboard.js | 57 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 www/windows/keyboard.js diff --git a/.gitignore b/.gitignore index b512c09..eb79dd5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules \ No newline at end of file +node_modules +.idea diff --git a/plugin.xml b/plugin.xml index 5dd2fc1..df66679 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,6 +1,8 @@ - + cordova-plugin-ionic-keyboard Ionic Keyboard Plugin Apache 2.0 @@ -10,14 +12,14 @@ Apache Software Foundation - + - + @@ -44,4 +46,11 @@ + + + + + + + diff --git a/www/windows/keyboard.js b/www/windows/keyboard.js new file mode 100644 index 0000000..86e8fa3 --- /dev/null +++ b/www/windows/keyboard.js @@ -0,0 +1,57 @@ +var keyboardScrollDisabled = true; +var inputPane = Windows.UI.ViewManagement.InputPane.getForCurrentView(); + +var Keyboard = function () { +}; + +Keyboard.isVisible = false; + +inputPane.addEventListener('hiding', function () { + if (!Keyboard.isVisible) { + return; + } + + cordova.fireWindowEvent('keyboardWillHide'); + Keyboard.isVisible = false; + cordova.fireWindowEvent('keyboardDidHide'); +}); + +inputPane.addEventListener('showing', function (e) { + if (Keyboard.isVisible) { + return; + } + + cordova.fireWindowEvent('keyboardWillShow', { + keyboardHeight: e.occludedRect.height + }); + if (keyboardScrollDisabled) { + // this disables automatic scrolling of view contents to show focused control + e.ensuredFocusedElementInView = true; + } + Keyboard.isVisible = true; + cordova.fireWindowEvent('keyboardDidShow', { + keyboardHeight: e.occludedRect.height + }); +}); + +Keyboard.hideFormAccessoryBar = Keyboard.hideKeyboardAccessoryBar = function (hide) { + console.warn("Keyboard.hideFormAccessoryBar() not supported in Windows"); +}; + +Keyboard.hide = function () { + if (typeof inputPane.tryShow === 'function') { + inputPane.tryHide(); + } +}; + +Keyboard.show = function () { + if (typeof inputPane.tryShow === 'function') { + inputPane.tryShow(); + } +}; + +Keyboard.setResizeMode = function (mode) { + console.warn("Keyboard.setResizeMode() not supported in Windows"); +}; + +module.exports = Keyboard;