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 all 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
Original file line number Diff line number Diff line change
Expand Up @@ -618,11 +618,19 @@ - (UIScreen*)mainScreenIfViewLoaded {
if (self.viewIfLoaded == nil) {
FML_LOG(WARNING) << "Trying to access the view before it is loaded.";
}
return self.viewIfLoaded.window.windowScene.screen;
return [self windowSceneIfViewLoaded].screen;
}
return UIScreen.mainScreen;
}

- (UIWindowScene*)windowSceneIfViewLoaded {
if (self.viewIfLoaded == nil) {
FML_LOG(WARNING) << "Trying to access the view before it is loaded.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unreachable

return nil;
}
return self.viewIfLoaded.window.windowScene;
}

- (BOOL)loadDefaultSplashScreenView {
NSString* launchscreenName =
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"UILaunchStoryboardName"];
Expand Down Expand Up @@ -1858,8 +1866,19 @@ - (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences {
[self setNeedsUpdateOfSupportedInterfaceOrientations];
}
} else {
UIInterfaceOrientationMask currentInterfaceOrientation =
1 << [[UIApplication sharedApplication] statusBarOrientation];
UIInterfaceOrientationMask currentInterfaceOrientation;
if (@available(iOS 13.0, *)) {
UIWindowScene* windowScene = [self windowSceneIfViewLoaded];
if (!windowScene) {
// When the view is not loaded, it does not make sense to access the interface
// orientation, bail.
FML_LOG(WARNING) << "Trying to access the window scene before the view is loaded.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add comment explaining when this will happen?

return;
}
currentInterfaceOrientation = 1 << windowScene.interfaceOrientation;
} else {
currentInterfaceOrientation = 1 << [[UIApplication sharedApplication] statusBarOrientation];
}
if (!(_orientationPreferences & currentInterfaceOrientation)) {
[UIViewController attemptRotationToDeviceOrientation];
// Force orientation switch if the current orientation is not allowed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1464,9 +1464,14 @@ - (void)orientationTestWithOrientationUpdate:(UIInterfaceOrientationMask)mask
} else {
OCMExpect([deviceMock setValue:@(resultingOrientation) forKey:@"orientation"]);
}

OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
OCMStub([mockApplication statusBarOrientation]).andReturn(currentOrientation);
if (@available(iOS 13.0, *)) {
mockWindowScene = OCMPartialMock(realVC.view.window.windowScene);
OCMStub(((UIWindowScene*)mockWindowScene).interfaceOrientation)
.andReturn(currentOrientation);
} else {
OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
OCMStub([mockApplication statusBarOrientation]).andReturn(currentOrientation);
}
}

[realVC performOrientationUpdate:mask];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ typedef void (^FlutterKeyboardAnimationCallback)(fml::TimePoint);
- (void)addInternalPlugins;
- (void)deregisterNotifications;
- (int32_t)accessibilityFlags;
- (UIWindowScene*)windowSceneIfViewLoaded API_AVAILABLE(ios(13.0));

@end

Expand Down