diff --git a/src/keyboard-toolbar.android.ts b/src/keyboard-toolbar.android.ts index 0eb1c34..28a76f5 100644 --- a/src/keyboard-toolbar.android.ts +++ b/src/keyboard-toolbar.android.ts @@ -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; @@ -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)) { @@ -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; } @@ -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(() => { }); @@ -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(() => { }); @@ -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) @@ -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 = (ad.getApplicationContext()); + const context = (Utils.ad.getApplicationContext()); let navBarHeight = 0; let windowManager = context.getSystemService(android.content.Context.WINDOW_SERVICE); let d = windowManager.getDefaultDisplay(); @@ -233,16 +226,16 @@ export class Toolbar extends ToolbarBase { } private static getNavbarHeightWhenKeyboardOpen() { - const resources = (ad.getApplicationContext()).getResources(); + const resources = (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(ad.getApplicationContext()).hasPermanentMenuKey(); + return android.view.ViewConfiguration.get(Utils.ad.getApplicationContext()).hasPermanentMenuKey(); } private static isVirtualNavbarHidden_butShowsWhenKeyboardIsOpen(): boolean { @@ -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); @@ -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; } } diff --git a/src/keyboard-toolbar.ios.ts b/src/keyboard-toolbar.ios.ts index d210746..765c50c 100644 --- a/src/keyboard-toolbar.ios.ts +++ b/src/keyboard-toolbar.ios.ts @@ -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; @@ -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; @@ -30,7 +24,7 @@ export class Toolbar extends ToolbarBase { if (!isFirstAnimation && this.hasFocus) { const parent = (this.content.parent); - parent.translateY = this.startPositionY - newKeyboardHeight - (this.lastHeight / screen.mainScreen.scale); + parent.translateY = this.startPositionY - newKeyboardHeight - (this.lastHeight / Screen.mainScreen.scale); } }); @@ -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(() => { }); @@ -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(() => { }); @@ -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(() => { }); @@ -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)) { @@ -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 { @@ -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) { diff --git a/src/package.json b/src/package.json index f2707b3..c18c5b4 100644 --- a/src/package.json +++ b/src/package.json @@ -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", @@ -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", @@ -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" diff --git a/src/references.d.ts b/src/references.d.ts index 1e5e961..d743326 100644 --- a/src/references.d.ts +++ b/src/references.d.ts @@ -1,2 +1 @@ -/// -/// +/// diff --git a/src/tsconfig.json b/src/tsconfig.json index fda1558..b3183d9 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -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, @@ -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"