From dafd63db5ffd3cfcc87fbfbc0718ad1ea2325cfd Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Fri, 30 Sep 2022 13:54:29 +1000 Subject: [PATCH] fix join open group screen --- Session/Open Groups/JoinOpenGroupVC.swift | 17 ++++++++++++++--- .../Open Groups/OpenGroupSuggestionGrid.swift | 7 ++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Session/Open Groups/JoinOpenGroupVC.swift b/Session/Open Groups/JoinOpenGroupVC.swift index c6fb9c912..29fd90510 100644 --- a/Session/Open Groups/JoinOpenGroupVC.swift +++ b/Session/Open Groups/JoinOpenGroupVC.swift @@ -88,6 +88,13 @@ final class JoinOpenGroupVC: BaseVC, UIPageViewControllerDataSource, UIPageViewC enterURLVC.constrainHeight(to: height) scanQRCodePlaceholderVC.constrainHeight(to: height) } + + override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { + super.viewWillTransition(to: size, with: coordinator) + enterURLVC.viewWidth?.constant = size.width + enterURLVC.suggestionGrid.refreshLayout(with: size.width - 2 * Values.largeSpacing) + scanQRCodePlaceholderVC.viewWidth?.constant = size.width + } // MARK: - General @@ -230,13 +237,15 @@ private final class EnterURLVC: UIViewController, UIGestureRecognizerDelegate, O return result }() - private lazy var suggestionGrid: OpenGroupSuggestionGrid = { + lazy var suggestionGrid: OpenGroupSuggestionGrid = { let maxWidth: CGFloat = (UIScreen.main.bounds.width - Values.largeSpacing * 2) let result: OpenGroupSuggestionGrid = OpenGroupSuggestionGrid(maxWidth: maxWidth) result.delegate = self return result }() + + var viewWidth: NSLayoutConstraint? // MARK: - Lifecycle @@ -270,7 +279,7 @@ private final class EnterURLVC: UIViewController, UIGestureRecognizerDelegate, O bottomConstraint = view.pin(.bottom, to: .bottom, of: stackView, withInset: bottomMargin) // Constraints - view.set(.width, to: UIScreen.main.bounds.width) + viewWidth = view.set(.width, to: UIScreen.main.bounds.width) // Dismiss keyboard on tap let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)) @@ -374,6 +383,8 @@ private final class EnterURLVC: UIViewController, UIGestureRecognizerDelegate, O private final class ScanQRCodePlaceholderVC: UIViewController { weak var joinOpenGroupVC: JoinOpenGroupVC? + var viewWidth: NSLayoutConstraint? + // MARK: - Lifecycle override func viewDidLoad() { @@ -403,7 +414,7 @@ private final class ScanQRCodePlaceholderVC: UIViewController { stackView.alignment = .center // Constraints - view.set(.width, to: UIScreen.main.bounds.width) + viewWidth = view.set(.width, to: UIScreen.main.bounds.width) view.addSubview(stackView) stackView.pin(.leading, to: .leading, of: view, withInset: Values.massiveSpacing) view.pin(.trailing, to: .trailing, of: stackView, withInset: Values.massiveSpacing) diff --git a/Session/Open Groups/OpenGroupSuggestionGrid.swift b/Session/Open Groups/OpenGroupSuggestionGrid.swift index 7ab0611f6..c6563d82e 100644 --- a/Session/Open Groups/OpenGroupSuggestionGrid.swift +++ b/Session/Open Groups/OpenGroupSuggestionGrid.swift @@ -5,7 +5,7 @@ import SessionUIKit final class OpenGroupSuggestionGrid: UIView, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { private let itemsPerSection: Int = (UIDevice.current.isIPad ? 4 : 2) - private let maxWidth: CGFloat + private var maxWidth: CGFloat private var rooms: [OpenGroupAPI.Room] = [] { didSet { update() } } private var heightConstraint: NSLayoutConstraint! var delegate: OpenGroupSuggestionGridDelegate? @@ -142,6 +142,11 @@ final class OpenGroupSuggestionGrid: UIView, UICollectionViewDataSource, UIColle errorView.isHidden = (roomCount > 0) } + public func refreshLayout(with maxWidth: CGFloat) { + self.maxWidth = maxWidth + collectionView.collectionViewLayout.invalidateLayout() + } + // MARK: - Layout func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {