mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Add pull to refresh for Subscriptions, Popular and Trending (fixes #31)
This commit is contained in:
42
Vendor/RefreshControl/RefreshControlModifier.swift
vendored
Normal file
42
Vendor/RefreshControl/RefreshControlModifier.swift
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// RefreshControlModifier.swift
|
||||
// SwiftUI_Pull_to_Refresh
|
||||
//
|
||||
// Created by Geri Borbás on 18/09/2021.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct RefreshControlModifier: ViewModifier {
|
||||
@State private var geometryReaderFrame: CGRect = .zero
|
||||
let refreshControl: RefreshControl
|
||||
|
||||
internal init(onValueChanged: @escaping (UIRefreshControl) -> Void) {
|
||||
refreshControl = RefreshControl(onValueChanged: onValueChanged)
|
||||
}
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.background(
|
||||
GeometryReader { geometry in
|
||||
ScrollViewMatcher(
|
||||
onResolve: { scrollView in
|
||||
refreshControl.add(to: scrollView)
|
||||
},
|
||||
geometryReaderFrame: $geometryReaderFrame
|
||||
)
|
||||
.preference(key: FramePreferenceKey.self, value: geometry.frame(in: .global))
|
||||
.onPreferenceChange(FramePreferenceKey.self) { frame in
|
||||
self.geometryReaderFrame = frame
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
func refreshControl(onValueChanged: @escaping (_ refreshControl: UIRefreshControl) -> Void) -> some View {
|
||||
modifier(RefreshControlModifier(onValueChanged: onValueChanged))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user