fix(8151): button textAlignment on IOS (UIButton) (#8181)

When setting the format of a "text view", we need to recover existing values for properties that will get default values otherwise.
The "textAlignment" of a UIButton is available through a "titleLabel" object instead of directly on itself (see IOS documentation fo UIButton).

Co-authored-by: Romain Vincent <54814371+romain20100@users.noreply.github.com>
Co-authored-by: Dimitar Topuzov <dtopuzov@gmail.com>
Co-authored-by: Vasil Trifonov <v.trifonov@gmail.com>
This commit is contained in:
Romain Vincent
2020-01-21 17:39:42 +01:00
committed by Vasil Trifonov
parent 3c79ded42b
commit 05ef9b0ff2

View File

@ -139,7 +139,12 @@ export class TextBase extends TextBaseCommon {
const paragraphStyle = NSMutableParagraphStyle.alloc().init(); const paragraphStyle = NSMutableParagraphStyle.alloc().init();
paragraphStyle.lineSpacing = this.lineHeight; paragraphStyle.lineSpacing = this.lineHeight;
// make sure a possible previously set text alignment setting is not lost when line height is specified // make sure a possible previously set text alignment setting is not lost when line height is specified
paragraphStyle.alignment = (<UITextField | UITextView | UILabel>this.nativeTextViewProtected).textAlignment; if (this.nativeTextViewProtected instanceof UIButton) {
paragraphStyle.alignment = (<UIButton>this.nativeTextViewProtected).titleLabel.textAlignment;
} else {
paragraphStyle.alignment = (<UITextField | UITextView | UILabel>this.nativeTextViewProtected).textAlignment;
}
if (this.nativeTextViewProtected instanceof UILabel) { if (this.nativeTextViewProtected instanceof UILabel) {
// make sure a possible previously set line break mode is not lost when line height is specified // make sure a possible previously set line break mode is not lost when line height is specified
paragraphStyle.lineBreakMode = this.nativeTextViewProtected.lineBreakMode; paragraphStyle.lineBreakMode = this.nativeTextViewProtected.lineBreakMode;
@ -192,7 +197,12 @@ export class TextBase extends TextBaseCommon {
const paragraphStyle = NSMutableParagraphStyle.alloc().init(); const paragraphStyle = NSMutableParagraphStyle.alloc().init();
paragraphStyle.lineSpacing = style.lineHeight; paragraphStyle.lineSpacing = style.lineHeight;
// make sure a possible previously set text alignment setting is not lost when line height is specified // make sure a possible previously set text alignment setting is not lost when line height is specified
paragraphStyle.alignment = (<UITextField | UITextView | UILabel>this.nativeTextViewProtected).textAlignment; if (this.nativeTextViewProtected instanceof UIButton) {
paragraphStyle.alignment = (<UIButton>this.nativeTextViewProtected).titleLabel.textAlignment;
} else {
paragraphStyle.alignment = (<UITextField | UITextView | UILabel>this.nativeTextViewProtected).textAlignment;
}
if (this.nativeTextViewProtected instanceof UILabel) { if (this.nativeTextViewProtected instanceof UILabel) {
// make sure a possible previously set line break mode is not lost when line height is specified // make sure a possible previously set line break mode is not lost when line height is specified
paragraphStyle.lineBreakMode = this.nativeTextViewProtected.lineBreakMode; paragraphStyle.lineBreakMode = this.nativeTextViewProtected.lineBreakMode;