mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Landscape orientation.
This commit is contained in:
parent
5adcbac5ef
commit
b5d5822b7b
3 changed files with 48 additions and 26 deletions
|
@ -1,13 +1,13 @@
|
|||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol ConversationCollectionViewDelegate <NSObject>
|
||||
|
||||
- (void)collectionViewWillChangeLayout;
|
||||
- (void)collectionViewDidChangeLayout;
|
||||
- (void)collectionViewWillChangeSizeFrom:(CGSize)oldSize to:(CGSize)newSize;
|
||||
- (void)collectionViewDidChangeSizeFrom:(CGSize)oldSize to:(CGSize)newSize;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ConversationCollectionView.h"
|
||||
|
@ -24,13 +24,15 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
// hacks in the conversation view's code.
|
||||
return;
|
||||
}
|
||||
BOOL isChanging = !CGSizeEqualToSize(frame.size, self.frame.size);
|
||||
CGSize oldSize = self.frame.size;
|
||||
CGSize newSize = frame.size;
|
||||
BOOL isChanging = !CGSizeEqualToSize(oldSize, newSize);
|
||||
if (isChanging) {
|
||||
[self.layoutDelegate collectionViewWillChangeLayout];
|
||||
[self.layoutDelegate collectionViewWillChangeSizeFrom:oldSize to:newSize];
|
||||
}
|
||||
[super setFrame:frame];
|
||||
if (isChanging) {
|
||||
[self.layoutDelegate collectionViewDidChangeLayout];
|
||||
[self.layoutDelegate collectionViewDidChangeSizeFrom:oldSize to:newSize];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,13 +50,15 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
// hacks in the conversation view's code.
|
||||
return;
|
||||
}
|
||||
BOOL isChanging = !CGSizeEqualToSize(bounds.size, self.bounds.size);
|
||||
CGSize oldSize = self.bounds.size;
|
||||
CGSize newSize = bounds.size;
|
||||
BOOL isChanging = !CGSizeEqualToSize(oldSize, newSize);
|
||||
if (isChanging) {
|
||||
[self.layoutDelegate collectionViewWillChangeLayout];
|
||||
[self.layoutDelegate collectionViewWillChangeSizeFrom:oldSize to:newSize];
|
||||
}
|
||||
[super setBounds:bounds];
|
||||
if (isChanging) {
|
||||
[self.layoutDelegate collectionViewDidChangeLayout];
|
||||
[self.layoutDelegate collectionViewDidChangeSizeFrom:oldSize to:newSize];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -563,6 +563,9 @@ typedef enum : NSUInteger {
|
|||
self.layout.delegate = self;
|
||||
// We use the root view bounds as the initial frame for the collection
|
||||
// view so that its contents can be laid out immediately.
|
||||
//
|
||||
// TODO: To avoid relayout, it'd be better to take into account safeAreaInsets,
|
||||
// but they're not yet set when this method is called.
|
||||
_collectionView =
|
||||
[[ConversationCollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:self.layout];
|
||||
self.collectionView.layoutDelegate = self;
|
||||
|
@ -1621,11 +1624,8 @@ typedef enum : NSUInteger {
|
|||
{
|
||||
OWSLogInfo(@"didChangePreferredContentSize");
|
||||
|
||||
// Evacuate cached cell sizes.
|
||||
for (id<ConversationViewItem> viewItem in self.viewItems) {
|
||||
[viewItem clearCachedLayoutState];
|
||||
}
|
||||
[self resetContentAndLayout];
|
||||
[self resetForSizeOrOrientationChange];
|
||||
|
||||
[self.inputToolbar updateFontSizes];
|
||||
}
|
||||
|
||||
|
@ -4218,18 +4218,18 @@ typedef enum : NSUInteger {
|
|||
|
||||
#pragma mark - ConversationCollectionViewDelegate
|
||||
|
||||
- (void)collectionViewWillChangeLayout
|
||||
- (void)collectionViewWillChangeSizeFrom:(CGSize)oldSize to:(CGSize)newSize
|
||||
{
|
||||
OWSAssertIsOnMainThread();
|
||||
}
|
||||
|
||||
- (void)collectionViewDidChangeLayout
|
||||
- (void)collectionViewDidChangeSizeFrom:(CGSize)oldSize to:(CGSize)newSize
|
||||
{
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
[self updateLastVisibleSortId];
|
||||
self.conversationStyle.viewWidth = self.collectionView.width;
|
||||
[self.collectionView.collectionViewLayout invalidateLayout];
|
||||
|
||||
[self resetForSizeOrOrientationChange];
|
||||
}
|
||||
|
||||
#pragma mark - View Items
|
||||
|
@ -4764,13 +4764,14 @@ typedef enum : NSUInteger {
|
|||
{
|
||||
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
|
||||
|
||||
self.conversationStyle.viewWidth = size.width;
|
||||
|
||||
for (id<ConversationViewItem> viewItem in self.viewItems) {
|
||||
[viewItem clearCachedLayoutState];
|
||||
}
|
||||
|
||||
[self resetContentAndLayout];
|
||||
__weak ConversationViewController *weakSelf = self;
|
||||
[coordinator
|
||||
animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
|
||||
// Do nothing.
|
||||
}
|
||||
completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
|
||||
[weakSelf resetForSizeOrOrientationChange];
|
||||
}];
|
||||
|
||||
// TODO: Ensure scroll state continuity?
|
||||
}
|
||||
|
@ -4783,6 +4784,23 @@ typedef enum : NSUInteger {
|
|||
[self ensureBannerState];
|
||||
}
|
||||
|
||||
- (void)resetForSizeOrOrientationChange
|
||||
{
|
||||
self.scrollContinuity = kScrollContinuityBottom;
|
||||
|
||||
self.conversationStyle.viewWidth = self.collectionView.width;
|
||||
// Evacuate cached cell sizes.
|
||||
for (id<ConversationViewItem> viewItem in self.viewItems) {
|
||||
[viewItem clearCachedLayoutState];
|
||||
}
|
||||
[self.collectionView.collectionViewLayout invalidateLayout];
|
||||
[self.collectionView reloadData];
|
||||
if (self.viewHasEverAppeared) {
|
||||
// Try to update the lastKnownDistanceFromBottom; the content size may have changed.
|
||||
[self updateLastKnownDistanceFromBottom];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
Loading…
Reference in a new issue