Skip to content

Commit 277bfe6

Browse files
authored
Support iPhone X safe area insets (flutter#4302)
This change exposes the view safe area insets (introduced in iOS 11) to the framework via MediaQuery.of(context).padding. Safe area insets are the view insets (padding) inside of which content can be relied on to display without truncation/clipping, as would occur with e.g. the iPhone X sensor notch. As this API was added in iOS 11, we place it behind a runtime guard checking OS level. Until the runtime support for @avialable lands in the next Fuchsia buildtools rev, ignore -Wunguarded-availability-new around the safe area insets check and use an FML runtime check instead.
1 parent b8fc6b7 commit 277bfe6

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ @implementation FlutterViewController {
7777
bool _platformSupportsTouchTypes;
7878
bool _platformSupportsTouchPressure;
7979
bool _platformSupportsTouchOrientationAndTilt;
80+
bool _platformSupportsSafeAreaInsets;
8081
BOOL _initialized;
8182
BOOL _connected;
8283
}
@@ -125,6 +126,7 @@ - (void)performCommonViewControllerInitialization {
125126
_platformSupportsTouchTypes = fml::IsPlatformVersionAtLeast(9);
126127
_platformSupportsTouchPressure = fml::IsPlatformVersionAtLeast(9);
127128
_platformSupportsTouchOrientationAndTilt = fml::IsPlatformVersionAtLeast(9, 1);
129+
_platformSupportsSafeAreaInsets = fml::IsPlatformVersionAtLeast(11, 0);
128130

129131
_orientationPreferences = UIInterfaceOrientationMaskAll;
130132
_statusBarStyle = UIStatusBarStyleDefault;
@@ -601,7 +603,20 @@ - (void)viewDidLayoutSubviews {
601603
_viewportMetrics.device_pixel_ratio = scale;
602604
_viewportMetrics.physical_width = viewSize.width * scale;
603605
_viewportMetrics.physical_height = viewSize.height * scale;
604-
_viewportMetrics.physical_padding_top = [self statusBarPadding] * scale;
606+
607+
// TODO(cbracken) once clang toolchain compiler-rt has been updated, replace with
608+
// if (@available(iOS 11, *)) {
609+
if (_platformSupportsSafeAreaInsets) {
610+
#pragma clang diagnostic push
611+
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
612+
_viewportMetrics.physical_padding_top = self.view.safeAreaInsets.top * scale;
613+
_viewportMetrics.physical_padding_left = self.view.safeAreaInsets.left * scale;
614+
_viewportMetrics.physical_padding_right = self.view.safeAreaInsets.right * scale;
615+
_viewportMetrics.physical_padding_bottom = self.view.safeAreaInsets.bottom * scale;
616+
#pragma clang diagnostic pop
617+
} else {
618+
_viewportMetrics.physical_padding_top = [self statusBarPadding] * scale;
619+
}
605620
[self updateViewportMetrics];
606621

607622
// This must run after updateViewportMetrics so that the surface creation tasks are queued after

0 commit comments

Comments
 (0)