Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Calling .focus()-function on "ui/search-bar".SearchBar doesn't show keayboard but returns true #1973

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

Closed
Metalmate opened this issue Apr 15, 2016 · 11 comments · Fixed by #10696
Assignees

Comments

@Metalmate
Copy link

When calling .focus() no keyboard is shown for the searchBar.

NativeScript CLI: 1.7.0
Platform: Android 5.1.1

@NickIliev
Copy link
Contributor

Hello @Metalmate

I have tested your case under API 19, 22 and 23 and indeed the focus does not work.

However consider the Android specific behaviour for the native showSoftInput() method.
It will trigger automatically when you navigate to a page with a searchBar and will open the software keyboard
(on emulators you should enable soft-keyboard from settings in order this to work)

@Metalmate
Copy link
Author

Hello @NickIliev

In our app we only show the searchbar when it is toggeled by pressing a search-icon in the navigation bar. And indeed, Android opens de keyboard by default, but not when the searchbar is set to visible programatically.

On iOS the .focus() opens the keyboard.

@NickIliev
Copy link
Contributor

github repo to reproduce : https://github.com/NickIliev/issue_1973

@hamorphis hamorphis assigned hamorphis and unassigned NickIliev Jul 4, 2016
@hamorphis hamorphis added this to the 2.2 (Under review) milestone Jul 4, 2016
@hamorphis
Copy link
Contributor

This appears to be some kind of Android bug: https://code.google.com/p/android/issues/detail?id=25812

@hamorphis
Copy link
Contributor

@Metalmate
I have created a workaround for this Android bug. Here is what you can do:

<Page xmlns="http://schemas.nativescript.org/tns.xsd">
  <StackLayout>
    <Button text="Toggle SearchBar Visibility" tap="onTap" />
    <Button text="searchBar.dismissSoftInput()" tap="onDismissSoftInput" />
    <SearchBar id="searchBar" visibility="collapse" />
  </StackLayout>
</Page>
import { EventData } from "data/observable";
import { Page } from "ui/page";
import { SearchBar } from "ui/search-bar";
import enums = require("ui/enums");
import utils = require("utils/utils")

declare var android;
export function onTap(args: EventData) {
    let searchBar = (<Page>(<any>args.object).page).getViewById<SearchBar>("searchBar");

    if (searchBar.visibility === enums.Visibility.collapse){
        searchBar.visibility = enums.Visibility.visible;
        searchBar.focus();
        if (searchBar.android){
            let imm = utils.ad.getInputMethodManager();
            if (imm){
                imm.toggleSoftInput(android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT, 0);
            }
        }
    }
    else {
        searchBar.visibility = enums.Visibility.collapse;
    }
}

export function onDismissSoftInput(args: EventData) {
    let searchBar = (<Page>(<any>args.object).page).getViewById<SearchBar>("searchBar");
    searchBar.dismissSoftInput();
}

You can clone the entire sample app from here: https://github.com/hamorphis/issue-1973

@hamorphis
Copy link
Contributor

@Metalmate Let me know if this workaround will do it for you so I can close the issue.

@hamorphis hamorphis removed this from the 2.2.0 milestone Jul 14, 2016
@hamorphis
Copy link
Contributor

I’m closing this issue because it has been inactive for a few months.

@suisseworks
Copy link

somebody has a solution?

@lano-vargas
Copy link

It's still an issue to this day, the workaround works for now but it state that the method toggleSoftInput Deprecated symbol used, consult docs for better alternative!

@CatchABus
Copy link
Contributor

It's still an issue to this day, the workaround works for now but it state that the method toggleSoftInput Deprecated symbol used, consult docs for better alternative!

This should be fixed in latest core next version and will be included in 8.9.0.
Thanks for pointing out the problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants