mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-18 13:51:27 +08:00
60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
import imageCommon = require("ui/image/image-common");
|
|
import dependencyObservable = require("ui/core/dependency-observable");
|
|
import proxy = require("ui/core/proxy");
|
|
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;
|
|
if (!image.android) {
|
|
return;
|
|
}
|
|
|
|
switch (data.newValue) {
|
|
case enums.Stretch.aspectFit:
|
|
image.android.setScaleType(android.widget.ImageView.ScaleType.FIT_CENTER);
|
|
break;
|
|
case enums.Stretch.aspectFill:
|
|
image.android.setScaleType(android.widget.ImageView.ScaleType.CENTER_CROP);
|
|
break;
|
|
case enums.Stretch.fill:
|
|
image.android.setScaleType(android.widget.ImageView.ScaleType.FIT_XY);
|
|
break;
|
|
case enums.Stretch.none:
|
|
default:
|
|
image.android.setScaleType(android.widget.ImageView.ScaleType.MATRIX);
|
|
break;
|
|
}
|
|
}
|
|
|
|
function onImageSourcePropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
|
var image = <Image>data.object;
|
|
if (!image.android) {
|
|
return;
|
|
}
|
|
|
|
image._setNativeImage(data.newValue ? data.newValue.android : 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 _android: android.widget.ImageView;
|
|
|
|
get android(): android.widget.ImageView {
|
|
return this._android;
|
|
}
|
|
|
|
public _createUI() {
|
|
this._android = new android.widget.ImageView(this._context);
|
|
}
|
|
|
|
public _setNativeImage(nativeImage: any) {
|
|
this.android.setImageBitmap(nativeImage);
|
|
}
|
|
} |