mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
Button textWrap implemented
This commit is contained in:
@ -8,6 +8,10 @@ export function getNativeText(button: buttonModule.Button): string {
|
|||||||
return button.android.getText();
|
return button.android.getText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getNativeTextWrap(button: buttonModule.Button): boolean {
|
||||||
|
return (<android.widget.Button>button.android).isSingleLine();
|
||||||
|
}
|
||||||
|
|
||||||
export function getNativeFontSize(button: buttonModule.Button): number {
|
export function getNativeFontSize(button: buttonModule.Button): number {
|
||||||
var density = utilsModule.layout.getDisplayDensity();
|
var density = utilsModule.layout.getDisplayDensity();
|
||||||
return button.android.getTextSize() / density;
|
return button.android.getTextSize() / density;
|
||||||
|
@ -3,6 +3,7 @@ import buttonModule = require("ui/button");
|
|||||||
import colorModule = require("color");
|
import colorModule = require("color");
|
||||||
|
|
||||||
export declare function getNativeText(button: buttonModule.Button): string;
|
export declare function getNativeText(button: buttonModule.Button): string;
|
||||||
|
export declare function getNativeTextWrap(button: buttonModule.Button): boolean;
|
||||||
export declare function getNativeFontSize(button: buttonModule.Button): number;
|
export declare function getNativeFontSize(button: buttonModule.Button): number;
|
||||||
export declare function getNativeColor(button: buttonModule.Button): colorModule.Color;
|
export declare function getNativeColor(button: buttonModule.Button): colorModule.Color;
|
||||||
export declare function getNativeBackgroundColor(button: buttonModule.Button): colorModule.Color;
|
export declare function getNativeBackgroundColor(button: buttonModule.Button): colorModule.Color;
|
||||||
|
@ -7,6 +7,10 @@ export function getNativeText(button: buttonModule.Button): string {
|
|||||||
return button.ios.titleForState(UIControlState.UIControlStateNormal);
|
return button.ios.titleForState(UIControlState.UIControlStateNormal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getNativeTextWrap(button: buttonModule.Button): boolean {
|
||||||
|
return (<UIButton>button.ios).titleLabel.lineBreakMode === NSLineBreakMode.NSLineBreakByWordWrapping;
|
||||||
|
}
|
||||||
|
|
||||||
export function getNativeFontSize(button: buttonModule.Button): number {
|
export function getNativeFontSize(button: buttonModule.Button): number {
|
||||||
return button.ios.titleLabel.font.pointSize;
|
return button.ios.titleLabel.font.pointSize;
|
||||||
}
|
}
|
||||||
|
@ -113,6 +113,21 @@ var _testSetText = function (views: Array<viewModule.View>) {
|
|||||||
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
|
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _testSetTextWrap = function (views: Array<viewModule.View>) {
|
||||||
|
var button = <buttonModule.Button>views[0];
|
||||||
|
// <snippet module="ui/button" title="button">
|
||||||
|
// ### Setting the text of a button
|
||||||
|
// ``` JavaScript
|
||||||
|
button.textWrap = true;
|
||||||
|
// ```
|
||||||
|
// </snippet>
|
||||||
|
|
||||||
|
var expectedValue = button.textWrap;
|
||||||
|
var actualValue = buttonTestsNative.getNativeTextWrap(button);
|
||||||
|
|
||||||
|
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
|
||||||
|
}
|
||||||
|
|
||||||
var _testOnClick = function (views: Array<viewModule.View>) {
|
var _testOnClick = function (views: Array<viewModule.View>) {
|
||||||
var button = <buttonModule.Button>views[0];
|
var button = <buttonModule.Button>views[0];
|
||||||
|
|
||||||
|
@ -37,6 +37,12 @@ export class Button extends view.View implements definition.Button {
|
|||||||
public static textProperty = textProperty;
|
public static textProperty = textProperty;
|
||||||
public static formattedTextProperty = formattedTextProperty;
|
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) {
|
public _onBindingContextChanged(oldValue: any, newValue: any) {
|
||||||
super._onBindingContextChanged(oldValue, newValue);
|
super._onBindingContextChanged(oldValue, newValue);
|
||||||
if (this.formattedText) {
|
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) {
|
private onFormattedTextChanged(eventData: observable.PropertyChangeData) {
|
||||||
this.setFormattedTextPropertyToNative(eventData.value);
|
this.setFormattedTextPropertyToNative(eventData.value);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,22 @@
|
|||||||
import common = require("./button-common");
|
import common = require("./button-common");
|
||||||
import utils = require("utils/utils")
|
import utils = require("utils/utils")
|
||||||
|
import dependencyObservable = require("ui/core/dependency-observable");
|
||||||
|
import proxy = require("ui/core/proxy");
|
||||||
|
|
||||||
global.moduleMerge(common, exports);
|
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 {
|
export class Button extends common.Button {
|
||||||
private _android: android.widget.Button;
|
private _android: android.widget.Button;
|
||||||
private _isPressed: boolean;
|
private _isPressed: boolean;
|
||||||
|
5
ui/button/button.d.ts
vendored
5
ui/button/button.d.ts
vendored
@ -36,6 +36,11 @@ declare module "ui/button" {
|
|||||||
*/
|
*/
|
||||||
text: string;
|
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.
|
* Gets or sets the formatted text (label) displayed by this instance.
|
||||||
*/
|
*/
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import common = require("./button-common");
|
import common = require("./button-common");
|
||||||
import stateChanged = require("ui/core/control-state-change");
|
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 {
|
class TapHandlerImpl extends NSObject {
|
||||||
private _owner: WeakRef<Button>;
|
private _owner: WeakRef<Button>;
|
||||||
@ -24,6 +26,18 @@ class TapHandlerImpl extends NSObject {
|
|||||||
|
|
||||||
global.moduleMerge(common, exports);
|
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 {
|
export class Button extends common.Button {
|
||||||
private _ios: UIButton;
|
private _ios: UIButton;
|
||||||
private _tapHandler: NSObject;
|
private _tapHandler: NSObject;
|
||||||
|
Reference in New Issue
Block a user