Is there a new way to specify availability for modifiers?
I'm looking for something like this (pseudocode):
struct Bar: View {
var body: some View {
Foo()
#if available(iOS 15)
.refreshable
#endif
}
}
or, perhaps even more clean:
struct Bar: View {
var body: some View {
Foo()
.refreshable_ios15
}
}
whereas refreshable_ios15 is a modifier that is marked in a special way with some availability marker, and does something on iOS 15 and nothing on previous OS versions (but still compiles without a problem).
instead of the current dance:
struct Bar: View {
var body: some View {
if #available(iOS 15, *) {
Foo()
.refreshable {
// something
}
} else {
Foo()
}
}
}
public extension View {
/// Modify a view with a `ViewBuilder` closure.
///
/// This represents a streamlining of the
/// [`modifier`](https://developer.apple.com/documentation/swiftui/view/modifier(_:))
/// \+ [`ViewModifier`](https://developer.apple.com/documentation/swiftui/viewmodifier)
/// pattern.
/// - Note: Useful only when you don't need to reuse the closure.
/// If you do, turn the closure into an extension! ♻️
func modifier<ModifiedContent: View>(
@ViewBuilder body: (_ content: Self) -> ModifiedContent
) -> ModifiedContent {
body(self)
}
}
I find it a bit hard to wrap some newer modifiers, such as popoverTip(_:arrowEdge:action:) , because it takes a newer type as a parameter.
It is true that I can still use the conditional view approach to wrap the whole view with an availability check, but the custom modifier approach seems not useful for this case. Do you have any advice on this? Thanks.