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

Commit 32d2d93

Browse files
author
Casey Hillers
authored
Revert "Use iOS 16 APIs to rotate orientation (#36874)" (#37165)
1 parent f91119f commit 32d2d93

File tree

2 files changed

+29
-80
lines changed

2 files changed

+29
-80
lines changed

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

+20-46
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
88

9-
#import <os/log.h>
109
#include <memory>
1110

1211
#include "flutter/fml/memory/weak_ptr.h"
@@ -1537,51 +1536,26 @@ - (void)onOrientationPreferencesUpdated:(NSNotification*)notification {
15371536
- (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences {
15381537
if (new_preferences != _orientationPreferences) {
15391538
_orientationPreferences = new_preferences;
1540-
1541-
if (@available(iOS 16.0, *)) {
1542-
for (UIScene* scene in UIApplication.sharedApplication.connectedScenes) {
1543-
if (![scene isKindOfClass:[UIWindowScene class]]) {
1544-
continue;
1545-
}
1546-
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] autorelease];
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-
}
1562-
}
1563-
} else {
1564-
UIInterfaceOrientationMask currentInterfaceOrientation =
1565-
1 << [[UIApplication sharedApplication] statusBarOrientation];
1566-
if (!(_orientationPreferences & currentInterfaceOrientation)) {
1567-
[UIViewController attemptRotationToDeviceOrientation];
1568-
// Force orientation switch if the current orientation is not allowed
1569-
if (_orientationPreferences & UIInterfaceOrientationMaskPortrait) {
1570-
// This is no official API but more like a workaround / hack (using
1571-
// key-value coding on a read-only property). This might break in
1572-
// the future, but currently it´s the only way to force an orientation change
1573-
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait)
1574-
forKey:@"orientation"];
1575-
} else if (_orientationPreferences & UIInterfaceOrientationMaskPortraitUpsideDown) {
1576-
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortraitUpsideDown)
1577-
forKey:@"orientation"];
1578-
} else if (_orientationPreferences & UIInterfaceOrientationMaskLandscapeLeft) {
1579-
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeLeft)
1580-
forKey:@"orientation"];
1581-
} else if (_orientationPreferences & UIInterfaceOrientationMaskLandscapeRight) {
1582-
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeRight)
1583-
forKey:@"orientation"];
1584-
}
1539+
[UIViewController attemptRotationToDeviceOrientation];
1540+
1541+
UIInterfaceOrientationMask currentInterfaceOrientation =
1542+
1 << [[UIApplication sharedApplication] statusBarOrientation];
1543+
if (!(_orientationPreferences & currentInterfaceOrientation)) {
1544+
// Force orientation switch if the current orientation is not allowed
1545+
if (_orientationPreferences & UIInterfaceOrientationMaskPortrait) {
1546+
// This is no official API but more like a workaround / hack (using
1547+
// key-value coding on a read-only property). This might break in
1548+
// the future, but currently it´s the only way to force an orientation change
1549+
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait) forKey:@"orientation"];
1550+
} else if (_orientationPreferences & UIInterfaceOrientationMaskPortraitUpsideDown) {
1551+
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortraitUpsideDown)
1552+
forKey:@"orientation"];
1553+
} else if (_orientationPreferences & UIInterfaceOrientationMaskLandscapeLeft) {
1554+
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeLeft)
1555+
forKey:@"orientation"];
1556+
} else if (_orientationPreferences & UIInterfaceOrientationMaskLandscapeRight) {
1557+
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeRight)
1558+
forKey:@"orientation"];
15851559
}
15861560
}
15871561
}

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

+9-34
Original file line numberDiff line numberDiff line change
@@ -888,47 +888,22 @@ - (void)orientationTestWithOrientationUpdate:(UIInterfaceOrientationMask)mask
888888
currentOrientation:(UIInterfaceOrientation)currentOrientation
889889
didChangeOrientation:(BOOL)didChange
890890
resultingOrientation:(UIInterfaceOrientation)resultingOrientation {
891-
id mockApplication = OCMClassMock([UIApplication class]);
892-
id mockWindowScene;
893-
id deviceMock;
894-
if (@available(iOS 16.0, *)) {
895-
mockWindowScene = OCMClassMock([UIWindowScene class]);
896-
OCMStub([mockWindowScene interfaceOrientation]).andReturn(currentOrientation);
897-
if (!didChange) {
898-
OCMReject([mockWindowScene requestGeometryUpdateWithPreferences:[OCMArg any]
899-
errorHandler:[OCMArg any]]);
900-
} else {
901-
OCMExpect([mockWindowScene
902-
requestGeometryUpdateWithPreferences:[OCMArg checkWithBlock:^BOOL(
903-
UIWindowSceneGeometryPreferencesIOS*
904-
preferences) {
905-
return preferences.interfaceOrientations == mask;
906-
}]
907-
errorHandler:[OCMArg any]]);
908-
}
909-
OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
910-
OCMStub([mockApplication connectedScenes]).andReturn([NSSet setWithObject:mockWindowScene]);
891+
id deviceMock = OCMPartialMock([UIDevice currentDevice]);
892+
if (!didChange) {
893+
OCMReject([deviceMock setValue:[OCMArg any] forKey:@"orientation"]);
911894
} else {
912-
deviceMock = OCMPartialMock([UIDevice currentDevice]);
913-
if (!didChange) {
914-
OCMReject([deviceMock setValue:[OCMArg any] forKey:@"orientation"]);
915-
} else {
916-
OCMExpect([deviceMock setValue:@(resultingOrientation) forKey:@"orientation"]);
917-
}
918-
919-
OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
920-
OCMStub([mockApplication statusBarOrientation]).andReturn(currentOrientation);
895+
OCMExpect([deviceMock setValue:@(resultingOrientation) forKey:@"orientation"]);
921896
}
897+
922898
FlutterViewController* realVC = [[FlutterViewController alloc] initWithEngine:self.mockEngine
923899
nibName:nil
924900
bundle:nil];
901+
id mockApplication = OCMClassMock([UIApplication class]);
902+
OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
903+
OCMStub([mockApplication statusBarOrientation]).andReturn(currentOrientation);
925904

926905
[realVC performOrientationUpdate:mask];
927-
if (@available(iOS 16.0, *)) {
928-
OCMVerifyAll(mockWindowScene);
929-
} else {
930-
OCMVerifyAll(deviceMock);
931-
}
906+
OCMVerifyAll(deviceMock);
932907
[deviceMock stopMocking];
933908
[mockApplication stopMocking];
934909
}

0 commit comments

Comments
 (0)