Button added

This commit is contained in:
Vladimir Enchev
2014-06-13 11:00:34 +03:00
parent 2c4781db01
commit 7783f19ff3
6 changed files with 89 additions and 1 deletions

View File

@ -271,6 +271,14 @@
<TypeScriptCompile Include="ui\dialogs\index.ts" />
<TypeScriptCompile Include="ui\dialogs\dialogs-common.ts" />
<TypeScriptCompile Include="ui\core\event-manager.ts" />
<TypeScriptCompile Include="ui\button\index.ts" />
<TypeScriptCompile Include="ui\button\button.d.ts" />
<TypeScriptCompile Include="ui\button\button.android.ts">
<DependentUpon>button.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="ui\button\button.ios.ts">
<DependentUpon>button.d.ts</DependentUpon>
</TypeScriptCompile>
<Content Include="_references.ts" />
<Content Include="image-source\Readme.md" />
<Content Include="http\Readme.md" />

View File

@ -0,0 +1,37 @@
import observable = require("ui/core/observable");
import view = require("ui/core/view");
import application = require("application");
export class Button extends view.View {
private static textProperty = "text";
private _android: android.widget.Button;
constructor() {
super();
this._android = new android.widget.Button(application.android.currentContext);
var that = this;
this._android.setOnClickListener(new android.view.View.OnClickListener({
onClick: function (v) { that.emit("click"); }
}));
}
get android(): android.widget.Button {
return this._android;
}
get text(): string {
return this.android.getText().toString();
}
set text(value: string) {
this.setProperty(Button.textProperty, value);
}
public setNativeProperty(data: observable.PropertyChangeData) {
if (data.propertyName === Button.textProperty) {
this.android.setText(data.value);
} else if (true) {
//
}
}
}

5
ui/button/button.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
declare module "ui/button" {
class Button {
text: string;
}
}

36
ui/button/button.ios.ts Normal file
View File

@ -0,0 +1,36 @@
import observable = require("ui/core/observable");
import view = require("ui/core/view");
import application = require("application");
export class Button extends view.View {
private static textProperty = "text";
private _ios: UIKit.UIButton;
constructor() {
super();
this._ios = UIKit.UIButton.buttonWithType(UIKit.UIButtonType.UIButtonTypeRoundedRect);
var that = this;
var target = Foundation.NSObject.extends({ click: (args) => { that.emit("click"); } }, { exposedMethods: { "click:": "v@:@" } });
this._ios.addTargetActionForControlEvents(new target(), "click:", UIKit.UIControlEvents.UIControlEventTouchUpInside);
}
get ios(): UIKit.UIButton {
return this._ios;
}
get text(): string {
return this.ios.titleForState(UIKit.UIControlState.UIControlStateNormal);
}
set text(value: string) {
this.setProperty(Button.textProperty, value);
}
public setNativeProperty(data: observable.PropertyChangeData) {
if (data.propertyName === Button.textProperty) {
this.ios.setTitleForState(data.value, UIKit.UIControlState.UIControlStateNormal);
} else if (true) {
//
}
}
}

2
ui/button/index.ts Normal file
View File

@ -0,0 +1,2 @@
declare var module, require;
module.exports = require("ui/button/button");

View File

@ -55,7 +55,7 @@ Custom dialogs:
d.show();
setTimeout(function(){ d.hide(); }, 2000);
//or cancelable
//or cancelable loading dialog
var d = new dialogs.Dialog("Loading...",
function(r){ dialogs.alert("You just canceled loading!"); }, { cancelButtonText: "Cancel" });
d.show();