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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ This release includes many iOS 11 and iPhone X hot fixes.
- Exposing auto-completion variables. By @dzenbot (#561)

##### Hot Fixes & Enhancements:
- Fixed the text input not being interactive on iOS. Making `SLKTextInputbar` a UIView subclass instead of `UIToolbar`. By @dzenbot (#624)
- Fixed the text input not being interactive on iOS 11. By @dzenbot (#624)
- Fixed iPhone X issue where the text input bar wouldn't expand to the bottom of the screen, below the home indicator. (#619)
- Fixed scroll view content inset adjustments on iOS 11. By @gim- (#643)
- Fixed compiler error in example app. By @BasThomas (#629)
- Fixed content offset for keyboard when uninverted. By @ZAndyL (#542)
Expand Down
2 changes: 1 addition & 1 deletion Source/SLKTextInputbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ typedef NS_ENUM(NSUInteger, SLKCounterPosition) {
NS_ASSUME_NONNULL_BEGIN

/** @name A custom tool bar encapsulating messaging controls. */
@interface SLKTextInputbar : UIView
@interface SLKTextInputbar : UIToolbar

Choose a reason for hiding this comment

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

@dzenbot @hipwelljo regression?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dzenbot intentionally reverted that to UIToolbar

Choose a reason for hiding this comment

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

I see, thanks

Copy link

Choose a reason for hiding this comment

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

We did revert it back tho, in https://github.com/slackhq/SlackTextViewController/pull/619/files#diff-19e165dd48b58feca5abccfcedc9efd8R29

Using UIToolbar was still better for being able to extend the view to the very bottom on iPhone X. I would have liked moving away from UIToolbar but this seemed like the quickest and safest way of being iPhone X complaint.


/** The centered text input view.
The maximum number of lines is configured by default, to best fit each devices dimensions.
Expand Down
20 changes: 5 additions & 15 deletions Source/SLKTextInputbar.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

@interface SLKTextInputbar ()

@property (nonatomic, strong) UIView *hairlineView;

@property (nonatomic, strong) NSLayoutConstraint *textViewBottomMarginC;
@property (nonatomic, strong) NSLayoutConstraint *contentViewHC;
@property (nonatomic, strong) NSLayoutConstraint *leftButtonWC;
Expand Down Expand Up @@ -85,15 +83,17 @@ - (void)slk_commonInit
self.autoHideRightButton = YES;
self.editorContentViewHeight = 38.0;
self.contentInset = UIEdgeInsetsMake(5.0, 8.0, 5.0, 8.0);
self.backgroundColor = [UIColor colorWithRed:247.0/255.0 green:247.0/255.0 blue:247.0/255.0 alpha:1.0]; //UIToolbar native bar tint color

// Since iOS 11, it is required to call -layoutSubviews before adding custom subviews
// so private UIToolbar subviews don't interfere on the touch hierarchy
[self layoutSubviews];

[self addSubview:self.editorContentView];
[self addSubview:self.leftButton];
[self addSubview:self.rightButton];
[self addSubview:self.textView];
[self addSubview:self.charCountLabel];
[self addSubview:self.contentView];
[self addSubview:self.hairlineView];

[self slk_setupViewConstraints];
[self slk_updateConstraintConstants];
Expand Down Expand Up @@ -156,16 +156,6 @@ - (SLKTextView *)textView
return _textView;
}

- (UIView *)hairlineView
{
if (!_hairlineView) {
_hairlineView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, [UIScreen mainScreen].bounds.size.width, 0.5)];
_hairlineView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleBottomMargin;
_hairlineView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
}
return _hairlineView;
}

- (UIView *)contentView
{
if (!_contentView) {
Expand Down Expand Up @@ -422,7 +412,7 @@ - (NSUInteger)slk_defaultNumberOfLines

- (void)setBackgroundColor:(UIColor *)color
{
[super setBackgroundColor:color];
self.barTintColor = color;

self.editorContentView.backgroundColor = color;
}
Expand Down
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 @@ -417,7 +424,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 @@ -428,6 +435,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 @@ -892,6 +906,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 @@ -2237,7 +2255,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