-
-
Notifications
You must be signed in to change notification settings - Fork 27
[trello.com/c/jKqpxiCa] update for paragraph 8 and 13 in the card #865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/3.11.0
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -836,12 +836,16 @@ extension ChatViewController { | |
fileprivate func updateScrollDownButtonVisibility() { | ||
let topCount = viewModel.unreadMessagesIds?.count ?? 0 | ||
self.scrollDownButton.updateCounter(topCount) | ||
guard state.isScrollDownButtonHidden != state.isScrollPositionNearlyTheBottom else { return } | ||
state.isScrollDownButtonHidden = state.isScrollPositionNearlyTheBottom | ||
|
||
let shouldShowButton = (topCount > 0) || !state.isScrollPositionNearlyTheBottom | ||
guard state.isScrollDownButtonHidden != !shouldShowButton else { return } | ||
|
||
state.isScrollDownButtonHidden = !shouldShowButton | ||
let buttonUpdate = { | ||
self.scrollDownButton.alpha = self.state.isScrollPositionNearlyTheBottom ? 0 : 1 | ||
self.scrollDownButton.alpha = shouldShowButton ? 1 : 0 | ||
self.updateScrollToUnreadButtonPosition() | ||
} | ||
|
||
if state.isAnimationAllowed { | ||
UIView.animate(withDuration: 0.3, delay: 0, options: .curveEaseInOut) { | ||
buttonUpdate() | ||
|
@@ -913,15 +917,7 @@ extension ChatViewController { | |
let button = ChatScrollButton(position: .down) | ||
button.action = { [weak self] in | ||
guard let self else { return } | ||
if viewModel.shouldScrollToBottom { | ||
state.isScrollingToBottom = true | ||
markMessagesFromCurrentToBottomAsRead() | ||
self.messagesCollectionView.scrollToBottom(animated: true) | ||
} else if let id = viewModel.unreadMessagesIds?.first { | ||
viewModel.animationType = MessageAnimationType.none | ||
self.scrollToPosition(.messageId(id), animated: true) | ||
viewModel.shouldScrollToBottom = true | ||
} | ||
scrollButtonAction() | ||
} | ||
button.alpha = 0 | ||
return button | ||
|
@@ -958,6 +954,60 @@ extension ChatViewController { | |
) | ||
return collection | ||
} | ||
|
||
fileprivate func scrollButtonAction() { | ||
if viewModel.shouldScrollToBottom { | ||
scrollToBottom() | ||
return | ||
} | ||
|
||
guard let firstUnreadId = viewModel.unreadMessagesIds?.first, | ||
let unreadIndex = viewModel.messages.firstIndex(where: { $0.messageId == firstUnreadId }) else { | ||
scrollToBottom() | ||
return | ||
} | ||
|
||
let visibleBounds = messagesCollectionView.bounds | ||
let restrictedVisibleRect = visibleBounds.insetBy(dx: 0, dy: 100) | ||
|
||
let visibleSections: Set<Int> = Set( | ||
vovameister marked this conversation as resolved.
Show resolved
Hide resolved
|
||
messagesCollectionView.indexPathsForVisibleItems.compactMap { indexPath in | ||
guard let attributes = messagesCollectionView.layoutAttributesForItem(at: indexPath) else { | ||
return nil | ||
} | ||
|
||
let frame = attributes.frame | ||
if restrictedVisibleRect.intersects(frame) { | ||
return indexPath.section | ||
} else { | ||
return nil | ||
} | ||
} | ||
) | ||
|
||
if visibleSections.contains(unreadIndex) { | ||
scrollToBottom() | ||
return | ||
} | ||
|
||
if let separatorIndex = viewModel.separatorState.separatorIndex, | ||
unreadIndex == separatorIndex + 1 { | ||
viewModel.animationType = .none | ||
scrollToPosition(.messageId(firstUnreadId), animated: false, setExtraOffset: true, scrollAt: .top) | ||
viewModel.shouldScrollToBottom = true | ||
return | ||
} | ||
|
||
viewModel.animationType = .none | ||
scrollToPosition(.messageId(firstUnreadId), animated: true, scrollAt: .top) | ||
viewModel.shouldScrollToBottom = true | ||
} | ||
|
||
fileprivate func scrollToBottom() { | ||
state.isScrollingToBottom = true | ||
markMessagesFromCurrentToBottomAsRead() | ||
messagesCollectionView.scrollToBottom(animated: true) | ||
} | ||
} | ||
|
||
// MARK: Other | ||
|
@@ -1395,4 +1445,11 @@ private let messagePadding: CGFloat = 12 | |
private let filesToolbarViewHeight: CGFloat = 140 | ||
private let targetYOffset: CGFloat = 20 | ||
private let scrollButtonHeight: CGFloat = 30 | ||
private let hiddenScrollViewPartHeight: CGFloat = 94 | ||
//not a real height just for reading messages | ||
private var hiddenScrollViewPartHeight: CGFloat { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How did you get this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the height of the elements above and below is 100, to read messages not at the very edge of the cell, but a little higher, I selected the most suitable values |
||
if isMacOS { | ||
return 93 | ||
} else { | ||
return 85 | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could combine this with previous checking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from the point of view of readability of the algorithm it is more convenient