简体   繁体   English

React Native - 有没有办法完全隐藏键盘?

[英]React Native - Is there a way to hide the keyboard completely?

I'm developing an app for a scanning device which does not use the virtual keyboard at all.我正在为根本不使用虚拟键盘的扫描设备开发应用程序。 So currently, I only show the keyboard when the user want to open it (by tapping the keyboard icon)所以目前,我只在用户想要打开它时显示键盘(通过点击键盘图标)

虚拟键盘打开

And tab again to turn the virtual keyboard off.并再次 Tab 以关闭虚拟键盘。

虚拟键盘关闭 . .

However, when I type the Input by hard keyboard (from PC / scanning device) or tap the input, the virtual keyboard still showing up and there is no way to prevent that.但是,当我通过硬键盘(从 PC / 扫描设备)输入输入或点击输入时,虚拟键盘仍然出现,无法阻止。 I can catch the event and dismiss the virtual keyboard by:我可以通过以下方式捕捉事件并关闭虚拟键盘:

onKeyPress={() => {
  Keyboard.dismiss();
}}

But it still create an annoying opening - closing virtual keyboard animation.但它仍然创建了一个恼人的开-关虚拟键盘animation。 Is there anyway to stop this animation or hide the virtual keyboard completely?有没有办法停止这个 animation 或完全隐藏虚拟键盘?

This is a known limitation of React Native.这是 React Native 的一个已知限制 You can try disabling pointer events as follows but I am not sure that will prevent the physical keyboard from creating events and you will lose text scrolling:您可以尝试如下禁用指针事件,但我不确定这会阻止物理键盘创建事件并且您将丢失文本滚动:

    <View pointerEvents="none">
      <Input
        value={String(value)}
        placeholder={placeholder}
      />
    </View>

use props of textInput 'showSoftInputOnFocus' example:使用 textInput 'showSoftInputOnFocus' 示例的道具:

<TextInput showSoftInputOnFocus={false} />

documentation here https://github.com/facebook/react-native/commit/d88e4701fc46b028861ddcfa3e6ffb141b3ede3d此处的文档https://github.com/facebook/react-native/commit/d88e4701fc46b028861ddcfa3e6ffb141b3ede3d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM