Member-only story

View Reparenting in SwiftUI

Including @Namespace and matchedGeometryEffect

Steven Curtis
3 min readOct 11, 2023
Photo by Paul Skorupskas on Unsplash

Difficulty: Beginner | Easy | Normal | Challenging

This article has been developed using Xcode 12.4, and Swift 5.7.2

Prerequisites:

You need to be able to code in Swift, perhaps using

Playgrounds and be able to use SwiftUI

Terminology

View: In SwiftUI a view is a protocol that defines a piece of user interface and is a building block for creating UI in SwiftUI

View reparenting: Changing the parent of a view after it has been createdPrerequisites

@Namespace

The @Namespace allows us to manage animations and transitions among views in SwiftUI. It will be used within the following article to move objects between sections in views.

View Reparenting

View reparenting is where we can move a view from one parent to another. In order to do so we need to deal with a namespace so SwiftUI can compute and animate the transition between them.

Code

Essentially matchedGeometryEffect is

--

--

No responses yet