Skip to content
Open
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
2 changes: 1 addition & 1 deletion ChatExample/ChatExample/Screens/ChatExampleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct ChatExampleView: View {
ChatView(messages: viewModel.messages, chatType: .conversation) { draft in
viewModel.send(draft: draft)
}
.enableLoadMore(pageSize: 3) { message in
.enableLoadMore { message in
await MainActor.run {
viewModel.loadMoreMessage(before: message)
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ These use `AnyView`, so please try to keep them easy enough
`setMediaPickerSelectionParameters` - a struct holding MediaPicker selection parameters (assetsPickerLimit and others like mediaType, selectionStyle, etc.).
`orientationHandler` - handle screen rotation

`enableLoadMore(offset: Int, handler: @escaping ChatPaginationClosure)` - when user scrolls to `offset`-th message from the end, call the handler function, so the user can load more messages. NOTE: New messages won't appear in the chat unless it's scrolled up to the very top - it's an optimization.
`enableLoadMore(handler: @escaping ChatPaginationClosure)` - when user scrolls to the final message, call the handler function, to load more messages

### Customize default UI
You can use `chatTheme` to customize colors and images of default UI. You can pass all/some colors and images:
Expand Down
4 changes: 1 addition & 3 deletions Sources/ExyteChat/Managers/PaginationState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ public typealias ChatPaginationClosure = @Sendable (Message) async -> Void

final actor PaginationHandler: ObservableObject {
let handleClosure: ChatPaginationClosure
let pageSize: Int

init(handleClosure: @escaping ChatPaginationClosure, pageSize: Int) {
init(handleClosure: @escaping ChatPaginationClosure) {
self.handleClosure = handleClosure
self.pageSize = pageSize
}
}
6 changes: 3 additions & 3 deletions Sources/ExyteChat/Views/ChatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -617,11 +617,11 @@ public extension ChatView {
return view
}

/// when user scrolls up to `pageSize`-th meassage, call the handler function, so user can load more messages
/// when user scrolls to the final message, call the handler function, to load more messages
/// NOTE: doesn't work well with `isScrollEnabled` false
func enableLoadMore(pageSize: Int, _ handler: @escaping ChatPaginationClosure) -> ChatView {
func enableLoadMore(_ handler: @escaping ChatPaginationClosure) -> ChatView {
var view = self
view.paginationHandler = PaginationHandler(handleClosure: handler, pageSize: pageSize)
view.paginationHandler = PaginationHandler(handleClosure: handler)
return view
}

Expand Down