Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 14 additions & 21 deletions src/keyboard-toolbar.android.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { android as AndroidApp } from "tns-core-modules/application";
import { screen } from "tns-core-modules/platform";
import { View } from "tns-core-modules/ui/core/view";
import { AnimationCurve } from "tns-core-modules/ui/enums";
import { Page } from "tns-core-modules/ui/page";
import { TabView } from "tns-core-modules/ui/tab-view";
import { ad } from "tns-core-modules/utils/utils";
import { Page, Enums, TabView, Frame, Utils, View, Screen, Application } from "@nativescript/core";
import { ToolbarBase } from "./keyboard-toolbar.common";
import { topmost } from "tns-core-modules/ui/frame";

export class Toolbar extends ToolbarBase {
private startPositionY: number;
Expand Down Expand Up @@ -45,8 +38,8 @@ export class Toolbar extends ToolbarBase {
};

let pg;
if (topmost()) {
pg = topmost().currentPage;
if (Frame.topmost()) {
pg = Frame.topmost().currentPage;
} else {
pg = this.content.parent;
while (pg && !(pg instanceof Page)) {
Expand Down Expand Up @@ -92,7 +85,7 @@ export class Toolbar extends ToolbarBase {
const rect = new android.graphics.Rect();
that.content.android.getWindowVisibleDisplayFrame(rect);

const newKeyboardHeight = (Toolbar.getUsableScreenSizeY() - rect.bottom) / screen.mainScreen.scale;
const newKeyboardHeight = (Toolbar.getUsableScreenSizeY() - rect.bottom) / Screen.mainScreen.scale;
if (newKeyboardHeight <= 0 && that.lastKeyboardHeight === undefined) {
return;
}
Expand Down Expand Up @@ -141,11 +134,11 @@ export class Toolbar extends ToolbarBase {
}
}

const animateToY = this.startPositionY - this.lastKeyboardHeight - (this.showWhenKeyboardHidden === true ? 0 : (this.lastHeight / screen.mainScreen.scale)) - navbarHeight;
const animateToY = this.startPositionY - this.lastKeyboardHeight - (this.showWhenKeyboardHidden === true ? 0 : (this.lastHeight / Screen.mainScreen.scale)) - navbarHeight;

parent.animate({
translate: {x: 0, y: animateToY},
curve: AnimationCurve.cubicBezier(.32, .49, .56, 1),
curve: Enums.AnimationCurve.cubicBezier(.32, .49, .56, 1),
duration: 370
}).then(() => {
});
Expand All @@ -156,7 +149,7 @@ export class Toolbar extends ToolbarBase {
// console.log("hideToolbar, animateToY: " + animateToY);
parent.animate({
translate: {x: 0, y: animateToY},
curve: AnimationCurve.cubicBezier(.32, .49, .56, 1), // perhaps make this one a little different as it's the same as the 'show' animation
curve: Enums.AnimationCurve.cubicBezier(.32, .49, .56, 1), // perhaps make this one a little different as it's the same as the 'show' animation
duration: 370
}).then(() => {
});
Expand Down Expand Up @@ -186,7 +179,7 @@ export class Toolbar extends ToolbarBase {
this.navbarHeight = Toolbar.getNavbarHeight();
this.isNavbarVisible = !!this.navbarHeight;

this.startPositionY = screen.mainScreen.heightDIPs - y - ((this.showWhenKeyboardHidden === true ? newHeight : 0) / screen.mainScreen.scale) - (this.isNavbarVisible ? this.navbarHeight : 0);
this.startPositionY = Screen.mainScreen.heightDIPs - y - ((this.showWhenKeyboardHidden === true ? newHeight : 0) / Screen.mainScreen.scale) - (this.isNavbarVisible ? this.navbarHeight : 0);

if (this.lastHeight === undefined) {
// this moves the keyboardview to the bottom (just move it offscreen/toggle visibility(?) if the user doesn't want to show it without the keyboard being up)
Expand All @@ -205,7 +198,7 @@ export class Toolbar extends ToolbarBase {

private static getNavbarHeight() {
// detect correct height from: https://shiv19.com/how-to-get-android-navbar-height-nativescript-vanilla/
const context = (<android.content.Context>ad.getApplicationContext());
const context = (<android.content.Context>Utils.ad.getApplicationContext());
let navBarHeight = 0;
let windowManager = context.getSystemService(android.content.Context.WINDOW_SERVICE);
let d = windowManager.getDefaultDisplay();
Expand Down Expand Up @@ -233,16 +226,16 @@ export class Toolbar extends ToolbarBase {
}

private static getNavbarHeightWhenKeyboardOpen() {
const resources = (<android.content.Context>ad.getApplicationContext()).getResources();
const resources = (<android.content.Context>Utils.ad.getApplicationContext()).getResources();
const resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
return resources.getDimensionPixelSize(resourceId) / screen.mainScreen.scale;
return resources.getDimensionPixelSize(resourceId) / Screen.mainScreen.scale;
}
return 0;
}

private static hasPermanentMenuKey() {
return android.view.ViewConfiguration.get(<android.content.Context>ad.getApplicationContext()).hasPermanentMenuKey();
return android.view.ViewConfiguration.get(<android.content.Context>Utils.ad.getApplicationContext()).hasPermanentMenuKey();
}

private static isVirtualNavbarHidden_butShowsWhenKeyboardIsOpen(): boolean {
Expand All @@ -252,7 +245,7 @@ export class Toolbar extends ToolbarBase {
const SAMSUNG_NAVIGATION_EVENT = "navigationbar_hide_bar_enabled";
try {
// eventId is 1 in case the virtual navbar is hidden (but it shows when the keyboard opens)
Toolbar.supportVirtualKeyboardCheck = android.provider.Settings.Global.getInt(AndroidApp.foregroundActivity.getContentResolver(), SAMSUNG_NAVIGATION_EVENT) === 1;
Toolbar.supportVirtualKeyboardCheck = android.provider.Settings.Global.getInt(Application.android.foregroundActivity.getContentResolver(), SAMSUNG_NAVIGATION_EVENT) === 1;
} catch (e) {
// non-Samsung devices throw a 'SettingNotFoundException'
console.log(">> e: " + e);
Expand All @@ -263,7 +256,7 @@ export class Toolbar extends ToolbarBase {

private static getUsableScreenSizeY(): number {
const screenSize = new android.graphics.Point();
AndroidApp.foregroundActivity.getWindowManager().getDefaultDisplay().getSize(screenSize);
Application.android.foregroundActivity.getWindowManager().getDefaultDisplay().getSize(screenSize);
return screenSize.y;
}
}
30 changes: 12 additions & 18 deletions src/keyboard-toolbar.ios.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import * as application from "tns-core-modules/application";
import { screen } from "tns-core-modules/platform";
import { View, ViewBase } from "tns-core-modules/ui/core/view";
import { EditableTextBase } from "tns-core-modules/ui/editable-text-base";
import { AnimationCurve } from "tns-core-modules/ui/enums";
import { Page } from "tns-core-modules/ui/page";
import { topmost } from "tns-core-modules/ui/frame";
import { Application, Screen, View, ViewBase, EditableTextBase, Enums, Page, Frame} from "@nativescript/core";
import { ToolbarBase } from "./keyboard-toolbar.common";

declare const IQKeyboardManager: any;
Expand All @@ -16,7 +10,7 @@ export class Toolbar extends ToolbarBase {
private keyboardNotificationObserver: any;

protected _loaded(): void {
this.keyboardNotificationObserver = application.ios.addNotificationObserver(
this.keyboardNotificationObserver = Application.ios.addNotificationObserver(
UIKeyboardWillChangeFrameNotification,
notification => {
const newKeyboardHeight = notification.userInfo.valueForKey(UIKeyboardFrameEndUserInfoKey).CGRectValue.size.height;
Expand All @@ -30,7 +24,7 @@ export class Toolbar extends ToolbarBase {

if (!isFirstAnimation && this.hasFocus) {
const parent = (<View>this.content.parent);
parent.translateY = this.startPositionY - newKeyboardHeight - (this.lastHeight / screen.mainScreen.scale);
parent.translateY = this.startPositionY - newKeyboardHeight - (this.lastHeight / Screen.mainScreen.scale);
}
});

Expand All @@ -52,12 +46,12 @@ export class Toolbar extends ToolbarBase {
this.hasFocus = true;
// wrap in a timeout, to make sure this runs after 'UIKeyboardWillChangeFrameNotification'
setTimeout(() => {
const animateToY = this.startPositionY - this.lastKeyboardHeight - (this.showWhenKeyboardHidden === true ? 0 : (this.lastHeight / screen.mainScreen.scale));
const animateToY = this.startPositionY - this.lastKeyboardHeight - (this.showWhenKeyboardHidden === true ? 0 : (this.lastHeight / Screen.mainScreen.scale));
this.log("focus, animateToY: " + animateToY);
parent.animate({
translate: {x: 0, y: animateToY},
// see http://cubic-bezier.com/#.17,.67,.69,1.04
curve: AnimationCurve.cubicBezier(.32, .49, .56, 1),
curve: Enums.AnimationCurve.cubicBezier(.32, .49, .56, 1),
duration: 370
}).then(() => {
});
Expand All @@ -74,7 +68,7 @@ export class Toolbar extends ToolbarBase {
this.log("blur, animateToY: " + animateToY);
parent.animate({
translate: {x: 0, y: animateToY},
curve: AnimationCurve.cubicBezier(.32, .49, .56, 1), // perhaps make this one a little different as it's the same as the 'show' animation
curve: Enums.AnimationCurve.cubicBezier(.32, .49, .56, 1), // perhaps make this one a little different as it's the same as the 'show' animation
duration: 370
}).then(() => {
});
Expand All @@ -83,12 +77,12 @@ export class Toolbar extends ToolbarBase {
} else {
// it's not a text widget, so just animate the toolbar
forView.on("tap", () => {
const animateToY = this.startPositionY - (this.lastHeight / screen.mainScreen.scale);
const animateToY = this.startPositionY - (this.lastHeight / Screen.mainScreen.scale);
this.log("tap, animateToY: " + animateToY);
parent.animate({
translate: {x: 0, y: animateToY},
// see http://cubic-bezier.com/#.17,.67,.69,1.04
curve: AnimationCurve.cubicBezier(.32, .49, .56, 1),
curve: Enums.AnimationCurve.cubicBezier(.32, .49, .56, 1),
duration: 370
}).then(() => {
});
Expand All @@ -108,8 +102,8 @@ export class Toolbar extends ToolbarBase {
if (attemptsLeft-- > 0) {
setTimeout(() => {
let pg;
if (topmost()) {
pg = topmost().currentPage;
if (Frame.topmost()) {
pg = Frame.topmost().currentPage;
} else {
pg = this.content.parent;
while (pg && !(pg instanceof Page)) {
Expand All @@ -131,7 +125,7 @@ export class Toolbar extends ToolbarBase {
}

protected _unloaded(): void {
application.ios.removeNotificationObserver(this.keyboardNotificationObserver, UIKeyboardWillChangeFrameNotification);
Application.ios.removeNotificationObserver(this.keyboardNotificationObserver, UIKeyboardWillChangeFrameNotification);
}

protected _layout(left: number, top: number, right: number, bottom: number): void {
Expand All @@ -142,7 +136,7 @@ export class Toolbar extends ToolbarBase {
}

const {y} = parent.getLocationOnScreen();
this.startPositionY = screen.mainScreen.heightDIPs - y - ((this.showWhenKeyboardHidden === true ? newHeight : 0) / screen.mainScreen.scale);
this.startPositionY = Screen.mainScreen.heightDIPs - y - ((this.showWhenKeyboardHidden === true ? newHeight : 0) / Screen.mainScreen.scale);
this.log("_layout, startPositionY: " + this.startPositionY);

if (this.lastHeight === undefined) {
Expand Down
19 changes: 11 additions & 8 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-keyboard-toolbar",
"version": "1.1.0",
"version": "1.1.1",
"description": "NativeScript Keyboard Toolbar plugin",
"main": "keyboard-toolbar",
"typings": "index.d.ts",
Expand All @@ -11,7 +11,8 @@
}
},
"scripts": {
"tsc": "tsc",
"setup": "npm i && ts-patch install",
"tsc": "tsc -skipLibCheck",
"build": "npm i && npm run tsc",
"package": "cd ../publish && ./pack.sh",
"test.android": "npm run tsc && npm run tslint && cd ../demo && tns build android && tns test android --justlaunch",
Expand Down Expand Up @@ -48,13 +49,15 @@
"homepage": "https://github.com/EddyVerbruggen/nativescript-keyboard-toolbar",
"readmeFilename": "README.md",
"devDependencies": {
"tns-core-modules": "~6.0.0",
"tns-platform-declarations": "~6.0.0",
"typescript": "~3.4.0",
"@nativescript/core": "~7.0.0",
"@nativescript/types": "~7.0.0",
"@nativescript/webpack": "~3.0.0",
"prompt": "^1.0.0",
"rimraf": "^2.6.2",
"tslint": "^5.11.0",
"semver": "^5.6.0"
"rimraf": "^2.6.3",
"semver": "^5.6.0",
"ts-patch": "^1.3.2",
"tslint": "^5.12.1",
"typescript": "~3.9.0"
},
"dependencies": {},
"bootstrapper": "nativescript-plugin-seed"
Expand Down
3 changes: 1 addition & 2 deletions src/references.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
/// <reference path="./node_modules/@nativescript/types/index.d.ts" />
23 changes: 11 additions & 12 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"target": "ES2017",
"module": "esnext",
"moduleResolution": "node",
"declaration": true,
"removeComments": true,
"noLib": false,
"skipLibCheck": true,
"lib": ["es6", "dom"],
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": false,
"skipLibCheck": true,
"lib": ["es6", "dom"],
"sourceMap": true,
"pretty": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
Expand All @@ -18,13 +19,11 @@
"noImplicitAny": false,
"noImplicitReturns": true,
"noImplicitUseStrict": false,
"noFallthroughCasesInSwitch": true,
"typeRoots": [
"./node_modules/@types",
"./node_modules"
],
"types": [
]
"plugins": [{
"transform": "@nativescript/webpack/transformers/ns-transform-native-classes",
"type": "raw"
}],
"noFallthroughCasesInSwitch": true
},
"exclude": [
"node_modules"
Expand Down