【问题标题】:onKeyPress not producing key pressed in React-Native WindowsonKeyPress 不产生在 React-Native Windows 中按下的键
【发布时间】:2018-05-22 17:09:02
【问题描述】:

我正在将 react-native 版本 0.54.0 用于 Windows 应用程序。我有一个TextInput 元素,我想实现onKeyPress。我有以下内容:

<TextInput 
ref = { this.setTextInputRef }
onChange = { (e) => this.setState({ currentString: e.nativeEvent.text }) }
onKeyPress = { (e) => { console.log(e) }}
onSubmitEditing = { () => this.doAThing() }
multiline = { true }
/>

在我的编辑器中,将鼠标悬停在onKeyPress 中的e 事件上表明它是一个字符串。但是,执行console.log(e) 表明它是一个 SyntheticEvent,其所有属性都为空。我知道onKeyPress 刚开始使用android,它与windows 不兼容吗?如果它是兼容的,我需要做什么才能让它工作?

所有这些都是为了监听输入事件,所以如果有其他选择,我也会很高兴。

【问题讨论】:

    标签: typescript react-native


    【解决方案1】:

    事实证明,Windows 对此很反感。将 multiline 设置为 true 时,幕后的侦听器会在 enter keypress 事件到达 onKeyPress 侦听器之前将其吞下。不得不破解 react-windows-native 中的修复程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-07
      • 2021-06-05
      • 2017-06-29
      • 1970-01-01
      • 2018-02-27
      • 1970-01-01
      相关资源
      最近更新 更多