Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Simon Lightfoot <simon@devangels.london>
Dwayne Slater <ds84182@gmail.com>
Tetsuhiro Ueda <najeira@gmail.com>
shoryukenn <naifu.guan@gmail.com>
SOTEC GmbH & Co. KG <sotec-contributors@sotec.eu>
Original file line number Diff line number Diff line change
Expand Up @@ -815,14 +815,33 @@ - (void)onOrientationPreferencesUpdated:(NSNotification*)notification {
if (update == nil) {
return;
}
[self performOrientationUpdate:update.unsignedIntegerValue];
});
}

NSUInteger new_preferences = update.unsignedIntegerValue;

if (new_preferences != _orientationPreferences) {
_orientationPreferences = new_preferences;
[UIViewController attemptRotationToDeviceOrientation];
- (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences {
if (new_preferences != _orientationPreferences) {
_orientationPreferences = new_preferences;
[UIViewController attemptRotationToDeviceOrientation];

UIInterfaceOrientationMask currentInterfaceOrientation =
1 << [[UIApplication sharedApplication] statusBarOrientation];
if (!(_orientationPreferences & currentInterfaceOrientation)) {
// Force orientation switch if the current orientation is not allowed
if (_orientationPreferences & UIInterfaceOrientationMaskPortrait) {
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait) forKey:@"orientation"];
Comment thread
josh-ksr marked this conversation as resolved.
} else if (_orientationPreferences & UIInterfaceOrientationMaskPortraitUpsideDown) {
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortraitUpsideDown)
forKey:@"orientation"];
} else if (_orientationPreferences & UIInterfaceOrientationMaskLandscapeLeft) {
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeLeft)
forKey:@"orientation"];
} else if (_orientationPreferences & UIInterfaceOrientationMaskLandscapeRight) {
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeRight)
forKey:@"orientation"];
}
}
});
}
}

- (BOOL)shouldAutorotate {
Expand Down
175 changes: 175 additions & 0 deletions shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ - (UIAccessibilityContrast)accessibilityContrast;
@end
#endif

@interface FlutterViewController (Tests)
- (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences;
@end

@implementation FlutterViewControllerTest

- (void)testBinaryMessenger {
Expand Down Expand Up @@ -236,6 +240,177 @@ - (void)testItReportsHighContrastWhenTraitCollectionRequestsIt {
[mockTraitCollection stopMocking];
}

- (void)testPerformOrientationUpdateForcesOrientationChange {
[self orientationTestWithMask:UIInterfaceOrientationMaskPortrait
current:UIInterfaceOrientationLandscapeLeft
force:YES
to:UIInterfaceOrientationPortrait];

[self orientationTestWithMask:UIInterfaceOrientationMaskPortrait
current:UIInterfaceOrientationLandscapeRight
force:YES
to:UIInterfaceOrientationPortrait];

[self orientationTestWithMask:UIInterfaceOrientationMaskPortrait
current:UIInterfaceOrientationPortraitUpsideDown
force:YES
to:UIInterfaceOrientationPortrait];

[self orientationTestWithMask:UIInterfaceOrientationMaskPortraitUpsideDown
current:UIInterfaceOrientationLandscapeLeft
force:YES
to:UIInterfaceOrientationPortraitUpsideDown];

[self orientationTestWithMask:UIInterfaceOrientationMaskPortraitUpsideDown
current:UIInterfaceOrientationLandscapeRight
force:YES
to:UIInterfaceOrientationPortraitUpsideDown];

[self orientationTestWithMask:UIInterfaceOrientationMaskPortraitUpsideDown
current:UIInterfaceOrientationPortrait
force:YES
to:UIInterfaceOrientationPortraitUpsideDown];

[self orientationTestWithMask:UIInterfaceOrientationMaskLandscape
current:UIInterfaceOrientationPortrait
force:YES
to:UIInterfaceOrientationLandscapeLeft];

[self orientationTestWithMask:UIInterfaceOrientationMaskLandscape
current:UIInterfaceOrientationPortraitUpsideDown
force:YES
to:UIInterfaceOrientationLandscapeLeft];

[self orientationTestWithMask:UIInterfaceOrientationMaskLandscapeLeft
current:UIInterfaceOrientationPortrait
force:YES
to:UIInterfaceOrientationLandscapeLeft];

[self orientationTestWithMask:UIInterfaceOrientationMaskLandscapeLeft
current:UIInterfaceOrientationLandscapeRight
force:YES
to:UIInterfaceOrientationLandscapeLeft];

[self orientationTestWithMask:UIInterfaceOrientationMaskLandscapeLeft
current:UIInterfaceOrientationPortraitUpsideDown
force:YES
to:UIInterfaceOrientationLandscapeLeft];

[self orientationTestWithMask:UIInterfaceOrientationMaskLandscapeRight
current:UIInterfaceOrientationPortrait
force:YES
to:UIInterfaceOrientationLandscapeRight];

[self orientationTestWithMask:UIInterfaceOrientationMaskLandscapeRight
current:UIInterfaceOrientationLandscapeLeft
force:YES
to:UIInterfaceOrientationLandscapeRight];

[self orientationTestWithMask:UIInterfaceOrientationMaskLandscapeRight
current:UIInterfaceOrientationPortraitUpsideDown
force:YES
to:UIInterfaceOrientationLandscapeRight];

[self orientationTestWithMask:UIInterfaceOrientationMaskAllButUpsideDown
current:UIInterfaceOrientationPortraitUpsideDown
force:YES
to:UIInterfaceOrientationPortrait];
}

- (void)testPerformOrientationUpdateDoesNotForceOrientationChange {
[self orientationTestWithMask:UIInterfaceOrientationMaskAll
current:UIInterfaceOrientationPortrait
force:NO
to:0];

[self orientationTestWithMask:UIInterfaceOrientationMaskAll
current:UIInterfaceOrientationPortraitUpsideDown
force:NO
to:0];

[self orientationTestWithMask:UIInterfaceOrientationMaskAll
current:UIInterfaceOrientationLandscapeLeft
force:NO
to:0];

[self orientationTestWithMask:UIInterfaceOrientationMaskAll
current:UIInterfaceOrientationLandscapeRight
force:NO
to:0];

[self orientationTestWithMask:UIInterfaceOrientationMaskAllButUpsideDown
current:UIInterfaceOrientationPortrait
force:NO
to:0];

[self orientationTestWithMask:UIInterfaceOrientationMaskAllButUpsideDown
current:UIInterfaceOrientationLandscapeLeft
force:NO
to:0];

[self orientationTestWithMask:UIInterfaceOrientationMaskAllButUpsideDown
current:UIInterfaceOrientationLandscapeRight
force:NO
to:0];

[self orientationTestWithMask:UIInterfaceOrientationMaskPortrait
current:UIInterfaceOrientationPortrait
force:NO
to:0];

[self orientationTestWithMask:UIInterfaceOrientationMaskPortraitUpsideDown
current:UIInterfaceOrientationPortraitUpsideDown
force:NO
to:0];

[self orientationTestWithMask:UIInterfaceOrientationMaskLandscape
current:UIInterfaceOrientationLandscapeLeft
force:NO
to:0];

[self orientationTestWithMask:UIInterfaceOrientationMaskLandscape
current:UIInterfaceOrientationLandscapeRight
force:NO
to:0];

[self orientationTestWithMask:UIInterfaceOrientationMaskLandscapeLeft
current:UIInterfaceOrientationLandscapeLeft
force:NO
to:0];

[self orientationTestWithMask:UIInterfaceOrientationMaskLandscapeRight
current:UIInterfaceOrientationLandscapeRight
force:NO
to:0];
}

- (void)orientationTestWithMask:(UIInterfaceOrientationMask)mask
Comment thread
josh-ksr marked this conversation as resolved.
Outdated
current:(UIInterfaceOrientation)currentOrientation
force:(BOOL)forceChange
to:(UIInterfaceOrientation)forcedOrientation {
id engine = OCMClassMock([FlutterEngine class]);

id deviceMock = OCMPartialMock([UIDevice currentDevice]);
if (!forceChange) {
OCMReject([deviceMock setValue:[OCMArg any] forKey:@"orientation"]);
} else {
OCMExpect([deviceMock setValue:@(forcedOrientation) forKey:@"orientation"]);
}

FlutterViewController* realVC = [[FlutterViewController alloc] initWithEngine:engine
nibName:nil
bundle:nil];
id mockApplication = OCMClassMock([UIApplication class]);
OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
OCMStub([mockApplication statusBarOrientation]).andReturn(currentOrientation);

[realVC performOrientationUpdate:mask];
OCMVerifyAll(deviceMock);
[engine stopMocking];
[deviceMock stopMocking];
[mockApplication stopMocking];
}

// Creates a mocked UITraitCollection with nil values for everything except accessibilityContrast,
// which is set to the given "contrast".
- (UITraitCollection*)fakeTraitCollectionWithContrast:(UIAccessibilityContrast)contrast {
Expand Down