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

Make a decision about the Dimensions module #291

Open
jsamr opened this issue Nov 12, 2020 · 5 comments
Open

Make a decision about the Dimensions module #291

jsamr opened this issue Nov 12, 2020 · 5 comments
Labels
🗣 Discussion This label identifies an ongoing discussion on a subject

Comments

@jsamr
Copy link

jsamr commented Nov 12, 2020

Introduction

A lot of React Native consumers rely on the screen and window dimensions to compute their layouts. Yet, after 5 years of React Native releases, this module is still unreliable. The frustration of users is palpable:

Details

The issue facebook/react-native#23693 has moreover been closed with a dubious rationale, "we've been provided with a hacky workaround, and you could use a third-party library, so I am going to close". For a lot of users, this attitude is infuriating, and makes them wonder what kind of dysfunctional human resources management at Facebook is ruling behind the scene.

Imagine a browser for which document.clientWidth and document.clientHeight behavior would depend on versions, platforms, etc... This is untenable for a project of this reach. Dimensions module is supposed to be a building block, it is expected to have an excellent test coverage, including on-device.

Discussion points

In my opinion, there are three ways to address the issue:

  • Put maximum efforts to make this module reliable, and commit publicly about it;
  • Deprecate the module, and recommend third-parties instead;
  • Deprecate React Native.

Don't get me wrong, React Native can be awesome. But I believe the community could be treated will a little more care, and I strongly recommend decision makers to take into account the image they project through their policies in Open Source communities.

@cristianoccazinsp
Copy link

Except a bug introduced with RN 0.63 that completely breaks the Dimensions API (which is fixed it seems facebook/react-native#29451), the API works fine most of the time.

I would like to address some of the issues here, rather than filing a new bug report for each separate problem (which can take months or will end up just ignored).

  • The StatusBar module does not update itself on orientation changes, so Android devices with variable status bar will eventually break.

  • Dimensions.get('window') returns unreliable values. First, it sometimes includes the height of the status bar, so any attempt to ge the actual available window height requires an extra call to StatusBar.currentHeight, which in turn breaks because of the above bug. Secondly, for devices with a notch/punch hole and/or variable status bars, Dimensions.get('window') will sometimes exclude the status bar height (e.g., Pixel 5 in portrait mode), and sometimes include it (same Pixel 5 but in landscape mode). I don't know for sure the source of these inconsistencies but they are quite game breaking.

Getting precise screen dimensions is sometimes a must for things like images, video, and camera layouts. The current flex-box engine is not enough for some cases, and the only available option is to do the layout ourselves using the dimensions API. Because of this, it is of uttermost importance for these primitives to work across all devices.

React native is great, requesting to deprecate it seems like too much, but looking at how each release introduces more bugs than improvements (that are at least useful), I would also recommend to at least get one major version of just bugfixes instead of new features.

@jsamr
Copy link
Author

jsamr commented Nov 13, 2020

@cristianoccazinsp Thank you for this summary. Just to add up to this, I believe this issue (facebook/react-native#27089) affecting Keyboard events measures is related to the notch inconsistency. Oh and deprecating React Native was intended as an absurd echo to "use a third party plz", it's a joke :-).

@kelset kelset added the 🗣 Discussion This label identifies an ongoing discussion on a subject label Nov 13, 2020
@elicwhite
Copy link

elicwhite commented Nov 13, 2020

Thanks for posting @jsamr, I appreciate how much care you have for React Native.

I agree that Dimensions is in a pretty sad state. There are other classes of problems we've seen with it that haven't been mentioned in your posts yet either. For example, if you have multiple root views it returns the dimensions of the first (I think) root view. That means that on desktop applications for Windows or macOS, if you have multiple windows Dimensions will only return the API for the first window, not the window it is being called from!

The issue facebook/react-native#23693 has moreover been closed with a dubious rationale, "we've been provided with a hacky workaround, and you could use a third-party library, so I am going to close". For a lot of users, this attitude is infuriating, and makes them wonder what kind of dysfunctional human resources management at Facebook is ruling behind the scene.

While it doesn't actually provide a resolution to the problem, it's worth noting that the team at Facebook agrees that a workaround is not a solution. While we are glad a workaround exists, this is still clearly a footgun that keeps people from falling into the pit of success with React Native for this use case. It's also worth noting that it wasn't closed by a Facebook employee. I'll reopen the issue because it is still a valid issue.

As we are a small team working on React Native, we have had to prioritize our attention. That attention has been spent on the major architecture projects like Fabric and TurboModules as these require the most specialized knowledge and we believe will have the biggest impact on the ecosystem.

Since we have been unable to prioritize improving these issues around Dimensions, the community has the opportunity to jump in. Either by sending PRs that improve the situation, or by contributing to a solution outside of core. We have merged PRs to Dimensions when they come up, like this one fixing the rotation issue 2 days ago.

One worry is that Dimensions has been broken for so long that apps may have hard coded workarounds such that fixes to the semantics to Dimensions would actually break their products. If that's the case, we may need a new API in core like useWindowDimensions, or one that considers other issues like multiple windows on desktop. The community should feel empowered to think about that problem space and make a proposal / send code before the React Native team itself is able to get around to prioritizing it.

@fabOnReact
Copy link

@cristianoccazinsp Thank you for this summary. Just to add up to this, I believe this issue (facebook/react-native#27089) affecting Keyboard events measures is related to the notch inconsistency. Oh and deprecating React Native was intended as an absurd echo to "use a third party plz", it's a joke :-).

I wrote pr facebook/react-native#30919 ☮️ 🙏 ❤️

@cristianoccazinsp
Copy link

Any ideas if facebook/react-native#29451 would also be fixed with this or other PRs included in the next release? We have been stuck with 0.62.2 for a while now due to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗣 Discussion This label identifies an ongoing discussion on a subject
Projects
None yet
Development

No branches or pull requests

5 participants