From bf0d92acfb695b9d7d393b6c5767db3db15179d1 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 10 Jan 2019 09:37:33 -0500 Subject: [PATCH 1/2] Landscape layout in gif picker. --- Signal/src/ViewControllers/GifPicker/GifPickerLayout.swift | 6 ++---- .../ViewControllers/GifPicker/GifPickerViewController.swift | 6 ++++++ SignalMessaging/utils/OWSWindowManager.m | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Signal/src/ViewControllers/GifPicker/GifPickerLayout.swift b/Signal/src/ViewControllers/GifPicker/GifPickerLayout.swift index 2743a073e..7a6bde857 100644 --- a/Signal/src/ViewControllers/GifPicker/GifPickerLayout.swift +++ b/Signal/src/ViewControllers/GifPicker/GifPickerLayout.swift @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // import Foundation @@ -60,9 +60,7 @@ class GifPickerLayout: UICollectionViewLayout { // We use 2 or 3 columns, depending on the device. // 2 columns will show fewer GIFs at a time, // but use less network & be a more responsive experience. - let screenSize = UIScreen.main.bounds.size - let screenWidth = min(screenSize.width, screenSize.height) - let columnCount = UInt(max(2, screenWidth / 130)) + let columnCount = UInt(max(2, collectionView.width() / 130)) let totalViewWidth = UInt(collectionView.width()) let hTotalWhitespace = (2 * hInset) + (hSpacing * (columnCount - 1)) diff --git a/Signal/src/ViewControllers/GifPicker/GifPickerViewController.swift b/Signal/src/ViewControllers/GifPicker/GifPickerViewController.swift index 41025af38..34a595745 100644 --- a/Signal/src/ViewControllers/GifPicker/GifPickerViewController.swift +++ b/Signal/src/ViewControllers/GifPicker/GifPickerViewController.swift @@ -518,4 +518,10 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect } tryToSearch() } + + public override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + + layout.invalidateLayout() + } } diff --git a/SignalMessaging/utils/OWSWindowManager.m b/SignalMessaging/utils/OWSWindowManager.m index ff8d1888d..5731de17d 100644 --- a/SignalMessaging/utils/OWSWindowManager.m +++ b/SignalMessaging/utils/OWSWindowManager.m @@ -490,7 +490,7 @@ const UIWindowLevel UIWindowLevel_MessageActions(void) OWSLogInfo(@"showing root window."); } - // By calling makeKeyAndVisible we ensure the rootViewController becomes firt responder. + // By calling makeKeyAndVisible we ensure the rootViewController becomes first responder. // In the normal case, that means the SignalViewController will call `becomeFirstResponder` // on the vc on top of its navigation stack. [self.rootWindow makeKeyAndVisible]; From cb228bdd29b2c2ba23234db76d06faecadfdc0fd Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 10 Jan 2019 09:45:48 -0500 Subject: [PATCH 2/2] Fix conversation view keyboard. --- .../ConversationViewController.m | 50 +++++++++++++++++-- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 0398deadc..6f5c625c1 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -367,10 +367,31 @@ typedef enum : NSUInteger { selector:@selector(profileWhitelistDidChange:) name:kNSNotificationName_ProfileWhitelistDidChange object:nil]; + // Keyboard events. + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillShow:) + name:UIKeyboardWillShowNotification + object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardDidShow:) + name:UIKeyboardDidShowNotification + object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillHide:) + name:UIKeyboardWillHideNotification + object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardDidHide:) + name:UIKeyboardDidHideNotification + object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardDidChangeFrame:) + name:UIKeyboardDidChangeFrameNotification + object:nil]; } - (BOOL)isGroupConversation @@ -3589,12 +3610,33 @@ typedef enum : NSUInteger { }); } +- (void)keyboardWillShow:(NSNotification *)notification +{ + [self handleKeyboardNotification:notification]; +} + +- (void)keyboardDidShow:(NSNotification *)notification +{ + [self handleKeyboardNotification:notification]; +} + +- (void)keyboardWillHide:(NSNotification *)notification +{ + [self handleKeyboardNotification:notification]; +} + +- (void)keyboardDidHide:(NSNotification *)notification +{ + [self handleKeyboardNotification:notification]; +} + - (void)keyboardWillChangeFrame:(NSNotification *)notification { - // `willChange` is the correct keyboard notifiation to observe when adjusting contentInset - // in lockstep with the keyboard presentation animation. `didChange` results in the contentInset - // not adjusting until after the keyboard is fully up. - OWSLogVerbose(@""); + [self handleKeyboardNotification:notification]; +} + +- (void)keyboardDidChangeFrame:(NSNotification *)notification +{ [self handleKeyboardNotification:notification]; }