Skip to content

Commit ebfe2fd

Browse files
committed
Fixes
1 parent 5e499aa commit ebfe2fd

File tree

4 files changed

+50
-48
lines changed

4 files changed

+50
-48
lines changed

src/image-zoom.android.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ export class ImageZoom extends ImageZoomBase {
6262
);
6363
this.nativeView.setImage(source);
6464
});
65+
} else {
66+
source = com.davemorrissey.labs.subscaleview.ImageSource.uri(src);
6567
}
6668

6769
if (this.nativeView && source) {

src/image-zoom.ios.ts

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,61 @@
1-
import {
2-
ImageZoomBase,
3-
srcProperty,
4-
maxZoomScaleProperty,
5-
minZoomScaleProperty,
6-
zoomScaleProperty
7-
} from './image-zoom.common';
8-
import { Image, stretchProperty, Stretch } from 'tns-core-modules/ui/image';
1+
import { Image, Stretch } from 'tns-core-modules/ui/image';
92
import { layout } from 'tns-core-modules/ui/core/view';
103
import { topmost } from 'tns-core-modules/ui/frame';
114
import * as imageSource from 'tns-core-modules/image-source';
12-
export class ImageZoom extends ImageZoomBase {
5+
import { ScrollView } from 'tns-core-modules/ui/scroll-view';
6+
7+
import { Property } from 'tns-core-modules/ui/core/view';
8+
9+
export const stretchProperty = new Property<ImageZoom, Stretch>({
10+
name: 'stretch'
11+
});
12+
13+
export const zoomScaleProperty = new Property<ImageZoom, number>({
14+
name: 'zoomScale',
15+
defaultValue: 1
16+
});
17+
18+
export const minZoomScaleProperty = new Property<ImageZoom, number>({
19+
name: 'minZoom',
20+
defaultValue: 1
21+
});
22+
23+
export const maxZoomScaleProperty = new Property<ImageZoom, number>({
24+
name: 'maxZoom',
25+
defaultValue: 4
26+
});
27+
28+
export const srcProperty = new Property<ImageZoom, string>({
29+
name: 'src'
30+
});
31+
32+
export class ImageZoom extends ScrollView {
1333
_image: Image;
1434
nativeView: UIScrollView;
1535
private layoutWidth: number;
1636
private layoutHeight: number;
1737
private delegate: any;
18-
38+
src: string;
39+
zoomScale: number;
40+
minZoom: number;
41+
maxZoom: number;
42+
stretch: string;
1943
constructor() {
2044
super();
2145
this.delegate = UIScrollViewDelegateImpl.initWithOwner(
2246
new WeakRef<ImageZoom>(this)
2347
);
24-
}
25-
26-
public createNativeView() {
48+
const nativeView = this.nativeView;
2749
this._image = new Image();
28-
topmost()._addView(this._image);
29-
return UIScrollView.new();
30-
}
31-
32-
public initNativeView() {
33-
this.nativeView.delegate = this.delegate;
34-
this.nativeView.zoomScale = this.zoomScale;
35-
this.nativeView.minimumZoomScale = this.minZoom;
36-
this.nativeView.maximumZoomScale = this.maxZoom;
37-
this.nativeView.addSubview(this._image.nativeView);
50+
nativeView.delegate = this.delegate;
51+
nativeView.zoomScale = this.zoomScale;
52+
nativeView.minimumZoomScale = this.minZoom;
53+
nativeView.maximumZoomScale = this.maxZoom;
54+
this.content = this._image;
3855
}
3956

4057
public disposeNativeView() {
4158
this.delegate = null;
42-
topmost()._removeView(this._image);
4359
}
4460

4561
[srcProperty.setNative](src: string) {
@@ -73,29 +89,14 @@ export class ImageZoom extends ImageZoomBase {
7389
this.nativeView.maximumZoomScale = scale;
7490
}
7591
}
76-
77-
public onLayout(
78-
left: number,
79-
top: number,
80-
right: number,
81-
bottom: number
82-
): void {
83-
super.onLayout(left, top, right, bottom);
84-
this.layoutWidth = right - left;
85-
this.layoutHeight = bottom - top;
86-
this._image.nativeView.frame = this.nativeView.bounds;
87-
}
88-
89-
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number) {
90-
const nativeView = this.nativeView;
91-
if (nativeView) {
92-
const width = layout.getMeasureSpecSize(widthMeasureSpec);
93-
const height = layout.getMeasureSpecSize(heightMeasureSpec);
94-
this.setMeasuredDimension(width, height);
95-
}
96-
}
9792
}
9893

94+
srcProperty.register(ImageZoom);
95+
stretchProperty.register(ImageZoom);
96+
zoomScaleProperty.register(ImageZoom);
97+
minZoomScaleProperty.register(ImageZoom);
98+
maxZoomScaleProperty.register(ImageZoom);
99+
99100
export class UIScrollViewDelegateImpl extends NSObject
100101
implements UIScrollViewDelegate {
101102
private owner: WeakRef<ImageZoom>;

src/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-image-zoom",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Zoom enabled ImageView for NativeScript",
55
"main": "image-zoom",
66
"typings": "index.d.ts",
@@ -13,7 +13,6 @@
1313
"scripts": {
1414
"tsc": "tsc -skipLibCheck",
1515
"build": "npm i && tsc",
16-
"postclone": "npm i && node scripts/postclone.js && cd ../demo && npm i && cd ../src && npm run plugin.link",
1716
"test.android": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build android && tns test android --justlaunch",
1817
"test.ios": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build ios && tns test ios --justlaunch",
1918
"tslint": "cd .. && tslint \"**/*.ts\" --config tslint.json --exclude \"**/node_modules/**\"",

0 commit comments

Comments
 (0)