Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Update bottom margin to accommodate iPhone X home indicator #619

Merged
merged 10 commits into from
Nov 2, 2017
22 changes: 20 additions & 2 deletions Source/SLKTextViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@ - (void)viewDidLayoutSubviews
[super viewDidLayoutSubviews];
}

- (void)viewSafeAreaInsetsDidChange
{
[super viewSafeAreaInsetsDidChange];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should still be wrapped in if (@available(iOS 11.0, *)) isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to. It's never called for older iOS versions, not by the system nor manually. If you run it on an iOS 10 device all is well. But it also wouldn't hurt to wrap it in that.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True


[self slk_updateViewConstraints];
}


#pragma mark - Getters

Expand Down Expand Up @@ -420,7 +427,7 @@ - (CGFloat)slk_appropriateKeyboardHeightFromRect:(CGRect)rect

- (CGFloat)slk_appropriateBottomMargin
{
// A bottom margin is required only if the view is extended out of it bounds
// A bottom margin is required if the view is extended out of it bounds
if ((self.edgesForExtendedLayout & UIRectEdgeBottom) > 0) {

UITabBar *tabBar = self.tabBarController.tabBar;
Expand All @@ -431,6 +438,13 @@ - (CGFloat)slk_appropriateBottomMargin
}
}

// A bottom margin is required for iPhone X
if (@available(iOS 11.0, *)) {
if (!self.textInputbar.isHidden) {
return self.view.safeAreaInsets.bottom;
}
}

return 0.0;
}

Expand Down Expand Up @@ -882,6 +896,10 @@ - (void)setTextInputbarHidden:(BOOL)hidden animated:(BOOL)animated
}

_textInputbar.hidden = hidden;

if (@available(iOS 11.0, *)) {
[self viewSafeAreaInsetsDidChange];
}

__weak typeof(self) weakSelf = self;

Expand Down Expand Up @@ -2227,7 +2245,7 @@ - (void)slk_setupViewConstraints
NSDictionary *views = @{@"scrollView": self.scrollViewProxy,
@"autoCompletionView": self.autoCompletionView,
@"typingIndicatorView": self.typingIndicatorProxyView,
@"textInputbar": self.textInputbar,
@"textInputbar": self.textInputbar
};

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[scrollView(0@750)][typingIndicatorView(0)]-0@999-[textInputbar(0)]|" options:0 metrics:nil views:views]];
Expand Down