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 Orientation listener in bridgeless mode #43971

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/react-native/React/CoreModules/RCTDeviceInfo.mm
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ - (void)initialize
selector:@selector(interfaceFrameDidChange)
name:RCTWindowFrameDidChangeNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(interfaceFrameDidChange)

Choose a reason for hiding this comment

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

@cipolleschi Should that really be calling interfaceFrameDidChange and not interfaceOrientationDidChange instead? I'm currently investigating an issue on 0.74.1, where orientation changes are not propagated correctly by Dimensions and/or useWindowDimensions and the culprit seems to be that nothing updates the dimensions properly on orientation change.

Choose a reason for hiding this comment

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

Actually, after some more debugging - [self _exportedDimensions] is always returning the previous dimension prior the orientation change, so the portrait dimensions when switching to landscape and vice versa. Is this related when the UIDeviceOrientationDidChangeNotification event is triggered or related to when we gather the dimension data?

Copy link

@MegaMaddin MegaMaddin May 22, 2024

Choose a reason for hiding this comment

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

Maybe related: https://snippet.zone/2022/11/
As well as: https://forums.developer.apple.com/forums/thread/713072

TL;DR it seems that the update of the bounds is not immediate.

name:UIDeviceOrientationDidChangeNotification
object:nil];

// TODO T175901725 - Registering the RCTDeviceInfo module to the notification is a short-term fix to unblock 0.73
// The actual behavior should be that the module is properly registered in the TurboModule/Bridge infrastructure
Expand Down Expand Up @@ -113,6 +117,8 @@ - (void)_cleanupObservers
[[NSNotificationCenter defaultCenter] removeObserver:self name:RCTWindowFrameDidChangeNotification object:nil];

[[NSNotificationCenter defaultCenter] removeObserver:self name:RCTBridgeWillInvalidateModulesNotification object:nil];

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}

static BOOL RCTIsIPhoneNotched()
Expand Down
Loading