Skip to content

Commit

Permalink
Use @available checks for iOS 11 features (flutter#4596)
Browse files Browse the repository at this point in the history
Guard code that deals with iOS safe area insets behind an @available
check.

This cleans up some old TODOs from before out clang toolchain supported
@available.
  • Loading branch information
cbracken authored Jan 26, 2018
1 parent f937d93 commit 89b6d43
Showing 1 changed file with 5 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ @implementation FlutterViewController {
bool _platformSupportsTouchTypes;
bool _platformSupportsTouchPressure;
bool _platformSupportsTouchOrientationAndTilt;
bool _platformSupportsSafeAreaInsets;
BOOL _initialized;
BOOL _connected;
}
Expand Down Expand Up @@ -130,7 +129,6 @@ - (void)performCommonViewControllerInitialization {
_platformSupportsTouchTypes = fml::IsPlatformVersionAtLeast(9);
_platformSupportsTouchPressure = fml::IsPlatformVersionAtLeast(9);
_platformSupportsTouchOrientationAndTilt = fml::IsPlatformVersionAtLeast(9, 1);
_platformSupportsSafeAreaInsets = fml::IsPlatformVersionAtLeast(11, 0);

_orientationPreferences = UIInterfaceOrientationMaskAll;
_statusBarStyle = UIStatusBarStyleDefault;
Expand Down Expand Up @@ -621,28 +619,21 @@ - (void)viewDidLayoutSubviews {
}

- (void)viewSafeAreaInsetsDidChange {
if (_platformSupportsSafeAreaInsets) {
[self updateViewportPadding];
[self updateViewportMetrics];
[super viewSafeAreaInsetsDidChange];
}
[self updateViewportPadding];
[self updateViewportMetrics];
[super viewSafeAreaInsetsDidChange];
}

// Updates _viewportMetrics physical padding.
//
// Viewport padding represents the iOS safe area insets.
- (void)updateViewportPadding {
CGFloat scale = [UIScreen mainScreen].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"
if (@available(iOS 11, *)) {
_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;
}
Expand Down Expand Up @@ -828,11 +819,8 @@ - (BOOL)isAlwaysUse24HourFormat {

- (void)handleStatusBarTouches:(UIEvent*)event {
CGFloat standardStatusBarHeight = kStandardStatusBarHeight;
if (_platformSupportsSafeAreaInsets) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
if (@available(iOS 11, *)) {
standardStatusBarHeight = self.view.safeAreaInsets.top;
#pragma clang diagnostic pop
}

// If the status bar is double-height, don't handle status bar taps. iOS
Expand Down

0 comments on commit 89b6d43

Please sign in to comment.