mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
Button added
This commit is contained in:
@ -271,6 +271,14 @@
|
|||||||
<TypeScriptCompile Include="ui\dialogs\index.ts" />
|
<TypeScriptCompile Include="ui\dialogs\index.ts" />
|
||||||
<TypeScriptCompile Include="ui\dialogs\dialogs-common.ts" />
|
<TypeScriptCompile Include="ui\dialogs\dialogs-common.ts" />
|
||||||
<TypeScriptCompile Include="ui\core\event-manager.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="_references.ts" />
|
||||||
<Content Include="image-source\Readme.md" />
|
<Content Include="image-source\Readme.md" />
|
||||||
<Content Include="http\Readme.md" />
|
<Content Include="http\Readme.md" />
|
||||||
|
37
ui/button/button.android.ts
Normal file
37
ui/button/button.android.ts
Normal 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
5
ui/button/button.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
declare module "ui/button" {
|
||||||
|
class Button {
|
||||||
|
text: string;
|
||||||
|
}
|
||||||
|
}
|
36
ui/button/button.ios.ts
Normal file
36
ui/button/button.ios.ts
Normal 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
2
ui/button/index.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
declare var module, require;
|
||||||
|
module.exports = require("ui/button/button");
|
@ -55,7 +55,7 @@ Custom dialogs:
|
|||||||
d.show();
|
d.show();
|
||||||
setTimeout(function(){ d.hide(); }, 2000);
|
setTimeout(function(){ d.hide(); }, 2000);
|
||||||
|
|
||||||
//or cancelable
|
//or cancelable loading dialog
|
||||||
var d = new dialogs.Dialog("Loading...",
|
var d = new dialogs.Dialog("Loading...",
|
||||||
function(r){ dialogs.alert("You just canceled loading!"); }, { cancelButtonText: "Cancel" });
|
function(r){ dialogs.alert("You just canceled loading!"); }, { cancelButtonText: "Cancel" });
|
||||||
d.show();
|
d.show();
|
||||||
|
Reference in New Issue
Block a user