feat(core): maxLines support for all text components (#9884)

This commit is contained in:
farfromrefuge
2022-04-30 19:50:05 +02:00
committed by GitHub
parent 17a87a4a86
commit df10ceb491
12 changed files with 57 additions and 40 deletions

View File

@@ -13,6 +13,7 @@ import { isString, isNullOrUndefined } from '../../utils/types';
import { iOSNativeHelper } from '../../utils';
import { Trace } from '../../trace';
import { CoreTypes } from '../../core-types';
import { maxLinesProperty } from './text-base-common';
export * from './text-base-common';
@@ -197,6 +198,24 @@ export class TextBase extends TextBaseCommon {
this._setShadow(value);
}
[maxLinesProperty.setNative](value: CoreTypes.MaxLinesType) {
const nativeTextViewProtected = this.nativeTextViewProtected;
const numberOfLines = this.whiteSpace === 'normal' ? value : 1;
if (nativeTextViewProtected instanceof UITextView) {
nativeTextViewProtected.textContainer.maximumNumberOfLines = numberOfLines;
if (value !== 0) {
nativeTextViewProtected.textContainer.lineBreakMode = NSLineBreakMode.ByTruncatingTail;
} else {
nativeTextViewProtected.textContainer.lineBreakMode = NSLineBreakMode.ByWordWrapping;
}
} else if (nativeTextViewProtected instanceof UILabel) {
nativeTextViewProtected.numberOfLines = numberOfLines;
} else if (nativeTextViewProtected instanceof UIButton) {
nativeTextViewProtected.titleLabel.numberOfLines = numberOfLines;
}
}
_setColor(color: UIColor): void {
if (this.nativeTextViewProtected instanceof UIButton) {
this.nativeTextViewProtected.setTitleColorForState(color, UIControlState.Normal);