fix(ios-textview): text alignment reset to default on blur (#6903)

This commit is contained in:
Manol Donev
2019-02-14 15:00:04 +02:00
committed by Alexander Djenkov
parent 57f07a3ec7
commit 0416f7e80e

View File

@ -138,6 +138,10 @@ export class TextBase extends TextBaseCommon {
paragraphStyle.lineBreakMode = this.nativeTextViewProtected.lineBreakMode; paragraphStyle.lineBreakMode = this.nativeTextViewProtected.lineBreakMode;
} }
attrText.addAttributeValueRange(NSParagraphStyleAttributeName, paragraphStyle, { location: 0, length: attrText.length }); attrText.addAttributeValueRange(NSParagraphStyleAttributeName, paragraphStyle, { location: 0, length: attrText.length });
} else if (this.nativeTextViewProtected instanceof UITextView) {
const paragraphStyle = NSMutableParagraphStyle.alloc().init();
paragraphStyle.alignment = (<UITextView>this.nativeTextViewProtected).textAlignment;
attrText.addAttributeValueRange(NSParagraphStyleAttributeName, paragraphStyle, { location: 0, length: attrText.length });
} }
if (this.nativeTextViewProtected instanceof UIButton) { if (this.nativeTextViewProtected instanceof UIButton) {
@ -175,6 +179,7 @@ export class TextBase extends TextBaseCommon {
dict.set(NSKernAttributeName, style.letterSpacing * this.nativeTextViewProtected.font.pointSize); dict.set(NSKernAttributeName, style.letterSpacing * this.nativeTextViewProtected.font.pointSize);
} }
const isTextView = this.nativeTextViewProtected instanceof UITextView;
if (style.lineHeight) { if (style.lineHeight) {
const paragraphStyle = NSMutableParagraphStyle.alloc().init(); const paragraphStyle = NSMutableParagraphStyle.alloc().init();
paragraphStyle.lineSpacing = style.lineHeight; paragraphStyle.lineSpacing = style.lineHeight;
@ -185,9 +190,12 @@ export class TextBase extends TextBaseCommon {
paragraphStyle.lineBreakMode = this.nativeTextViewProtected.lineBreakMode; paragraphStyle.lineBreakMode = this.nativeTextViewProtected.lineBreakMode;
} }
dict.set(NSParagraphStyleAttributeName, paragraphStyle); dict.set(NSParagraphStyleAttributeName, paragraphStyle);
} else if (isTextView) {
const paragraphStyle = NSMutableParagraphStyle.alloc().init();
paragraphStyle.alignment = (<UITextView>this.nativeTextViewProtected).textAlignment;
dict.set(NSParagraphStyleAttributeName, paragraphStyle);
} }
const isTextView = this.nativeTextViewProtected instanceof UITextView;
if (style.color && (dict.size > 0 || isTextView)) { if (style.color && (dict.size > 0 || isTextView)) {
dict.set(NSForegroundColorAttributeName, style.color.ios); dict.set(NSForegroundColorAttributeName, style.color.ios);
} }