question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong button position when using KeyboardAvoidingView in combination with SafeAreaView and autofocus

See original GitHub issue

Description

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

safeareavie 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:open
  • Created 3 years ago
  • Reactions:22
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

20reactions
gabrieldonadelcommented, Jan 28, 2021

I’m on react-native 0.63.3 and still face this issue

8reactions
martin056commented, Aug 20, 2021

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 😦

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found