mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
add pull to refresh for ipad grid view
This commit is contained in:
parent
9bdc96c567
commit
1ca25c87bd
1 changed files with 22 additions and 2 deletions
|
|
@ -329,9 +329,21 @@ import Views
|
|||
}
|
||||
}
|
||||
.padding()
|
||||
.background(Color(.systemGroupedBackground))
|
||||
.background(
|
||||
GeometryReader {
|
||||
Color(.systemGroupedBackground).preference(
|
||||
key: ScrollViewOffsetPreferenceKey.self,
|
||||
value: $0.frame(in: .global).origin.y
|
||||
)
|
||||
}
|
||||
)
|
||||
.onPreferenceChange(ScrollViewOffsetPreferenceKey.self) { offset in
|
||||
if !viewModel.isLoading, abs(offset) > 240 {
|
||||
viewModel.loadItems(dataService: dataService, searchQuery: searchQuery, isRefresh: true)
|
||||
}
|
||||
}
|
||||
|
||||
if viewModel.isLoading {
|
||||
if viewModel.items.isEmpty, viewModel.isLoading {
|
||||
LoadingSection()
|
||||
}
|
||||
}
|
||||
|
|
@ -339,3 +351,11 @@ import Views
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
struct ScrollViewOffsetPreferenceKey: PreferenceKey {
|
||||
typealias Value = CGFloat
|
||||
static var defaultValue = CGFloat.zero
|
||||
static func reduce(value: inout Value, nextValue: () -> Value) {
|
||||
value += nextValue()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue