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

@@ -1,4 +1,4 @@
import { TextViewBase as TextViewBaseCommon, maxLinesProperty } from './text-view-common';
import { TextViewBase as TextViewBaseCommon } from './text-view-common';
import { CSSType } from '../core/view';
export * from '../text-base';
@@ -15,20 +15,6 @@ export class TextView extends TextViewBaseCommon {
this.nativeTextViewProtected.setGravity(android.view.Gravity.TOP | android.view.Gravity.START);
}
[maxLinesProperty.getDefault](): number {
return 0;
}
[maxLinesProperty.setNative](value: number) {
if (value <= 0) {
this.nativeTextViewProtected.setMaxLines(Number.MAX_VALUE);
return;
}
this.nativeTextViewProtected.setMaxLines(value);
}
public _onReturnPress() {
this.notify({ eventName: TextView.returnPressEvent, object: this });
}

View File

@@ -1,6 +1,6 @@
import { ScrollEventData } from '../scroll-view';
import { textProperty } from '../text-base';
import { TextViewBase as TextViewBaseCommon, maxLinesProperty } from './text-view-common';
import { TextViewBase as TextViewBaseCommon } from './text-view-common';
import { editableProperty, hintProperty, placeholderColorProperty, _updateCharactersInRangeReplacementString } from '../editable-text-base';
import { CoreTypes } from '../../core-types';
import { CSSType } from '../core/view';
@@ -408,18 +408,6 @@ export class TextView extends TextViewBaseCommon {
right: inset.right,
};
}
[maxLinesProperty.getDefault](): number {
return 0;
}
[maxLinesProperty.setNative](value: number) {
this.nativeTextViewProtected.textContainer.maximumNumberOfLines = value;
if (value !== 0) {
this.nativeTextViewProtected.textContainer.lineBreakMode = NSLineBreakMode.ByTruncatingTail;
} else {
this.nativeTextViewProtected.textContainer.lineBreakMode = NSLineBreakMode.ByWordWrapping;
}
}
}
TextView.prototype.recycleNativeView = 'auto';

View File

@@ -1,14 +1,7 @@
import { TextView as TextViewDefinition } from '.';
import { EditableTextBase } from '../editable-text-base';
import { Property } from '../core/properties';
export class TextViewBase extends EditableTextBase implements TextViewDefinition {
public static returnPressEvent = 'returnPress';
public maxLines: number;
}
export const maxLinesProperty = new Property<EditableTextBase, number>({
name: 'maxLines',
valueConverter: parseInt,
});
maxLinesProperty.register(EditableTextBase);
}