mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix horizontal text-align for Button in iOS, use horizontalContentAlign of the native button
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import { ControlStateChangeListener } from "ui/core/control-state-change";
|
import { ControlStateChangeListener } from "ui/core/control-state-change";
|
||||||
import {
|
import {
|
||||||
ButtonBase, PseudoClassHandler, whiteSpaceProperty,
|
ButtonBase, PseudoClassHandler, whiteSpaceProperty,
|
||||||
borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty,
|
borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty, textAlignmentProperty,
|
||||||
paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty, Length, WhiteSpace
|
paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty, Length, WhiteSpace, TextAlignment
|
||||||
} from "./button-common";
|
} from "./button-common";
|
||||||
|
|
||||||
export * from "./button-common";
|
export * from "./button-common";
|
||||||
@@ -160,6 +160,25 @@ export class Button extends ButtonBase {
|
|||||||
let left = this.effectivePaddingLeft + this.effectiveBorderLeftWidth;
|
let left = this.effectivePaddingLeft + this.effectiveBorderLeftWidth;
|
||||||
this.nativeView.contentEdgeInsets = { top: inset.top, left: left, bottom: inset.bottom, right: inset.right };
|
this.nativeView.contentEdgeInsets = { top: inset.top, left: left, bottom: inset.bottom, right: inset.right };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get [textAlignmentProperty.native](): TextAlignment {
|
||||||
|
return Button.nativeToJsTextAlignment[this.nativeView.contentHorizontalAlignment];
|
||||||
|
}
|
||||||
|
set [textAlignmentProperty.native](value: TextAlignment) {
|
||||||
|
this.nativeView.contentHorizontalAlignment = Button.jsToNativeTextAlignment[value];
|
||||||
|
}
|
||||||
|
|
||||||
|
private static nativeToJsTextAlignment: { [key: number]: TextAlignment } = {
|
||||||
|
[UIControlContentHorizontalAlignment.Left]: "left",
|
||||||
|
[UIControlContentHorizontalAlignment.Center]: "center",
|
||||||
|
[UIControlContentHorizontalAlignment.Right]: "right",
|
||||||
|
[UIControlContentHorizontalAlignment.Fill]: "center"
|
||||||
|
}
|
||||||
|
private static jsToNativeTextAlignment: { [key in TextAlignment]: UIControlContentHorizontalAlignment } = {
|
||||||
|
"left": UIControlContentHorizontalAlignment.Left,
|
||||||
|
"center": UIControlContentHorizontalAlignment.Center,
|
||||||
|
"right": UIControlContentHorizontalAlignment.Right
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TapHandlerImpl extends NSObject {
|
class TapHandlerImpl extends NSObject {
|
||||||
|
|||||||
@@ -104,9 +104,7 @@ export class TextBase extends TextBaseCommon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
set [textAlignmentProperty.native](value: TextAlignment) {
|
set [textAlignmentProperty.native](value: TextAlignment) {
|
||||||
let nativeView = this.nativeView;
|
let nativeView = <UITextField | UITextView | UILabel>this.nativeView;
|
||||||
nativeView = nativeView instanceof UIButton ? nativeView.titleLabel : nativeView;
|
|
||||||
// NOTE: if Button textAlignment is not enough - set also btn.contentHorizontalAlignment
|
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case "left":
|
case "left":
|
||||||
nativeView.textAlignment = NSTextAlignment.Left;
|
nativeView.textAlignment = NSTextAlignment.Left;
|
||||||
|
|||||||
Reference in New Issue
Block a user