Wrong button position when using KeyboardAvoidingView in combination with SafeAreaView and autofocus
See original GitHub issueDescription
I have an input with autoFocus, a SafeAreaView, and a KeyboardAvoidingView. However the Button which should have his position exactly above the keyboard gets some margin when using SafeAreaView in combination with autoFocus.
It is to mention that if I add a delay to autoFocus of around 250ms it is working as expected.
I’ve build an expo snack here: https://snack.expo.io/@simbob/keyboardavoidingview-bug
React Native version:
react: ~16.11.0 => 16.11.0
react-native: https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz => 0.62.2
Expected Results
Button should have the same position all time.
Steps To Reproduce
import React from "react";
import {
StyleSheet,
Text,
View,
TextInput,
KeyboardAvoidingView,
TouchableOpacity,
Keyboard,
SafeAreaView,
} from "react-native";
export default function App() {
return (
<SafeAreaView style={styles.container}>
<KeyboardAvoidingView style={styles.container} behavior="padding">
<View style={styles.top}>
<Text>Open up App.js to start working on your app!</Text>
<TextInput style={{ borderWidth: 1 }} autoFocus={true} />
</View>
<View style={styles.bottom}>
<TouchableOpacity
style={styles.loginScreenButton}
onPress={Keyboard.dismiss}
>
<Text style={styles.loginText}>Blur</Text>
</TouchableOpacity>
</View>
</KeyboardAvoidingView>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
marginHorizontal: 16,
},
top: {
flex: 0.7,
},
bottom: {
flex: 0.3,
justifyContent: "flex-end",
},
loginScreenButton: {
paddingTop: 10,
paddingBottom: 10,
backgroundColor: "#1E6738",
borderWidth: 1,
},
loginText: {
color: "#fff",
textAlign: "center",
},
});
Issue Analytics
- State:
- Created 3 years ago
- Reactions:22
- Comments:15 (1 by maintainers)
Top Results From Across the Web
KeyboardAvoidingView + React Navigation + Safe Area View ...
So as Alex over at this Github issue pointed out, wrapping the app in SafeAreaProvider fixes the insets not returning values properly.
Read more >KeyboardAvoidingView - React Native
This component will automatically adjust its height, position, or bottom padding based on the keyboard height to remain visible while the ...
Read more >Using KeyboardAwareScrollView and KeyboardAvoidingView ...
This tutorial explains what KeyboardAvoidingView and KeyboardAwareScrollView are and how to use them for different purposes.
Read more >https://cdn.jsdelivr.net/npm/@types/react-native@0...
`numberOfLines` must be set in conjunction with this prop. ... Use TouchableHighlight anywhere where you would use a button or link on web....
Read more >react navigation keyboardavoidingview - You.com | The AI ...
KeyboardAvoidingView + React Navigation + Safe Area View = not working ... SafeAreaView, ScrollView, Button, StatusBar } from 'react-native'; ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m on react-native 0.63.3 and still face this issue
I experience the same issue.
I can say that I see it on iOS only. It does not appear on most of the devices that I’ve tried. It appears on iPhone Xr.
Removing the
autoFocus
from the input solves the issue with the padding but introduces bad UX in my case 😦