react-native 键盘自动隐藏问题

Sky*_*thi 6 keyboard react-native

目前,我正在开发一个 react-native 应用程序。问题是,当我触摸文本输入框时,只有每次重新启动我的应用程序时,键盘才会第一次自动隐藏。

我的 TextInput 组件在这里:

<TextInput
  blurOnSubmit={false}
  placeholder={"Email..."}
  autoCapitalize="none"
  style={{
    height: 40,
    paddingLeft: 10,
    fontSize: 18,
    fontWeight: "bold",
    width: "90%",
  }}
  onChangeText={(email) => {
    this.setState({ email });
    this.validateEmail(email).then((res) => this.handleResponse(res));
  }}
  value={this.state.email}
  ref={(ref) => (this.email = ref)}
  onSubmitEditing={() => this.mobile.focus()}
/>
Run Code Online (Sandbox Code Playgroud)

我的 Package.json 依赖项

  "dependencies": {
    "@react-native-community/async-storage": "^1.11.0",
    "@react-native-community/masked-view": "^0.1.10",
    "@react-navigation/bottom-tabs": "^5.5.2",
    "@react-navigation/drawer": "^5.8.2",
    "@react-navigation/native": "^5.5.1",
    "@react-navigation/stack": "^5.5.1",
    "react": "16.11.0",
    "react-native": "0.62.2",
    "react-native-datepicker": "^1.7.2",
    "react-native-gesture-handler": "^1.6.1",
    "react-native-looped-carousel": "^0.1.13",
    "react-native-reanimated": "^1.9.0",
    "react-native-safe-area-context": "^3.0.5",
    "react-native-safe-area-view": "^1.1.1",
    "react-native-screens": "^2.8.0",
    "react-native-vector-icons": "^6.6.0"
  },
Run Code Online (Sandbox Code Playgroud)

zid*_*ryi -2

您可以像下面这样修改 AndroidManifes.xml,这个错误出现在 React Native 以上>59 中。

  <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:screenOrientation="portrait"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize"
        >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>

Run Code Online (Sandbox Code Playgroud)

然后保存并再次运行您的应用程序项目。

  • 请指定确切应该修复该行为的设置。我们不能仅仅复制整个文件,因为这些设置中的大多数都是不相关的并且在每个应用程序上都是不同的。 (2认同)