Skip to content

Instantly share code, notes, and snippets.

@allfinlir
Created August 4, 2023 20:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allfinlir/194c92d3807913fe7588a201aa7d35f9 to your computer and use it in GitHub Desktop.
Save allfinlir/194c92d3807913fe7588a201aa7d35f9 to your computer and use it in GitHub Desktop.
struct CardView: View {
var item: ItemData
var animation: Namespace.ID
var body: some View {
HStack {
Circle()
.frame(width: 75)
.foregroundColor(item.color)
.overlay {
Text(item.shapeSymbol)
.font(.title2)
.foregroundColor(.white)
}
.matchedGeometryEffect(id: "\(item.id)", in: animation)
Text(item.title)
.font(.title)
}
.padding()
.background(
Color(.purple)
.opacity(0.3)
.cornerRadius(7)
)
}
}
struct DetailView: View {
@Binding var selectedItem: ItemData
@Binding var show: Bool
var animation: Namespace.ID
@State var loadContent = false
var body: some View {
VStack(spacing: 20) {
HStack {
Button(action: {
withAnimation(.spring(response: 0.35, dampingFraction: 0.7)) {
show.toggle()
}
}, label: {
Image(systemName: "chevron.left")
})
Spacer()
}
.opacity(show ? 1 : 0)
ZStack {
Circle()
.frame(width: 200)
.foregroundColor(selectedItem.color)
Text(selectedItem.shapeSymbol)
.font(.largeTitle)
.foregroundColor(.white)
}
.matchedGeometryEffect(id: "\(selectedItem.id)", in: animation)
Text(selectedItem.title)
.opacity(show ? 1 : 0)
Text("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.")
.opacity(show ? 1 : 0)
Spacer()
}
.padding()
.onAppear {
withAnimation(Animation.spring().delay(0.45)) {
loadContent.toggle()
}
}
}
}
import Foundation
import SwiftUI
struct ItemData: Identifiable {
var id = UUID().uuidString
var color: Color
var shapeSymbol: String
var title: String
}
var items = [
ItemData(color: Color(.orange), shapeSymbol: "Y", title: "Youth Academy"),
ItemData(color: Color(.black), shapeSymbol: "H", title: "Harvard"),
ItemData(color: Color(.green), shapeSymbol: "C", title: "Chalmers")
]
struct StartView: View {
@State var selectedItem: ItemData = items[0]
@State var show: Bool = false
@Namespace var animation
var body: some View {
ZStack {
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(items) { item in
CardView(item: item, animation: animation)
.onTapGesture {
withAnimation(.spring(response: 0.35, dampingFraction: 0.7)) {
selectedItem = item
show.toggle()
}
}
}
.padding()
}
}
.opacity(show ? 0 : 1)
if show {
DetailView(selectedItem: $selectedItem, show: $show, animation: animation)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment