Button textWrap implemented

This commit is contained in:
Vladimir Enchev
2015-11-02 11:11:25 +02:00
parent a3601b06cd
commit 0f3732d73f
8 changed files with 71 additions and 1 deletions

View File

@@ -37,6 +37,12 @@ export class Button extends view.View implements definition.Button {
public static textProperty = textProperty;
public static formattedTextProperty = formattedTextProperty;
public static textWrapProperty = new dependencyObservable.Property(
"textWrap",
"Button",
new proxy.PropertyMetadata(false, dependencyObservable.PropertyMetadataSettings.AffectsLayout)
);
public _onBindingContextChanged(oldValue: any, newValue: any) {
super._onBindingContextChanged(oldValue, newValue);
if (this.formattedText) {
@@ -68,6 +74,13 @@ export class Button extends view.View implements definition.Button {
}
}
get textWrap(): boolean {
return this._getValue(Button.textWrapProperty);
}
set textWrap(value: boolean) {
this._setValue(Button.textWrapProperty, value);
}
private onFormattedTextChanged(eventData: observable.PropertyChangeData) {
this.setFormattedTextPropertyToNative(eventData.value);
}

View File

@@ -1,8 +1,22 @@
import common = require("./button-common");
import utils = require("utils/utils")
import dependencyObservable = require("ui/core/dependency-observable");
import proxy = require("ui/core/proxy");
global.moduleMerge(common, exports);
function onTextWrapPropertyChanged(data: dependencyObservable.PropertyChangeData) {
var btn = <Button>data.object;
if (!btn.android) {
return;
}
btn.android.setSingleLine(data.newValue);
}
// register the setNativeValue callback
(<proxy.PropertyMetadata>common.Button.textWrapProperty.metadata).onSetNativeValue = onTextWrapPropertyChanged;
export class Button extends common.Button {
private _android: android.widget.Button;
private _isPressed: boolean;

View File

@@ -36,6 +36,11 @@ declare module "ui/button" {
*/
text: string;
/**
* Gets or sets whether the Button wraps text or not.
*/
textWrap: boolean;
/**
* Gets or sets the formatted text (label) displayed by this instance.
*/

View File

@@ -1,5 +1,7 @@
import common = require("./button-common");
import stateChanged = require("ui/core/control-state-change");
import dependencyObservable = require("ui/core/dependency-observable");
import proxy = require("ui/core/proxy");
class TapHandlerImpl extends NSObject {
private _owner: WeakRef<Button>;
@@ -24,6 +26,18 @@ class TapHandlerImpl extends NSObject {
global.moduleMerge(common, exports);
function onTextWrapPropertyChanged(data: dependencyObservable.PropertyChangeData) {
var btn = <Button>data.object;
if (!btn.ios) {
return;
}
btn.ios.titleLabel.lineBreakMode = data.newValue ? NSLineBreakMode.NSLineBreakByWordWrapping : 0;
}
// register the setNativeValue callback
(<proxy.PropertyMetadata>common.Button.textWrapProperty.metadata).onSetNativeValue = onTextWrapPropertyChanged;
export class Button extends common.Button {
private _ios: UIButton;
private _tapHandler: NSObject;