简体   繁体   English

在Nexus Player,Android Cordova应用程序上打开虚拟键盘时输入第一个字符

[英]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.

相关问题 打开Android键盘时,Cordova应用程序表单无法向上滚动 - Cordova app form doesn't scroll up when Android keyboard is opened Cordova 应用程序在首次打开时需要 Internet - Cordova App in Requires Internet First Time It Is Opened 装有Android 6.0.1的Nexus 7上的Cordova相机访问崩溃应用 - Cordova Camera access crash app on Nexus 7 with Android 6.0.1 cordova应用未在Nexus,Motorol(基于Google的android设备)中运行 - cordova app is not running in Nexus, Motorol (google based android devices) 输入输入类型编号时如何防止“0”作为第一个字符? - How to prevent a "0" as the first character when typing in input type number? 如何检查Android应用程序首先运行 - 科尔多瓦 - How to check android app first run - Cordova Cordova ios WKWebView首次触摸启动事件在键盘启动时不会触发 - Cordova ios WKWebView first touchstart event not firing when keyboard is up 显示键盘 android (cordova) - show keyboard android (cordova) 当第一个玩家玩游戏时如何不允许输入某些角色? - How to not allow certain character to be entered when first player is playing the game? 键盘关闭后渲染组件或在 cordova android 的反应应用程序中收听键盘关闭事件 - Render component after keyboard closes or listen to keyboard close event in react app in cordova android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM