mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Fix input toolbar margins issue.
This commit is contained in:
parent
8d87449986
commit
18c890bb95
5 changed files with 78 additions and 6 deletions
|
@ -47,7 +47,7 @@
|
|||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>2.34.0.14</string>
|
||||
<string>2.34.0.20</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LOGS_EMAIL</key>
|
||||
|
|
|
@ -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
|
||||
|
@ -53,6 +53,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
- (void)updateFontSizes;
|
||||
|
||||
- (void)updateLayoutWithIsLandscape:(BOOL)isLandscape safeAreaInsets:(UIEdgeInsets)safeAreaInsets;
|
||||
|
||||
#pragma mark - Voice Memo
|
||||
|
||||
- (void)ensureTextViewHeight;
|
||||
|
|
|
@ -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"
|
||||
|
@ -53,6 +53,9 @@ 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) BOOL isLandscapeLayout;
|
||||
@property (nonatomic) UIEdgeInsets receivedSafeAreaInsets;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -68,6 +71,8 @@ const CGFloat kMaxTextViewHeight = 98;
|
|||
self = [super initWithFrame:CGRectZero];
|
||||
|
||||
_conversationStyle = conversationStyle;
|
||||
_isLandscapeLayout = NO;
|
||||
_receivedSafeAreaInsets = UIEdgeInsetsZero;
|
||||
|
||||
if (self) {
|
||||
[self createContents];
|
||||
|
@ -163,7 +168,18 @@ const CGFloat kMaxTextViewHeight = 98;
|
|||
self.contentRows.axis = UILayoutConstraintAxisVertical;
|
||||
|
||||
[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];
|
||||
}
|
||||
|
@ -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
|
||||
{
|
||||
switch (sender.state) {
|
||||
|
|
|
@ -747,6 +747,7 @@ typedef enum : NSUInteger {
|
|||
NSTimeInterval appearenceDuration = CACurrentMediaTime() - self.viewControllerCreatedAt;
|
||||
OWSLogVerbose(@"First viewWillAppear took: %.2fms", appearenceDuration * 1000);
|
||||
}
|
||||
[self updateInputToolbarLayout];
|
||||
}
|
||||
|
||||
- (NSArray<id<ConversationViewItem>> *)viewItems
|
||||
|
@ -1249,6 +1250,8 @@ 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,6 +4847,8 @@ typedef enum : NSUInteger {
|
|||
// new size.
|
||||
[strongSelf resetForSizeOrOrientationChange];
|
||||
|
||||
[strongSelf updateInputToolbarLayout];
|
||||
|
||||
if (lastVisibleIndexPath) {
|
||||
[strongSelf.collectionView scrollToItemAtIndexPath:lastVisibleIndexPath
|
||||
atScrollPosition:UICollectionViewScrollPositionBottom
|
||||
|
@ -4876,6 +4881,24 @@ 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
|
||||
{
|
||||
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
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
<key>CFBundleShortVersionString</key>
|
||||
<string>2.34.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>2.34.0.14</string>
|
||||
<string>2.34.0.20</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
|
|
Loading…
Reference in a new issue