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

Calculate Correct Window Dimensions for iOS #19932

Closed
wants to merge 3 commits into from

Conversation

rdonnelly
Copy link
Contributor

@rdonnelly rdonnelly commented Jun 27, 2018

Fixes: #16152

Changelog:

[iOS] [Fixed] - Pass back correct dimensions for application window in Dimensions module

Test Plan:

Before:
On iOS, when using Dimensions.get() for either screen or window, the same value for width and height would be passed back for both screen and window. These values both represent the width and height of the whole screen regardless of the size of the window.

This behavior was similar for listening to the Dimension change event. The even would fire for orientation changes, but would not fire for changes to the window size (e.g. split view app resizing).

After:
On iOS, when the Dimensions module passes back dimensions for the screen, it uses the full screen dimensions. For window, it now uses just the dimensions of the window. This goes back to Objective C and uses RCTKeyWindow.

For event handling, the code watches for the application to become active (UIApplicationDidBecomeActiveNotification) and then recalculates the window dimensions, compares it to the previous dimensions, and sends a change event if there was a change.

For testing, I threw together a project. I pointed it to a branch on my forked version of react-native.
https://github.com/rdonnelly/WindowVsScreenRN

Please feel free to let me know if anything needs re-working.

@rdonnelly rdonnelly requested a review from shergin as a code owner June 27, 2018 18:49
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 27, 2018
@janicduplessis
Copy link
Contributor

Hey @rdonnelly, I opened a similar PR yesterday (#19919) to fix Dimensions when the in-call status bar is active. I didn't think about split view so this is still useful. I'll see if I can get my PR reviewed soon and then you could rebase this on top of it.

@rdonnelly
Copy link
Contributor Author

@janicduplessis Sounds wonderful! I subscribed your PR, so I'll keep an eye out.

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[_bridge.eventDispatcher sendDeviceEventWithName:@"didUpdateDimensions"
body:RCTExportedDimensions(_bridge)];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to not call RCTExportedDimensions two times, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point, I'll update. Thanks!

@hackrmomo
Copy link

Any updates on when this is being merged? I'm working on an app right now that's due on the App Store by Tuesday and instead of doing something terribly messy, I'd like to just update my RN version to use this.

@hramos
Copy link
Contributor

hramos commented Jul 26, 2018

@RoyalKingMomo even if this were to be merged today, it would not make a stable release for at least another month. In your case, you can patch this change into your own fork and manually cut a release.

@facebook-github-bot

This comment has been minimized.

@rdonnelly
Copy link
Contributor Author

@shergin any chance you have time to review this? Or know who might have the time/expertise on this? Any help would be greatly appreciated! 😃

When the app becomes active, check to see if the window size has changed. If so, send a device event with update dimensions.
@rdonnelly
Copy link
Contributor Author

Apologies to those that I tagged for review yesterday. I was attempting to fix the failing checks, and at one point added some commits that auto-requested reviews.

@djw27
Copy link

djw27 commented Nov 6, 2018

Any progress with this getting reviewed? We've got a workaround running but would be nice not to have to rely on it!

@gaodeng
Copy link
Contributor

gaodeng commented Dec 4, 2018

any news no this?

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hramos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@rdonnelly
Copy link
Contributor Author

@hramos Saw you imported this PR, not sure what that means for the process, but please let me know if there’s anything I can do to help. It’s been a while since I’ve looked at this.

@rickhanlonii
Copy link
Member

@rdonnelly looks like this failed to build internally, we'll need to make an update to land

@rdonnelly
Copy link
Contributor Author

@rickhanlonii Is that anything I can do or help with? Do I just need to pull/rebase with master? Thanks!

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @rdonnelly in 33b55cc.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Apr 10, 2019
dsyang pushed a commit to dsyang/react-native that referenced this pull request Apr 12, 2019
Summary:
Fixes: facebook#16152

[iOS] [Fixed] - Pass back correct dimensions for application window in Dimensions module
Pull Request resolved: facebook#19932

Reviewed By: cpojer

Differential Revision: D14312906

Pulled By: PeteTheHeat

fbshipit-source-id: aacb729c89862267465eefc3534c48d9d4b5d746
grabbou pushed a commit that referenced this pull request Apr 17, 2019
Summary:
Fixes: #16152

[iOS] [Fixed] - Pass back correct dimensions for application window in Dimensions module
Pull Request resolved: #19932

Reviewed By: cpojer

Differential Revision: D14312906

Pulled By: PeteTheHeat

fbshipit-source-id: aacb729c89862267465eefc3534c48d9d4b5d746
@danjus10
Copy link

Hi, not sure if the PR above is meant to be a breaking change but I've posted an Issue on React Navigation repo - https://github.com/react-navigation/react-navigation/issues/6120 that is related to this change, specifically the dims being passed back as window appear to be different to those when used on initial render.

Sorry - Not sure on history of the change so can't be sure which repo needs to be changed. But wanted to let you know about downstream impact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Platform: iOS iOS applications.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dimensions window support for Split View and Slide Over on iPad