Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit dd1dc72

Browse files
authored
Always set orientation preferences on iOS 16+ (#38230)
1 parent 9872cc7 commit dd1dc72

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

shell/platform/darwin/ios/framework/Source/FlutterViewController.mm

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,21 +1544,17 @@ - (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences {
15441544
continue;
15451545
}
15461546
UIWindowScene* windowScene = (UIWindowScene*)scene;
1547-
UIInterfaceOrientationMask currentInterfaceOrientation =
1548-
1 << windowScene.interfaceOrientation;
1549-
if (!(_orientationPreferences & currentInterfaceOrientation)) {
1550-
[self setNeedsUpdateOfSupportedInterfaceOrientations];
1551-
UIWindowSceneGeometryPreferencesIOS* preference =
1552-
[[UIWindowSceneGeometryPreferencesIOS alloc]
1553-
initWithInterfaceOrientations:_orientationPreferences];
1554-
[windowScene
1555-
requestGeometryUpdateWithPreferences:preference
1556-
errorHandler:^(NSError* error) {
1557-
os_log_error(OS_LOG_DEFAULT,
1558-
"Failed to change device orientation: %@",
1559-
error);
1560-
}];
1561-
}
1547+
UIWindowSceneGeometryPreferencesIOS* preference =
1548+
[[UIWindowSceneGeometryPreferencesIOS alloc]
1549+
initWithInterfaceOrientations:_orientationPreferences];
1550+
[windowScene
1551+
requestGeometryUpdateWithPreferences:preference
1552+
errorHandler:^(NSError* error) {
1553+
os_log_error(OS_LOG_DEFAULT,
1554+
"Failed to change device orientation: %@",
1555+
error);
1556+
}];
1557+
[self setNeedsUpdateOfSupportedInterfaceOrientations];
15621558
}
15631559
} else {
15641560
UIInterfaceOrientationMask currentInterfaceOrientation =

shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -891,13 +891,17 @@ - (void)orientationTestWithOrientationUpdate:(UIInterfaceOrientationMask)mask
891891
id mockApplication = OCMClassMock([UIApplication class]);
892892
id mockWindowScene;
893893
id deviceMock;
894+
FlutterViewController* realVC = [[FlutterViewController alloc] initWithEngine:self.mockEngine
895+
nibName:nil
896+
bundle:nil];
894897
if (@available(iOS 16.0, *)) {
895898
mockWindowScene = OCMClassMock([UIWindowScene class]);
896-
OCMStub([mockWindowScene interfaceOrientation]).andReturn(currentOrientation);
897-
if (!didChange) {
899+
if (realVC.supportedInterfaceOrientations == mask) {
898900
OCMReject([mockWindowScene requestGeometryUpdateWithPreferences:[OCMArg any]
899901
errorHandler:[OCMArg any]]);
900902
} else {
903+
// iOS 16 will decide whether to rotate based on the new preference, so always set it
904+
// when it changes.
901905
OCMExpect([mockWindowScene
902906
requestGeometryUpdateWithPreferences:[OCMArg checkWithBlock:^BOOL(
903907
UIWindowSceneGeometryPreferencesIOS*
@@ -919,9 +923,6 @@ - (void)orientationTestWithOrientationUpdate:(UIInterfaceOrientationMask)mask
919923
OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
920924
OCMStub([mockApplication statusBarOrientation]).andReturn(currentOrientation);
921925
}
922-
FlutterViewController* realVC = [[FlutterViewController alloc] initWithEngine:self.mockEngine
923-
nibName:nil
924-
bundle:nil];
925926

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

0 commit comments

Comments
 (0)