Skip to content

Commit

Permalink
matchedgeometryeffect sample
Browse files Browse the repository at this point in the history
  • Loading branch information
TahaTesser committed Oct 7, 2024
1 parent 98bf05c commit f24aa1a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
Binary file not shown.
8 changes: 7 additions & 1 deletion SwiftUIPlayground/Samples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,11 @@ public let samples: [String: AnyView] = [
"ViewThatFits": AnyView(ViewThatFitsSample()),
]
)),

"Animations": AnyView(SamplesList(
title: "Animations", samples:
[
// https://developer.apple.com/documentation/swiftui/view/matchedgeometryeffect(id:in:properties:anchor:issource:)
"matchedgeometryeffect": AnyView(MatchedGeometryEffectSample()),
]
)),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// MatchedGeometryEffectSample.swift
// SwiftUIPlayground
//
// Created by Taha Tesser on 07.10.2024.
//

import SwiftUI

struct MatchedGeometryEffectSample: View {
@Namespace private var animation
@State private var isExpanded: Bool = false

var body: some View {
ZStack {
if isExpanded {
ZStack {
RoundedRectangle(cornerRadius: 10)
.fill(.black)
.clipShape(RoundedRectangle(cornerRadius: 16))
Image(systemName: "rainbow")
.symbolRenderingMode(.multicolor)
.resizable()
.scaledToFit()
.padding()
.matchedGeometryEffect(id: "park", in: animation)

}
} else {
ZStack {
RoundedRectangle(cornerRadius: 10)
.fill(.black)
.frame(height: 100)
.clipShape(RoundedRectangle(cornerRadius: 16))
Image(systemName: "rainbow")
.symbolRenderingMode(.multicolor)
.resizable()
.scaledToFit()
.frame(height: 80)
.matchedGeometryEffect(id: "park", in: animation)
}
.padding()
}
}
.onTapGesture {
withAnimation(.spring()) {
isExpanded.toggle()
}
}
.ignoresSafeArea() }
}

#Preview {
MatchedGeometryEffectSample()
}

0 comments on commit f24aa1a

Please sign in to comment.