diff --git a/src/image-zoom.android.ts b/src/image-zoom.android.ts index b4adce6..9d470f7 100644 --- a/src/image-zoom.android.ts +++ b/src/image-zoom.android.ts @@ -62,6 +62,8 @@ export class ImageZoom extends ImageZoomBase { ); this.nativeView.setImage(source); }); + } else { + source = com.davemorrissey.labs.subscaleview.ImageSource.uri(src); } if (this.nativeView && source) { diff --git a/src/image-zoom.ios.ts b/src/image-zoom.ios.ts index 4bb93d5..403384b 100644 --- a/src/image-zoom.ios.ts +++ b/src/image-zoom.ios.ts @@ -1,45 +1,61 @@ -import { - ImageZoomBase, - srcProperty, - maxZoomScaleProperty, - minZoomScaleProperty, - zoomScaleProperty -} from './image-zoom.common'; -import { Image, stretchProperty, Stretch } from 'tns-core-modules/ui/image'; +import { Image, Stretch } from 'tns-core-modules/ui/image'; import { layout } from 'tns-core-modules/ui/core/view'; import { topmost } from 'tns-core-modules/ui/frame'; import * as imageSource from 'tns-core-modules/image-source'; -export class ImageZoom extends ImageZoomBase { +import { ScrollView } from 'tns-core-modules/ui/scroll-view'; + +import { Property } from 'tns-core-modules/ui/core/view'; + +export const stretchProperty = new Property({ + name: 'stretch' +}); + +export const zoomScaleProperty = new Property({ + name: 'zoomScale', + defaultValue: 1 +}); + +export const minZoomScaleProperty = new Property({ + name: 'minZoom', + defaultValue: 1 +}); + +export const maxZoomScaleProperty = new Property({ + name: 'maxZoom', + defaultValue: 4 +}); + +export const srcProperty = new Property({ + name: 'src' +}); + +export class ImageZoom extends ScrollView { _image: Image; nativeView: UIScrollView; private layoutWidth: number; private layoutHeight: number; private delegate: any; - + src: string; + zoomScale: number; + minZoom: number; + maxZoom: number; + stretch: string; constructor() { super(); this.delegate = UIScrollViewDelegateImpl.initWithOwner( new WeakRef(this) ); - } - - public createNativeView() { + const nativeView = this.nativeView; this._image = new Image(); - topmost()._addView(this._image); - return UIScrollView.new(); - } - - public initNativeView() { - this.nativeView.delegate = this.delegate; - this.nativeView.zoomScale = this.zoomScale; - this.nativeView.minimumZoomScale = this.minZoom; - this.nativeView.maximumZoomScale = this.maxZoom; - this.nativeView.addSubview(this._image.nativeView); + nativeView.delegate = this.delegate; + nativeView.zoomScale = this.zoomScale; + nativeView.minimumZoomScale = this.minZoom; + nativeView.maximumZoomScale = this.maxZoom; + this.content = this._image; } public disposeNativeView() { this.delegate = null; - topmost()._removeView(this._image); } [srcProperty.setNative](src: string) { @@ -73,29 +89,14 @@ export class ImageZoom extends ImageZoomBase { this.nativeView.maximumZoomScale = scale; } } - - public onLayout( - left: number, - top: number, - right: number, - bottom: number - ): void { - super.onLayout(left, top, right, bottom); - this.layoutWidth = right - left; - this.layoutHeight = bottom - top; - this._image.nativeView.frame = this.nativeView.bounds; - } - - public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number) { - const nativeView = this.nativeView; - if (nativeView) { - const width = layout.getMeasureSpecSize(widthMeasureSpec); - const height = layout.getMeasureSpecSize(heightMeasureSpec); - this.setMeasuredDimension(width, height); - } - } } +srcProperty.register(ImageZoom); +stretchProperty.register(ImageZoom); +zoomScaleProperty.register(ImageZoom); +minZoomScaleProperty.register(ImageZoom); +maxZoomScaleProperty.register(ImageZoom); + export class UIScrollViewDelegateImpl extends NSObject implements UIScrollViewDelegate { private owner: WeakRef; diff --git a/src/package-lock.json b/src/package-lock.json index 20a79e7..c40249c 100644 --- a/src/package-lock.json +++ b/src/package-lock.json @@ -1,6 +1,6 @@ { "name": "nativescript-image-zoom", - "version": "1.0.0", + "version": "1.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/package.json b/src/package.json index ddd169e..005a3ca 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "nativescript-image-zoom", - "version": "1.1.0", + "version": "1.1.1", "description": "Zoom enabled ImageView for NativeScript", "main": "image-zoom", "typings": "index.d.ts", @@ -13,7 +13,6 @@ "scripts": { "tsc": "tsc -skipLibCheck", "build": "npm i && tsc", - "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/**\"",