Files
antigravity-skills-reference/skills/swiftui-ui-patterns/references/overlay.md
sickn33 d2be634870 feat(skills): Import curated Apple workflow skills
Add fourteen skills from Dimillian/Skills, integrate the merged Snowflake and WordPress updates into the maintainer sync, and refresh registry metadata, attributions, walkthrough notes, and the 8.9.0 release notes while keeping validation warnings within budget.
2026-03-25 11:53:08 +01:00

1.2 KiB
Raw Blame History

Overlay and toasts

Intent

Use overlays for transient UI (toasts, banners, loaders) without affecting layout.

Core patterns

  • Use .overlay(alignment:) to place global UI without changing the underlying layout.
  • Keep overlays lightweight and dismissible.
  • Use a dedicated ToastCenter (or similar) for global state if multiple features trigger toasts.

Example: toast overlay

struct AppRootView: View {
  @State private var toast: Toast?

  var body: some View {
    content
      .overlay(alignment: .top) {
        if let toast {
          ToastView(toast: toast)
            .transition(.move(edge: .top).combined(with: .opacity))
            .onAppear {
              DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
                withAnimation { self.toast = nil }
              }
            }
        }
      }
  }
}

Design choices to keep

  • Prefer overlays for transient UI rather than embedding in layout stacks.
  • Use transitions and short auto-dismiss timers.
  • Keep the overlay aligned to a clear edge (.top or .bottom).

Pitfalls

  • Avoid overlays that block all interaction unless explicitly needed.
  • Dont stack many overlays; use a queue or replace the current toast.