Here is a view modifier that I am using. So, .bpTextCase(.none) can be used in iOS 13 and 14.
extension View {
func bpTextCase(_ textCase: BPTextCase.Case?) -> some View {
self.modifier(BPTextCase(textCase: textCase))
}
}
struct BPTextCase: ViewModifier {
enum Case {
case lowerCase
case upperCase
@available(iOS 14, *)
var textCase: Text.Case? {
switch self {
case .lowerCase:
return Text.Case.lowercase
case .upperCase:
return Text.Case.uppercase
}
}
}
let textCase: Case?
func body(content: Content) -> some View {
Group {
if #available(iOS 14, *) {
// This compiles without AnyView but crashes on iOS 13 due to
// the unknown class in the resulting type.
AnyView(content.textCase(textCase?.textCase))
} else {
content
}
}
}
}