Spring transition

This commit is contained in:
Jed Fox 2022-12-20 12:36:43 -05:00
parent 4bcf76740f
commit 7235ba3fb2
No known key found for this signature in database
GPG Key ID: 0B61D18EA54B47E1
1 changed files with 5 additions and 0 deletions

View File

@ -12,6 +12,7 @@ struct MediaAltTextOverlay: View {
var altDescription: String? var altDescription: String?
@State private var showingAlt = false @State private var showingAlt = false
@Namespace private var namespace
var body: some View { var body: some View {
GeometryReader { geom in GeometryReader { geom in
@ -26,13 +27,16 @@ struct MediaAltTextOverlay: View {
.frame(width: 20, height: 20) .frame(width: 20, height: 20)
} }
} }
.transition(.scale(scale: 0.1, anchor: .bottomLeading))
.padding(8) .padding(8)
.frame(width: geom.size.width) .frame(width: geom.size.width)
.fixedSize() .fixedSize()
.matchedGeometryEffect(id: "background", in: namespace)
} else { } else {
Button("ALT") { showingAlt = true } Button("ALT") { showingAlt = true }
.fixedSize() .fixedSize()
.buttonStyle(AltButtonStyle()) .buttonStyle(AltButtonStyle())
.matchedGeometryEffect(id: "background", in: namespace)
} }
} }
} }
@ -40,6 +44,7 @@ struct MediaAltTextOverlay: View {
.tint(.white) .tint(.white)
.background(Color.black.opacity(0.85)) .background(Color.black.opacity(0.85))
.cornerRadius(4) .cornerRadius(4)
.animation(.spring(response: 0.25), value: showingAlt)
.frame(width: geom.size.width, height: geom.size.height, alignment: .bottomLeading) .frame(width: geom.size.width, height: geom.size.height, alignment: .bottomLeading)
} }
.padding(.horizontal, 16) .padding(.horizontal, 16)