Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keyboard and Modal with React native (UI Kitten)

I have one model with textinput inside, but, my keyboard overlap this field.
I tried to use KeyboardAvoidingView, but did not work.

Can someone help me please?

Wrong

like image 233
Paulo Vitor Nascimento Avatar asked Feb 01 '26 10:02

Paulo Vitor Nascimento


1 Answers

Detect the keyboard height and move the modal that exact value:

This is the useEffect that I used in order to get the keyboard height every time the keyboard appeared or disappeared:

const [keyboardSize, setKeyboardSize] = React.useState(0);

useEffect(() => {
    Keyboard.addListener("keyboardDidShow", (e) => {
        setKeyboardSize(e.endCoordinates.height)
    })

    Keyboard.addListener("keyboardDidHide", (e) => {
        setKeyboardSize(e.endCoordinates.height)
    })

    return (() => {
        Keyboard.removeAllListeners("keyboardDidShow");
        Keyboard.removeAllListeners("keyboardDidHide");
    })
}, [])

And this is the modal and card with the style:

<Modal
     visible={addUserModal}
     backdropStyle={styles.backdrop}
     style={styles.modal}
     onBackdropPress={() => setAddUserModal(false)}>
     <Card style={{ marginBottom: keyboardSize }} disabled={true}>
         <AddUser finished={() => { setAddUserModal(false) }}></AddUser>
     </Card>
</Modal>
like image 171
Said Torres Avatar answered Feb 03 '26 23:02

Said Torres



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!