首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >移动键盘可以始终在离子应用程序中打开吗?

移动键盘可以始终在离子应用程序中打开吗?
EN

Stack Overflow用户
提问于 2019-12-29 23:30:28
回答 1查看 107关注 0票数 2

在Ionic Chat应用程序的聊天页面中发送消息后,我想始终打开我的移动键盘。因为在单击发送按钮时,第一次单击时,键盘会关闭,然后,在第二次单击时,消息会被发送。因此,在Ionic 3应用程序中,它需要时间并显示出滞后。

有没有办法解决离子应用(离子3/4)中的键盘问题?

EN

回答 1

Stack Overflow用户

发布于 2020-02-12 14:20:13

preventDefault() and stopPropagation()是帮助保持键盘打开的主要概念。为了完成此功能,我在聊天页面的Send Button中添加了#sendButton。并使用ViewChild,

代码语言:javascript
复制
    @ViewChild('sendButton') private sendButton:Button;

然后,我将以下代码添加到我的.ts页面。并在ngOnInit()上调用此函数(也可以使用ionViewDidLoad()或ionViewWillLoad())

代码语言:javascript
复制
keepKeyboardVisible() {
    if(!!this.sendButton){
        let el = this.sendButton._elementRef.nativeElement;
        console.log(el);
        el.addEventListener('click', (event) => {
            this.stopBubble(event);
        });
        el.addEventListener('touchdown', (event) => {
            this.stopBubble(event);
        });
        el.addEventListener('touchmove', (event) => {
            this.stopBubble(event);
        });
        el.addEventListener('touchstart', (event) => {
            this.stopBubble(event);
        });
        el.addEventListener('touchend', (event) => { //Triggered by a phone
            this.stopBubble(event);
            this.sendMessage();
        });
    }
}

stopBubble(event) {
    console.log(event);
    event.preventDefault(); 
    event.stopPropagation(); //Stops event bubbling
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59520735

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档