diff --git a/types/cordova-plugin-keyboard/cordova-plugin-keyboard-tests.ts b/types/cordova-plugin-keyboard/cordova-plugin-keyboard-tests.ts index 767eaa6ed2..fa5cf72a30 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: 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 427a5425e5..af880d732a 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,6 +127,9 @@ 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; @@ -110,65 +138,48 @@ interface Keyboard { */ automaticScrollToTopOnHiding: boolean, - // Events + /** + * Deprecated Events + */ + onshow(): void, - /** - * 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, + onhide(): void, + onhiding(): void, + + onshowing(): void } -declare var Keyboard:Keyboard; +interface CordovaKeyboardEvent extends Event { + /** The height of the keyboard */ + keyboardHeight: number; +} + +interface WindowEventMap { + /** + * This event is fired when keyboard fully shown. + */ + 'keyboardDidShow': Event, + + /** + * This event is fired when the keyboard is fully closed. + */ + 'keyboardDidHide': Event, + + /** + * This event fires before keyboard will be shown. + */ + 'keyboardWillShow': Event, + + /** + * This event is fired when the keyboard is fully closed. + */ + 'keyboardWillHide': Event, + + /** + * This event is fired when the keyboard is fully closed. + */ + 'keyboardHeightWillChange': CordovaKeyboardEvent + } + +declare var Keyboard: Keyboard;