From 456ad287da94ec8d61b161d9bab088a4ea2b8820 Mon Sep 17 00:00:00 2001 From: Dan Manastireanu Date: Sat, 31 Oct 2015 14:37:32 +0200 Subject: [PATCH] Added type definition for Cordova Keyboard plugin. Closes #4699 --- cordova/cordova-tests.ts | 29 +++++- cordova/cordova.d.ts | 1 + cordova/plugins/Keyboard.d.ts | 174 ++++++++++++++++++++++++++++++++++ 3 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 cordova/plugins/Keyboard.d.ts diff --git a/cordova/cordova-tests.ts b/cordova/cordova-tests.ts index 491b49773a..d0e6e68897 100644 --- a/cordova/cordova-tests.ts +++ b/cordova/cordova-tests.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Open Technologies, Inc. -// Licensed under the MIT license. +// Licensed under the MIT license. /// @@ -203,7 +203,7 @@ file.abort(); // InAppBrowser plugin //---------------------------------------------------------------------- -// signature of window.open() added by InAppBrowser plugin +// signature of window.open() added by InAppBrowser plugin // is similar to native window.open signature, so the compiler can's // select proper overload, but we cast result to InAppBrowser manually. var iab = window.open('google.com', '_self'); @@ -307,3 +307,28 @@ db.transaction( navigator.notification.vibrate(100); navigator.notification.vibrateWithPattern([100, 200, 200, 150, 50], 3); setTimeout(navigator.notification.cancelVibration, 1000); + +// Keyboard plugin +//---------------------------------------------------------------------- +Keyboard.shrinkView(true); +Keyboard.shrinkView(false); +Keyboard.hideFormAccessoryBar(true); +Keyboard.hideFormAccessoryBar(false); +Keyboard.disableScrollingInShrinkView(true); +Keyboard.disableScrollingInShrinkView(false); +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'); +}; diff --git a/cordova/cordova.d.ts b/cordova/cordova.d.ts index 32ef0a76b6..019fdddc86 100644 --- a/cordova/cordova.d.ts +++ b/cordova/cordova.d.ts @@ -25,6 +25,7 @@ /// /// /// +/// interface Cordova { /** Invokes native functionality by specifying corresponding service name, action and optional parameters. diff --git a/cordova/plugins/Keyboard.d.ts b/cordova/plugins/Keyboard.d.ts new file mode 100644 index 0000000000..414cd87fac --- /dev/null +++ b/cordova/plugins/Keyboard.d.ts @@ -0,0 +1,174 @@ +// Type definitions for Apache Cordova Keyboard plugin v0.1.2 +// Project: https://github.com/apache/cordova-plugins/tree/master/keyboard +// Definitions by: Dan Manastireanu +// Definitions: https://github.com/borisyankov/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 + + /** + * Shrink the WebView when the keyboard comes up. + * + * Set to true to shrink the WebView when the keyboard comes up. + * The WebView shrinks instead of the viewport shrinking and the page scrollable. + * 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. + * + * Example: + * + * Keyboard.shrinkView(true); + * Keyboard.shrinkView(false); + * + * + * @param shrink + */ + shrinkView(shrink:boolean): void, + + /** + * Hide the keyboard toolbar. + * + * Set to true to hide the additional toolbar that is on top of the keyboard. + * This toolbar features the Prev, Next, and Done buttons. + * + * Example: + * + * Keyboard.hideFormAccessoryBar(true); + * Keyboard.hideFormAccessoryBar(false); + * + * + * @param hide + */ + hideFormAccessoryBar(hide:boolean): void, + + /** + * Disable scrolling when the the WebView is shrunk. + * + * Set to true to disable scrolling when the WebView is shrunk. + * + * Example: + * + * Keyboard.disableScrollingInShrinkView(true); + * Keyboard.disableScrollingInShrinkView(false); + * + * + * @param disable + */ + disableScrollingInShrinkView(disable:boolean): void, + + // Properties + + /** + * Determine if the keyboard is visible. + * + * Read this property to determine if the keyboard is visible. + * + * Example: + * + * if (Keyboard.isVisible) { + * // do something + * } + * + * + */ + isVisible: boolean, + /** + * Specifies whenether content of page would be autoamtically scrolled to the top of the page when keyboard is hiding. + * + * 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. + * + * 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, + +} + +declare var Keyboard:Keyboard;