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

Always set orientation preferences on iOS 16+ #38230

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
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
26 changes: 11 additions & 15 deletions shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1544,21 +1544,17 @@ - (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences {
continue;
}
UIWindowScene* windowScene = (UIWindowScene*)scene;
UIInterfaceOrientationMask currentInterfaceOrientation =
1 << windowScene.interfaceOrientation;
if (!(_orientationPreferences & currentInterfaceOrientation)) {
Comment on lines -1547 to -1549
Copy link
Member Author

Choose a reason for hiding this comment

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

These are the lines that were removed. Always set -requestGeometryUpdateWithPreferences: if the preference mask changes since the OS should handle orientation based on those preferences.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmmm, will this fix the issue?

if (_orientationPreferences & currentInterfaceOrientation) // removed `!`

Copy link
Member Author

Choose a reason for hiding this comment

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

If the current preference is "portrait" and the current orientation is "portrait", and the preference is updated to "all orientations", then we always need to set the preference so as soon as the user rotates to landscape, it works. Likewise if the preference is "all orientations" and the current orientation is "portrait", and the preference is updated to "just portrait" then we also need to set it so that when the user tries to rotate to landscape it stays in portrait.

That's the bug this is fixing--it was only updating the preference based on the current orientation.

[self setNeedsUpdateOfSupportedInterfaceOrientations];
UIWindowSceneGeometryPreferencesIOS* preference =
[[UIWindowSceneGeometryPreferencesIOS alloc]
initWithInterfaceOrientations:_orientationPreferences];
[windowScene
requestGeometryUpdateWithPreferences:preference
errorHandler:^(NSError* error) {
os_log_error(OS_LOG_DEFAULT,
"Failed to change device orientation: %@",
error);
}];
}
UIWindowSceneGeometryPreferencesIOS* preference =
[[UIWindowSceneGeometryPreferencesIOS alloc]
initWithInterfaceOrientations:_orientationPreferences];
[windowScene
requestGeometryUpdateWithPreferences:preference
errorHandler:^(NSError* error) {
os_log_error(OS_LOG_DEFAULT,
"Failed to change device orientation: %@",
error);
}];
[self setNeedsUpdateOfSupportedInterfaceOrientations];
}
} else {
UIInterfaceOrientationMask currentInterfaceOrientation =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -891,13 +891,17 @@ - (void)orientationTestWithOrientationUpdate:(UIInterfaceOrientationMask)mask
id mockApplication = OCMClassMock([UIApplication class]);
id mockWindowScene;
id deviceMock;
FlutterViewController* realVC = [[FlutterViewController alloc] initWithEngine:self.mockEngine
nibName:nil
bundle:nil];
if (@available(iOS 16.0, *)) {
mockWindowScene = OCMClassMock([UIWindowScene class]);
OCMStub([mockWindowScene interfaceOrientation]).andReturn(currentOrientation);
if (!didChange) {
if (realVC.supportedInterfaceOrientations == mask) {
OCMReject([mockWindowScene requestGeometryUpdateWithPreferences:[OCMArg any]
errorHandler:[OCMArg any]]);
} else {
// iOS 16 will decide whether to rotate based on the new preference, so always set it
// when it changes.
OCMExpect([mockWindowScene
requestGeometryUpdateWithPreferences:[OCMArg checkWithBlock:^BOOL(
UIWindowSceneGeometryPreferencesIOS*
Expand All @@ -919,9 +923,6 @@ - (void)orientationTestWithOrientationUpdate:(UIInterfaceOrientationMask)mask
OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
OCMStub([mockApplication statusBarOrientation]).andReturn(currentOrientation);
}
FlutterViewController* realVC = [[FlutterViewController alloc] initWithEngine:self.mockEngine
nibName:nil
bundle:nil];

[realVC performOrientationUpdate:mask];
if (@available(iOS 16.0, *)) {
Expand Down