1

I'm not sure if things aren't working the way they should, or my understanding is off. So I'm hoping someone can give me a nudge in the right direction.

I'm looking to use FormattedString within a TextView in a NativeScript (Typescript-based) application. Well, I can get the text to appear and all that just fine, but if I start adding text, it doesn't seem to get picked up how I'd expect.

For example, I have this in my HTML:

<Button text="Test" (tap)="onTestData()"></Button>
<TextView #testTextView></TextView>

and this in my component:

export class MyTestComponent implements OnInit {
  @ViewChild('testTextView', { static: false }) textViewRef: ElementRef;
  private textView: TextView;
......  

ngAfterViewInit() {
   this.textView = this.textViewRef.nativeElement;
   this.textView.formattedText = this.testFormattedString;
  }
......

onTestData() {
    if (isIOS) {
      let span: Span;
      let spanCount: number;
      spanCount = this.textView.formattedText.spans.length
      for (let i = 0; i < spanCount; i++) {
        span = this.textView.formattedText.spans.getItem(i);
        console.log('FormattedText Span ' + i + ' text is: ' + span.text);
        console.log('Text property is: ' + this.textView.text);
      }
    }
  }

Now, in the simulator, I put my cursor at the end of the text in the TextView field, and enter "hippo", and then nothing shows up as being added to .span.text when I click my Test button. However, it does appear in the .text property.

But if I put my cursor between the last two characters and add "pottumous", then the text gets listed both within the .span.text and the .text properties.

Shouldn't text that gets entered at the very end of an existing formatted span get tacked onto that existing span (and listed within the formatted.span[x].text property)? Or am I missing something?

Thanks!

Rick
  • 245
  • 3
  • 13
  • No, it won't. The result is expected. The formatted string will not auto update, the span sticks to its original start and end index. On iOS, You have [typingAttributes](https://developer.apple.com/documentation/uikit/uitextview/1618629-typingattributes) method by setting which you may auto format what user is typing. – Manoj May 23 '20 at 09:35

0 Answers0