|
1 | 1 | import { TextFieldBase, secureProperty } from './text-field-common';
|
2 |
| -import { textProperty } from '../text-base'; |
| 2 | +import { textOverflowProperty, textProperty, whiteSpaceProperty } from '../text-base'; |
3 | 3 | import { hintProperty, placeholderColorProperty, _updateCharactersInRangeReplacementString } from '../editable-text-base';
|
4 | 4 | import { CoreTypes } from '../../core-types';
|
5 | 5 | import { Color } from '../../color';
|
@@ -317,4 +317,39 @@ export class TextField extends TextFieldBase {
|
317 | 317 | [paddingLeftProperty.setNative](value: CoreTypes.LengthType) {
|
318 | 318 | // Padding is realized via UITextFieldImpl.textRectForBounds method
|
319 | 319 | }
|
| 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 | + } |
320 | 355 | }
|
0 commit comments