Skip to content

Commit 7acc03b

Browse files
committed
feat(TextField): support css white-space and text-overflow
1 parent bc887df commit 7acc03b

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

packages/core/ui/text-field/index.ios.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TextFieldBase, secureProperty } from './text-field-common';
2-
import { textProperty } from '../text-base';
2+
import { textOverflowProperty, textProperty, whiteSpaceProperty } from '../text-base';
33
import { hintProperty, placeholderColorProperty, _updateCharactersInRangeReplacementString } from '../editable-text-base';
44
import { CoreTypes } from '../../core-types';
55
import { Color } from '../../color';
@@ -317,4 +317,39 @@ export class TextField extends TextFieldBase {
317317
[paddingLeftProperty.setNative](value: CoreTypes.LengthType) {
318318
// Padding is realized via UITextFieldImpl.textRectForBounds method
319319
}
320+
321+
[whiteSpaceProperty.setNative](value: CoreTypes.WhiteSpaceType) {
322+
this.adjustLineBreak();
323+
}
324+
325+
[textOverflowProperty.setNative](value: CoreTypes.TextOverflowType) {
326+
this.adjustLineBreak();
327+
}
328+
329+
private adjustLineBreak() {
330+
let paragraphStyle: NSMutableParagraphStyle;
331+
332+
switch (this.whiteSpace) {
333+
case 'nowrap':
334+
switch (this.textOverflow) {
335+
case 'clip':
336+
paragraphStyle = NSMutableParagraphStyle.new();
337+
paragraphStyle.lineBreakMode = NSLineBreakMode.ByClipping;
338+
break;
339+
default:
340+
// ellipsis
341+
paragraphStyle = NSMutableParagraphStyle.new();
342+
paragraphStyle.lineBreakMode = NSLineBreakMode.ByTruncatingTail;
343+
break;
344+
}
345+
break;
346+
}
347+
348+
if (paragraphStyle) {
349+
let attributedString = NSMutableAttributedString.alloc().initWithString(this.nativeViewProtected.text);
350+
attributedString.addAttributeValueRange(NSParagraphStyleAttributeName, paragraphStyle, NSRangeFromString(`{0,${attributedString.length}}`));
351+
352+
this.nativeViewProtected.attributedText = attributedString;
353+
}
354+
}
320355
}

0 commit comments

Comments
 (0)