From 4bb1bedbf3915446aa123805809400a3057d2ad7 Mon Sep 17 00:00:00 2001 From: Nora Trapp Date: Sat, 2 Apr 2022 14:12:17 -0700 Subject: [PATCH] Start with group replies scrolled to top --- .../StoryGroupReplyLoader.swift | 26 +++++++++++++------ .../StoryGroupReplySheet.swift | 11 +++----- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Signal/src/ViewControllers/HomeView/Stories/Group Reply Sheet/StoryGroupReplyLoader.swift b/Signal/src/ViewControllers/HomeView/Stories/Group Reply Sheet/StoryGroupReplyLoader.swift index e1157cee0b..a799ddcb39 100644 --- a/Signal/src/ViewControllers/HomeView/Stories/Group Reply Sheet/StoryGroupReplyLoader.swift +++ b/Signal/src/ViewControllers/HomeView/Stories/Group Reply Sheet/StoryGroupReplyLoader.swift @@ -34,7 +34,17 @@ class StoryGroupReplyLoader: Dependencies { var isScrolledToBottom: Bool { AssertIsOnMainThread() - return tableView?.indexPathsForVisibleRows?.lazy.map { $0.row }.contains(replyUniqueIds.count - 1) ?? false + guard let tableView = tableView else { return false } + + let lastIndexPath = IndexPath(row: replyUniqueIds.count - 1, section: 0) + + guard tableView.indexPathsForVisibleRows?.contains(lastIndexPath) ?? false else { return false } + + var container = tableView.bounds + container.y += tableView.contentInset.top + tableView.safeAreaInsets.top + container.height -= tableView.contentInset.totalHeight + tableView.safeAreaInsets.totalHeight + + return container.contains(tableView.rectForRow(at: lastIndexPath)) } init?(storyMessage: StoryMessage, threadUniqueId: String?, tableView: UITableView) { @@ -155,27 +165,28 @@ class StoryGroupReplyLoader: Dependencies { do { switch mode { case .initial: - try self.messageMapping.loadNewestMessagePage( + try self.messageMapping.loadInitialMessagePage( + focusMessageId: nil, reusableInteractions: reusableInteractions, - deletedInteractionIds: nil, + deletedInteractionIds: deletedInteractionIds, transaction: transaction ) case .newer: try self.messageMapping.loadNewerMessagePage( reusableInteractions: reusableInteractions, - deletedInteractionIds: nil, + deletedInteractionIds: deletedInteractionIds, transaction: transaction ) case .older: try self.messageMapping.loadOlderMessagePage( reusableInteractions: reusableInteractions, - deletedInteractionIds: nil, + deletedInteractionIds: deletedInteractionIds, transaction: transaction ) case .reload: try self.messageMapping.loadSameLocation( reusableInteractions: reusableInteractions, - deletedInteractionIds: nil, + deletedInteractionIds: deletedInteractionIds, transaction: transaction ) } @@ -190,13 +201,12 @@ class StoryGroupReplyLoader: Dependencies { DispatchQueue.main.async { let wasScrolledToBottom = self.isScrolledToBottom - let wasInitialLoad = mode == .initial self.replyUniqueIds = replyUniqueIds self.replyItems = newReplyItems self.tableView?.reloadData() - if wasScrolledToBottom || wasInitialLoad { self.scrollToBottomOfLoadWindow(animated: !wasInitialLoad) } + if wasScrolledToBottom { self.scrollToBottomOfLoadWindow(animated: true) } } } diff --git a/Signal/src/ViewControllers/HomeView/Stories/Group Reply Sheet/StoryGroupReplySheet.swift b/Signal/src/ViewControllers/HomeView/Stories/Group Reply Sheet/StoryGroupReplySheet.swift index bd3248d4d5..b46d8ed622 100644 --- a/Signal/src/ViewControllers/HomeView/Stories/Group Reply Sheet/StoryGroupReplySheet.swift +++ b/Signal/src/ViewControllers/HomeView/Stories/Group Reply Sheet/StoryGroupReplySheet.swift @@ -8,6 +8,7 @@ import SignalServiceKit class StoryGroupReplySheet: InteractiveSheetViewController { override var renderExternalHandle: Bool { false } + override var interactiveScrollViews: [UIScrollView] { [tableView] } private lazy var tableView = UITableView() private lazy var inputToolbar = StoryReplyInputToolbar() @@ -61,11 +62,11 @@ class StoryGroupReplySheet: InteractiveSheetViewController { tableView.separatorStyle = .none tableView.rowHeight = UITableView.automaticDimension tableView.keyboardDismissMode = .interactive - tableView.contentInset = UIEdgeInsets(top: 30, left: 0, bottom: 0, right: 0) tableView.addInteraction(contextMenu) contentView.addSubview(tableView) - tableView.autoPinEdgesToSuperviewEdges() + tableView.autoPinWidthToSuperview() + tableView.autoPinEdge(toSuperviewEdge: .bottom) // We add the handle directly to the content view, // so that it doesn't scroll with the table. @@ -73,6 +74,7 @@ class StoryGroupReplySheet: InteractiveSheetViewController { contentView.addSubview(handleContainer) handleContainer.autoPinWidthToSuperview() handleContainer.autoPinEdge(toSuperviewEdge: .top) + handleContainer.autoPinEdge(.bottom, to: .top, of: tableView) let handle = UIView() handle.backgroundColor = .ows_gray65 @@ -109,11 +111,6 @@ class StoryGroupReplySheet: InteractiveSheetViewController { } } - override func viewDidAppear(_ animated: Bool) { - super.viewDidAppear(animated) - replyLoader?.scrollToBottomOfLoadWindow(animated: true) - } - fileprivate func tryToSendMessage(_ message: TSOutgoingMessage) { guard let thread = thread else { return owsFailDebug("Unexpectedly missing thread")