|
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'; |
9 | 2 | import { layout } from 'tns-core-modules/ui/core/view'; |
10 | 3 | import { topmost } from 'tns-core-modules/ui/frame'; |
11 | 4 | 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 { |
13 | 33 | _image: Image; |
14 | 34 | nativeView: UIScrollView; |
15 | 35 | private layoutWidth: number; |
16 | 36 | private layoutHeight: number; |
17 | 37 | private delegate: any; |
18 | | - |
| 38 | + src: string; |
| 39 | + zoomScale: number; |
| 40 | + minZoom: number; |
| 41 | + maxZoom: number; |
| 42 | + stretch: string; |
19 | 43 | constructor() { |
20 | 44 | super(); |
21 | 45 | this.delegate = UIScrollViewDelegateImpl.initWithOwner( |
22 | 46 | new WeakRef<ImageZoom>(this) |
23 | 47 | ); |
24 | | - } |
25 | | - |
26 | | - public createNativeView() { |
| 48 | + const nativeView = this.nativeView; |
27 | 49 | 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; |
38 | 55 | } |
39 | 56 |
|
40 | 57 | public disposeNativeView() { |
41 | 58 | this.delegate = null; |
42 | | - topmost()._removeView(this._image); |
43 | 59 | } |
44 | 60 |
|
45 | 61 | [srcProperty.setNative](src: string) { |
@@ -73,29 +89,14 @@ export class ImageZoom extends ImageZoomBase { |
73 | 89 | this.nativeView.maximumZoomScale = scale; |
74 | 90 | } |
75 | 91 | } |
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 | | - } |
97 | 92 | } |
98 | 93 |
|
| 94 | +srcProperty.register(ImageZoom); |
| 95 | +stretchProperty.register(ImageZoom); |
| 96 | +zoomScaleProperty.register(ImageZoom); |
| 97 | +minZoomScaleProperty.register(ImageZoom); |
| 98 | +maxZoomScaleProperty.register(ImageZoom); |
| 99 | + |
99 | 100 | export class UIScrollViewDelegateImpl extends NSObject |
100 | 101 | implements UIScrollViewDelegate { |
101 | 102 | private owner: WeakRef<ImageZoom>; |
|
0 commit comments