From 2d23c6a91bd16e260ebe9688a91dd4851622f245 Mon Sep 17 00:00:00 2001 From: Jochen Becker Date: Tue, 21 Nov 2017 16:52:56 +0100 Subject: [PATCH 1/2] [cordova-plugin-keyboard] update to version 1.2.0 add methods "hide" and "show" --- .../cordova-plugin-keyboard-tests.ts | 34 +-- types/cordova-plugin-keyboard/index.d.ts | 195 +++++++++--------- 2 files changed, 124 insertions(+), 105 deletions(-) diff --git a/types/cordova-plugin-keyboard/cordova-plugin-keyboard-tests.ts b/types/cordova-plugin-keyboard/cordova-plugin-keyboard-tests.ts index 767eaa6ed2..8a707f057d 100644 --- a/types/cordova-plugin-keyboard/cordova-plugin-keyboard-tests.ts +++ b/types/cordova-plugin-keyboard/cordova-plugin-keyboard-tests.ts @@ -1,23 +1,31 @@ Keyboard.shrinkView(true); Keyboard.shrinkView(false); +Keyboard.shrinkView(null, (currentValue) => console.log(currentValue)); + Keyboard.hideFormAccessoryBar(true); Keyboard.hideFormAccessoryBar(false); +Keyboard.hideFormAccessoryBar(null, (currentValue) => console.log(currentValue)); + Keyboard.disableScrollingInShrinkView(true); Keyboard.disableScrollingInShrinkView(false); +Keyboard.disableScrollingInShrinkView(null, (currentValue) => console.log(currentValue)); + +Keyboard.hide(); + +Keyboard.show(); + if (Keyboard.isVisible) { console.log('Keyboard is visible'); } -Keyboard.automaticScrollToTopOnHiding = true; -Keyboard.onshow = function () { - console.log('onshow'); -}; -Keyboard.onhide = function () { - console.log('onhide'); -}; -Keyboard.onshowing = function () { - console.log('onshowing'); -}; -Keyboard.onhiding= function () { - console.log('onhiding'); -}; +Keyboard.automaticScrollToTopOnHiding = true; + +window.addEventListener('keyboardDidShow', () => console.log('keyboardDidShow')); + +window.addEventListener('keyboardDidHide', () => console.log('keyboardDidHide')); + +window.addEventListener('keyboardWillShow', () => console.log('keyboardWillShow')); + +window.addEventListener('keyboardWillHide', () => console.log('keyboardWillHide')); + +window.addEventListener('keyboardHeightWillChange', (event) => console.log(`keyboardHeightWillChange - keyboard height: ${event.keyboardHeight}`)); diff --git a/types/cordova-plugin-keyboard/index.d.ts b/types/cordova-plugin-keyboard/index.d.ts index 427a5425e5..6298050b2c 100644 --- a/types/cordova-plugin-keyboard/index.d.ts +++ b/types/cordova-plugin-keyboard/index.d.ts @@ -1,32 +1,9 @@ -// Type definitions for Apache Cordova Keyboard plugin v0.1.2 -// Project: https://github.com/apache/cordova-plugins/tree/master/keyboard -// Definitions by: Dan Manastireanu +// Type definitions for Apache Cordova Keyboard plugin v1.2.0 +// Project: https://github.com/cjpearson/cordova-plugin-keyboard +// Definitions by: Dan Manastireanu +// Jochen Becker // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/** - * The Keyboard object provides some functions to customize the iOS keyboard. - * - * Supported Platforms: iOS - * - * This plugin has only been tested in Cordova 3.2 or greater, - * and its use in previous Cordova versions is not recommended - * (potential conflict with keyboard customization code present in the core in previous Cordova versions). - * - * If you do use this plugin in an older Cordova version (again, not recommended), - * you have to make sure the HideKeyboardFormAccessoryBar and KeyboardShrinksView preference values are always false, - * and only use the API functions to turn things on/off. - * - * This plugin supports the HideKeyboardFormAccessoryBar (boolean) - * and KeyboardShrinksView (boolean) preferences in config.xml. - * - * Permissions in config.xml - * - * - * - * - * - * - */ interface Keyboard { // Methods @@ -39,15 +16,20 @@ interface Keyboard { * This applies to apps that position their elements relative to the bottom of the WebView. * This is the default behaviour on Android, and makes a lot of sense when building apps as opposed to webpages. * + * Supported Platforms: + * - iOS + * * Example: * * Keyboard.shrinkView(true); * Keyboard.shrinkView(false); + * Keyboard.shrinkView(null, function (currentValue) { console.log(currentValue); }); * * * @param shrink + * @param successCallback A success callbackfunction */ - shrinkView(shrink:boolean): void, + shrinkView(shrink: boolean, successCallback?: (currentValue: any) => void): void, /** * Hide the keyboard toolbar. @@ -55,21 +37,29 @@ interface Keyboard { * Set to true to hide the additional toolbar that is on top of the keyboard. * This toolbar features the Prev, Next, and Done buttons. * + * Supported Platforms: + * - iOS + * * Example: * * Keyboard.hideFormAccessoryBar(true); * Keyboard.hideFormAccessoryBar(false); + * Keyboard.hideFormAccessoryBar(null, function (currentValue) { console.log(currentValue); }); * * * @param hide + * @param successCallback A success callbackfunction */ - hideFormAccessoryBar(hide:boolean): void, + hideFormAccessoryBar(hide: boolean, successCallback?: (currentValue: any) => void): void, /** * Disable scrolling when the the WebView is shrunk. * * Set to true to disable scrolling when the WebView is shrunk. * + * Supported Platforms: + * - iOS + * * Example: * * Keyboard.disableScrollingInShrinkView(true); @@ -77,8 +67,40 @@ interface Keyboard { * * * @param disable + * @param successCallback A success callbackfunction */ - disableScrollingInShrinkView(disable:boolean): void, + disableScrollingInShrinkView(disable: boolean, successCallback?: (currentValue: any) => void): void, + + /** + * Hide the keyboard + * + * Call this method to hide the keyboard + * + * Supported Platforms: + * - iOS + * - Android + * + * Example: + * + * Keyboard.hide(); + * + */ + hide(): void, + + /** + * Show the keyboard + * + * Call this method to show the keyboard. + * + * Supported Platforms: + * - Android + * + * Example: + * + * Keyboard.show(); + * + */ + show(): void, // Properties @@ -87,6 +109,9 @@ interface Keyboard { * * Read this property to determine if the keyboard is visible. * + * Supported Platforms: + * - iOS + * * Example: * * if (Keyboard.isVisible) { @@ -102,73 +127,59 @@ interface Keyboard { * Set this to true if you need that page scroll to beginning when keyboard is hiding. * This is allows to fix issue with elements declared with position: fixed, after keyboard is hiding. * + * Supported Platforms: + * - iOS + * * Example: * * Keyboard.automaticScrollToTopOnHiding = true; * * */ - automaticScrollToTopOnHiding: boolean, - - // Events - - /** - * If defined, this function is fired when keyboard fully shown. - * - * Attach handler to this event to be able to receive notification when keyboard is shown. - * - * Example: - * - * Keyboard.onshow = function () { - * // Describe your logic which will be run each time keyboard is shown. - * } - * - * - */ - onshow():void, - /** - * If defined, this function is fired when keyboard fully closed. - * - * Attach handler to this event to be able to receive notification when keyboard is closed. - * - * Example: - * - * Keyboard.onhide = function () { - * // Describe your logic which will be run each time keyboard is closed. - * } - * - * - */ - onhide():void, - /** - * If defined, this function is fired before keyboard will be shown. - * - * Attach handler to this event to be able to receive notification when keyboard is about to be shown on the screen. - * - * Example: - * - * Keyboard.onshowing = function () { - * // Describe your logic which will be run each time when keyboard is about to be shown. - * } - * - * - */ - onshowing():void, - /** - * If defined, this function is fired when keyboard is about to be closed. - * - * Attach handler to this event to be able to receive notification when keyboard is about to be closed. - * - * Example: - * - * Keyboard.onhiding = function () { - * // Describe your logic which will be run each time when keyboard is about to be closed. - * } - * - * - */ - onhiding():void, - + automaticScrollToTopOnHiding: boolean } -declare var Keyboard:Keyboard; +interface CordovaKeyboardEvent extends Event { + /** The height of the keyboard */ + keyboardHeight: number; +} + +interface Window { + /** + * @param type This event is fired when keyboard fully shown. + * + * @param callback Function is called when keyboard is shown. + */ + addEventListener(type: 'keyboardDidShow', callback: () => any, useCapture?: boolean): void; + + /** + * @param type This event is fired when the keyboard is fully closed. + * + * @param callback Function is called when keyboard is closed. + */ + addEventListener(type: 'keyboardDidHide', callback: () => any, useCapture?: boolean): void; + + /** + * @param type This event fires before keyboard will be shown. + * + * @param callback Function is called when keyboard is about to be shown on the screen. + */ + addEventListener(type: 'keyboardWillShow', callback: () => any, useCapture?: boolean): void; + + /** + * @param type This event is fired when the keyboard is fully closed. + * + * @param callback Function is called when keyboard is about to be closed. + */ + addEventListener(type: 'keyboardWillHide', callback: () => any, useCapture?: boolean): void; + + /** + * @param type This event is fired when the keyboard is fully closed. + * + * @param callback Function is called when keyboard is about to be closed. The function is + * passed an InAppBrowserEvent object as a parameter. + */ + addEventListener(type: 'keyboardHeightWillChange', callback: (event: CordovaKeyboardEvent) => any, useCapture?: boolean): void; +} + +declare var Keyboard: Keyboard; From 004b817c7c23daa667d810f72a3deb6fe015648f Mon Sep 17 00:00:00 2001 From: Jochen Becker Date: Wed, 22 Nov 2017 14:48:54 +0100 Subject: [PATCH 2/2] [cordova-plugin-keyboard] Support for deprecated events --- .../cordova-plugin-keyboard-tests.ts | 2 +- types/cordova-plugin-keyboard/index.d.ts | 48 +++++++++---------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/types/cordova-plugin-keyboard/cordova-plugin-keyboard-tests.ts b/types/cordova-plugin-keyboard/cordova-plugin-keyboard-tests.ts index 8a707f057d..fa5cf72a30 100644 --- a/types/cordova-plugin-keyboard/cordova-plugin-keyboard-tests.ts +++ b/types/cordova-plugin-keyboard/cordova-plugin-keyboard-tests.ts @@ -28,4 +28,4 @@ window.addEventListener('keyboardWillShow', () => console.log('keyboardWillShow' window.addEventListener('keyboardWillHide', () => console.log('keyboardWillHide')); -window.addEventListener('keyboardHeightWillChange', (event) => console.log(`keyboardHeightWillChange - keyboard height: ${event.keyboardHeight}`)); +window.addEventListener('keyboardHeightWillChange', (event: CordovaKeyboardEvent) => console.log(`keyboardHeightWillChange - keyboard height: ${event.keyboardHeight}`)); diff --git a/types/cordova-plugin-keyboard/index.d.ts b/types/cordova-plugin-keyboard/index.d.ts index 6298050b2c..af880d732a 100644 --- a/types/cordova-plugin-keyboard/index.d.ts +++ b/types/cordova-plugin-keyboard/index.d.ts @@ -136,7 +136,18 @@ interface Keyboard { * * */ - automaticScrollToTopOnHiding: boolean + automaticScrollToTopOnHiding: boolean, + + /** + * Deprecated Events + */ + onshow(): void, + + onhide(): void, + + onhiding(): void, + + onshowing(): void } interface CordovaKeyboardEvent extends Event { @@ -144,42 +155,31 @@ interface CordovaKeyboardEvent extends Event { keyboardHeight: number; } -interface Window { +interface WindowEventMap { /** - * @param type This event is fired when keyboard fully shown. - * - * @param callback Function is called when keyboard is shown. + * This event is fired when keyboard fully shown. */ - addEventListener(type: 'keyboardDidShow', callback: () => any, useCapture?: boolean): void; + 'keyboardDidShow': Event, /** - * @param type This event is fired when the keyboard is fully closed. - * - * @param callback Function is called when keyboard is closed. + * This event is fired when the keyboard is fully closed. */ - addEventListener(type: 'keyboardDidHide', callback: () => any, useCapture?: boolean): void; + 'keyboardDidHide': Event, /** - * @param type This event fires before keyboard will be shown. - * - * @param callback Function is called when keyboard is about to be shown on the screen. + * This event fires before keyboard will be shown. */ - addEventListener(type: 'keyboardWillShow', callback: () => any, useCapture?: boolean): void; + 'keyboardWillShow': Event, /** - * @param type This event is fired when the keyboard is fully closed. - * - * @param callback Function is called when keyboard is about to be closed. + * This event is fired when the keyboard is fully closed. */ - addEventListener(type: 'keyboardWillHide', callback: () => any, useCapture?: boolean): void; + 'keyboardWillHide': Event, /** - * @param type This event is fired when the keyboard is fully closed. - * - * @param callback Function is called when keyboard is about to be closed. The function is - * passed an InAppBrowserEvent object as a parameter. + * This event is fired when the keyboard is fully closed. */ - addEventListener(type: 'keyboardHeightWillChange', callback: (event: CordovaKeyboardEvent) => any, useCapture?: boolean): void; -} + 'keyboardHeightWillChange': CordovaKeyboardEvent + } declare var Keyboard: Keyboard;