DismissSoftInput()用于Nativescript-Vue的搜索栏 [英] DismissSoftInput() for search-bar for Nativescript-Vue

查看:108
本文介绍了DismissSoftInput()用于Nativescript-Vue的搜索栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解释问题:

搜索栏无法关闭打开的键盘.这使得 搜索栏非常不可用,因为普通用户模式是 用户搜索某些内容,然后按该项目并进行导航 那里.在Android上(至少在> = 5.x上),打开的键盘将 继续保持打开状态,即使在新页面上也是如此.

The search-bar has no way of dismissing an open keyboard. This makes the search-bar a quite unusable as the normal user pattern is that the user search for something and then press the item and gets navigated there. On Android (at least on >= 5.x), the open keyboard will continue to stay open, even on the new page.

请参考 Github 上的问题,任何人如何针对Nativescript- Vue,不适用于带有Typescript的Nativescript

Referring to the question on Github, anyone how to do that for Nativescript-Vue and not for Nativescript with Typescript

添加了游乐场: https://play.nativescript.org/? template = play-vue& id = hrrcW9

如果我最小化该应用程序,然后再次单击它,则键盘会再次弹出打开窗口.

If I minimize the app, then click on it again, the keyboard pops open again.

推荐答案

正如您在链接问题中已经可以看到的那样,功能请求已完成. dismissSoftInput()是SearchBar上的一种方法,它现在隐藏了键盘.

As you could already see in the linked issue, the feature request is closed as completed. dismissSoftInput() is a method on SearchBar now that hides the keyboard.

如果仍然有问题,请共享您的代码.

If you have issues still, please share your code.

更新:

这是Android的默认行为,即将第一个可聚焦元素集中在片段/活动上.添加事件侦听器/超时以从每个屏幕上移开焦点可能会很烦人,我更喜欢将自动聚焦视图用作布局的第一个元素(这不会对屏幕设计产生任何影响),这样会阻止自动聚焦于文本字段/搜索栏.

It's the default behaviour of Android to focus first focusable element on fragment / activity. Adding event listeners / timeouts to remove focus from each screen might be annoying, I would prefer using a auto focus view as first element (which will not have any impact on the screen design) of my layout, that would prevent auto focusing on my text fields / search bar.

import { View } from "tns-core-modules/ui/core/view";

export class AutoFocusView extends View {

    createNativeView() {
        if (typeof android !== "undefined") {
            const linearLayout = new android.widget.LinearLayout(this._context);
            linearLayout.setFocusableInTouchMode(true);
            linearLayout.setFocusable(true);
            return linearLayout;
        }
        return super.createNativeView();
    }

    onLoaded() {
        super.onLoaded();
        if (typeof android !== 'undefined') {
            this.requestFocus();
        }
    }

    requestFocus() {
        if (typeof android !== "undefined") {
            const nativeViewProtected = this.nativeViewProtected;
            nativeViewProtected.requestFocus();
        }
    }
}

游乐场样本

这篇关于DismissSoftInput()用于Nativescript-Vue的搜索栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆