-
-
Save mszpro/fb6bb8a95376402daf433220de222389 to your computer and use it in GitHub Desktop.
Use a custom SwiftUI view modifier to adapt different modifiers for different system version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public extension View { | |
func halfModal<Item, Sheet>(item: Binding<Item?>, | |
preferredHeight: CGFloat = 335, | |
@ViewBuilder sheet: @escaping (Item?) -> Sheet | |
) -> some View where Item : Identifiable, Sheet : View { | |
if #available(iOS 16.0, *) { | |
return self | |
.sheet(item: item, content: { item in | |
sheet(item).presentationDetents([.height(preferredHeight)]) | |
}) | |
} else { | |
return self | |
.background { | |
CustomHalfSheetModel(...) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment