forked from NativeScript/NativeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage.ios.ts
More file actions
64 lines (53 loc) · 2.24 KB
/
image.ios.ts
File metadata and controls
64 lines (53 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import imageCommon = require("ui/image/image-common");
import dependencyObservable = require("ui/core/dependency-observable");
import proxy = require("ui/core/proxy");
import definition = require("ui/image");
import enums = require("ui/enums");
// merge the exports of the common file with the exports of this file
declare var exports;
require("utils/module-merge").merge(imageCommon, exports);
function onStretchPropertyChanged(data: dependencyObservable.PropertyChangeData) {
var image = <Image>data.object;
switch (data.newValue) {
case enums.Stretch.aspectFit:
image.ios.contentMode = UIViewContentMode.UIViewContentModeScaleAspectFit;
break;
case enums.Stretch.aspectFill:
image.ios.contentMode = UIViewContentMode.UIViewContentModeScaleAspectFill;
break;
case enums.Stretch.fill:
image.ios.contentMode = UIViewContentMode.UIViewContentModeScaleToFill;
break;
case enums.Stretch.none:
default:
image.ios.contentMode = UIViewContentMode.UIViewContentModeTopLeft;
break;
}
}
function onImageSourcePropertyChanged(data: dependencyObservable.PropertyChangeData) {
var image = <Image>data.object;
image._setNativeImage(data.newValue ? data.newValue.ios : null);
}
// register the setNativeValue callback
(<proxy.PropertyMetadata>imageCommon.Image.imageSourceProperty.metadata).onSetNativeValue = onImageSourcePropertyChanged;
(<proxy.PropertyMetadata>imageCommon.Image.stretchProperty.metadata).onSetNativeValue = onStretchPropertyChanged;
export class Image extends imageCommon.Image {
private _ios: UIImageView;
constructor(options?: definition.Options) {
super(options);
//TODO: Think of unified way of setting all the default values.
this._ios = new UIImageView();
this._ios.contentMode = UIViewContentMode.UIViewContentModeScaleAspectFit;
this._ios.clipsToBounds = true;
super._prepareNativeView(this._ios);
}
get ios(): UIImageView {
return this._ios;
}
public _setNativeImage(nativeImage: any) {
this.ios.image = nativeImage;
if (isNaN(this.width) || isNaN(this.height)) {
this.requestLayout();
}
}
}