Skip to content

Commit 0847045

Browse files
Remove unused pageSize from enableLoadMore
Pagination offset (the distance from the top message before we start loading more) used to be determined by the offset parameter passed to enableLoadMore, like so: if ids.prefix(offset + 1).contains(message.id) { onEvent?(message) } This got changed in 568d00d. Now, we rely on paginationTargetIndexPath instead, which is hardcoded to be the last already loaded message: IndexPath(row: lastSection.rows.count - 1, section: sections.count - 1) As a result, pageSize is no longer used. Remove it to make sure that consumers do not expect different behaviour when they modify the parameter.
1 parent 61851e7 commit 0847045

4 files changed

Lines changed: 6 additions & 8 deletions

File tree

ChatExample/ChatExample/Screens/ChatExampleView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct ChatExampleView: View {
2525
ChatView(messages: viewModel.messages, chatType: .conversation) { draft in
2626
viewModel.send(draft: draft)
2727
}
28-
.enableLoadMore(pageSize: 3) { message in
28+
.enableLoadMore { message in
2929
await MainActor.run {
3030
viewModel.loadMoreMessage(before: message)
3131
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ These use `AnyView`, so please try to keep them easy enough
253253
`setMediaPickerSelectionParameters` - a struct holding MediaPicker selection parameters (assetsPickerLimit and others like mediaType, selectionStyle, etc.).
254254
`orientationHandler` - handle screen rotation
255255

256-
`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.
256+
`enableLoadMore(handler: @escaping ChatPaginationClosure)` - when user scrolls to the final message, call the handler function, to load more messages
257257

258258
### Customize default UI
259259
You can use `chatTheme` to customize colors and images of default UI. You can pass all/some colors and images:

Sources/ExyteChat/Managers/PaginationState.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ public typealias ChatPaginationClosure = @Sendable (Message) async -> Void
88

99
final actor PaginationHandler: ObservableObject {
1010
let handleClosure: ChatPaginationClosure
11-
let pageSize: Int
1211

13-
init(handleClosure: @escaping ChatPaginationClosure, pageSize: Int) {
12+
init(handleClosure: @escaping ChatPaginationClosure) {
1413
self.handleClosure = handleClosure
15-
self.pageSize = pageSize
1614
}
1715
}

Sources/ExyteChat/Views/ChatView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,11 +617,11 @@ public extension ChatView {
617617
return view
618618
}
619619

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

0 commit comments

Comments
 (0)