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

useWindowDimensions doesn't update when rotating the screen on an open alert #41375

Open
robrechtme opened this issue Nov 8, 2023 · 3 comments

Comments

@robrechtme
Copy link

Description

When rotating the screen on an open alert, the useWindowDimensions hook doesn't update.
Happens on both iOS and Android.

React Native Version

0.72.6

Output of npx react-native info

System:
  OS: macOS 14.0
  CPU: (10) arm64 Apple M1 Pro
  Memory: 110.34 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.18.0
    path: ~/.asdf/installs/nodejs/18.18.0/bin/node
  Yarn:
    version: 1.22.19
    path: ~/.asdf/shims/yarn
  npm:
    version: 9.8.1
    path: ~/.asdf/plugins/nodejs/shims/npm
  Watchman:
    version: 2023.09.25.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.2
    path: /Users/robrechtme/.asdf/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.0
      - iOS 17.0
      - macOS 14.0
      - tvOS 17.0
      - watchOS 10.0
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.3 AI-223.8836.35.2231.10406996
  Xcode:
    version: 15.0.1/15A507
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 18.0.2.1
    path: /Users/robrechtme/.asdf/shims/javac
  Ruby:
    version: 3.2.2
    path: /Users/robrechtme/.asdf/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.6
    wanted: 0.72.6
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Steps to reproduce

  1. Trigger an alert in portrait mode
  2. Rotate the screen to landscape during the alert
  3. Close the alert
    => The useWindowDimensions hook still returns portrait mode info

Snack, screenshot, or link to a repository

iphone.mp4

https://snack.expo.dev/@robrechtme/usewindowdimensions-bug

import { Text, SafeAreaView, StyleSheet, useWindowDimensions, Button, Alert } from 'react-native';

export default function App() {
  const { width, height } = useWindowDimensions();
  return (
    <SafeAreaView style={styles.container}>
      <Button title="trigger alert" onPress={() => Alert.alert('now rotate the screen before closing')} />
      <Text style={styles.paragraph}>
        Width: {width}
      </Text>
      <Text style={styles.paragraph}>
        Height: {height}
      </Text>
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    backgroundColor: '#ecf0f1',
    padding: 8,
  },
  paragraph: {
    margin: 24,
    fontSize: 18,
    fontWeight: 'bold',
    textAlign: 'center',
  },
});
@cortinico
Copy link
Contributor

Basically a duplicate of #37704

@galih9
Copy link

galih9 commented Mar 22, 2024

any update on this?

@katandtonic
Copy link

I'm experiencing the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants