Skip to content

Commit f81cfb2

Browse files
Support IQKeyboardManager #2
1 parent 45542d1 commit f81cfb2

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

demo/app/main-page.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,4 @@
9595
</kt:Toolbar>
9696

9797
</GridLayout>
98-
</Page>
98+
</Page>

demo/app/main-view-model.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { topmost } from "tns-core-modules/ui/frame";
44
import { TextView } from "tns-core-modules/ui/text-view";
55
const emailValidator = require("email-validator");
66

7+
declare const IQKeyboardManager: any;
8+
79
export class HelloWorldModel extends Observable {
810

911
email: string;
@@ -27,6 +29,9 @@ export class HelloWorldModel extends Observable {
2729
constructor() {
2830
super();
2931

32+
// this suppresses IQKeyboardManager's toolbar (the one with < > and OK buttons)
33+
IQKeyboardManager.sharedManager().enableAutoToolbar = false;
34+
3035
// laughable code, I know, but it's just a quick demo
3136
setTimeout(() => {
3237
const page = topmost().currentPage;

demo/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"dependencies": {
1212
"email-validator": "^2.0.4",
13+
"nativescript-iqkeyboardmanager": "^1.3.0",
1314
"nativescript-keyboard-toolbar": "file:../src",
1415
"nativescript-theme-core": "^1.0.4",
1516
"nativescript-unit-test-runner": "^0.3.4",

src/keyboard-toolbar.ios.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { AnimationCurve } from "tns-core-modules/ui/enums";
66
import { topmost } from "tns-core-modules/ui/frame";
77
import { ToolbarBase } from "./keyboard-toolbar.common";
88

9+
declare const IQKeyboardManager: any;
10+
911
export class Toolbar extends ToolbarBase {
1012
private startPositionY: number;
1113
private lastHeight: number;
@@ -37,8 +39,15 @@ export class Toolbar extends ToolbarBase {
3739
// experimental support for non-text widgets.. but not sure if this is useful, so not documenting it yet
3840
const isText = forView instanceof EditableTextBase;
3941

42+
const hasIQKeyboardManagerInstalled = typeof(IQKeyboardManager) !== "undefined";
43+
const iqKeyboardManagerOriginalDistance = hasIQKeyboardManagerInstalled ? IQKeyboardManager.sharedManager().keyboardDistanceFromTextField : 0;
44+
4045
if (isText) {
4146
forView.on("focus", () => {
47+
if (hasIQKeyboardManagerInstalled) {
48+
IQKeyboardManager.sharedManager().keyboardDistanceFromTextField = iqKeyboardManagerOriginalDistance + parent.height;
49+
}
50+
4251
this.hasFocus = true;
4352
// wrap in a timeout, to make sure this runs after 'UIKeyboardWillChangeFrameNotification'
4453
setTimeout(() => {
@@ -55,6 +64,10 @@ export class Toolbar extends ToolbarBase {
5564
});
5665

5766
forView.on("blur", () => {
67+
if (hasIQKeyboardManagerInstalled) {
68+
IQKeyboardManager.sharedManager().keyboardDistanceFromTextField = iqKeyboardManagerOriginalDistance;
69+
}
70+
5871
this.hasFocus = false;
5972
const animateToY = this.showWhenKeyboardHidden === true && this.showAtBottomWhenKeyboardHidden !== true ? 0 : this.startPositionY;
6073
this.log("blur, animateToY: " + animateToY);

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-keyboard-toolbar",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "NativeScript Keyboard Toolbar plugin",
55
"main": "keyboard-toolbar",
66
"typings": "index.d.ts",

0 commit comments

Comments
 (0)