Landscape orientation.

pull/1/head
Matthew Chen 6 years ago
parent 5adcbac5ef
commit b5d5822b7b

@ -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 NS_ASSUME_NONNULL_BEGIN
@protocol ConversationCollectionViewDelegate <NSObject> @protocol ConversationCollectionViewDelegate <NSObject>
- (void)collectionViewWillChangeLayout; - (void)collectionViewWillChangeSizeFrom:(CGSize)oldSize to:(CGSize)newSize;
- (void)collectionViewDidChangeLayout; - (void)collectionViewDidChangeSizeFrom:(CGSize)oldSize to:(CGSize)newSize;
@end @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" #import "ConversationCollectionView.h"
@ -24,13 +24,15 @@ NS_ASSUME_NONNULL_BEGIN
// hacks in the conversation view's code. // hacks in the conversation view's code.
return; 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) { if (isChanging) {
[self.layoutDelegate collectionViewWillChangeLayout]; [self.layoutDelegate collectionViewWillChangeSizeFrom:oldSize to:newSize];
} }
[super setFrame:frame]; [super setFrame:frame];
if (isChanging) { 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. // hacks in the conversation view's code.
return; 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) { if (isChanging) {
[self.layoutDelegate collectionViewWillChangeLayout]; [self.layoutDelegate collectionViewWillChangeSizeFrom:oldSize to:newSize];
} }
[super setBounds:bounds]; [super setBounds:bounds];
if (isChanging) { if (isChanging) {
[self.layoutDelegate collectionViewDidChangeLayout]; [self.layoutDelegate collectionViewDidChangeSizeFrom:oldSize to:newSize];
} }
} }

@ -563,6 +563,9 @@ typedef enum : NSUInteger {
self.layout.delegate = self; self.layout.delegate = self;
// We use the root view bounds as the initial frame for the collection // We use the root view bounds as the initial frame for the collection
// view so that its contents can be laid out immediately. // 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 = _collectionView =
[[ConversationCollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:self.layout]; [[ConversationCollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:self.layout];
self.collectionView.layoutDelegate = self; self.collectionView.layoutDelegate = self;
@ -1621,11 +1624,8 @@ typedef enum : NSUInteger {
{ {
OWSLogInfo(@"didChangePreferredContentSize"); OWSLogInfo(@"didChangePreferredContentSize");
// Evacuate cached cell sizes. [self resetForSizeOrOrientationChange];
for (id<ConversationViewItem> viewItem in self.viewItems) {
[viewItem clearCachedLayoutState];
}
[self resetContentAndLayout];
[self.inputToolbar updateFontSizes]; [self.inputToolbar updateFontSizes];
} }
@ -4218,18 +4218,18 @@ typedef enum : NSUInteger {
#pragma mark - ConversationCollectionViewDelegate #pragma mark - ConversationCollectionViewDelegate
- (void)collectionViewWillChangeLayout - (void)collectionViewWillChangeSizeFrom:(CGSize)oldSize to:(CGSize)newSize
{ {
OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();
} }
- (void)collectionViewDidChangeLayout - (void)collectionViewDidChangeSizeFrom:(CGSize)oldSize to:(CGSize)newSize
{ {
OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();
[self updateLastVisibleSortId]; [self updateLastVisibleSortId];
self.conversationStyle.viewWidth = self.collectionView.width;
[self.collectionView.collectionViewLayout invalidateLayout]; [self resetForSizeOrOrientationChange];
} }
#pragma mark - View Items #pragma mark - View Items
@ -4764,13 +4764,14 @@ typedef enum : NSUInteger {
{ {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
self.conversationStyle.viewWidth = size.width; __weak ConversationViewController *weakSelf = self;
[coordinator
for (id<ConversationViewItem> viewItem in self.viewItems) { animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
[viewItem clearCachedLayoutState]; // Do nothing.
} }
completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
[self resetContentAndLayout]; [weakSelf resetForSizeOrOrientationChange];
}];
// TODO: Ensure scroll state continuity? // TODO: Ensure scroll state continuity?
} }
@ -4783,6 +4784,23 @@ typedef enum : NSUInteger {
[self ensureBannerState]; [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 @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

Loading…
Cancel
Save