Skip to content

Commit 37f91f2

Browse files
hipwelljoIgnacio Romero Zurbuchen
authored and
Ignacio Romero Zurbuchen
committed
Update bottom margin to accommodate iPhone X home indicator (slackhq#619)
* Update bottom margin to accommodate iPhone X home indicator * Skips the bottom safe area when the textinputbar is hidden * Reverting slackhq#624 to be using UIToolbar again, specially for iPhone X compatibility so the bottom edge of the input bar expands to the bottom of the screen Fixes slackhq#619 * [skip-ci] updating changelog
1 parent 4dc83a1 commit 37f91f2

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ This release includes many iOS 11 and iPhone X hot fixes.
1010
- Exposing auto-completion variables. By @dzenbot (#561)
1111

1212
##### Hot Fixes & Enhancements:
13-
- Fixed the text input not being interactive on iOS. Making `SLKTextInputbar` a UIView subclass instead of `UIToolbar`. By @dzenbot (#624)
13+
- Fixed the text input not being interactive on iOS 11. By @dzenbot (#624)
14+
- Fixed iPhone X issue where the text input bar wouldn't expand to the bottom of the screen, below the home indicator. (#619)
1415
- Fixed scroll view content inset adjustments on iOS 11. By @gim- (#643)
1516
- Fixed compiler error in example app. By @BasThomas (#629)
1617
- Fixed content offset for keyboard when uninverted. By @ZAndyL (#542)

Source/SLKTextInputbar.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ typedef NS_ENUM(NSUInteger, SLKCounterPosition) {
2626
NS_ASSUME_NONNULL_BEGIN
2727

2828
/** @name A custom tool bar encapsulating messaging controls. */
29-
@interface SLKTextInputbar : UIView
29+
@interface SLKTextInputbar : UIToolbar
3030

3131
/** The centered text input view.
3232
The maximum number of lines is configured by default, to best fit each devices dimensions.

Source/SLKTextInputbar.m

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
@interface SLKTextInputbar ()
2121

22-
@property (nonatomic, strong) UIView *hairlineView;
23-
2422
@property (nonatomic, strong) NSLayoutConstraint *textViewBottomMarginC;
2523
@property (nonatomic, strong) NSLayoutConstraint *contentViewHC;
2624
@property (nonatomic, strong) NSLayoutConstraint *leftButtonWC;
@@ -85,15 +83,17 @@ - (void)slk_commonInit
8583
self.autoHideRightButton = YES;
8684
self.editorContentViewHeight = 38.0;
8785
self.contentInset = UIEdgeInsetsMake(5.0, 8.0, 5.0, 8.0);
88-
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
86+
87+
// Since iOS 11, it is required to call -layoutSubviews before adding custom subviews
88+
// so private UIToolbar subviews don't interfere on the touch hierarchy
89+
[self layoutSubviews];
8990

9091
[self addSubview:self.editorContentView];
9192
[self addSubview:self.leftButton];
9293
[self addSubview:self.rightButton];
9394
[self addSubview:self.textView];
9495
[self addSubview:self.charCountLabel];
9596
[self addSubview:self.contentView];
96-
[self addSubview:self.hairlineView];
9797

9898
[self slk_setupViewConstraints];
9999
[self slk_updateConstraintConstants];
@@ -156,16 +156,6 @@ - (SLKTextView *)textView
156156
return _textView;
157157
}
158158

159-
- (UIView *)hairlineView
160-
{
161-
if (!_hairlineView) {
162-
_hairlineView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, [UIScreen mainScreen].bounds.size.width, 0.5)];
163-
_hairlineView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleBottomMargin;
164-
_hairlineView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
165-
}
166-
return _hairlineView;
167-
}
168-
169159
- (UIView *)contentView
170160
{
171161
if (!_contentView) {
@@ -422,7 +412,7 @@ - (NSUInteger)slk_defaultNumberOfLines
422412

423413
- (void)setBackgroundColor:(UIColor *)color
424414
{
425-
[super setBackgroundColor:color];
415+
self.barTintColor = color;
426416

427417
self.editorContentView.backgroundColor = color;
428418
}

Source/SLKTextViewController.m

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ - (void)viewDidLayoutSubviews
237237
[super viewDidLayoutSubviews];
238238
}
239239

240+
- (void)viewSafeAreaInsetsDidChange
241+
{
242+
[super viewSafeAreaInsetsDidChange];
243+
244+
[self slk_updateViewConstraints];
245+
}
246+
240247

241248
#pragma mark - Getters
242249

@@ -417,7 +424,7 @@ - (CGFloat)slk_appropriateKeyboardHeightFromRect:(CGRect)rect
417424

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

423430
UITabBar *tabBar = self.tabBarController.tabBar;
@@ -428,6 +435,13 @@ - (CGFloat)slk_appropriateBottomMargin
428435
}
429436
}
430437

438+
// A bottom margin is required for iPhone X
439+
if (@available(iOS 11.0, *)) {
440+
if (!self.textInputbar.isHidden) {
441+
return self.view.safeAreaInsets.bottom;
442+
}
443+
}
444+
431445
return 0.0;
432446
}
433447

@@ -892,6 +906,10 @@ - (void)setTextInputbarHidden:(BOOL)hidden animated:(BOOL)animated
892906
}
893907

894908
_textInputbar.hidden = hidden;
909+
910+
if (@available(iOS 11.0, *)) {
911+
[self viewSafeAreaInsetsDidChange];
912+
}
895913

896914
__weak typeof(self) weakSelf = self;
897915

@@ -2237,7 +2255,7 @@ - (void)slk_setupViewConstraints
22372255
NSDictionary *views = @{@"scrollView": self.scrollViewProxy,
22382256
@"autoCompletionView": self.autoCompletionView,
22392257
@"typingIndicatorView": self.typingIndicatorProxyView,
2240-
@"textInputbar": self.textInputbar,
2258+
@"textInputbar": self.textInputbar
22412259
};
22422260

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

0 commit comments

Comments
 (0)