title: Nativescript scroll to bottom of ScrollView programmatically
body: <p>In my Nativescript Angular application, I have a TextView within a ScrollView, defined as such:</p>
  
  <pre><code>&lt;ScrollView orientation="vertical" height="70%" width="100%" style="margin-bottom: 1%; background-color:white" (loaded)="onScrollerLoaded($event)"&gt;
      &lt;TextView 
          id="terminal" [text]="terminalText" editable="false"
          style="color: whitesmoke; background-color: black; font-size: 8%; font-family: monospace" height="100%"     
          (tap)="onTap($event)" (loaded)="onTerminalLoaded($event)"&gt;
      &lt;/TextView&gt;
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>The purpose of this element is to act as a terminal, and is rapidly printing incoming messages from a bluetooth device.</p>
  
  <p>Currently, the ScrollView is scrolling back to the top whenever I add some text to the <code>terminalText</code> variable, to which the TextView is bound. <strong>I would like to be able to keep the ScrollView at the bottom of the TextView.</strong></p>
  
  <hr>
  
  <p>A few notes:</p>
  
  <p>I am adding text to the <code>terminalText</code> variable within my associated component class through this method:</p>
  
  <pre><code>public appendToTerminal(appendStr){
      this.terminalText += appendStr;
  }
  </code></pre>
  
  <p>I have tried implementing the following code that would execute once the ScrollView loads:</p>
  
  <pre><code>private scrollIntervalId;
  onScrollerLoaded(data: EventData){
      if(!this.scrollIntervalId){
          this.scrollIntervalId = setInterval(()=&gt;{
              this.ngZone.run(() =&gt;
                  (data.object as any).scrollToVerticalOffset((data.object as any).scrollableHeight, false)
              )
          }, 10);
      }
  }
  </code></pre>
  
  <p>(This attempt is based on an explanation given <a href="https://stackoverflow.com/questions/38304993/auto-scroll-to-bottom">here</a></p>
  
  <p>I have only tried this on an Android device, as I do not have access to an Apple device.</p>