Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
triniwiz committed Jan 5, 2018
1 parent 5e499aa commit ebfe2fd
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 48 deletions.
2 changes: 2 additions & 0 deletions src/image-zoom.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
91 changes: 46 additions & 45 deletions src/image-zoom.ios.ts
Original file line number Diff line number Diff line change
@@ -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<ImageZoom, Stretch>({
name: 'stretch'
});

export const zoomScaleProperty = new Property<ImageZoom, number>({
name: 'zoomScale',
defaultValue: 1
});

export const minZoomScaleProperty = new Property<ImageZoom, number>({
name: 'minZoom',
defaultValue: 1
});

export const maxZoomScaleProperty = new Property<ImageZoom, number>({
name: 'maxZoom',
defaultValue: 4
});

export const srcProperty = new Property<ImageZoom, string>({
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<ImageZoom>(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) {
Expand Down Expand Up @@ -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<ImageZoom>;
Expand Down
2 changes: 1 addition & 1 deletion src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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/**\"",
Expand Down

0 comments on commit ebfe2fd

Please sign in to comment.