Skip to content

Instantly share code, notes, and snippets.

@mkaulfers
Created November 12, 2023 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkaulfers/8cd727480d31aa7e6603feeff316c33f to your computer and use it in GitHub Desktop.
Save mkaulfers/8cd727480d31aa7e6603feeff316c33f to your computer and use it in GitHub Desktop.
Mastering Matched Geometry Effect in SwiftUI | List to Full-Screen Animation Tutorial
import SwiftUI
struct ContentView: View {
@Namespace var animation
@Namespace var backgroundID
@State var showingFullScreen = false
var body: some View {
TabView {
ZStack {
Color.gray
if !showingFullScreen {
Button(action: {
showingFullScreen = true
}, label: {
RoundedRectangle(cornerRadius: 30)
.matchedGeometryEffect(id: backgroundID, in: animation)
.frame(maxHeight: 100)
.padding()
})
.tint(.black)
} else {
RoundedRectangle(cornerRadius: 30)
.matchedGeometryEffect(id: backgroundID, in: animation)
.padding()
.overlay {
Button(action: {
showingFullScreen = false
}, label: {
Text("Dismiss")
})
}
}
}
.ignoresSafeArea()
.toolbar(showingFullScreen ? .hidden : .visible, for: .tabBar)
.toolbar(showingFullScreen ? .hidden : .visible, for: .navigationBar)
.tabItem {
Label("Home", systemImage: "house.fill")
}
.animation(.easeInOut, value: showingFullScreen)
}
}
}
#Preview {
ContentView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment