Created
July 23, 2020 01:13
-
-
Save marcovincit/dae93f4c18727a589fc60cc9cb988e4c to your computer and use it in GitHub Desktop.
Vew height without keyboard react native
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useState } from "react"; | |
import { Keyboard, TextInput, Dimensions } from "react-native"; | |
const Example = () => { | |
const [heightDefined, setHeightDefined] = useState(100); | |
useEffect(() => { | |
Keyboard.addListener("keyboardDidShow", (e) => { | |
setHeightDefined( | |
Dimensions.get("window").height - e.endCoordinates.height | |
); | |
}); | |
Keyboard.addListener("keyboardDidHide", (e) => { | |
setHeightDefined(100); | |
}); | |
}, []); | |
return ( | |
<TextInput | |
style={{ | |
borderWidth: 1, | |
backgroundColor: "pink", | |
height: heightDefined, | |
}} | |
placeholder="Click here ..." | |
onSubmitEditing={Keyboard.dismiss} | |
/> | |
); | |
}; | |
export default Example; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment