Created
March 13, 2021 02:53
-
-
Save aaronlab/b2600c0828ff923d8e15cd8403575a91 to your computer and use it in GitHub Desktop.
A view modifier to use '.sheet ' and '.fullScreenCover' at the same time
This file contains hidden or 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
struct ChooseableSheet<Destination>: ViewModifier where Destination: View { | |
@Binding var isFullScreen: Bool | |
@Binding var isPresented: Bool | |
private let fullScreenContent: () -> Destination? | |
private let modalContent: () -> Destination? | |
init( | |
isFullScreen: Binding<Bool>, | |
isPresented: Binding<Bool>, | |
@ViewBuilder fullScreenContent: @escaping () -> Destination? = { nil }, | |
@ViewBuilder modalContent: @escaping () -> Destination? = { nil } | |
) { | |
self._isFullScreen = isFullScreen | |
self._isPresented = isPresented | |
self.fullScreenContent = fullScreenContent | |
self.modalContent = modalContent | |
} | |
func body(content: Content) -> some View { | |
if isFullScreen { | |
return AnyView( | |
content | |
.fullScreenCover(isPresented: $isPresented) { | |
fullScreenContent() | |
} | |
) | |
} else { | |
return AnyView( | |
content | |
.sheet(isPresented: $isPresented) { | |
modalContent() | |
} | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment