Skip to content
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

[CIS-2084] Fix message list jumps by removing the inverted table view #2208

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions DemoApp/DemoAppConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ enum DemoAppConfiguration {

configureAtlantisIfNeeded()
trackPerformanceIfNeeded()
enableMessageDiffingIfNeeded()
}

// HTTP and WebSocket Proxy with Proxyman.app
Expand All @@ -51,9 +50,4 @@ enum DemoAppConfiguration {
PerformanceMonitor.shared().start()
}
}

// Enable message diffing in Message List
private static func enableMessageDiffingIfNeeded() {
StreamChatWrapper.shared.setMessageDiffingEnabled(isStreamInternalConfiguration)
}
}
8 changes: 0 additions & 8 deletions DemoApp/StreamChat/StreamChatWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,3 @@ extension StreamChatWrapper {
try? ChatPushNotificationInfo(content: response.notification.request.content)
}
}

// MARK: Develop configuration

extension StreamChatWrapper {
func setMessageDiffingEnabled(_ isEnabled: Bool) {
Components.default._messageListDiffingEnabled = isEnabled
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public class ChatChannelController: DataController, DelegateCallable, DataStoreP
return nil
}
guard let cid = self.cid else { return nil }
let sortAscending = self.messageOrdering == .topToBottom ? false : true
let sortAscending = self.messageOrdering == .topToBottom ? true : false
var deletedMessageVisibility: ChatClientConfig.DeletedMessageVisibility?
var shouldShowShadowedMessages: Bool?
self.client.databaseContainer.viewContext.performAndWait { [weak self] in
Expand Down Expand Up @@ -731,7 +731,7 @@ public extension ChatChannelController {
return
}

guard let messageId = messageId ?? messages.last?.id else {
guard let messageId = messageId ?? messages.first?.id else {
log.error(ClientError.ChannelEmptyMessages().localizedDescription)
callback { completion?(ClientError.ChannelEmptyMessages()) }
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ private extension ChatMessageController {
return nil
}

let sortAscending = self.listOrdering == .topToBottom ? false : true
let sortAscending = self.listOrdering == .topToBottom ? true : false
let deletedMessageVisibility = self.client.databaseContainer.viewContext
.deletedMessagesVisibility ?? .visibleForCurrentUser
let shouldShowShadowedMessages = self.client.databaseContainer.viewContext.shouldShowShadowedMessages ?? false
Expand Down
42 changes: 22 additions & 20 deletions Sources/StreamChatUI/ChatChannel/ChatChannelVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ open class ChatChannelVC: _ViewController,
keyboardHandler.stop()
}

/// Handles loading the previous messages.
open func loadPreviousMessages() {
guard channelController.state == .remoteDataFetched else {
return
}
guard !isLoadingPreviousMessages else {
return
}
isLoadingPreviousMessages = true

messageListVC.showLoadingPreviousMessagesView()
channelController.loadPreviousMessages { [weak self] _ in
self?.isLoadingPreviousMessages = false
self?.messageListVC.hideLoadingPreviousMessagesView()
}
}

// MARK: - ChatMessageListVCDataSource

public var messages: [ChatMessage] {
Expand Down Expand Up @@ -186,26 +203,7 @@ open class ChatChannelVC: _ViewController,
_ vc: ChatMessageListVC,
willDisplayMessageAt indexPath: IndexPath
) {
if channelController.state != .remoteDataFetched {
return
}

guard messageListVC.listView.isTrackingOrDecelerating else {
return
}

if indexPath.row < channelController.messages.count - 10 {
return
}

guard !isLoadingPreviousMessages else {
return
}
isLoadingPreviousMessages = true

channelController.loadPreviousMessages { [weak self] _ in
self?.isLoadingPreviousMessages = false
}
// No-op
}

open func chatMessageListVC(
Expand Down Expand Up @@ -247,6 +245,10 @@ open class ChatChannelVC: _ViewController,
messageComposerVC.dismissSuggestions()
}

open func chatMessageListVCShouldLoadPreviousMessages(_ vc: ChatMessageListVC) {
loadPreviousMessages()
}

// MARK: - ChatChannelControllerDelegate

open func channelController(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
import UIKit

/// Stream's custom transitioning delegate to handle a modal presentation.
///
/// This should be used if you are presenting the ``ChatChannelVC`` in a modal.
/// The reason this custom transition should be used instead of the native one is because we use an inverted
/// `UITableView` for the message list component which it doesn't play well with the native modal transition.
open class StreamModalTransitioningDelegate: NSObject, UIViewControllerTransitioningDelegate {
public func presentationController(
forPresented presented: UIViewController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ open class ChatMessageLayoutOptionsResolver {
}

// The current message is the last message so it's either a standalone or last in sequence.
guard messageIndexPath.item > 0 else { return true }
guard messageIndexPath.item < messages.count - 1 else { return true }

let nextMessageIndex = messages.index(before: messageIndex)
let nextMessageIndex = messages.index(after: messageIndex)
guard let nextMessage = messages[safe: nextMessageIndex] else {
indexNotFoundAssertion()
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ open class ChatMessageListScrollOverlayView: _View, ThemeProvider {
else { return }

let overlayText = self.dataSource?.scrollOverlay(self, textForItemAt: indexPath)

// If we have no date we have no reason to display `dateView`
self.isHidden = (overlayText ?? "").isEmpty
self.content = overlayText

// Apple's naming is quite weird as actually this property should rather be named `isScrolling`
Expand All @@ -63,6 +60,15 @@ open class ChatMessageListScrollOverlayView: _View, ThemeProvider {
// that reacts on `panGestureRecognizer` states and can handle this case properly
if !tb.isDragging {
self.setAlpha(0)
} else {
self.setAlpha(1)
}

/// If the date separators are enabled per cell, don't show the overlay
/// for the the top cell since the top cell has always a list date separator.
let isDateSeparatorEnabled = self.components.messageListDateSeparatorEnabled
if isDateSeparatorEnabled, refPointInListView.y < tb.rectForRow(at: indexPath).height {
self.setAlpha(0)
}
}

Expand Down Expand Up @@ -105,6 +111,7 @@ open class ChatMessageListScrollOverlayView: _View, ThemeProvider {
open func setAlpha(_ alpha: CGFloat) {
Animate(isAnimated: true) {
self.alpha = alpha
self.isHidden = alpha == 0
}
}
}
Loading