Created
November 12, 2023 18:57
-
-
Save mkaulfers/8cd727480d31aa7e6603feeff316c33f to your computer and use it in GitHub Desktop.
Mastering Matched Geometry Effect in SwiftUI | List to Full-Screen Animation Tutorial
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
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