I have an overlay transition that uses matchedgeometry effect, as shown in this video:
Matched Geometry Effect with same sized text
I want to enlarge the transitioned text after the animation, but it seems that the text frame isn’t being scaled in time, causing the text to be shortened in transition.
Matched Geometry Effect with different sized text
Is there a way to overcome this?
The original text:
Text(info.name)
.font(.system(size: 22, weight: .bold))
.matchedGeometryEffect(id: info.name, in: namespace)
The transitioned text:
Text(currentCard.name)
.font(.title.bold())
.matchedGeometryEffect(id: currentCard.name, in: namespace)
Thanks
2
Answers
I understand text is not animating with matchedGeometryEffect (macOS 12 / Xcode 13). I could not find a way to do it. Either the matchedGeo is working, or an AnimatableModifier on the font, but not both at the same time.
For some use cases you can work around it by forcing the container sizes of the original text and the container size of the transitioned text staying equal with a .frame modifier. This has the effect that there are at least no ellipses ("…") showing during animation:
Finally figured it out!
Add a separate font size
@State var
that you trigger inside yourmatchedGeometryEffect
‘sif
statement.onAppear
.Combine this with the
AnimatableCustomFontModifier
and the font size will animate just fine!I know. It sounds gross. You wouldn’t believe how long this took. Here’s a working example.
Unfortunately, it’s a little buggy if you try to reverse the animation before it’s finished. Should’t be a problem if you can delay interaction until the animation is finished.