Skip to content

Upgrade to NS7 #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
});
```
Expand Down
2 changes: 1 addition & 1 deletion demo/app/app.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import * as application from 'tns-core-modules/application';
import * as application from '@nativescript/core/application';
application.start({ moduleName: "main-page" });
10 changes: 5 additions & 5 deletions demo/app/main-page.ts
Original file line number Diff line number Diff line change
@@ -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 = <pages.Page>args.object;
let page = <Page>args.object;
page.bindingContext = new HelloWorldModel();
}
17 changes: 7 additions & 10 deletions demo/app/main-view-model.ts
Original file line number Diff line number Diff line change
@@ -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([]);
Expand All @@ -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();
}
Expand All @@ -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;

(<any> topmost().getViewById('hint')).visibility = 'collapse';
(<any> Frame.topmost().getViewById('hint')).visibility = 'collapse';
} else {
console.log('User pressed cancel');
}
Expand Down
5 changes: 2 additions & 3 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions demo/references.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/// <reference path="../src/node_modules/tns-platform-declarations/ios.d.ts" />
/// <reference path="../src/node_modules/tns-platform-declarations/android.d.ts" />
/// <reference path="../src/node_modules/@nativescript/types/index.d.ts" />
4 changes: 4 additions & 0 deletions publish/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
31 changes: 18 additions & 13 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
}
11 changes: 5 additions & 6 deletions src/rad-imagepicker.android.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -40,19 +39,19 @@ 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;
}
}
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);

Expand Down
2 changes: 1 addition & 1 deletion src/rad-imagepicker.common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Observable } from 'tns-core-modules/data/observable';
import { Observable } from '@nativescript/core';

export class Common extends Observable {
constructor() {
Expand Down
16 changes: 8 additions & 8 deletions src/rad-imagepicker.ios.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -27,7 +26,7 @@ export class RadImagepicker extends Common {

pick(options: PickerOptions): Promise<Array<any>> {
return new Promise((resolve, reject) => {
const viewController = frame.topmost().currentPage.ios;
const viewController = Frame.topmost().currentPage.ios;

imagePickerController = ImagePickerController.new();

Expand Down Expand Up @@ -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 <ImagePickerDelegateImpl>super.new();
Expand All @@ -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);
}

Expand All @@ -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<UIImage>): void {
const viewController = frame.topmost().currentPage.ios;
const viewController = Frame.topmost().currentPage.ios;
if (images.count < 1) {
viewController.dismissViewControllerAnimatedCompletion(true, null);
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/references.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// <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" />
/// <reference path="./typings/android.d.ts" />
/// <reference path="./typings/objc!ImagePicker.d.ts" />
/// <reference path="./typings/objc!Lightbox.d.ts" />
29 changes: 18 additions & 11 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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,
}
18 changes: 9 additions & 9 deletions src/typings/android.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/// <reference path="./android.os.Bundle.d.ts" />
/// <reference path="./android.support.v4.app.Fragment.d.ts" />
/// <reference path="./android.support.v4.app.FragmentActivity.d.ts" />
/// <reference path="./androidx.fragment.app.Fragment.d.ts" />
/// <reference path="./androidx.fragment.app.FragmentActivity.d.ts" />
/// <reference path="./android.view.MotionEvent.d.ts" />
/// <reference path="./android.view.View.d.ts" />
declare module com {
Expand Down Expand Up @@ -223,7 +223,7 @@ declare module com {
import androidgraphicsCanvas = android.graphics.Canvas;
/// <reference path="./android.content.Context.d.ts" />
/// <reference path="./android.graphics.Canvas.d.ts" />
/// <reference path="./android.support.v7.widget.RecyclerView.d.ts" />
/// <reference path="./androidx.recyclerview.widget.RecyclerView.d.ts" />
/// <reference path="./android.view.View.d.ts" />
declare module com {
export module fxn {
Expand Down Expand Up @@ -268,8 +268,8 @@ declare module com {
}
}

/// <reference path="./android.support.v4.app.Fragment.d.ts" />
/// <reference path="./android.support.v4.app.FragmentActivity.d.ts" />
/// <reference path="./androidx.fragment.app.Fragment.d.ts" />
/// <reference path="./androidx.fragment.app.FragmentActivity.d.ts" />
/// <reference path="./com.fxn.interfaces.WorkFinish.d.ts" />
declare module com {
export module fxn {
Expand All @@ -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;
Expand All @@ -308,7 +308,7 @@ import javalangLong = java.lang.Long;
/// <reference path="./android.content.Context.d.ts" />
/// <reference path="./android.database.Cursor.d.ts" />
/// <reference path="./android.graphics.Bitmap.d.ts" />
/// <reference path="./android.support.v7.app.AppCompatActivity.d.ts" />
/// <reference path="./androidx.appcompat.app.AppCompatActivity.d.ts" />
/// <reference path="./android.support.v7.widget.RecyclerView.d.ts" />
/// <reference path="./android.view.View.d.ts" />
/// <reference path="./android.view.ViewPropertyAnimator.d.ts" />
Expand Down