Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exclude StatusBar height from useWindowDimensions if StatusBar is not translucent #837

Merged
merged 2 commits into from
Feb 27, 2025

Conversation

kirillzyusko
Copy link
Owner

@kirillzyusko kirillzyusko commented Feb 26, 2025

📜 Description

Exclude StatusBar height from useWindowDimensions if StatusBar is not translucent.

💡 Motivation and Context

In #468 I added own implementation of useWindowDimensions

I mentioned this:

image

And as you can see returned values do not match values returned by useSafeAreaInsets. Turns out they should match each other to make components like KeyboardAvoidingView to work properly.

So in this PR I'm excluding the marginTop to match useSafeAreaInsets behavior.

Closes #833

Reproduction code:

import React from 'react';
import {
  Button,
  StyleSheet,
  TextInput,
  View,
} from 'react-native';
import { KeyboardAvoidingView, KeyboardProvider } from 'react-native-keyboard-controller';
import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context';


function Example (): React.JSX.Element {
  return (
    <SafeAreaView
      edges={['bottom', 'left', 'right', 'top']}
      style={styles.safeContainer}>
      <KeyboardAvoidingView
        behavior="height"
        keyboardVerticalOffset={0}
        style={styles.content}>
        <View style={styles.inner}>
          <TextInput placeholder="Name" style={styles.textInput}  />
          <Button title="Submit" />
        </View>
      </KeyboardAvoidingView>
    </SafeAreaView>
  );
}


function App(): React.JSX.Element {
  return (
    <SafeAreaProvider>
      <KeyboardProvider>
        <Example />
      </KeyboardProvider>
    </SafeAreaProvider>
  );
}

const styles = StyleSheet.create({
  safeAreaView: {
    flex: 1,
  },
  safeContainer: {
    flex: 1,
  },
  content: {
    flex:1,
  },
  container: {
    flex: 1,
  },
  inner: {
    flex: 1,
    justifyContent: 'space-between',
  },
  textInput: {
    borderWidth: 1,
    borderColor: 'red',
  },
});

export default App;

📢 Changelog

Android

  • exclude marginTop from useWindowDimensions;

🤔 How Has This Been Tested?

Tested on Pixel 7 Pro with Android 15.

📸 Screenshots (if appropriate):

statusBarTranslucent={false}

Before (buggy) After
telegram-cloud-document-2-5330396151998868945.mp4
telegram-cloud-document-2-5330396151998868977.mp4

statusBarTranslucent={true}

Before After
telegram-cloud-document-2-5330396151998868968.mp4
telegram-cloud-document-2-5330396151998868974.mp4

📝 Checklist

  • CI successfully passed
  • I added new mocks and corresponding unit-tests if library API was changed

@kirillzyusko kirillzyusko added 🐛 bug Something isn't working 🤖 android Android specific labels Feb 26, 2025
@kirillzyusko kirillzyusko self-assigned this Feb 26, 2025
Copy link
Contributor

github-actions bot commented Feb 26, 2025

📊 Package size report

Current size Target Size Difference
169831 bytes 169847 bytes -16 bytes 📉

@kirillzyusko kirillzyusko marked this pull request as ready for review February 27, 2025 10:24
@kirillzyusko kirillzyusko merged commit 1714227 into main Feb 27, 2025
16 checks passed
@kirillzyusko kirillzyusko deleted the fix/status-bar-translucent-use-window-dimensions branch February 27, 2025 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖 android Android specific 🐛 bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KeyboardAvoidingView doesn't work with space-between
1 participant