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

Commit 53900d5

Browse files
authored
Revert "Issue 13238: on iOS, force an orientation change when the current orientation is not allowed" (#13160)
This reverts commit c38ed2c.
1 parent 9add166 commit 53900d5

File tree

3 files changed

+6
-206
lines changed

3 files changed

+6
-206
lines changed

AUTHORS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ Simon Lightfoot <simon@devangels.london>
1515
Dwayne Slater <ds84182@gmail.com>
1616
Tetsuhiro Ueda <najeira@gmail.com>
1717
shoryukenn <naifu.guan@gmail.com>
18-
SOTEC GmbH & Co. KG <sotec-contributors@sotec.eu>

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

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -828,36 +828,14 @@ - (void)onOrientationPreferencesUpdated:(NSNotification*)notification {
828828
if (update == nil) {
829829
return;
830830
}
831-
[self performOrientationUpdate:update.unsignedIntegerValue];
832-
});
833-
}
834831

835-
- (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences {
836-
if (new_preferences != _orientationPreferences) {
837-
_orientationPreferences = new_preferences;
838-
[UIViewController attemptRotationToDeviceOrientation];
839-
840-
UIInterfaceOrientationMask currentInterfaceOrientation =
841-
1 << [[UIApplication sharedApplication] statusBarOrientation];
842-
if (!(_orientationPreferences & currentInterfaceOrientation)) {
843-
// Force orientation switch if the current orientation is not allowed
844-
if (_orientationPreferences & UIInterfaceOrientationMaskPortrait) {
845-
// This is no official API but more like a workaround / hack (using
846-
// key-value coding on a read-only property). This might break in
847-
// the future, but currently it´s the only way to force an orientation change
848-
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait) forKey:@"orientation"];
849-
} else if (_orientationPreferences & UIInterfaceOrientationMaskPortraitUpsideDown) {
850-
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortraitUpsideDown)
851-
forKey:@"orientation"];
852-
} else if (_orientationPreferences & UIInterfaceOrientationMaskLandscapeLeft) {
853-
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeLeft)
854-
forKey:@"orientation"];
855-
} else if (_orientationPreferences & UIInterfaceOrientationMaskLandscapeRight) {
856-
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeRight)
857-
forKey:@"orientation"];
858-
}
832+
NSUInteger new_preferences = update.unsignedIntegerValue;
833+
834+
if (new_preferences != _orientationPreferences) {
835+
_orientationPreferences = new_preferences;
836+
[UIViewController attemptRotationToDeviceOrientation];
859837
}
860-
}
838+
});
861839
}
862840

863841
- (BOOL)shouldAutorotate {

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

Lines changed: 0 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ - (UIAccessibilityContrast)accessibilityContrast;
4545
@end
4646
#endif
4747

48-
@interface FlutterViewController (Tests)
49-
- (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences;
50-
@end
51-
5248
@implementation FlutterViewControllerTest
5349

5450
- (void)testBinaryMessenger {
@@ -256,179 +252,6 @@ - (void)testItReportsHighContrastWhenTraitCollectionRequestsIt {
256252
[mockTraitCollection stopMocking];
257253
}
258254

259-
- (void)testPerformOrientationUpdateForcesOrientationChange {
260-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortrait
261-
currentOrientation:UIInterfaceOrientationLandscapeLeft
262-
didChangeOrientation:YES
263-
resultingOrientation:UIInterfaceOrientationPortrait];
264-
265-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortrait
266-
currentOrientation:UIInterfaceOrientationLandscapeRight
267-
didChangeOrientation:YES
268-
resultingOrientation:UIInterfaceOrientationPortrait];
269-
270-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortrait
271-
currentOrientation:UIInterfaceOrientationPortraitUpsideDown
272-
didChangeOrientation:YES
273-
resultingOrientation:UIInterfaceOrientationPortrait];
274-
275-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortraitUpsideDown
276-
currentOrientation:UIInterfaceOrientationLandscapeLeft
277-
didChangeOrientation:YES
278-
resultingOrientation:UIInterfaceOrientationPortraitUpsideDown];
279-
280-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortraitUpsideDown
281-
currentOrientation:UIInterfaceOrientationLandscapeRight
282-
didChangeOrientation:YES
283-
resultingOrientation:UIInterfaceOrientationPortraitUpsideDown];
284-
285-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortraitUpsideDown
286-
currentOrientation:UIInterfaceOrientationPortrait
287-
didChangeOrientation:YES
288-
resultingOrientation:UIInterfaceOrientationPortraitUpsideDown];
289-
290-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscape
291-
currentOrientation:UIInterfaceOrientationPortrait
292-
didChangeOrientation:YES
293-
resultingOrientation:UIInterfaceOrientationLandscapeLeft];
294-
295-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscape
296-
currentOrientation:UIInterfaceOrientationPortraitUpsideDown
297-
didChangeOrientation:YES
298-
resultingOrientation:UIInterfaceOrientationLandscapeLeft];
299-
300-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeLeft
301-
currentOrientation:UIInterfaceOrientationPortrait
302-
didChangeOrientation:YES
303-
resultingOrientation:UIInterfaceOrientationLandscapeLeft];
304-
305-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeLeft
306-
currentOrientation:UIInterfaceOrientationLandscapeRight
307-
didChangeOrientation:YES
308-
resultingOrientation:UIInterfaceOrientationLandscapeLeft];
309-
310-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeLeft
311-
currentOrientation:UIInterfaceOrientationPortraitUpsideDown
312-
didChangeOrientation:YES
313-
resultingOrientation:UIInterfaceOrientationLandscapeLeft];
314-
315-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeRight
316-
currentOrientation:UIInterfaceOrientationPortrait
317-
didChangeOrientation:YES
318-
resultingOrientation:UIInterfaceOrientationLandscapeRight];
319-
320-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeRight
321-
currentOrientation:UIInterfaceOrientationLandscapeLeft
322-
didChangeOrientation:YES
323-
resultingOrientation:UIInterfaceOrientationLandscapeRight];
324-
325-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeRight
326-
currentOrientation:UIInterfaceOrientationPortraitUpsideDown
327-
didChangeOrientation:YES
328-
resultingOrientation:UIInterfaceOrientationLandscapeRight];
329-
330-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAllButUpsideDown
331-
currentOrientation:UIInterfaceOrientationPortraitUpsideDown
332-
didChangeOrientation:YES
333-
resultingOrientation:UIInterfaceOrientationPortrait];
334-
}
335-
336-
- (void)testPerformOrientationUpdateDoesNotForceOrientationChange {
337-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAll
338-
currentOrientation:UIInterfaceOrientationPortrait
339-
didChangeOrientation:NO
340-
resultingOrientation:0];
341-
342-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAll
343-
currentOrientation:UIInterfaceOrientationPortraitUpsideDown
344-
didChangeOrientation:NO
345-
resultingOrientation:0];
346-
347-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAll
348-
currentOrientation:UIInterfaceOrientationLandscapeLeft
349-
didChangeOrientation:NO
350-
resultingOrientation:0];
351-
352-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAll
353-
currentOrientation:UIInterfaceOrientationLandscapeRight
354-
didChangeOrientation:NO
355-
resultingOrientation:0];
356-
357-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAllButUpsideDown
358-
currentOrientation:UIInterfaceOrientationPortrait
359-
didChangeOrientation:NO
360-
resultingOrientation:0];
361-
362-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAllButUpsideDown
363-
currentOrientation:UIInterfaceOrientationLandscapeLeft
364-
didChangeOrientation:NO
365-
resultingOrientation:0];
366-
367-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAllButUpsideDown
368-
currentOrientation:UIInterfaceOrientationLandscapeRight
369-
didChangeOrientation:NO
370-
resultingOrientation:0];
371-
372-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortrait
373-
currentOrientation:UIInterfaceOrientationPortrait
374-
didChangeOrientation:NO
375-
resultingOrientation:0];
376-
377-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortraitUpsideDown
378-
currentOrientation:UIInterfaceOrientationPortraitUpsideDown
379-
didChangeOrientation:NO
380-
resultingOrientation:0];
381-
382-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscape
383-
currentOrientation:UIInterfaceOrientationLandscapeLeft
384-
didChangeOrientation:NO
385-
resultingOrientation:0];
386-
387-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscape
388-
currentOrientation:UIInterfaceOrientationLandscapeRight
389-
didChangeOrientation:NO
390-
resultingOrientation:0];
391-
392-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeLeft
393-
currentOrientation:UIInterfaceOrientationLandscapeLeft
394-
didChangeOrientation:NO
395-
resultingOrientation:0];
396-
397-
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeRight
398-
currentOrientation:UIInterfaceOrientationLandscapeRight
399-
didChangeOrientation:NO
400-
resultingOrientation:0];
401-
}
402-
403-
// Perform an orientation update test that fails when the expected outcome
404-
// for an orientation update is not met
405-
- (void)orientationTestWithOrientationUpdate:(UIInterfaceOrientationMask)mask
406-
currentOrientation:(UIInterfaceOrientation)currentOrientation
407-
didChangeOrientation:(BOOL)didChange
408-
resultingOrientation:(UIInterfaceOrientation)resultingOrientation {
409-
id engine = OCMClassMock([FlutterEngine class]);
410-
411-
id deviceMock = OCMPartialMock([UIDevice currentDevice]);
412-
if (!didChange) {
413-
OCMReject([deviceMock setValue:[OCMArg any] forKey:@"orientation"]);
414-
} else {
415-
OCMExpect([deviceMock setValue:@(resultingOrientation) forKey:@"orientation"]);
416-
}
417-
418-
FlutterViewController* realVC = [[FlutterViewController alloc] initWithEngine:engine
419-
nibName:nil
420-
bundle:nil];
421-
id mockApplication = OCMClassMock([UIApplication class]);
422-
OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
423-
OCMStub([mockApplication statusBarOrientation]).andReturn(currentOrientation);
424-
425-
[realVC performOrientationUpdate:mask];
426-
OCMVerifyAll(deviceMock);
427-
[engine stopMocking];
428-
[deviceMock stopMocking];
429-
[mockApplication stopMocking];
430-
}
431-
432255
// Creates a mocked UITraitCollection with nil values for everything except accessibilityContrast,
433256
// which is set to the given "contrast".
434257
- (UITraitCollection*)fakeTraitCollectionWithContrast:(UIAccessibilityContrast)contrast {

0 commit comments

Comments
 (0)