Created
November 19, 2024 20:19
-
-
Save tarrouye/a935d440093c6397656a694cf4724246 to your computer and use it in GitHub Desktop.
Transmission Hero Move Example
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 | |
import Transmission // https://github.com/nathantannar4/Transmission | |
struct HeroMoveExample: View { | |
let colors: [Color] = [.blue, .red, .green, .orange] | |
var body: some View { | |
NavigationStack { | |
ScrollView(.vertical) { | |
ForEach(colors, id: \.hashValue) { color in | |
PresentationLink( | |
transition: .matchedGeometry(options: .init(edges: .all, preferredCornerRadius: 10)) | |
) { | |
Destination(color: color) | |
} label: { | |
RoundedRectangle(cornerRadius: 10) | |
.foregroundStyle(color) | |
.frame(height: 100) | |
} | |
} | |
} | |
.padding(.horizontal) | |
.navigationTitle("Hero Move Example") | |
} | |
} | |
} | |
struct Destination: View { | |
@Environment(\.presentationCoordinator) private var presentationCoordinator | |
let color: Color | |
var body: some View { | |
TransitionReader { proxy in | |
ZStack(alignment: .topTrailing) { | |
color | |
.ignoresSafeArea(.all) | |
Image(systemName: "x.circle.fill") | |
.resizable() | |
.frame(width: 30, height: 30) | |
.onTapGesture { | |
presentationCoordinator.dismiss() | |
} | |
.padding(.horizontal) | |
.opacity(proxy.progress) // fade with transition | |
} | |
} | |
} | |
} | |
#Preview { | |
HeroMoveExample() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment