【问题标题】:Need to click twice in KeyboardAvoidingView even when keyboardshouldpersisttaps is always需要在 KeyboardAvoidingView 中单击两次,即使在始终保持键盘时也是如此
【发布时间】:2019-09-27 18:55:04
【问题描述】:

我正在使用 KeyboardAvoidingView 来使用键盘向上移动按钮,其中我有一个滚动视图,其中 keybordShouldPersistTaps 设置为始终,在滚动视图中,我使用的是 Formik 表单。我仍然需要双击一个按钮两次才能让键盘关闭并提交我的数据。我一直试图手动关闭/处理滚动视图上的键盘,但没有运气,我应该尝试其他方法吗?

<KeyboardAvoidingView style={{ flex: 1 }} behavior={'padding'}>
    <ScrollView contentContainerStyle={{ flexGrow: 1 }} keyboardShouldPersistTaps={'always'}>
        <Formik
            initialValues={this.state}
            validationSchema={this.schema}
            onSubmit={(values, actions) => {              
              actions.setSubmitting(false);
            }}
            render={({ handleBlur, handleChange, handleSubmit, values, isValid }) => {
              return (
                <View style={onboardingStyles.inputContainer}>
                  <View>
                    <Text theme={theme} style={onboardingStyles.headerText}>
                      {i18n.t('phone_verify')}
                    </Text>
                    <TextInput
                      activeHighlight
                      value={RizeCore.util.formatPhoneDOM(values.phone)}
                      onChangeText={(val: string) => {

                        const phone = RizeCore.util.parseOutDigits(val, 10);
                        return handleChange('phone')(phone);
                      }}
                      onBlur={() => handleBlur('phone')}
                      label={i18n.t('phone_number')}
                      style={onboardingStyles.input}
                      labelStyle={{ color: 'white' }}
                      keyboardType={Platform.OS === 'web' ? 'default' : 'number-pad'}
                      returnKeyType="done"
                    />
                  </View>
                  <BottomFixedCTA
                    ctaLabel={i18n.t('phone_send_code')}
                    loading={smsCodeIsBusy}
                    disabled={!isValid}
                    onPress={handleSubmit as undefined}
                    onBackPress={this._navSignUp}
                  />
                </View>
              );
            }}
          />
        </ScrollView>
      </KeyboardAvoidingView>

【问题讨论】:

    标签: typescript react-native formik


    【解决方案1】:

    您可以尝试在scoolview中添加参数keyboardShouldPersistTaps = "handled"

    【讨论】:

      【解决方案2】:

      尝试使用:

      keyboardShouldPersistTaps="handled"
      

      【讨论】:

      • 虽然这段代码可以回答问题,但最好解释一下如何解决问题,并提供代码作为示例或参考。仅代码的答案可能会令人困惑且缺乏上下文。
      • 我确实尝试过使用它,不幸的是没有实际变化
      猜你喜欢
      • 2020-04-24
      • 1970-01-01
      • 1970-01-01
      • 2017-12-30
      • 2022-08-14
      • 2022-01-17
      • 2019-08-09
      • 2012-09-17
      • 1970-01-01
      相关资源
      最近更新 更多