From 37727ff411428f5f35caad5085cc7be13184f5da Mon Sep 17 00:00:00 2001 From: Stanimir Karoserov Date: Mon, 9 Jun 2014 17:18:28 +0300 Subject: [PATCH] new ui image + minor label fix --- BCL.csproj | 8 +++++++ ui/image/image.android.ts | 44 +++++++++++++++++++++++++++++++++++++++ ui/image/image.d.ts | 11 ++++++++++ ui/image/image.ios.ts | 36 ++++++++++++++++++++++++++++++++ ui/image/index.ts | 2 ++ ui/label/label.ios.ts | 2 +- 6 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 ui/image/image.android.ts create mode 100644 ui/image/image.d.ts create mode 100644 ui/image/image.ios.ts create mode 100644 ui/image/index.ts diff --git a/BCL.csproj b/BCL.csproj index d6d1f20fd..26c484dee 100644 --- a/BCL.csproj +++ b/BCL.csproj @@ -161,6 +161,14 @@ view.d.ts + + image.d.ts + + + + image.d.ts + + diff --git a/ui/image/image.android.ts b/ui/image/image.android.ts new file mode 100644 index 000000000..945150b48 --- /dev/null +++ b/ui/image/image.android.ts @@ -0,0 +1,44 @@ + +import observable = require("ui/core/observable"); +import view = require("ui/core/view"); +import application = require("application"); +import imageSource = require("image-source"); + +export class Image extends view.View { + private static sourceProperty = "source"; + private _source: imageSource.ImageSource; + private _android: android.widget.ImageView; + + constructor() { + super(); + + // TODO: Verify that this is always true + var context = application.android.currentContext; + if (!context) { + // TODO: Delayed loading? + } + + this._android = new android.widget.ImageView(context); + + } + + get android(): android.widget.ImageView { + return this._android; + } + + get source(): imageSource.ImageSource { + return this._source; + } + + set source(value: imageSource.ImageSource) { + this.setProperty(Image.sourceProperty, value); + } + + public setNativeProperty(data: observable.PropertyChangeData) { + if (data.propertyName === Image.sourceProperty) { + this._source = data.value; + this._android.setImageBitmap(data.value.android); + } else if (true) { + } + } +} diff --git a/ui/image/image.d.ts b/ui/image/image.d.ts new file mode 100644 index 000000000..5156112eb --- /dev/null +++ b/ui/image/image.d.ts @@ -0,0 +1,11 @@ +declare module "ui/image" { + + import imageSource = require("image-source"); + + class Image { + android: android.widget.ImageView; + ios: UIKit.UIImageView; + + source: imageSource.ImageSource; + } +} \ No newline at end of file diff --git a/ui/image/image.ios.ts b/ui/image/image.ios.ts new file mode 100644 index 000000000..f70988f3b --- /dev/null +++ b/ui/image/image.ios.ts @@ -0,0 +1,36 @@ + +import observable = require("ui/core/observable"); +import view = require("ui/core/view"); +import imageSource = require("image-source"); + +export class Image extends view.View { + private static sourceProperty = "source"; + private _source: imageSource.ImageSource; + private _ios: UIKit.UIImageView; + + constructor() { + super(); + this._ios = new UIKit.UIImageView(); + } + + get ios(): UIKit.UIImageView { + return this._ios; + } + + get source(): imageSource.ImageSource { + return this._source; + } + + set source(value: imageSource.ImageSource) { + this.setProperty(Image.sourceProperty, value); + } + + public setNativeProperty(data: observable.PropertyChangeData) { + if (data.propertyName === Image.sourceProperty) { + this._source = data.value; + this._ios.image = this._source.ios; + this._ios.sizeToFit(); + } else if (true) { + } + } +} \ No newline at end of file diff --git a/ui/image/index.ts b/ui/image/index.ts new file mode 100644 index 000000000..1ace44111 --- /dev/null +++ b/ui/image/index.ts @@ -0,0 +1,2 @@ +declare var module, require; +module.exports = require("ui/image/image"); \ No newline at end of file diff --git a/ui/label/label.ios.ts b/ui/label/label.ios.ts index 8b242082d..d853bddfc 100644 --- a/ui/label/label.ios.ts +++ b/ui/label/label.ios.ts @@ -16,7 +16,7 @@ export class Label extends view.View { var extendsBody = Foundation.NSObject.extends( { observeValueForKeyPathOfObjectChangeContext: function (path: string, sender: Foundation.NSObject, change: Foundation.NSDictionary, context) { - that.updateTwoWayBinding(Label.textProperty, change.objectForKey("new")); + that.updateTwoWayBinding(Label.textProperty, change.objectForKey(Foundation.NSKeyValueChangeNewKey)); } }, {});