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.
This commit is contained in:
Chris Bracken
2017-10-31 14:30:07 -07:00
committed by GitHub
parent 06355f7c80
commit 285c6840ab

View File

@@ -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