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.

Invalid negative/zero values returned by Dimensions API under iOS 15

See original GitHub issue

Description

Several of our users are reporting problems that we’ve found to be attributable to Dimensions.get(‘window’) erroneously returning 0 for width.

Version

0.63.4

Output of npx react-native info

info Fetching system and libraries information… System: OS: macOS 12.1 CPU: (16) x64 Intel® Core™ i9-9880H CPU @ 2.30GHz Memory: 1.89 GB / 32.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node Yarn: 1.17.3 - ~/qgenda.mobile/node_modules/.bin/yarn npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm Watchman: 2021.11.01.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.2 - /Users/beauwilkinson/.rbenv/shims/pod SDKs: iOS SDK: Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3 Android SDK: Not Found IDEs: Android Studio: 2020.3 AI-203.7717.56.2031.7678000 Xcode: 13.2/13C5066c - /usr/bin/xcodebuild Languages: Java: 1.8.0_301 - /usr/bin/javac Python: 2.7.18 - /usr/bin/python npmPackages: @react-native-community/cli: Not Found react: 16.13.1 => 16.14.0 react-native: 0.63.4 => 0.62.3 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

Call Dimensions.get(‘window’).width on an iPhone 13 Pro Max (iPhone14,3) running iOS 15. The value obtained will be 0.

Snack, code example, screenshot, or link to a repository

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

1reaction
adamivanczacommented, Feb 18, 2022

I’m facing the same issue on 0.62.3 and I think I found out why is that happening. This is the piece of the relevant code that figures out screen size on 0.62.3: https://github.com/facebook/react-native/blob/83425fa72f1f9a12f6b6deefd66fa8bd154a3651/React/UIUtils/RCTUIUtils.m#L19 And this was changed on a later version to: https://github.com/facebook/react-native/blob/8bd3edec88148d0ab1f225d2119435681fbbba33/React/UIUtils/RCTUIUtils.m#L20 as part of this commit: https://github.com/facebook/react-native/commit/e85372298109abf258d5154e2a28bc6496fb9529

so after I moved this changed to 0.62.3 this issue was resolved for me. Here is a patch file which you can run to fix this:

diff --git a/node_modules/react-native/React/UIUtils/RCTUIUtils.m b/node_modules/react-native/React/UIUtils/RCTUIUtils.m
index 64b97bf..d729310 100644
--- a/node_modules/react-native/React/UIUtils/RCTUIUtils.m
+++ b/node_modules/react-native/React/UIUtils/RCTUIUtils.m
@@ -16,7 +16,7 @@ RCTDimensions RCTGetDimensions(CGFloat fontScale)
 
   UIView *mainWindow;
   mainWindow = RCTKeyWindow();
-  CGSize windowSize = mainWindow.bounds.size;
+  CGSize windowSize = mainWindow ? mainWindow.bounds.size : screenSize;
 
   RCTDimensions result;
   typeof (result.screen) dimsScreen = {
0reactions
github-actions[bot]commented, Oct 28, 2022

This issue was closed because it has been stalled for 7 days with no activity.

Read more comments on GitHub >

github_iconTop Results From Across the Web

negative or zero sizes are not supported in the flow layout
I noticed if I just return a float value e.g. 500, in my UICollectionView sizeForItemAtIndexPath: method, it doesn't crash. My collection view ...
Read more >
TN3107: Resolving Sign in with Apple response errors
Diagnose errors received by the Sign in with Apple client, or its server infrastructure, by identifying the underlying causes of common ...
Read more >
API - ESBuild
This API call is used by the command-line interface if no input files are provided and the --bundle flag is not present. In...
Read more >
LLVM Language Reference Manual
This doesn't apply for values returned in callee-saved registers. ... Prior to LLVM 15, pointer types also specified a pointee type, such as...
Read more >
CSS Values and Units Module Level 4 - W3C
For example, the value 1em2em would be parsed as a single <dimension-token> with the number 1 and the identifier em2em, which is an...
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