// MARK: Refreshable - Modifier for Refreshable based on OS:
**(note: inline code does NOT work... is not my fault...)
**
// accesory:
public func isCatalyst()->Bool {
//tolerate warnings!
#if targetEnvironment(macCatalyst)
return true
#endif
return false
}
public typealias RefreshAction = ()->()
private struct MyRefreshableModifier: ViewModifier {
internal init(action: @escaping RefreshAction) {
self.action = action
}
private let action: RefreshAction
public func body(content: Content) -> some View {
#if os(iOS)
// Catalyst IS under iOS:
if isCatalyst(){
content
}else{
content
.refreshable {
action()
}
}
#elseif os(macOS)
content
// nada. We throw away
#endif
}
}
public extension View {
func portableRefreshableModifier(action: @escaping RefreshAction) -> some View {
modifier(MyRefreshableModifier(action: action) )
}
}
// usage:
/*
List {
Text("Hello World")
Text("Hello World")
Text("Hello World")
}.refreshable {
print("refresh....")
}
will be:
List {
Text("Hello World")
Text("Hello World")
Text("Hello World")
}.portableRefreshableModifier {
print("refresh....")
}
*/