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

Commit 26b9d3b

Browse files
authored
[ios]make the screenIfViewLoaded and windowSceneIfLoaded helpers reusable (#44303)
The existing `screenIfViewLoaded` and `windowSceneIfLoaded` functions are private helpers of `FlutterViewController` class. This PR moves the logic to a category of the `UIViewController`, so it can be reused for any `UIViewController`s. *List which issues are fixed by this PR. You must list at least one issue.* #43972 (comment) *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 9522ce9 commit 26b9d3b

10 files changed

+174
-49
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,6 +2672,9 @@ ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/KeyCodeMap_I
26722672
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.h + ../../../flutter/LICENSE
26732673
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm + ../../../flutter/LICENSE
26742674
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm + ../../../flutter/LICENSE
2675+
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.h + ../../../flutter/LICENSE
2676+
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.mm + ../../../flutter/LICENSE
2677+
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/UIViewController_FlutterScreenAndSceneIfLoadedTest.mm + ../../../flutter/LICENSE
26752678
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/VsyncWaiterIosTest.mm + ../../../flutter/LICENSE
26762679
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h + ../../../flutter/LICENSE
26772680
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm + ../../../flutter/LICENSE
@@ -5395,6 +5398,9 @@ FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/KeyCodeMap_Int
53955398
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.h
53965399
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm
53975400
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm
5401+
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.h
5402+
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.mm
5403+
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/UIViewController_FlutterScreenAndSceneIfLoadedTest.mm
53985404
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/VsyncWaiterIosTest.mm
53995405
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h
54005406
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm

shell/platform/darwin/ios/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ source_set("flutter_framework_source") {
123123
"framework/Source/KeyCodeMap_Internal.h",
124124
"framework/Source/SemanticsObject.h",
125125
"framework/Source/SemanticsObject.mm",
126+
"framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.h",
127+
"framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.mm",
126128
"framework/Source/accessibility_bridge.h",
127129
"framework/Source/accessibility_bridge.mm",
128130
"framework/Source/accessibility_text_entry.h",
@@ -298,6 +300,7 @@ shared_library("ios_test_flutter") {
298300
"framework/Source/FlutterUndoManagerPluginTest.mm",
299301
"framework/Source/FlutterViewControllerTest.mm",
300302
"framework/Source/SemanticsObjectTest.mm",
303+
"framework/Source/UIViewController_FlutterScreenAndSceneIfLoadedTest.mm",
301304
"framework/Source/connection_collection_test.mm",
302305
]
303306
deps = [

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerDelegate.h"
3131
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerPlugin.h"
3232
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
33+
#import "flutter/shell/platform/darwin/ios/framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.h"
3334
#import "flutter/shell/platform/darwin/ios/framework/Source/connection_collection.h"
3435
#import "flutter/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.h"
3536
#import "flutter/shell/platform/darwin/ios/framework/Source/profiler_metrics_ios.h"
@@ -880,7 +881,7 @@ - (BOOL)createShell:(NSString*)entrypoint
880881

881882
#if APPLICATION_EXTENSION_API_ONLY
882883
if (@available(iOS 13.0, *)) {
883-
_isGpuDisabled = self.viewController.windowSceneIfViewLoaded.activationState ==
884+
_isGpuDisabled = self.viewController.flutterWindowSceneIfViewLoaded.activationState ==
884885
UISceneActivationStateBackground;
885886
} else {
886887
// [UIApplication sharedApplication API is not available for app extension.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "flutter/fml/logging.h"
1313
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
14+
#import "flutter/shell/platform/darwin/ios/framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.h"
1415

1516
namespace {
1617

@@ -293,7 +294,7 @@ - (void)popSystemNavigator:(BOOL)isAnimated {
293294
#if APPLICATION_EXTENSION_API_ONLY
294295
if (@available(iOS 15.0, *)) {
295296
rootViewController =
296-
[engineViewController windowSceneIfViewLoaded].keyWindow.rootViewController;
297+
[engineViewController flutterWindowSceneIfViewLoaded].keyWindow.rootViewController;
297298
} else {
298299
FML_LOG(WARNING)
299300
<< "rootViewController is not available in application extension prior to iOS 15.0.";

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

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputDelegate.h"
2727
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h"
2828
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h"
29+
#import "flutter/shell/platform/darwin/ios/framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.h"
2930
#import "flutter/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.h"
3031
#import "flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h"
3132
#import "flutter/shell/platform/darwin/ios/platform_view_ios.h"
@@ -516,25 +517,6 @@ - (void)loadView {
516517
return pointer_data;
517518
}
518519

519-
- (UIWindowScene*)windowSceneIfViewLoaded {
520-
if (self.viewIfLoaded == nil) {
521-
FML_LOG(WARNING) << "Trying to access the window scene before the view is loaded.";
522-
return nil;
523-
}
524-
return self.viewIfLoaded.window.windowScene;
525-
}
526-
527-
- (UIScreen*)screenIfViewLoaded {
528-
if (@available(iOS 13.0, *)) {
529-
if (self.viewIfLoaded == nil) {
530-
FML_LOG(WARNING) << "Trying to access the screen before the view is loaded.";
531-
return nil;
532-
}
533-
return [self windowSceneIfViewLoaded].screen;
534-
}
535-
return UIScreen.mainScreen;
536-
}
537-
538520
static void SendFakeTouchEvent(UIScreen* screen,
539521
FlutterEngine* engine,
540522
CGPoint location,
@@ -554,7 +536,7 @@ - (BOOL)scrollViewShouldScrollToTop:(UIScrollView*)scrollView {
554536
return NO;
555537
}
556538
CGPoint statusBarPoint = CGPointZero;
557-
UIScreen* screen = [self screenIfViewLoaded];
539+
UIScreen* screen = [self flutterScreenIfViewLoaded];
558540
if (screen) {
559541
SendFakeTouchEvent(screen, _engine.get(), statusBarPoint, flutter::PointerData::Change::kDown);
560542
SendFakeTouchEvent(screen, _engine.get(), statusBarPoint, flutter::PointerData::Change::kUp);
@@ -869,8 +851,8 @@ - (void)viewDidAppear:(BOOL)animated {
869851
BOOL stateIsActive = YES;
870852
#if APPLICATION_EXTENSION_API_ONLY
871853
if (@available(iOS 13.0, *)) {
872-
stateIsActive =
873-
self.windowSceneIfViewLoaded.activationState == UISceneActivationStateForegroundActive;
854+
stateIsActive = self.flutterWindowSceneIfViewLoaded.activationState ==
855+
UISceneActivationStateForegroundActive;
874856
}
875857
#else
876858
stateIsActive = UIApplication.sharedApplication.applicationState == UIApplicationStateActive;
@@ -1166,7 +1148,7 @@ - (void)dispatchTouches:(NSSet*)touches
11661148
// Activate or pause the correction of delivery frame rate of touch events.
11671149
[self triggerTouchRateCorrectionIfNeeded:touches];
11681150

1169-
const CGFloat scale = [self screenIfViewLoaded].scale;
1151+
const CGFloat scale = [self flutterScreenIfViewLoaded].scale;
11701152
auto packet =
11711153
std::make_unique<flutter::PointerDataPacket>(touches.count + touches_to_remove_count);
11721154

@@ -1381,7 +1363,7 @@ - (void)updateViewportMetricsIfNeeded {
13811363

13821364
- (void)viewDidLayoutSubviews {
13831365
CGRect viewBounds = self.view.bounds;
1384-
CGFloat scale = [self screenIfViewLoaded].scale;
1366+
CGFloat scale = [self flutterScreenIfViewLoaded].scale;
13851367

13861368
// Purposefully place this not visible.
13871369
_scrollView.get().frame = CGRectMake(0.0, 0.0, viewBounds.size.width, 0.0);
@@ -1400,8 +1382,8 @@ - (void)viewDidLayoutSubviews {
14001382
bool applicationOrSceneIsActive = YES;
14011383
#if APPLICATION_EXTENSION_API_ONLY
14021384
if (@available(iOS 13.0, *)) {
1403-
applicationOrSceneIsActive =
1404-
self.windowSceneIfViewLoaded.activationState == UISceneActivationStateForegroundActive;
1385+
applicationOrSceneIsActive = self.flutterWindowSceneIfViewLoaded.activationState ==
1386+
UISceneActivationStateForegroundActive;
14051387
}
14061388
#else
14071389
applicationOrSceneIsActive =
@@ -1436,7 +1418,7 @@ - (void)viewSafeAreaInsetsDidChange {
14361418

14371419
// Set _viewportMetrics physical size.
14381420
- (void)setViewportMetricsSize {
1439-
UIScreen* screen = [self screenIfViewLoaded];
1421+
UIScreen* screen = [self flutterScreenIfViewLoaded];
14401422
if (!screen) {
14411423
return;
14421424
}
@@ -1450,7 +1432,7 @@ - (void)setViewportMetricsSize {
14501432
//
14511433
// Viewport paddings represent the iOS safe area insets.
14521434
- (void)setViewportMetricsPaddings {
1453-
UIScreen* screen = [self screenIfViewLoaded];
1435+
UIScreen* screen = [self flutterScreenIfViewLoaded];
14541436
if (!screen) {
14551437
return;
14561438
}
@@ -1616,7 +1598,7 @@ - (FlutterKeyboardMode)calculateKeyboardAttachMode:(NSNotification*)notification
16161598
return FlutterKeyboardModeHidden;
16171599
}
16181600

1619-
CGRect screenRect = [self screenIfViewLoaded].bounds;
1601+
CGRect screenRect = [self flutterScreenIfViewLoaded].bounds;
16201602
CGRect adjustedKeyboardFrame = keyboardFrame;
16211603
adjustedKeyboardFrame.origin.y += [self calculateMultitaskingAdjustment:screenRect
16221604
keyboardFrame:keyboardFrame];
@@ -1656,7 +1638,7 @@ - (CGFloat)calculateMultitaskingAdjustment:(CGRect)screenRect keyboardFrame:(CGR
16561638
}
16571639
CGRect viewRectRelativeToScreen =
16581640
[self.viewIfLoaded convertRect:self.viewIfLoaded.frame
1659-
toCoordinateSpace:[self screenIfViewLoaded].coordinateSpace];
1641+
toCoordinateSpace:[self flutterScreenIfViewLoaded].coordinateSpace];
16601642
CGFloat viewBottom = CGRectGetMaxY(viewRectRelativeToScreen);
16611643
CGFloat offset = screenHeight - viewBottom;
16621644
if (offset > 0) {
@@ -1672,14 +1654,14 @@ - (CGFloat)calculateKeyboardInset:(CGRect)keyboardFrame keyboardMode:(NSInteger)
16721654
// Calculate how much of the keyboard intersects with the view.
16731655
CGRect viewRectRelativeToScreen =
16741656
[self.viewIfLoaded convertRect:self.viewIfLoaded.frame
1675-
toCoordinateSpace:[self screenIfViewLoaded].coordinateSpace];
1657+
toCoordinateSpace:[self flutterScreenIfViewLoaded].coordinateSpace];
16761658
CGRect intersection = CGRectIntersection(keyboardFrame, viewRectRelativeToScreen);
16771659
CGFloat portionOfKeyboardInView = CGRectGetHeight(intersection);
16781660

16791661
// The keyboard is treated as an inset since we want to effectively reduce the window size by
16801662
// the keyboard height. The Dart side will compute a value accounting for the keyboard-consuming
16811663
// bottom padding.
1682-
CGFloat scale = [self screenIfViewLoaded].scale;
1664+
CGFloat scale = [self flutterScreenIfViewLoaded].scale;
16831665
return portionOfKeyboardInView * scale;
16841666
}
16851667
return 0;
@@ -1974,8 +1956,9 @@ - (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences {
19741956
if (@available(iOS 16.0, *)) {
19751957
NSSet<UIScene*>* scenes =
19761958
#if APPLICATION_EXTENSION_API_ONLY
1977-
self.windowSceneIfViewLoaded ? [NSSet setWithObject:self.windowSceneIfViewLoaded]
1978-
: [NSSet set];
1959+
self.flutterWindowSceneIfViewLoaded
1960+
? [NSSet setWithObject:self.flutterWindowSceneIfViewLoaded]
1961+
: [NSSet set];
19791962
#else
19801963
[UIApplication.sharedApplication.connectedScenes
19811964
filteredSetUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(
@@ -1987,7 +1970,7 @@ - (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences {
19871970
} else {
19881971
UIInterfaceOrientationMask currentInterfaceOrientation;
19891972
if (@available(iOS 13.0, *)) {
1990-
UIWindowScene* windowScene = [self windowSceneIfViewLoaded];
1973+
UIWindowScene* windowScene = [self flutterWindowSceneIfViewLoaded];
19911974
if (!windowScene) {
19921975
FML_LOG(WARNING)
19931976
<< "Accessing the interface orientation when the window scene is unavailable.";
@@ -2410,7 +2393,7 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer
24102393

24112394
- (void)hoverEvent:(UIPanGestureRecognizer*)recognizer API_AVAILABLE(ios(13.4)) {
24122395
CGPoint location = [recognizer locationInView:self.view];
2413-
CGFloat scale = [self screenIfViewLoaded].scale;
2396+
CGFloat scale = [self flutterScreenIfViewLoaded].scale;
24142397
CGPoint oldLocation = _mouseState.location;
24152398
_mouseState.location = {location.x * scale, location.y * scale};
24162399

@@ -2467,7 +2450,7 @@ - (void)hoverEvent:(UIPanGestureRecognizer*)recognizer API_AVAILABLE(ios(13.4))
24672450

24682451
- (void)discreteScrollEvent:(UIPanGestureRecognizer*)recognizer API_AVAILABLE(ios(13.4)) {
24692452
CGPoint translation = [recognizer translationInView:self.view];
2470-
const CGFloat scale = [self screenIfViewLoaded].scale;
2453+
const CGFloat scale = [self flutterScreenIfViewLoaded].scale;
24712454

24722455
translation.x *= scale;
24732456
translation.y *= scale;
@@ -2496,7 +2479,7 @@ - (void)discreteScrollEvent:(UIPanGestureRecognizer*)recognizer API_AVAILABLE(io
24962479

24972480
- (void)continuousScrollEvent:(UIPanGestureRecognizer*)recognizer API_AVAILABLE(ios(13.4)) {
24982481
CGPoint translation = [recognizer translationInView:self.view];
2499-
const CGFloat scale = [self screenIfViewLoaded].scale;
2482+
const CGFloat scale = [self flutterScreenIfViewLoaded].scale;
25002483

25012484
flutter::PointerData pointer_data = [self generatePointerDataAtLastMouseLocation];
25022485
pointer_data.device = reinterpret_cast<int64_t>(recognizer);

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterFakeKeyEvents.h"
1717
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h"
1818
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
19+
#import "flutter/shell/platform/darwin/ios/framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.h"
1920
#import "flutter/shell/platform/embedder/embedder.h"
2021
#import "flutter/third_party/spring_animation/spring_animation.h"
2122

@@ -129,7 +130,6 @@ - (void)updateViewportMetricsIfNeeded;
129130
- (void)onUserSettingsChanged:(NSNotification*)notification;
130131
- (void)applicationWillTerminate:(NSNotification*)notification;
131132
- (void)goToApplicationLifecycle:(nonnull NSString*)state;
132-
- (UIScreen*)screenIfViewLoaded;
133133
- (void)handleKeyboardNotification:(NSNotification*)notification;
134134
- (CGFloat)calculateKeyboardInset:(CGRect)keyboardFrame keyboardMode:(int)keyboardMode;
135135
- (BOOL)shouldIgnoreKeyboardNotification:(NSNotification*)notification;
@@ -199,7 +199,7 @@ - (id)setUpMockView:(FlutterViewController*)viewControllerMock
199199
screen:(UIScreen*)screen
200200
viewFrame:(CGRect)viewFrame
201201
convertedFrame:(CGRect)convertedFrame {
202-
OCMStub([viewControllerMock screenIfViewLoaded]).andReturn(screen);
202+
OCMStub([viewControllerMock flutterScreenIfViewLoaded]).andReturn(screen);
203203
id mockView = OCMClassMock([UIView class]);
204204
OCMStub([mockView frame]).andReturn(viewFrame);
205205
OCMStub([mockView convertRect:viewFrame toCoordinateSpace:[OCMArg any]])
@@ -680,7 +680,7 @@ - (void)testCalculateKeyboardInset {
680680
bundle:nil];
681681
FlutterViewController* viewControllerMock = OCMPartialMock(viewController);
682682
UIScreen* screen = [self setUpMockScreen];
683-
OCMStub([viewControllerMock screenIfViewLoaded]).andReturn(screen);
683+
OCMStub([viewControllerMock flutterScreenIfViewLoaded]).andReturn(screen);
684684

685685
CGFloat screenWidth = screen.bounds.size.width;
686686
CGFloat screenHeight = screen.bounds.size.height;
@@ -943,7 +943,7 @@ - (void)testUpdateViewportMetricsIfNeeded_DoesNotInvokeEngineWhenShouldBeIgnored
943943
bundle:nil];
944944
FlutterViewController* viewControllerMock = OCMPartialMock(viewController);
945945
UIScreen* screen = [self setUpMockScreen];
946-
OCMStub([viewControllerMock screenIfViewLoaded]).andReturn(screen);
946+
OCMStub([viewControllerMock flutterScreenIfViewLoaded]).andReturn(screen);
947947
mockEngine.viewController = viewController;
948948

949949
id mockCoordinator = OCMProtocolMock(@protocol(UIViewControllerTransitionCoordinator));
@@ -965,7 +965,7 @@ - (void)testViewWillTransitionToSize_DoesDelayEngineCallIfNonZeroDuration {
965965
bundle:nil];
966966
FlutterViewController* viewControllerMock = OCMPartialMock(viewController);
967967
UIScreen* screen = [self setUpMockScreen];
968-
OCMStub([viewControllerMock screenIfViewLoaded]).andReturn(screen);
968+
OCMStub([viewControllerMock flutterScreenIfViewLoaded]).andReturn(screen);
969969
mockEngine.viewController = viewController;
970970

971971
// Mimic the device rotation with non-zero transition duration.
@@ -999,7 +999,7 @@ - (void)testViewWillTransitionToSize_DoesNotDelayEngineCallIfZeroDuration {
999999
bundle:nil];
10001000
FlutterViewController* viewControllerMock = OCMPartialMock(viewController);
10011001
UIScreen* screen = [self setUpMockScreen];
1002-
OCMStub([viewControllerMock screenIfViewLoaded]).andReturn(screen);
1002+
OCMStub([viewControllerMock flutterScreenIfViewLoaded]).andReturn(screen);
10031003
mockEngine.viewController = viewController;
10041004

10051005
// Mimic the device rotation with zero transition duration.
@@ -1512,7 +1512,7 @@ - (void)orientationTestWithOrientationUpdate:(UIInterfaceOrientationMask)mask
15121512
if (@available(iOS 16.0, *)) {
15131513
mockWindowScene = OCMClassMock([UIWindowScene class]);
15141514
mockVC = OCMPartialMock(realVC);
1515-
OCMStub([mockVC windowSceneIfViewLoaded]).andReturn(mockWindowScene);
1515+
OCMStub([mockVC flutterWindowSceneIfViewLoaded]).andReturn(mockWindowScene);
15161516
if (realVC.supportedInterfaceOrientations == mask) {
15171517
OCMReject([mockWindowScene requestGeometryUpdateWithPreferences:[OCMArg any]
15181518
errorHandler:[OCMArg any]]);
@@ -1540,7 +1540,7 @@ - (void)orientationTestWithOrientationUpdate:(UIInterfaceOrientationMask)mask
15401540
if (@available(iOS 13.0, *)) {
15411541
mockWindowScene = OCMClassMock([UIWindowScene class]);
15421542
mockVC = OCMPartialMock(realVC);
1543-
OCMStub([mockVC windowSceneIfViewLoaded]).andReturn(mockWindowScene);
1543+
OCMStub([mockVC flutterWindowSceneIfViewLoaded]).andReturn(mockWindowScene);
15441544
OCMStub(((UIWindowScene*)mockWindowScene).interfaceOrientation)
15451545
.andReturn(currentOrientation);
15461546
} else {

shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ typedef void (^FlutterKeyboardAnimationCallback)(fml::TimePoint);
6565
- (void)addInternalPlugins;
6666
- (void)deregisterNotifications;
6767
- (int32_t)accessibilityFlags;
68-
- (UIWindowScene*)windowSceneIfViewLoaded API_AVAILABLE(ios(13.0));
6968

7069
@end
7170

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef FLUTTER_UIVIEWCONTROLLER_FLUTTERSCREENANDSCENEIFLOADED_H_
6+
#define FLUTTER_UIVIEWCONTROLLER_FLUTTERSCREENANDSCENEIFLOADED_H_
7+
8+
#import <UIKit/UIKit.h>
9+
10+
@interface UIViewController (FlutterScreenAndSceneIfLoaded)
11+
12+
/// Returns a UIWindowScene if the UIViewController's view is loaded, and nil otherwise.
13+
- (UIWindowScene*)flutterWindowSceneIfViewLoaded API_AVAILABLE(ios(13.0));
14+
15+
/// Before iOS 13, returns the main screen; After iOS 13, returns the screen the UIViewController is
16+
/// attached to if its view is loaded, and nil otherwise.
17+
- (UIScreen*)flutterScreenIfViewLoaded;
18+
19+
@end
20+
21+
#endif // FLUTTER_UIVIEWCONTROLLER_FLUTTERSCREENANDSCENEIFLOADED_H_

0 commit comments

Comments
 (0)