26
26
#import " flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputDelegate.h"
27
27
#import " flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h"
28
28
#import " flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h"
29
+ #import " flutter/shell/platform/darwin/ios/framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.h"
29
30
#import " flutter/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.h"
30
31
#import " flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h"
31
32
#import " flutter/shell/platform/darwin/ios/platform_view_ios.h"
@@ -516,25 +517,6 @@ - (void)loadView {
516
517
return pointer_data;
517
518
}
518
519
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
-
538
520
static void SendFakeTouchEvent (UIScreen* screen,
539
521
FlutterEngine* engine,
540
522
CGPoint location,
@@ -554,7 +536,7 @@ - (BOOL)scrollViewShouldScrollToTop:(UIScrollView*)scrollView {
554
536
return NO ;
555
537
}
556
538
CGPoint statusBarPoint = CGPointZero;
557
- UIScreen* screen = [self screenIfViewLoaded ];
539
+ UIScreen* screen = [self flutterScreenIfViewLoaded ];
558
540
if (screen) {
559
541
SendFakeTouchEvent (screen, _engine.get (), statusBarPoint, flutter::PointerData::Change::kDown );
560
542
SendFakeTouchEvent (screen, _engine.get (), statusBarPoint, flutter::PointerData::Change::kUp );
@@ -869,8 +851,8 @@ - (void)viewDidAppear:(BOOL)animated {
869
851
BOOL stateIsActive = YES ;
870
852
#if APPLICATION_EXTENSION_API_ONLY
871
853
if (@available (iOS 13.0 , *)) {
872
- stateIsActive =
873
- self. windowSceneIfViewLoaded . activationState == UISceneActivationStateForegroundActive;
854
+ stateIsActive = self. flutterWindowSceneIfViewLoaded . activationState ==
855
+ UISceneActivationStateForegroundActive;
874
856
}
875
857
#else
876
858
stateIsActive = UIApplication.sharedApplication .applicationState == UIApplicationStateActive;
@@ -1166,7 +1148,7 @@ - (void)dispatchTouches:(NSSet*)touches
1166
1148
// Activate or pause the correction of delivery frame rate of touch events.
1167
1149
[self triggerTouchRateCorrectionIfNeeded: touches];
1168
1150
1169
- const CGFloat scale = [self screenIfViewLoaded ].scale ;
1151
+ const CGFloat scale = [self flutterScreenIfViewLoaded ].scale ;
1170
1152
auto packet =
1171
1153
std::make_unique<flutter::PointerDataPacket>(touches.count + touches_to_remove_count);
1172
1154
@@ -1381,7 +1363,7 @@ - (void)updateViewportMetricsIfNeeded {
1381
1363
1382
1364
- (void )viewDidLayoutSubviews {
1383
1365
CGRect viewBounds = self.view .bounds ;
1384
- CGFloat scale = [self screenIfViewLoaded ].scale ;
1366
+ CGFloat scale = [self flutterScreenIfViewLoaded ].scale ;
1385
1367
1386
1368
// Purposefully place this not visible.
1387
1369
_scrollView.get ().frame = CGRectMake (0.0 , 0.0 , viewBounds.size .width , 0.0 );
@@ -1400,8 +1382,8 @@ - (void)viewDidLayoutSubviews {
1400
1382
bool applicationOrSceneIsActive = YES ;
1401
1383
#if APPLICATION_EXTENSION_API_ONLY
1402
1384
if (@available (iOS 13.0 , *)) {
1403
- applicationOrSceneIsActive =
1404
- self. windowSceneIfViewLoaded . activationState == UISceneActivationStateForegroundActive;
1385
+ applicationOrSceneIsActive = self. flutterWindowSceneIfViewLoaded . activationState ==
1386
+ UISceneActivationStateForegroundActive;
1405
1387
}
1406
1388
#else
1407
1389
applicationOrSceneIsActive =
@@ -1436,7 +1418,7 @@ - (void)viewSafeAreaInsetsDidChange {
1436
1418
1437
1419
// Set _viewportMetrics physical size.
1438
1420
- (void )setViewportMetricsSize {
1439
- UIScreen* screen = [self screenIfViewLoaded ];
1421
+ UIScreen* screen = [self flutterScreenIfViewLoaded ];
1440
1422
if (!screen) {
1441
1423
return ;
1442
1424
}
@@ -1450,7 +1432,7 @@ - (void)setViewportMetricsSize {
1450
1432
//
1451
1433
// Viewport paddings represent the iOS safe area insets.
1452
1434
- (void )setViewportMetricsPaddings {
1453
- UIScreen* screen = [self screenIfViewLoaded ];
1435
+ UIScreen* screen = [self flutterScreenIfViewLoaded ];
1454
1436
if (!screen) {
1455
1437
return ;
1456
1438
}
@@ -1616,7 +1598,7 @@ - (FlutterKeyboardMode)calculateKeyboardAttachMode:(NSNotification*)notification
1616
1598
return FlutterKeyboardModeHidden;
1617
1599
}
1618
1600
1619
- CGRect screenRect = [self screenIfViewLoaded ].bounds ;
1601
+ CGRect screenRect = [self flutterScreenIfViewLoaded ].bounds ;
1620
1602
CGRect adjustedKeyboardFrame = keyboardFrame;
1621
1603
adjustedKeyboardFrame.origin .y += [self calculateMultitaskingAdjustment: screenRect
1622
1604
keyboardFrame: keyboardFrame];
@@ -1656,7 +1638,7 @@ - (CGFloat)calculateMultitaskingAdjustment:(CGRect)screenRect keyboardFrame:(CGR
1656
1638
}
1657
1639
CGRect viewRectRelativeToScreen =
1658
1640
[self .viewIfLoaded convertRect: self .viewIfLoaded.frame
1659
- toCoordinateSpace: [self screenIfViewLoaded ].coordinateSpace];
1641
+ toCoordinateSpace: [self flutterScreenIfViewLoaded ].coordinateSpace];
1660
1642
CGFloat viewBottom = CGRectGetMaxY (viewRectRelativeToScreen);
1661
1643
CGFloat offset = screenHeight - viewBottom;
1662
1644
if (offset > 0 ) {
@@ -1672,14 +1654,14 @@ - (CGFloat)calculateKeyboardInset:(CGRect)keyboardFrame keyboardMode:(NSInteger)
1672
1654
// Calculate how much of the keyboard intersects with the view.
1673
1655
CGRect viewRectRelativeToScreen =
1674
1656
[self .viewIfLoaded convertRect: self .viewIfLoaded.frame
1675
- toCoordinateSpace: [self screenIfViewLoaded ].coordinateSpace];
1657
+ toCoordinateSpace: [self flutterScreenIfViewLoaded ].coordinateSpace];
1676
1658
CGRect intersection = CGRectIntersection (keyboardFrame, viewRectRelativeToScreen);
1677
1659
CGFloat portionOfKeyboardInView = CGRectGetHeight (intersection);
1678
1660
1679
1661
// The keyboard is treated as an inset since we want to effectively reduce the window size by
1680
1662
// the keyboard height. The Dart side will compute a value accounting for the keyboard-consuming
1681
1663
// bottom padding.
1682
- CGFloat scale = [self screenIfViewLoaded ].scale ;
1664
+ CGFloat scale = [self flutterScreenIfViewLoaded ].scale ;
1683
1665
return portionOfKeyboardInView * scale;
1684
1666
}
1685
1667
return 0 ;
@@ -1974,8 +1956,9 @@ - (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences {
1974
1956
if (@available (iOS 16.0 , *)) {
1975
1957
NSSet <UIScene*>* scenes =
1976
1958
#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 ];
1979
1962
#else
1980
1963
[UIApplication.sharedApplication.connectedScenes
1981
1964
filteredSetUsingPredicate: [NSPredicate predicateWithBlock: ^BOOL (
@@ -1987,7 +1970,7 @@ - (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences {
1987
1970
} else {
1988
1971
UIInterfaceOrientationMask currentInterfaceOrientation;
1989
1972
if (@available (iOS 13.0 , *)) {
1990
- UIWindowScene* windowScene = [self windowSceneIfViewLoaded ];
1973
+ UIWindowScene* windowScene = [self flutterWindowSceneIfViewLoaded ];
1991
1974
if (!windowScene) {
1992
1975
FML_LOG (WARNING)
1993
1976
<< " Accessing the interface orientation when the window scene is unavailable." ;
@@ -2410,7 +2393,7 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer
2410
2393
2411
2394
- (void )hoverEvent : (UIPanGestureRecognizer*)recognizer API_AVAILABLE(ios(13.4 )) {
2412
2395
CGPoint location = [recognizer locationInView: self .view];
2413
- CGFloat scale = [self screenIfViewLoaded ].scale ;
2396
+ CGFloat scale = [self flutterScreenIfViewLoaded ].scale ;
2414
2397
CGPoint oldLocation = _mouseState.location ;
2415
2398
_mouseState.location = {location.x * scale, location.y * scale};
2416
2399
@@ -2467,7 +2450,7 @@ - (void)hoverEvent:(UIPanGestureRecognizer*)recognizer API_AVAILABLE(ios(13.4))
2467
2450
2468
2451
- (void )discreteScrollEvent : (UIPanGestureRecognizer*)recognizer API_AVAILABLE(ios(13.4 )) {
2469
2452
CGPoint translation = [recognizer translationInView: self .view];
2470
- const CGFloat scale = [self screenIfViewLoaded ].scale ;
2453
+ const CGFloat scale = [self flutterScreenIfViewLoaded ].scale ;
2471
2454
2472
2455
translation.x *= scale;
2473
2456
translation.y *= scale;
@@ -2496,7 +2479,7 @@ - (void)discreteScrollEvent:(UIPanGestureRecognizer*)recognizer API_AVAILABLE(io
2496
2479
2497
2480
- (void )continuousScrollEvent : (UIPanGestureRecognizer*)recognizer API_AVAILABLE(ios(13.4 )) {
2498
2481
CGPoint translation = [recognizer translationInView: self .view];
2499
- const CGFloat scale = [self screenIfViewLoaded ].scale ;
2482
+ const CGFloat scale = [self flutterScreenIfViewLoaded ].scale ;
2500
2483
2501
2484
flutter::PointerData pointer_data = [self generatePointerDataAtLastMouseLocation ];
2502
2485
pointer_data.device = reinterpret_cast <int64_t >(recognizer);
0 commit comments