Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextView new line closes virtual keyboard on Android #3111

Closed
fuleshu opened this issue Nov 17, 2016 · 9 comments · Fixed by #3189
Closed

TextView new line closes virtual keyboard on Android #3111

fuleshu opened this issue Nov 17, 2016 · 9 comments · Fixed by #3189

Comments

@fuleshu
Copy link

fuleshu commented Nov 17, 2016

I want to enter multiple lines in a TextView. As far as I understood this is what the TextView is for.
I use NativeScript with Angular 2.
I use a simple TextView like this in the xml:
<TextView></TextView >
When I tap on it the virtual keyboard opens as expected. Then I enter text. But when I enter return to start a new line, the keyboard closes. The new line is still inserted. But I have to click on the TextView again to reopen the keyboard.

This happens with version 2.3 and 2.4
I use an Android Device (LG Flex 2)

Do I have to configure the TextView somehow? How can I stop the keyboard from closing?

Thanks a lot,

Timo

@tsonevn tsonevn self-assigned this Nov 18, 2016
@tsonevn
Copy link
Contributor

tsonevn commented Nov 18, 2016

Hi @fuleshu,
I reviewed the given scenario, however was unable to reproduce this behavior and indeed when you have selected the TextView and tap return button it should go on a new line. I am attaching a sample code, which I have used to test your case.
app.component.html

<StackLayout>
    <TextView hint="sample text=""" text="" editable="true"></TextView>

    <Label text="Tap the button" class="title"></Label>

    <Button text="TAP" (tap)="onTap()"></Button>

    <Label [text]="message" class="message" textWrap="true"></Label>
</StackLayout>

I have tested the case with tns-core-modules 2.4.0 on Android emulator API level 23 and 17 and real device with API level 18. It would help if you could give us sample code, where the problem could be debugged locally. It would also help if you could test your code on different device or emulator.

Regards,
@tsonevn

@fuleshu
Copy link
Author

fuleshu commented Nov 18, 2016

Hi,

thanks for your fast reply.
I tried the TextView on my Nexus 5 Device (Api 23) and the emulator with API 23 and actually everything works fine there.
On my LG, which has the problem, runs Android 5.1.1, that means API 22.
So I changed the emulator to API 22, and there is also no bug.

That means the problem is specific to my LG Flex 2 :(
Perhaps the LG-Keyboard? But I do not have any weird keyboard closing behavior with my phone with my installed apps.
Is there I way I can debug that?

Thanks a lot!

@fuleshu
Copy link
Author

fuleshu commented Nov 18, 2016

To narrow things down, I created a native Android app with just a TextEdit, which is what the NativeScript TextView is using.
This app works on my LG as expected without the keyboard bug.

Then I created from scratch one NativeScript application without templates and one using Angular2.
In both I added the TextView as you did in the example and in both I again had the keyboard disappearing on enter.

So it seems like this is a NativeScript bug that just occurs on my LG.

@hamorphis
Copy link
Contributor

hamorphis commented Nov 21, 2016

@fuleshu Since we can't really reproduce this on our side, here is what we can do.

In your app folder, in the file /node_modules/tns-core-modules/ui/editable-text-base/editable-text-base.android.js, locate the dismissSoftInput method and add the following console logs there:

    EditableTextBase.prototype.dismissSoftInput = function () {
        console.log(">>> dismissSoftInput <<<");
        console.trace();
        utils.ad.dismissSoftInput(this._nativeView);
    };

Then run the app and if something appears in the console log, paste it here.

@tsonevn tsonevn removed their assignment Nov 23, 2016
@fuleshu
Copy link
Author

fuleshu commented Nov 23, 2016

Hi,

here is the console log:

Stack Trace:
    at TextView.EditableTextBase.dismissSoftInput (/data/data/org.nativescript.PillowBook/files/app/tns_modules/ui/editable-text-base/editable-text-base.js:113:17)
    at onEditorAction (/data/data/org.nativescript.PillowBook/files/app/tns_modules/ui/editable-text-base/editable-text-base.js:91:31) (d:\src\js\PillowBook\node_modules\tns-core-modules\console\console.js:292:14)

Hope this helps!

@fuleshu
Copy link
Author

fuleshu commented Nov 23, 2016

I digged a little further into it.
I set a breakpoint in setOnFocusChangeListener, that is called when it happens.
The actionId is 0.

@fuleshu
Copy link
Author

fuleshu commented Nov 23, 2016

I don't know if this was a clever thing to do, but in the setOnFocusChangeListener function after the if (owner) { in line 84, I added:

if ((owner._cssType === "textview") && (event && event.getKeyCode() === android.view.KeyEvent.KEYCODE_ENTER)) {
    return false;
}

This solves the issue on my LG phone.

@hamorphis
Copy link
Contributor

@fuleshu Thank you so much. I might refine the if to check about the type of the owner in a more proper way, but yeah, your idea is valid. I will fix this on Monday.

@lock
Copy link

lock bot commented Aug 29, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Aug 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
2.5
Done
Development

Successfully merging a pull request may close this issue.

3 participants