即使在键盘应该始终按击的情况下,也需要在KeyboardAvoidingView中单击两次

时间:2019-05-09 21:31:08

标签: typescript react-native formik

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

<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>

2 个答案:

答案 0 :(得分:1)

尝试使用:

keyboardShouldPersistTaps="handled"

答案 1 :(得分:0)

您可以尝试将参数添加到scroolview keyboardShouldPersistTaps = "handled"