【问题标题】:Is there any way to handel onClose keyboard device button in React native?有没有办法在 React native 中处理 onClose 键盘设备按钮?
【发布时间】:2023-03-10 19:30:01
【问题描述】:

我不想让关闭屏幕上的键盘,所以我尝试处理这个按钮

【问题讨论】:

    标签: android react-native keyboard


    【解决方案1】:

    <TextField /> 获得焦点时,键盘应该会自动打开。当元素挂载link 时,您可以使用autoFocus 属性使其成为焦点

    另外,你可以检查这个答案

    How to open keyboard automatically in React Native?

    顺便说一下,你想为此控制硬件返回按钮,访问这个链接

    React Native - Device back button handling

    这里是硬件后退按钮的示例代码。

    import { BackHandler } from 'react-native';
    
    constructor(props) {
        super(props)
        this.handleBackButtonClick = this.handleBackButtonClick.bind(this);
    }
    
    componentWillMount() {
        BackHandler.addEventListener('hardwareBackPress', this.handleBackButtonClick);
    }
    
    componentWillUnmount() {
        BackHandler.removeEventListener('hardwareBackPress', this.handleBackButtonClick);
    }
    
    handleBackButtonClick() {
        this.props.navigation.goBack(null);
        return true;
    }
    

    【讨论】:

    • 感谢您的回答,但所有这些都不是我的解决方案,我不想让用户关闭键盘
    • 你能分享你的代码吗,也许我可以在查看你的代码后修复它
    猜你喜欢
    • 2019-06-24
    • 1970-01-01
    • 2017-12-15
    • 1970-01-01
    • 2020-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多