mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Revert "Issue 13238: on iOS, force an orientation change when the current orientation is not allowed" (flutter/engine#13160)
This reverts commit 0790110fd28dd9ff72140ce15d3f6f877e2095e8.
This commit is contained in:
parent
da2f9e2448
commit
f200ea0af9
@ -15,4 +15,3 @@ 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>
|
||||
@ -828,36 +828,14 @@ static flutter::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* touch)
|
||||
if (update == nil) {
|
||||
return;
|
||||
}
|
||||
[self performOrientationUpdate:update.unsignedIntegerValue];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences {
|
||||
if (new_preferences != _orientationPreferences) {
|
||||
_orientationPreferences = new_preferences;
|
||||
[UIViewController attemptRotationToDeviceOrientation];
|
||||
NSUInteger new_preferences = update.unsignedIntegerValue;
|
||||
|
||||
UIInterfaceOrientationMask currentInterfaceOrientation =
|
||||
1 << [[UIApplication sharedApplication] statusBarOrientation];
|
||||
if (!(_orientationPreferences & currentInterfaceOrientation)) {
|
||||
// Force orientation switch if the current orientation is not allowed
|
||||
if (_orientationPreferences & UIInterfaceOrientationMaskPortrait) {
|
||||
// This is no official API but more like a workaround / hack (using
|
||||
// key-value coding on a read-only property). This might break in
|
||||
// the future, but currently it´s the only way to force an orientation change
|
||||
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait) forKey:@"orientation"];
|
||||
} 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"];
|
||||
}
|
||||
if (new_preferences != _orientationPreferences) {
|
||||
_orientationPreferences = new_preferences;
|
||||
[UIViewController attemptRotationToDeviceOrientation];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (BOOL)shouldAutorotate {
|
||||
|
||||
@ -45,10 +45,6 @@ typedef enum UIAccessibilityContrast : NSInteger {
|
||||
@end
|
||||
#endif
|
||||
|
||||
@interface FlutterViewController (Tests)
|
||||
- (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences;
|
||||
@end
|
||||
|
||||
@implementation FlutterViewControllerTest
|
||||
|
||||
- (void)testBinaryMessenger {
|
||||
@ -256,179 +252,6 @@ typedef enum UIAccessibilityContrast : NSInteger {
|
||||
[mockTraitCollection stopMocking];
|
||||
}
|
||||
|
||||
- (void)testPerformOrientationUpdateForcesOrientationChange {
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortrait
|
||||
currentOrientation:UIInterfaceOrientationLandscapeLeft
|
||||
didChangeOrientation:YES
|
||||
resultingOrientation:UIInterfaceOrientationPortrait];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortrait
|
||||
currentOrientation:UIInterfaceOrientationLandscapeRight
|
||||
didChangeOrientation:YES
|
||||
resultingOrientation:UIInterfaceOrientationPortrait];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortrait
|
||||
currentOrientation:UIInterfaceOrientationPortraitUpsideDown
|
||||
didChangeOrientation:YES
|
||||
resultingOrientation:UIInterfaceOrientationPortrait];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortraitUpsideDown
|
||||
currentOrientation:UIInterfaceOrientationLandscapeLeft
|
||||
didChangeOrientation:YES
|
||||
resultingOrientation:UIInterfaceOrientationPortraitUpsideDown];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortraitUpsideDown
|
||||
currentOrientation:UIInterfaceOrientationLandscapeRight
|
||||
didChangeOrientation:YES
|
||||
resultingOrientation:UIInterfaceOrientationPortraitUpsideDown];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortraitUpsideDown
|
||||
currentOrientation:UIInterfaceOrientationPortrait
|
||||
didChangeOrientation:YES
|
||||
resultingOrientation:UIInterfaceOrientationPortraitUpsideDown];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscape
|
||||
currentOrientation:UIInterfaceOrientationPortrait
|
||||
didChangeOrientation:YES
|
||||
resultingOrientation:UIInterfaceOrientationLandscapeLeft];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscape
|
||||
currentOrientation:UIInterfaceOrientationPortraitUpsideDown
|
||||
didChangeOrientation:YES
|
||||
resultingOrientation:UIInterfaceOrientationLandscapeLeft];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeLeft
|
||||
currentOrientation:UIInterfaceOrientationPortrait
|
||||
didChangeOrientation:YES
|
||||
resultingOrientation:UIInterfaceOrientationLandscapeLeft];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeLeft
|
||||
currentOrientation:UIInterfaceOrientationLandscapeRight
|
||||
didChangeOrientation:YES
|
||||
resultingOrientation:UIInterfaceOrientationLandscapeLeft];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeLeft
|
||||
currentOrientation:UIInterfaceOrientationPortraitUpsideDown
|
||||
didChangeOrientation:YES
|
||||
resultingOrientation:UIInterfaceOrientationLandscapeLeft];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeRight
|
||||
currentOrientation:UIInterfaceOrientationPortrait
|
||||
didChangeOrientation:YES
|
||||
resultingOrientation:UIInterfaceOrientationLandscapeRight];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeRight
|
||||
currentOrientation:UIInterfaceOrientationLandscapeLeft
|
||||
didChangeOrientation:YES
|
||||
resultingOrientation:UIInterfaceOrientationLandscapeRight];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeRight
|
||||
currentOrientation:UIInterfaceOrientationPortraitUpsideDown
|
||||
didChangeOrientation:YES
|
||||
resultingOrientation:UIInterfaceOrientationLandscapeRight];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAllButUpsideDown
|
||||
currentOrientation:UIInterfaceOrientationPortraitUpsideDown
|
||||
didChangeOrientation:YES
|
||||
resultingOrientation:UIInterfaceOrientationPortrait];
|
||||
}
|
||||
|
||||
- (void)testPerformOrientationUpdateDoesNotForceOrientationChange {
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAll
|
||||
currentOrientation:UIInterfaceOrientationPortrait
|
||||
didChangeOrientation:NO
|
||||
resultingOrientation:0];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAll
|
||||
currentOrientation:UIInterfaceOrientationPortraitUpsideDown
|
||||
didChangeOrientation:NO
|
||||
resultingOrientation:0];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAll
|
||||
currentOrientation:UIInterfaceOrientationLandscapeLeft
|
||||
didChangeOrientation:NO
|
||||
resultingOrientation:0];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAll
|
||||
currentOrientation:UIInterfaceOrientationLandscapeRight
|
||||
didChangeOrientation:NO
|
||||
resultingOrientation:0];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAllButUpsideDown
|
||||
currentOrientation:UIInterfaceOrientationPortrait
|
||||
didChangeOrientation:NO
|
||||
resultingOrientation:0];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAllButUpsideDown
|
||||
currentOrientation:UIInterfaceOrientationLandscapeLeft
|
||||
didChangeOrientation:NO
|
||||
resultingOrientation:0];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAllButUpsideDown
|
||||
currentOrientation:UIInterfaceOrientationLandscapeRight
|
||||
didChangeOrientation:NO
|
||||
resultingOrientation:0];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortrait
|
||||
currentOrientation:UIInterfaceOrientationPortrait
|
||||
didChangeOrientation:NO
|
||||
resultingOrientation:0];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortraitUpsideDown
|
||||
currentOrientation:UIInterfaceOrientationPortraitUpsideDown
|
||||
didChangeOrientation:NO
|
||||
resultingOrientation:0];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscape
|
||||
currentOrientation:UIInterfaceOrientationLandscapeLeft
|
||||
didChangeOrientation:NO
|
||||
resultingOrientation:0];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscape
|
||||
currentOrientation:UIInterfaceOrientationLandscapeRight
|
||||
didChangeOrientation:NO
|
||||
resultingOrientation:0];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeLeft
|
||||
currentOrientation:UIInterfaceOrientationLandscapeLeft
|
||||
didChangeOrientation:NO
|
||||
resultingOrientation:0];
|
||||
|
||||
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeRight
|
||||
currentOrientation:UIInterfaceOrientationLandscapeRight
|
||||
didChangeOrientation:NO
|
||||
resultingOrientation:0];
|
||||
}
|
||||
|
||||
// Perform an orientation update test that fails when the expected outcome
|
||||
// for an orientation update is not met
|
||||
- (void)orientationTestWithOrientationUpdate:(UIInterfaceOrientationMask)mask
|
||||
currentOrientation:(UIInterfaceOrientation)currentOrientation
|
||||
didChangeOrientation:(BOOL)didChange
|
||||
resultingOrientation:(UIInterfaceOrientation)resultingOrientation {
|
||||
id engine = OCMClassMock([FlutterEngine class]);
|
||||
|
||||
id deviceMock = OCMPartialMock([UIDevice currentDevice]);
|
||||
if (!didChange) {
|
||||
OCMReject([deviceMock setValue:[OCMArg any] forKey:@"orientation"]);
|
||||
} else {
|
||||
OCMExpect([deviceMock setValue:@(resultingOrientation) 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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user