Remove safe area insets hack in conversation input toolbar.

pull/1/head
Matthew Chen 6 years ago
parent 70359b1843
commit 70775e7852

@ -54,8 +54,6 @@ NS_ASSUME_NONNULL_BEGIN
- (void)updateFontSizes;
- (void)updateLayoutWithSafeAreaInsets:(UIEdgeInsets)safeAreaInsets;
#pragma mark - Voice Memo
- (void)ensureTextViewHeight;

@ -69,8 +69,6 @@ const CGFloat kMaxTextViewHeight = 98;
@property (nonatomic, nullable) UILabel *recordingLabel;
@property (nonatomic) BOOL isRecordingVoiceMemo;
@property (nonatomic) CGPoint voiceMemoGestureStartLocation;
@property (nonatomic, nullable) NSArray<NSLayoutConstraint *> *layoutContraints;
@property (nonatomic) UIEdgeInsets receivedSafeAreaInsets;
@property (nonatomic, nullable) InputLinkPreview *inputLinkPreview;
@property (nonatomic) BOOL wasLinkPreviewCancelled;
@property (nonatomic, nullable, weak) LinkPreviewView *linkPreviewView;
@ -86,7 +84,6 @@ const CGFloat kMaxTextViewHeight = 98;
self = [super initWithFrame:CGRectZero];
_conversationStyle = conversationStyle;
_receivedSafeAreaInsets = UIEdgeInsetsZero;
if (self) {
[self createContents];
@ -202,6 +199,8 @@ const CGFloat kMaxTextViewHeight = 98;
[self addSubview:self.hStack];
[self.hStack autoPinEdgeToSuperviewEdge:ALEdgeTop];
[self.hStack autoPinEdgeToSuperviewSafeArea:ALEdgeBottom];
[self.hStack autoPinEdgeToSuperviewSafeArea:ALEdgeLeading];
[self.hStack autoPinEdgeToSuperviewSafeArea:ALEdgeTrailing];
[self.hStack setContentHuggingHorizontalLow];
[self.hStack setCompressionResistanceHorizontalLow];
@ -371,35 +370,6 @@ 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.hStack autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:self.receivedSafeAreaInsets.left],
[self.hStack autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:self.receivedSafeAreaInsets.right],
];
}
- (void)updateLayoutWithSafeAreaInsets:(UIEdgeInsets)safeAreaInsets
{
BOOL didChange = !UIEdgeInsetsEqualToEdgeInsets(self.receivedSafeAreaInsets, safeAreaInsets);
BOOL hasLayout = self.layoutContraints != nil;
self.receivedSafeAreaInsets = safeAreaInsets;
if (didChange || !hasLayout) {
[self updateContentLayout];
}
}
- (void)handleLongPress:(UIGestureRecognizer *)sender
{
switch (sender.state) {

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

Loading…
Cancel
Save