tjvantoll / nativescript-IQKeyboardManager

NativeScript wrapper for the popular IQKeyboardManager iOS framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PreviousNextView not working with textfield focused programmatically

felixelgato92 opened this issue · comments

First let me say that this plugin is awesome,

Now second, I have an issue with PreviousNextView. It's working great for the most part, but I have a page set up so that the first textfield is focused as soon as the page is opened (so that the user can start typing right away). The problem is that when I use textfield.focus() then the arrows are messed up for the first textfield. They point up when I have the first textfield selected, and neither arrow work. I have to unselect the textfield, and then selected it back again.

Here I have a playground example with the minimal code to reproduce it (notice the arrows as soon as the second page is opened):
https://play.nativescript.org/?template=play-ng&id=p9cTUW&v=6

So I have a textfield like this:

<TextField
    (layoutChanged)="onNameInputLayoutChanged($event.object)"
    [hint]="'projectName' | translate"
    [(ngModel)]="projectInput.name"
></TextField>

and the .ts file like this:

public onNameInputLayoutChanged(textfield: TextField): void {
   textfield.focus()
  }

If you guys could look into it that would be awesome. Thank you!

Looks like you're focusing that textfield as soon as it's loaded, and perhaps other parts of the page haven't yet. So a little timeout will go a long way. I would actually use an even longer timeout so the screen transition has finished so it looks a little nicer.

Updated playground: https://play.nativescript.org/?template=play-ng&id=p9cTUW&v=7

Changed code in textfields.component.ts:

    public onLayoutChanged(textfield): void {
        setTimeout(() => {
            textfield.focus();
        }, 0);
    }

Hey thanks so much for the fast reply! It does work, but it causes some flickering. I'll probably add some delay time as suggested or maybe use a ViewChild reference to the object once the page is fully loaded.

Thanks again! I wasn't expecting a same day reply