【问题标题】:React-native keyboard反应本机键盘
【发布时间】:2020-04-22 05:58:47
【问题描述】:

当 texInput 聚焦于 react-native 时,当键盘打开时,我的标题会从屏幕上消失。我无法在 android manifest.xml keyboardSoftINputMode 中进行更改以调整大小。因为如果我调整调整大小,那么keyboardAwareScrollView 不起作用。

请建议我一种方法,以便当我的 TextInput 聚焦时,我的标题不会离开屏幕。这发生在 react-native 中。

【问题讨论】:

  • 您是否尝试过使用KeyboardAvoidingView

标签: react-native textinput


【解决方案1】:

您可以使用 KeyboardAvoidingView 在 TextInput 突出显示时自动调整可见区域的大小。

用法:只需将您的顶级<View> 或其他组件包装在您的Apprender() 函数中,并使用<KeyboardAvoidingView>

import {KeyboardAvoidingView} from 'react-native';

...
<KeyboardAvoidingView>
  ... your UI ...
</KeyboardAvoidingView>;

【讨论】:

  • 是的,我试过了,但结果还是一样。它不工作。
  • 请向我们展示您的代码,以便我们知道您在尝试什么
  • render() { const { styles } = this.state const style = this.props.testType === 'practice' ? styles.containerStyleCPP : styles.container return ( {this.renderQuestionBasedOnType()} {/* */} ) } } const getStyle = () => StyleSheet.create({ container: { height: heightPercentage(100) } })
【解决方案2】:

渲染(){ 常量 { 样式 } = this.state const style = this.props.testType === 'practice' ?样式.containerStyleCPP : 样式.container 返回 ( {this.renderQuestionBasedOnType()} {/* */} ) } }

const getStyle = () => StyleSheet.create({ 容器: { 高度:高度百分比(100) }, 容器样式CPP:{ 宽度:宽度百分比(100) } })

这是我的代码

【讨论】:

    猜你喜欢
    • 2018-01-04
    • 2018-02-15
    • 2020-10-14
    • 2018-12-10
    • 1970-01-01
    • 1970-01-01
    • 2020-08-06
    • 2019-12-18
    • 2016-09-30
    相关资源
    最近更新 更多