Fix input toolbar margins issue.

This commit is contained in:
Matthew Chen 2019-01-11 09:24:24 -05:00
parent 8d87449986
commit 18c890bb95
5 changed files with 78 additions and 6 deletions

View file

@ -47,7 +47,7 @@
</dict> </dict>
</array> </array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>2.34.0.14</string> <string>2.34.0.20</string>
<key>ITSAppUsesNonExemptEncryption</key> <key>ITSAppUsesNonExemptEncryption</key>
<false/> <false/>
<key>LOGS_EMAIL</key> <key>LOGS_EMAIL</key>

View file

@ -1,5 +1,5 @@
// //
// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // Copyright (c) 2019 Open Whisper Systems. All rights reserved.
// //
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -53,6 +53,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)updateFontSizes; - (void)updateFontSizes;
- (void)updateLayoutWithIsLandscape:(BOOL)isLandscape safeAreaInsets:(UIEdgeInsets)safeAreaInsets;
#pragma mark - Voice Memo #pragma mark - Voice Memo
- (void)ensureTextViewHeight; - (void)ensureTextViewHeight;

View file

@ -1,5 +1,5 @@
// //
// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // Copyright (c) 2019 Open Whisper Systems. All rights reserved.
// //
#import "ConversationInputToolbar.h" #import "ConversationInputToolbar.h"
@ -53,6 +53,9 @@ const CGFloat kMaxTextViewHeight = 98;
@property (nonatomic, nullable) UILabel *recordingLabel; @property (nonatomic, nullable) UILabel *recordingLabel;
@property (nonatomic) BOOL isRecordingVoiceMemo; @property (nonatomic) BOOL isRecordingVoiceMemo;
@property (nonatomic) CGPoint voiceMemoGestureStartLocation; @property (nonatomic) CGPoint voiceMemoGestureStartLocation;
@property (nonatomic, nullable) NSArray<NSLayoutConstraint *> *layoutContraints;
@property (nonatomic) BOOL isLandscapeLayout;
@property (nonatomic) UIEdgeInsets receivedSafeAreaInsets;
@end @end
@ -68,6 +71,8 @@ const CGFloat kMaxTextViewHeight = 98;
self = [super initWithFrame:CGRectZero]; self = [super initWithFrame:CGRectZero];
_conversationStyle = conversationStyle; _conversationStyle = conversationStyle;
_isLandscapeLayout = NO;
_receivedSafeAreaInsets = UIEdgeInsetsZero;
if (self) { if (self) {
[self createContents]; [self createContents];
@ -163,7 +168,18 @@ const CGFloat kMaxTextViewHeight = 98;
self.contentRows.axis = UILayoutConstraintAxisVertical; self.contentRows.axis = UILayoutConstraintAxisVertical;
[self addSubview:self.contentRows]; [self addSubview:self.contentRows];
[self.contentRows autoPinEdgesToSuperviewEdges]; [self.contentRows autoPinEdgeToSuperviewEdge:ALEdgeTop];
[self.contentRows autoPinEdgeToSuperviewSafeArea:ALEdgeBottom];
// See comments on updateContentLayout:.
if (@available(iOS 11, *)) {
self.contentRows.insetsLayoutMarginsFromSafeArea = NO;
self.composeRow.insetsLayoutMarginsFromSafeArea = NO;
self.insetsLayoutMarginsFromSafeArea = NO;
}
self.contentRows.preservesSuperviewLayoutMargins = NO;
self.composeRow.preservesSuperviewLayoutMargins = NO;
self.preservesSuperviewLayoutMargins = NO;
[self ensureShouldShowVoiceMemoButtonAnimated:NO doLayout:NO]; [self ensureShouldShowVoiceMemoButtonAnimated:NO doLayout:NO];
} }
@ -322,6 +338,37 @@ const CGFloat kMaxTextViewHeight = 98;
} }
} }
// iOS doesn't always update the safeAreaInsets correctly & in a timely
// way for the inputAccessoryView after a orientation change. The best
// workaround appears to be to use the safeAreaInsets from
// ConversationViewController's view. ConversationViewController updates
// this input toolbar using updateLayoutWithIsLandscape:.
- (void)updateContentLayout
{
if (self.layoutContraints) {
[NSLayoutConstraint deactivateConstraints:self.layoutContraints];
}
self.layoutContraints = @[
[self.contentRows autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:self.receivedSafeAreaInsets.left],
[self.contentRows autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:self.receivedSafeAreaInsets.right],
];
}
- (void)updateLayoutWithIsLandscape:(BOOL)isLandscape safeAreaInsets:(UIEdgeInsets)safeAreaInsets
{
BOOL didChange = (self.isLandscapeLayout != isLandscape
|| !UIEdgeInsetsEqualToEdgeInsets(self.receivedSafeAreaInsets, safeAreaInsets));
BOOL hasLayout = self.layoutContraints != nil;
self.isLandscapeLayout = isLandscape;
self.receivedSafeAreaInsets = safeAreaInsets;
if (didChange || !hasLayout) {
[self updateContentLayout];
}
}
- (void)handleLongPress:(UIGestureRecognizer *)sender - (void)handleLongPress:(UIGestureRecognizer *)sender
{ {
switch (sender.state) { switch (sender.state) {

View file

@ -747,6 +747,7 @@ typedef enum : NSUInteger {
NSTimeInterval appearenceDuration = CACurrentMediaTime() - self.viewControllerCreatedAt; NSTimeInterval appearenceDuration = CACurrentMediaTime() - self.viewControllerCreatedAt;
OWSLogVerbose(@"First viewWillAppear took: %.2fms", appearenceDuration * 1000); OWSLogVerbose(@"First viewWillAppear took: %.2fms", appearenceDuration * 1000);
} }
[self updateInputToolbarLayout];
} }
- (NSArray<id<ConversationViewItem>> *)viewItems - (NSArray<id<ConversationViewItem>> *)viewItems
@ -1249,6 +1250,8 @@ typedef enum : NSUInteger {
// Clear the "on open" state after the view has been presented. // Clear the "on open" state after the view has been presented.
self.actionOnOpen = ConversationViewActionNone; self.actionOnOpen = ConversationViewActionNone;
[self updateInputToolbarLayout];
} }
// `viewWillDisappear` is called whenever the view *starts* to disappear, // `viewWillDisappear` is called whenever the view *starts* to disappear,
@ -4844,6 +4847,8 @@ typedef enum : NSUInteger {
// new size. // new size.
[strongSelf resetForSizeOrOrientationChange]; [strongSelf resetForSizeOrOrientationChange];
[strongSelf updateInputToolbarLayout];
if (lastVisibleIndexPath) { if (lastVisibleIndexPath) {
[strongSelf.collectionView scrollToItemAtIndexPath:lastVisibleIndexPath [strongSelf.collectionView scrollToItemAtIndexPath:lastVisibleIndexPath
atScrollPosition:UICollectionViewScrollPositionBottom atScrollPosition:UICollectionViewScrollPositionBottom
@ -4876,6 +4881,24 @@ typedef enum : NSUInteger {
// Try to update the lastKnownDistanceFromBottom; the content size may have changed. // Try to update the lastKnownDistanceFromBottom; the content size may have changed.
[self updateLastKnownDistanceFromBottom]; [self updateLastKnownDistanceFromBottom];
} }
[self updateInputToolbarLayout];
}
- (void)viewSafeAreaInsetsDidChange
{
[super viewSafeAreaInsetsDidChange];
[self updateInputToolbarLayout];
}
- (void)updateInputToolbarLayout
{
BOOL isLandscape = self.view.width > self.view.height;
UIEdgeInsets safeAreaInsets = UIEdgeInsetsZero;
if (@available(iOS 11, *)) {
safeAreaInsets = self.view.safeAreaInsets;
}
[self.inputToolbar updateLayoutWithIsLandscape:isLandscape safeAreaInsets:safeAreaInsets];
} }
@end @end

View file

@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>2.34.0</string> <string>2.34.0</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>2.34.0.14</string> <string>2.34.0.20</string>
<key>ITSAppUsesNonExemptEncryption</key> <key>ITSAppUsesNonExemptEncryption</key>
<false/> <false/>
<key>NSAppTransportSecurity</key> <key>NSAppTransportSecurity</key>