Created
April 16, 2021 11:19
-
-
Save shadone/1fec3ade4af2966297656bcf8d0841ca to your computer and use it in GitHub Desktop.
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
import SwiftUI | |
struct Item: Identifiable { | |
var id: String { "abc" } | |
var title: String = "abcfoo" | |
} | |
extension View { | |
func popup<Item, Content>(item: Binding<Item?>, @ViewBuilder content: (Item) -> Content) -> some View where Item: Identifiable, Content: View { | |
return ZStack(alignment: .top, content: { | |
self | |
item.wrappedValue.map { unwrapped in | |
Group { | |
Color.black.opacity(0.8) | |
.transition(AnyTransition.opacity.animation(.easeInOut(duration: 0.15))) | |
// .tappable { | |
// item.wrappedValue = nil | |
// } | |
content(unwrapped) | |
.animation(.easeInOut(duration: 0.3)) | |
.transition(.move(edge: .top)) | |
} | |
} | |
}) | |
} | |
} | |
struct SheetView: View { | |
@Environment(\.presentationMode) var presentationMode | |
var body: some View { | |
Button("Press to dismiss") { | |
presentationMode.wrappedValue.dismiss() | |
} | |
.font(.title) | |
.padding() | |
.background(Color.black) | |
} | |
} | |
struct ContentView: View { | |
@State private var showingSheet = false | |
@State var item: Item? = Item() | |
var body: some View { | |
Button("Show Sheet") { | |
showingSheet.toggle() | |
} | |
.sheet(isPresented: $showingSheet) { | |
VStack { | |
Text("Hello") | |
} | |
.popup(item: self.$item, content: { test in | |
VStack { | |
Text(test.title) | |
} | |
}) | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment