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 {
|
||||
ButtonBase, PseudoClassHandler, whiteSpaceProperty,
|
||||
borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty,
|
||||
paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty, Length, WhiteSpace
|
||||
borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty, textAlignmentProperty,
|
||||
paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty, Length, WhiteSpace, TextAlignment
|
||||
} from "./button-common";
|
||||
|
||||
export * from "./button-common";
|
||||
@@ -160,6 +160,25 @@ export class Button extends ButtonBase {
|
||||
let left = this.effectivePaddingLeft + this.effectiveBorderLeftWidth;
|
||||
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 {
|
||||
|
||||
@@ -104,9 +104,7 @@ export class TextBase extends TextBaseCommon {
|
||||
}
|
||||
}
|
||||
set [textAlignmentProperty.native](value: TextAlignment) {
|
||||
let nativeView = this.nativeView;
|
||||
nativeView = nativeView instanceof UIButton ? nativeView.titleLabel : nativeView;
|
||||
// NOTE: if Button textAlignment is not enough - set also btn.contentHorizontalAlignment
|
||||
let nativeView = <UITextField | UITextView | UILabel>this.nativeView;
|
||||
switch (value) {
|
||||
case "left":
|
||||
nativeView.textAlignment = NSTextAlignment.Left;
|
||||
|
||||
Reference in New Issue
Block a user