Start with group replies scrolled to top

This commit is contained in:
Nora Trapp 2022-04-02 14:12:17 -07:00
parent 433f3da3f1
commit 4bb1bedbf3
2 changed files with 22 additions and 15 deletions

View File

@ -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) }
}
}

View File

@ -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")