Skip to content

Commit

Permalink
fix: 修正首屏显示不满时的分页加载
Browse files Browse the repository at this point in the history
  • Loading branch information
yichengchen committed Jun 10, 2024
1 parent 31de567 commit 930a50b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,15 @@ class FeedCollectionViewController: UIViewController {

func appendData(displayData: [any DisplayData]) {
_displayData.append(contentsOf: displayData.map { AnyDispplayData(data: $0) }.filter({ !_displayData.contains($0) }))
if displayData.count < pageSize - 5 {
if displayData.count < pageSize - 5 || displayData.count == 0 {
finished = true
}
isLoading = false

if _displayData.count < 12 {
isLoading = true
loadMore?()
}
}

override func viewDidLoad() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class FollowsViewController: StandardVideoCollectionViewController<DynamicFeedDa
}
let info = try await WebRequest.requestFollowsFeed(offset: lastOffset, page: page)
lastOffset = info.offset
Logger.debug("request page\(page) get count:\(info.videoFeeds.count) next offset:\(info.offset)")
return info.videoFeeds
}

Expand All @@ -39,6 +40,7 @@ extension WebRequest {
let offset: String
let update_num: Int
let update_baseline: String
let has_more: Bool
var videoFeeds: [DynamicFeedData] {
return items
.filter({ $0.aid != 0 || $0.modules.module_dynamic.major?.pgc != nil })
Expand All @@ -51,6 +53,9 @@ extension WebRequest {
param["offset"] = offsetNum
}
let res: DynamicFeedInfo = try await request(url: "https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all", parameters: param)
if res.videoFeeds.isEmpty, res.has_more {
return try await requestFollowsFeed(offset: res.offset, page: page)
}
return res
}
}
Expand Down

0 comments on commit 930a50b

Please # to comment.