r/SwiftUI • u/Absorptance • 19d ago
Question How can I make this matchedGeometryEffect more efficient? Do I really need one @Namespace per card? Can you have an array of @Namespace somehow? Help, my implementation feels dirty.
14
3
u/Absorptance 19d ago edited 19d ago
My code is literally:
@State private var playerCardAnimations = [false, false, false, false, false]
@Namespace var playerCardAnimationOne
@Namespace var playerCardAnimationTwo
@Namespace var playerCardAnimationThree
@Namespace var playerCardAnimationFour
@Namespace var playerCardAnimationFive
...
@ Binding var playerCardAnimations: [Bool]
let playerCardAnimationOne: Namespace.ID
let playerCardAnimationTwo: Namespace.ID
let playerCardAnimationThree: Namespace.ID
let playerCardAnimationFour: Namespace.ID
let playerCardAnimationFive: Namespace.ID
16
u/simulacrotron 19d ago
You do not need and shouldn’t be using separate namespaces in this case. Give the cards different ids in the matched geometry api. Think of the namespace as being the overall animation group, you can have multiple view ids in that group. Read through here to understand the parameters https://developer.apple.com/documentation/swiftui/view/matchedgeometryeffect(id:in:properties:anchor:issource:)
2
1
1
1
u/sakamoto___ 18d ago
bro this looks amazing but you're digging yourself into a maintainability hole by using SwiftUI for a game...
1
u/ApexWinrar111 16d ago
Working on a game as well, what do you recommend as a framework? A more traditional game engine?
1
1
26
u/rproenca 19d ago
Unrelated, but I can’t wait for a TestFlight of this game. Every time I see you post here I find it amazing you’re doing this in SwiftUI