Ezequiel Santos
iOS Developer & Creative Technologist

Playing with Custom Modifiers in SwiftUI

Flip modifier in SwiftUI demo
Figure 1: Flip modifier applied in SwiftUI

This post documents my first experiment creating a custom ViewModifier in SwiftUI. The goal was to implement a reusable flip effect that simulates 3D rotation, horizontally or vertically. While the core functionality is quite simple, the process helped me better understand modifier chaining and declarative view extensions in SwiftUI.

Background

SwiftUI provides a declarative API to build view hierarchies. While standard modifiers like .rotation3DEffect are powerful, combining them into reusable components can greatly improve code clarity. The Flip modifier wraps a 180-degree rotation in a reusable form and allows directional flipping along either the X or Y axis.

Flip Modifier Implementation

The implementation consists of three parts:

  1. An enum to represent flip direction
  2. An extension to apply directional 3D rotation
  3. A ViewModifier that uses the above components

The rotate helper keeps the syntax concise and separates axis logic from the actual modifier body. This allows clean use in the following example:

Further Improvements

Conclusion

This was a great starting point to understand SwiftUI modifiers and how view composition benefits from small abstractions. I’m open to suggestions for improvement — especially around making it more flexible or animated!