From 285c6840ab5e57e5f65bb41f3c39d327aa423728 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 31 Oct 2017 14:30:07 -0700 Subject: [PATCH] Support iPhone X safe area insets (flutter/engine#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. --- .../framework/Source/FlutterViewController.mm | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 855283f623..0f088470a4 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -77,6 +77,7 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse { bool _platformSupportsTouchTypes; bool _platformSupportsTouchPressure; bool _platformSupportsTouchOrientationAndTilt; + bool _platformSupportsSafeAreaInsets; BOOL _initialized; BOOL _connected; } @@ -125,6 +126,7 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse { _platformSupportsTouchTypes = fml::IsPlatformVersionAtLeast(9); _platformSupportsTouchPressure = fml::IsPlatformVersionAtLeast(9); _platformSupportsTouchOrientationAndTilt = fml::IsPlatformVersionAtLeast(9, 1); + _platformSupportsSafeAreaInsets = fml::IsPlatformVersionAtLeast(11, 0); _orientationPreferences = UIInterfaceOrientationMaskAll; _statusBarStyle = UIStatusBarStyleDefault; @@ -601,7 +603,20 @@ static inline blink::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* to _viewportMetrics.device_pixel_ratio = scale; _viewportMetrics.physical_width = viewSize.width * scale; _viewportMetrics.physical_height = viewSize.height * scale; - _viewportMetrics.physical_padding_top = [self statusBarPadding] * scale; + + // TODO(cbracken) once clang toolchain compiler-rt has been updated, replace with + // if (@available(iOS 11, *)) { + if (_platformSupportsSafeAreaInsets) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunguarded-availability-new" + _viewportMetrics.physical_padding_top = self.view.safeAreaInsets.top * scale; + _viewportMetrics.physical_padding_left = self.view.safeAreaInsets.left * scale; + _viewportMetrics.physical_padding_right = self.view.safeAreaInsets.right * scale; + _viewportMetrics.physical_padding_bottom = self.view.safeAreaInsets.bottom * scale; +#pragma clang diagnostic pop + } else { + _viewportMetrics.physical_padding_top = [self statusBarPadding] * scale; + } [self updateViewportMetrics]; // This must run after updateViewportMetrics so that the surface creation tasks are queued after