我使用 Expo XDE (xde-2.19.3) 创建了一个 React Native 项目,屏幕上有一些 TextInputs。我使用 KeyboardAwareScrollView 将键盘下方的输入滚动到 View 中,并且在 iOS 上运行良好,但在 Android 上不起作用。希望这是有道理的。

看了一下KeyboardAwareScrollView docs,发现需要配置AndroidManifest.xml 但是expo好像已经整理好了:https://github.com/expo/expo/blob/master/template-files/android/AndroidManifest.xml

但是我仍然无法在Android上运行它......

我可能会错过什么?

render() {
    return (
      <KeyboardAwareScrollView
        enableOnAndroid='true'
        enableAutoAutomaticScrol='true'
        keyboardOpeningTime={0}
      >
      <ScrollView style={styles.container}>
        <View style={styles.subcontainer}>
          <View style={styles.form}>
              <TextInput
                ref='NoduleCountInput'
                onFocus={() => this.onFocus()}
                onBlur={() => this.onBlur()}
                keyboardType='phone-pad'
                returnKeyType='done'
                placeholder='Test'
                style={styles.field}
              />
              <TextInput
                ref='NoduleCountInput'
                onFocus={() => this.onFocus()}
                onBlur={() => this.onBlur()}
                keyboardType='phone-pad'
                returnKeyType='done'
                placeholder='Test'
                style={styles.field}
              />
              <TextInput
                ref='NoduleCountInput'
                onFocus={() => this.onFocus()}
                onBlur={() => this.onBlur()}
                keyboardType='phone-pad'
                returnKeyType='done'
                placeholder='Test'
                style={styles.field}
              />
              <TextInput
                ref='NoduleCountInput'
                onFocus={() => this.onFocus()}
                onBlur={() => this.onBlur()}
                keyboardType='phone-pad'
                returnKeyType='done'
                placeholder='Test'
                style={styles.field}
              />
              <TextInput
                ref='NoduleCountInput'
                onFocus={() => this.onFocus()}
                onBlur={() => this.onBlur()}
                keyboardType='phone-pad'
                returnKeyType='done'
                placeholder='Test'
                style={styles.field}
              />
              <TextInput
                ref='NoduleCountInput'
                onFocus={() => this.onFocus()}
                onBlur={() => this.onBlur()}
                keyboardType='phone-pad'
                returnKeyType='done'
                placeholder='Test'
                style={styles.field}
              />
              <TextInput
                ref='NoduleCountInput'
                onFocus={() => this.onFocus()}
                onBlur={() => this.onBlur()}
                keyboardType='phone-pad'
                returnKeyType='done'
                placeholder='Test'
                style={styles.field}
              />
            </View>
         </View>
        </ScrollView>
      </KeyboardAwareScrollView>
    );
  }

最佳答案

我尝试了上述跨平台支持的解决方案,但它不正确。如果您希望自动滚动到 TextInput 的焦点起作用,正确且完整的解决方案是设置参数如下:

<KeyboardAwareScrollView
  enableOnAndroid={true}
  enableAutomaticScroll={(Platform.OS === 'ios')}
>
...
</KeyboardAwareScrollView>

这是因为默认情况下启用enableAutomaticScroll并将它与Android的 native 行为混合在一起以产生意外结果。因此,当平台为 Android 时,将此字段设置为 false。

是的还在 app.json 中设置以下内容,否则它将无法工作。
"androidStatusBar": {
  "backgroundColor": "#000000"
}

10-04 22:59
查看更多