KeyboardAvoidingView не регулирует высоту - PullRequest
0 голосов
/ 01 апреля 2020

Я пытаюсь вывести текстовое представление и кнопку в центр при вызове клавиатуры. Я попытался обернуть мой SafeArea с KeyboardAvoidingView, но это не сработало. Я также попытался установить поведение KeyBoardAvoidingView на position, которое также не работало. Любое руководство будет оценено.

KeyboardAvoidingView не работает должным образом.

** Что происходит: **

enter image description here

enter image description here

* * Вот мой код: **

<SafeAreaView style={{ flex: 1, backgroundColor: '#376772' }}>
        <KeyboardAvoidingView
            style={{ flex: 1 }}
            behavior={Platform.Os == 'ios' ? 'padding' : null}
        >
            <TouchableWithoutFeedback onPress={Keyboard.dismiss}>
                <View style={{ flex: 1 }}>
                    <MapView
                        style={{ flex: 0.6 }}
                        showsMyLocationButton={true}
                        showsUserLocation={true}
                        followsUserLocation={lock}
                        onTouchStart={() => {
                            set(false)
                        }}
                        onPress={(loc) => {
                            setLocation(loc.nativeEvent.coordinate)
                        }}
                    >
                        <Marker coordinate={location} />
                    </MapView>
                    <Fragment>
                        <View
                            style={{
                                alignSelf: 'center',
                                alignContent: 'center',
                                backgroundColor: '#202B35',
                                padding: 10,
                                paddingHorizontal: 35,
                                margin: 5,
                                borderRadius: 5,
                                alignItems: 'center',
                                position: 'absolute',
                            }}
                        >
                            <View style={{ flexDirection: 'row' }}>
                                <Badge
                                    status="error"
                                    containerStyle={{ padding: 5 }}
                                />
                                <Text
                                    style={{
                                        color: '#fff',
                                        fontSize: 16,
                                        marginBottom: 5,
                                    }}
                                >
                                    New Crossing
                                </Text>
                                <Text
                                    style={{
                                        color: '#fff',
                                        fontSize: 10,
                                        padding: 5,
                                    }}
                                >
                                    (Tap to add)
                                </Text>
                            </View>

                            <View style={{ flexDirection: 'row' }}>
                                <Badge
                                    status="primary"
                                    containerStyle={{ padding: 5 }}
                                />
                                <Text
                                    style={{
                                        color: '#fff',
                                        fontSize: 16,
                                    }}
                                >
                                    {'Existing Crossings'}
                                </Text>
                            </View>
                        </View>
                    </Fragment>

                    <View
                        style={{
                            flex: 0.4,
                            backgroundColor: '#376772',
                            margin: 5,
                            borderRadius: 5,
                        }}
                    >
                        <Input
                            placeholder="Enter Crossing name here"
                            inputStyle={{ color: 'orange' }}
                            rightIcon={
                                <Icon
                                    name="edit"
                                    size={25}
                                    color="orange"
                                />
                            }
                            placeholderTextColor={'orange'}
                            errorStyle={{ color: 'red' }}
                        />

                        <Button
                            buttonStyle={{
                                margin: 10,
                                top: scale(10),
                                padding: 15,

                                backgroundColor: '#5cb85c',
                                borderRadius: 4,
                            }}
                            icon={
                                <Icon name="send" size={15} color="white" />
                            }
                            iconRight
                            titleStyle={{ fontWeight: 'bold' }}
                            title="Submit  "
                        />
                    </View>
                </View>
            </TouchableWithoutFeedback>
        </KeyboardAvoidingView>
    </SafeAreaView>

1 Ответ

1 голос
/ 01 апреля 2020

Настройка поведения на «position» сработала для меня, убрав flex: 1 из стилей, например

<KeyboardAvoidingView behavior="position">
  {children}
</KeyboardAvoidingView>

Cheers!

...