[英]Virtual keyboard typing first character when it is opened on Nexus Player, Android Cordova app
I know this is a very specific question on a specific device, but I need some insight on how to prevent this from happening in general. 我知道这是特定设备上的一个非常具体的问题,但我需要了解如何防止这种情况发生。
I have a ReactJS app which has a build for Android using Cordova. 我有一个ReactJS应用程序,它使用Cordova构建Android。 One of the supported devices is the Nexus Player. 其中一个受支持的设备是Nexus Player。 For some reason, ONLY on the nexus player, when I open the virtual keyboard, it immediately types in the first character. 出于某种原因,仅在nexus播放器上,当我打开虚拟键盘时,它会立即输入第一个字符。 This is usually wherever I left the character selector last. 这通常是我最后离开字符选择器的地方。
So say I have an email input, if I type myemail@email.com
and move on to the next input field, as I open the virtual keyboard it will type m
. 所以说我有一个电子邮件输入,如果我输入myemail@email.com
并转到下一个输入字段,当我打开虚拟键盘时它将输入m
。 Of course this goes from being a minor nuisance to an actual problem if the user leaves the virtual keyboard at say the Enter
key, which will block it from being opened and/or immediately submit the forms. 当然,如果用户离开虚拟键盘,例如Enter
键,这将从轻微的麻烦变为实际问题,这将阻止其被打开和/或立即提交表格。 I am currently out of ideas on how to deal with it. 我目前没有关于如何处理它的想法。
For the inputs I am using a controlled component and setting it through the state, so the render function looks something like this: 对于输入我使用受控组件并通过状态设置它,因此render函数看起来像这样:
render () {
return (
<form onSubmit={onSubmit} role='form' className='form'>
<div className='form-group'>
<div data-focusable data-focus-container>
<input
type='text'
className='form-control'
value={myValue}
onChange={evt => this.setState({myValue: evt.target.value})}
data-focusable
/>
</div>
</div>
</form>
)
}
Now... Because this is a navigation app, I have a keyboard listener that listens to whatever key I press from the remote on my component. 现在......因为这是一个导航应用程序,我有一个键盘监听器,可以监听我从组件上的遥控器按下的任何键。 I think that may be the way to handle this problem. 我认为这可能是解决这个问题的方法。
keydownHandler(evt) {
if (isDeviceNexuPlayer()) {
if (keyCodeIs('select', evt)) {
// do something to stop the first key from being immediately pressed
console.log('this is being called as expected')
}
}
})
As the console.log states, this works as expected. 正如console.log所述,这可以按预期工作。 What I need to know is how I can stop that first key from being fired. 我需要知道的是如何阻止第一把钥匙被解雇。 I have tried a few things, so for nothing has worked: 我尝试了一些东西,所以没有任何效果:
evt.stopPropagation()
: does nothing, still presses the first key upon opening the virtual keyboard evt.stopPropagation()
:什么都不做,在打开虚拟键盘时仍然按下第一个键 evt.stopImmediatePropagation()
: Stops the whole thing to the point that it doesn't allow any key to work even after it has been opened evt.stopImmediatePropagation()
:停止整个事情,即使在任何密钥打开后也不允许任何密钥工作 I don't know what else to do. 我不知道还能做什么。 I guess it doesn't even have to only apply to the nexus player. 我想它甚至不必仅适用于nexus播放器。 In general, what can I do to prevent that extra key from being pressed as I open the virtual keyboard? 通常,我可以做什么来防止在打开虚拟键盘时按下额外的键?
This may sound a bit daft, but worth trying. 这可能听起来有些愚蠢,但值得一试。 Try to turn off the keyboard, take out the batteries, wait a bit, then put them back in and try again? 尝试关闭键盘,拿出电池,等一下,然后把它们放回去再试一次? When it restarts it may not be firing that first key. 当它重新启动时,它可能不会触发第一个键。 Also, not sure why the attached code is relevant? 另外,不确定为什么附加的代码是相关的?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.