Visitar URL original
feat(text-view): moved implementation to TextView · NativeScript/NativeScript@1975774 · GitHub
Skip to content

Commit 1975774

Browse files
author
Surdu
committed
feat(text-view): moved implementation to TextView
1 parent c6cc551 commit 1975774

9 files changed

Lines changed: 51 additions & 42 deletions

File tree

‎nativescript-core/ui/editable-text-base/editable-text-base-common.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export abstract class EditableTextBase extends TextBase implements EditableTextB
1616
public autocorrect: boolean;
1717
public hint: string;
1818
public maxLength: number;
19-
public maxLines: number;
2019

2120
public abstract dismissSoftInput();
2221
public abstract _setInputType(inputType: number): void;
@@ -68,6 +67,3 @@ hintProperty.register(EditableTextBase);
6867

6968
export const maxLengthProperty = new Property<EditableTextBase, number>({ name: "maxLength", defaultValue: Number.POSITIVE_INFINITY, valueConverter: parseInt });
7069
maxLengthProperty.register(EditableTextBase);
71-
72-
export const maxLinesProperty = new Property<EditableTextBase, number>({ name: "maxLines", valueConverter: parseInt });
73-
maxLinesProperty.register(EditableTextBase);

‎nativescript-core/ui/editable-text-base/editable-text-base.android.ts‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
EditableTextBase as EditableTextBaseCommon, keyboardTypeProperty,
33
returnKeyTypeProperty, editableProperty,
44
autocapitalizationTypeProperty, autocorrectProperty, hintProperty, resetSymbol,
5-
textProperty, placeholderColorProperty, Color, textTransformProperty, maxLengthProperty, maxLinesProperty
5+
textProperty, placeholderColorProperty, Color, textTransformProperty, maxLengthProperty
66
} from "./editable-text-base-common";
77

88
import { ad } from "../../utils/utils";
@@ -456,12 +456,4 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
456456
this.nativeTextViewProtected.setFilters(newFilters);
457457
}
458458
}
459-
460-
[maxLinesProperty.getDefault](): number {
461-
return -1;
462-
}
463-
464-
[maxLinesProperty.setNative](value: number) {
465-
this.nativeTextViewProtected.setMaxLines(value);
466-
}
467459
}

‎nativescript-core/ui/editable-text-base/editable-text-base.d.ts‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ export class EditableTextBase extends TextBase {
5252
*/
5353
maxLength: number;
5454

55-
/**
56-
* Limits input to a certain number of lines.
57-
*/
58-
maxLines: number;
59-
6055
/**
6156
* Hides the soft input method, ususally a soft keyboard.
6257
*/
@@ -84,7 +79,6 @@ export const autocorrectProperty: Property<EditableTextBase, boolean>;
8479
export const hintProperty: Property<EditableTextBase, string>;
8580
export const placeholderColorProperty: CssProperty<Style, Color>;
8681
export const maxLengthProperty: Property<EditableTextBase, number>;
87-
export const maxLinesProperty: Property<EditableTextBase, number>;
8882

8983
//@private
9084
/**

‎nativescript-core/ui/editable-text-base/editable-text-base.ios.ts‎

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
EditableTextBase as EditableTextBaseCommon, keyboardTypeProperty,
33
returnKeyTypeProperty,
4-
autocapitalizationTypeProperty, autocorrectProperty, FormattedString, maxLinesProperty
4+
autocapitalizationTypeProperty, autocorrectProperty, FormattedString
55
} from "./editable-text-base-common";
66

77
export * from "./editable-text-base-common";
@@ -186,21 +186,6 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
186186

187187
this.nativeTextViewProtected.autocorrectionType = newValue;
188188
}
189-
190-
[maxLinesProperty.getDefault](): number {
191-
return 0;
192-
}
193-
194-
[maxLinesProperty.setNative](value: number) {
195-
this.nativeTextViewProtected.textContainer.maximumNumberOfLines = value;
196-
197-
if (value !== 0) {
198-
this.nativeTextViewProtected.textContainer.lineBreakMode = NSLineBreakMode.ByTruncatingTail;
199-
}
200-
else {
201-
this.nativeTextViewProtected.textContainer.lineBreakMode = NSLineBreakMode.ByWordWrapping;
202-
}
203-
}
204189
}
205190

206191
export function _updateCharactersInRangeReplacementString(formattedText: FormattedString, rangeLocation: number, rangeLength: number, replacementString: string): void {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { TextView as TextViewDefinition } from ".";
2+
import { EditableTextBase } from "../editable-text-base";
3+
import { Property } from "../text-base";
4+
5+
export class TextViewBase extends EditableTextBase implements TextViewDefinition {
6+
public maxLines: number;
7+
}
8+
9+
export const maxLinesProperty = new Property<EditableTextBase, number>({ name: "maxLines", valueConverter: parseInt });
10+
maxLinesProperty.register(EditableTextBase);
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { TextView as TextViewDefinition } from ".";
2-
import { EditableTextBase, CSSType } from "../editable-text-base";
1+
import { TextViewBase as TextViewBaseCommon, maxLinesProperty } from "./text-view-common";
2+
import { CSSType } from "../editable-text-base";
33

44
export * from "../text-base";
55

66
@CSSType("TextView")
7-
export class TextView extends EditableTextBase implements TextViewDefinition {
8-
7+
export class TextView extends TextViewBaseCommon {
98
public _configureEditText(editText: android.widget.EditText) {
109
editText.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_NORMAL | android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE | android.text.InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
1110
editText.setGravity(android.view.Gravity.TOP | android.view.Gravity.START);
@@ -15,6 +14,14 @@ export class TextView extends EditableTextBase implements TextViewDefinition {
1514
super.resetNativeView();
1615
this.nativeTextViewProtected.setGravity(android.view.Gravity.TOP | android.view.Gravity.START);
1716
}
17+
18+
[maxLinesProperty.getDefault](): number {
19+
return -1;
20+
}
21+
22+
[maxLinesProperty.setNative](value: number) {
23+
this.nativeTextViewProtected.setMaxLines(value);
24+
}
1825
}
1926

2027
TextView.prototype.recycleNativeView = "auto";

‎nativescript-core/ui/text-view/text-view.d.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/ /** */
55

66
import { EditableTextBase } from "../editable-text-base";
7+
import { Property } from "../text-base";
78

89
/**
910
* Represents an editable multiline text view.
@@ -18,4 +19,11 @@ export class TextView extends EditableTextBase {
1819
* Gets the native iOS [UITextView](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextView_Class/) that represents the user interface for this component. Valid only when running on iOS.
1920
*/
2021
ios: any /* UITextView */;
22+
23+
/**
24+
* Limits input to a certain number of lines.
25+
*/
26+
maxLines: number;
2127
}
28+
29+
export const maxLinesProperty: Property<EditableTextBase, number>;

‎nativescript-core/ui/text-view/text-view.ios.ts‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ScrollEventData } from "../scroll-view";
2-
import { TextView as TextViewDefinition } from ".";
2+
import { TextViewBase as TextViewBaseCommon, maxLinesProperty } from "./text-view-common";
33
import {
4-
EditableTextBase, editableProperty, hintProperty, textProperty, colorProperty, placeholderColorProperty,
4+
editableProperty, hintProperty, textProperty, colorProperty, placeholderColorProperty,
55
borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty,
66
paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty,
77
Length, _updateCharactersInRangeReplacementString, Color, layout,
@@ -110,7 +110,7 @@ class NoScrollAnimationUITextView extends UITextView {
110110
}
111111

112112
@CSSType("TextView")
113-
export class TextView extends EditableTextBase implements TextViewDefinition {
113+
export class TextView extends TextViewBaseCommon {
114114
nativeViewProtected: UITextView;
115115
private _delegate: UITextViewDelegateImpl;
116116
private _isShowingHint: boolean;
@@ -333,6 +333,20 @@ export class TextView extends EditableTextBase implements TextViewDefinition {
333333
let left = layout.toDeviceIndependentPixels(this.effectivePaddingLeft + this.effectiveBorderLeftWidth);
334334
this.nativeTextViewProtected.textContainerInset = { top: inset.top, left: left, bottom: inset.bottom, right: inset.right };
335335
}
336+
[maxLinesProperty.getDefault](): number {
337+
return 0;
338+
}
339+
[maxLinesProperty.setNative](value: number) {
340+
this.nativeTextViewProtected.textContainer.maximumNumberOfLines = value;
341+
342+
if (value !== 0) {
343+
this.nativeTextViewProtected.textContainer.lineBreakMode = NSLineBreakMode.ByTruncatingTail;
344+
}
345+
else {
346+
this.nativeTextViewProtected.textContainer.lineBreakMode = NSLineBreakMode.ByWordWrapping;
347+
}
348+
}
349+
336350
}
337351

338352
TextView.prototype.recycleNativeView = "auto";

‎tns-core-modules-package/bundle-entry-points.js‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)