diff --git a/README.md b/README.md index a371351..0c4fa8e 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ radImagepicker.pick(opts).then((selectedImages) => { // Do something with selected images // currently // the image will be of type nativescript image source - // tns-core-modules/image-source + // @nativescript/core/ui/image-source } }); ``` diff --git a/demo/app/app.ts b/demo/app/app.ts index a17b0bd..cad5913 100644 --- a/demo/app/app.ts +++ b/demo/app/app.ts @@ -1,2 +1,2 @@ -import * as application from 'tns-core-modules/application'; +import * as application from '@nativescript/core/application'; application.start({ moduleName: "main-page" }); diff --git a/demo/app/main-page.ts b/demo/app/main-page.ts index 8ef1850..e77b57a 100644 --- a/demo/app/main-page.ts +++ b/demo/app/main-page.ts @@ -1,10 +1,10 @@ -import * as observable from 'tns-core-modules/data/observable'; -import * as pages from 'tns-core-modules/ui/page'; -import {HelloWorldModel} from './main-view-model'; +import { Observable } from '@nativescript/core'; +import { Page } from '@nativescript/core/ui'; +import { HelloWorldModel } from './main-view-model'; // Event handler for Page 'loaded' event attached in main-page.xml -export function pageLoaded(args: observable.EventData) { +export function pageLoaded(args: Observable.EventData) { // Get the event sender - let page = args.object; + let page = args.object; page.bindingContext = new HelloWorldModel(); } diff --git a/demo/app/main-view-model.ts b/demo/app/main-view-model.ts index 8029a65..4e7c078 100644 --- a/demo/app/main-view-model.ts +++ b/demo/app/main-view-model.ts @@ -1,9 +1,6 @@ import { PickerOptions, RadImagepicker } from "@nstudio/nativescript-rad-imagepicker"; -import { Observable } from "tns-core-modules/data/observable"; -import { ObservableArray } from "tns-core-modules/data/observable-array"; -import { screen } from "tns-core-modules/platform"; -import { topmost } from "tns-core-modules/ui/frame"; -import { Repeater } from "tns-core-modules/ui/repeater"; +import { Observable, ObservableArray, Screen, Frame } from "@nativescript/core"; +import { Repeater } from "@nativescript/core/ui"; export class HelloWorldModel extends Observable { public images = new ObservableArray([]); @@ -14,10 +11,10 @@ export class HelloWorldModel extends Observable { constructor() { super(); - if (screen.mainScreen.widthDIPs >= 350) { - this.imageWidth = screen.mainScreen.widthDIPs / 4; + if (Screen.mainScreen.widthDIPs >= 350) { + this.imageWidth = Screen.mainScreen.widthDIPs / 4; } else { - this.imageWidth = screen.mainScreen.widthDIPs / 3; + this.imageWidth = Screen.mainScreen.widthDIPs / 3; } this.radImagepicker = new RadImagepicker(); } @@ -39,10 +36,10 @@ export class HelloWorldModel extends Observable { }); } - const repeaterView: Repeater = topmost().getViewById("repeaterView"); + const repeaterView: Repeater = Frame.topmost().getViewById("repeaterView"); repeaterView.items = this.images; - ( topmost().getViewById('hint')).visibility = 'collapse'; + ( Frame.topmost().getViewById('hint')).visibility = 'collapse'; } else { console.log('User pressed cancel'); } diff --git a/demo/package.json b/demo/package.json index ed4cf0e..cec16e4 100644 --- a/demo/package.json +++ b/demo/package.json @@ -9,10 +9,10 @@ } }, "dependencies": { + "@nativescript/core": "7.3.0", "@nstudio/nativescript-rad-imagepicker": "file:../src", "nativescript-theme-core": "^1.0.4", - "nativescript-unit-test-runner": "^0.3.4", - "tns-core-modules": "^4.1.0" + "nativescript-unit-test-runner": "^0.3.4" }, "devDependencies": { "awesome-typescript-loader": "~5.0.0", @@ -35,7 +35,6 @@ "nativescript-worker-loader": "~0.8.1", "raw-loader": "~0.5.1", "resolve-url-loader": "~2.3.0", - "tns-platform-declarations": "^4.1.0", "tslint": "~5.4.3", "typescript": "~2.7.2", "webpack": "~4.5.0", diff --git a/demo/references.d.ts b/demo/references.d.ts index 680f3ef..e276cc3 100644 --- a/demo/references.d.ts +++ b/demo/references.d.ts @@ -1,2 +1 @@ -/// -/// +/// diff --git a/publish/package.json b/publish/package.json index d5c28e9..5415599 100644 --- a/publish/package.json +++ b/publish/package.json @@ -3,7 +3,11 @@ "version": "1.0.0", "description": "Publish helper", "devDependencies": { + "@nativescript/core": "^7.3.0", "ncp": "^2.0.0", "rimraf": "^2.5.0" + }, + "dependencies": { + "ts-node": "^9.1.1" } } diff --git a/src/package.json b/src/package.json index 3a1931e..82bf394 100644 --- a/src/package.json +++ b/src/package.json @@ -1,23 +1,22 @@ { "name": "@nstudio/nativescript-rad-imagepicker", - "version": "2.0.4", + "version": "2.0.8", "description": "Whatsapp style imagepicker for NativeScript apps", "main": "rad-imagepicker", "typings": "index.d.ts", "nativescript": { "platforms": { - "android": "4.0.0", - "ios": "4.0.0" + "android": "7.0.0", + "ios": "7.0.0" } }, "scripts": { - "tsc": "tsc -skipLibCheck", - "build": "npm i && tsc && npm run build.native", + "build": "npm i && ts-patch install && tsc && npm run build.native", "build.native": "node scripts/build-native.js", "postclone": "npm i && node scripts/postclone.js && cd ../demo && npm i && cd ../src && npm run plugin.link", "test.android": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build android && tns test android --justlaunch", "test.ios": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build ios && tns test ios --justlaunch", - "tslint": "cd .. && tslint \"**/*.ts\" --config tslint.json --exclude \"**/node_modules/**\"", + "tslint": "cd .. && tslint \"**/*.ts\" --config tslint.json --exclude \"**/node_modules/**\" --exclude \"*demo*/platforms/**\" --exclude \"**/typings/**\"", "plugin.link": "npm link && cd ../demo && npm link nativescript-rad-imagepicker && cd ../src", "plugin.tscwatch": "npm run tsc -- -w", "demo.ios": "npm i && npm run tsc && cd ../demo && tns run ios --syncAllFiles", @@ -47,16 +46,22 @@ "license": "Apache-2.0", "homepage": "https://github.com/nstudio/nativescript-rad-imagepicker", "devDependencies": { - "tns-core-modules": "^4.0.0", - "tns-platform-declarations": "^4.0.0", - "typescript": "~2.7.2", + "@nativescript/core": "~7.0.3", + "@nativescript/types": "~7.0.3", + "@nativescript/webpack": "~3.0.4", + "husky": "^4.2.5", + "lint-staged": "^10.2.11", + "ng-packagr": "~10.1.0", + "prettier": "^2.0.5", "prompt": "^1.0.0", - "rimraf": "^2.5.0", - "tslint": "^5.0.0", - "semver": "^5.5.0" + "rimraf": "^2.6.3", + "tslint": "~6.0.0", + "ts-patch": "^1.3.0", + "ts-node": "~9.0.0", + "typescript": "~3.9.7" }, "dependencies": { - "nativescript-permissions": "~1.2.3" + "nativescript-permissions": "~1.3.11" }, "bootstrapper": "nativescript-plugin-seed" } diff --git a/src/rad-imagepicker.android.ts b/src/rad-imagepicker.android.ts index ad7e8b9..4584830 100644 --- a/src/rad-imagepicker.android.ts +++ b/src/rad-imagepicker.android.ts @@ -1,8 +1,7 @@ +import * as app from "@nativescript/core/application"; import { Common, PickerOptions } from './rad-imagepicker.common'; -import * as app from "tns-core-modules/application"; -import * as frame from "tns-core-modules/ui/frame"; +import { Frame, ImageSource } from "@nativescript/core"; import * as permissions from "nativescript-permissions"; -import * as imageSource from "tns-core-modules/image-source"; declare var com: any; const Pix = com.fxn.pix.Pix; @@ -40,11 +39,11 @@ export class RadImagepicker extends Common { const imgArray = returnValue.toArray(); const images = []; for (let i = 0; i < imgArray.length; i++ ) { - images.push(imageSource.fromFile(imgArray[i].toString())); + images.push( ImageSource.fromFile(imgArray[i].toString())); } resolve(images); } else if (resultCode == android.app.Activity.RESULT_CANCELED) { - resolve(); + resolve(undefined); } } break; @@ -52,7 +51,7 @@ export class RadImagepicker extends Common { } app.android.on(app.AndroidApplication.activityResultEvent, onResult); - let activity = frame.topmost().android.activity; + let activity = Frame.topmost().android.activity; let i = new android.content.Intent(activity, com.fxn.pix.Pix.class); i.putExtra("selection", options.imageLimit); diff --git a/src/rad-imagepicker.common.ts b/src/rad-imagepicker.common.ts index 92155e2..ca179e2 100644 --- a/src/rad-imagepicker.common.ts +++ b/src/rad-imagepicker.common.ts @@ -1,4 +1,4 @@ -import { Observable } from 'tns-core-modules/data/observable'; +import { Observable } from '@nativescript/core'; export class Common extends Observable { constructor() { diff --git a/src/rad-imagepicker.ios.ts b/src/rad-imagepicker.ios.ts index 767d143..d071b50 100644 --- a/src/rad-imagepicker.ios.ts +++ b/src/rad-imagepicker.ios.ts @@ -1,6 +1,5 @@ +import { Frame, ImageSource } from "@nativescript/core"; import { Common, PickerOptions } from './rad-imagepicker.common'; -import * as frame from "tns-core-modules/ui/frame"; -import * as imageSource from "tns-core-modules/image-source"; let imagePickerController; declare var NSDocumentDirectory; @@ -16,7 +15,7 @@ function createImageSourceFromUIImage(image, i) { const data = UIImagePNGRepresentation(image); data.writeToFileAtomically(path, true); - return imageSource.fromFile(path); + return ImageSource.fromFileSync(path); } export class RadImagepicker extends Common { @@ -27,7 +26,7 @@ export class RadImagepicker extends Common { pick(options: PickerOptions): Promise> { return new Promise((resolve, reject) => { - const viewController = frame.topmost().currentPage.ios; + const viewController = Frame.topmost().currentPage.ios; imagePickerController = ImagePickerController.new(); @@ -59,7 +58,8 @@ export class RadImagepicker extends Common { } } -export class ImagePickerDelegateImpl extends NSObject implements ImagePickerDelegate { +@NativeClass() +class ImagePickerDelegateImpl extends NSObject implements ImagePickerDelegate { public static ObjCProtocols = [ImagePickerDelegate]; static new(): ImagePickerDelegateImpl { return super.new(); @@ -73,7 +73,7 @@ export class ImagePickerDelegateImpl extends NSObject implements ImagePickerDele cancelButtonDidPress(imagePicker: ImagePickerController): void { this._callback(); - const viewController = frame.topmost().currentPage.ios; + const viewController = Frame.topmost().currentPage.ios; viewController.dismissViewControllerAnimatedCompletion(true, null); } @@ -83,12 +83,12 @@ export class ImagePickerDelegateImpl extends NSObject implements ImagePickerDele selectedImages.push(createImageSourceFromUIImage(images[i], i)); } this._callback(selectedImages); - const viewController = frame.topmost().currentPage.ios; + const viewController = Frame.topmost().currentPage.ios; viewController.dismissViewControllerAnimatedCompletion(true, null); } wrapperDidPressImages(imagePicker: ImagePickerController, images: NSArray): void { - const viewController = frame.topmost().currentPage.ios; + const viewController = Frame.topmost().currentPage.ios; if (images.count < 1) { viewController.dismissViewControllerAnimatedCompletion(true, null); } else { diff --git a/src/references.d.ts b/src/references.d.ts index b40c21b..2841d1e 100644 --- a/src/references.d.ts +++ b/src/references.d.ts @@ -1,5 +1,4 @@ -/// -/// +/// /// /// /// diff --git a/src/tsconfig.json b/src/tsconfig.json index 2c33e90..ec12868 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -1,26 +1,33 @@ { "compilerOptions": { - "target": "es5", - "module": "commonjs", - "declaration": true, + "target": "es2017", + "module": "esnext", + "moduleResolution": "node", "removeComments": true, - "noLib": false, - "emitDecoratorMetadata": true, + "declaration": false, "experimentalDecorators": true, - "lib": ["es6", "dom"], "sourceMap": true, - "pretty": true, + "skipLibCheck": true, + "noLib": false, + "noEmitHelpers": true, "allowUnreachableCode": false, "allowUnusedLabels": false, - "noEmitHelpers": true, "noEmitOnError": false, "noImplicitAny": false, "noImplicitReturns": true, "noImplicitUseStrict": false, - "noFallthroughCasesInSwitch": true + "noFallthroughCasesInSwitch": true, + "lib": ["es2017", "dom", "es6"], + "baseUrl": ".", + "plugins": [ + { + "transform": "@nativescript/webpack/transformers/ns-transform-native-classes", + "type": "raw" + } + ] }, "exclude": [ - "node_modules" + "node_modules", "platforms", "typings/android.d.ts", "typings/objc!ImagePicker.d.ts", "typings/objc!Lightbox.d.ts" ], - "compileOnSave": false + "compileOnSave": false, } diff --git a/src/typings/android.d.ts b/src/typings/android.d.ts index f1b7339..82f6fdb 100644 --- a/src/typings/android.d.ts +++ b/src/typings/android.d.ts @@ -173,13 +173,13 @@ declare module com { } } -import androidsupportv4appFragment = android.support.v4.app.Fragment; -import androidsupportv4appFragmentActivity = android.support.v4.app.FragmentActivity; +import androidsupportv4appFragment = androidx.fragment.app.Fragment; +import androidsupportv4appFragmentActivity = androidx.fragment.app.FragmentActivity; import androidosBundle = android.os.Bundle; import androidviewMotionEvent = android.view.MotionEvent; /// -/// -/// +/// +/// /// /// declare module com { @@ -223,7 +223,7 @@ declare module com { import androidgraphicsCanvas = android.graphics.Canvas; /// /// -/// +/// /// declare module com { export module fxn { @@ -268,8 +268,8 @@ declare module com { } } -/// -/// +/// +/// /// declare module com { export module fxn { @@ -296,7 +296,7 @@ declare module com { } } -import androidsupportv7appAppCompatActivity = android.support.v7.app.AppCompatActivity; +import androidsupportv7appAppCompatActivity = androidx.appcompat.app.AppCompatActivity; import androidappActivity = android.app.Activity; import javautilCalendar = java.util.Calendar; import androidviewViewPropertyAnimator = android.view.ViewPropertyAnimator; @@ -308,7 +308,7 @@ import javalangLong = java.lang.Long; /// /// /// -/// +/// /// /// ///