r/SwiftUI • • 16h ago

Tutorial Rendering Mac App Store screenshots from my SwiftUI views: 4 gotchas

0 Upvotes

Added a debug flag that renders the store screenshots from the real views with sample data. What tripped me up:

  • Render inside a real offscreen NSWindow, or scroll views and text editors don't draw right.
  • Disable animations. There's no display link offscreen, so transitions never finish.
  • Blur vanishes offscreen. I swapped it for radial gradients.
  • cacheDisplay can't draw the sidebar material. I used CGWindowListCreateImage for that window.

That last one is deprecated though. Anyone found another way to capture vibrancy from your own window?


r/SwiftUI • • 8h ago

Recreated the Trip.com splash screen animation in SwiftUI

1 Upvotes

I really liked the Trip launch animation, so I recreated it. The logo's letters get swallowed by the orange dot, the dot stretches into a streak, and a circle sweeps in to reveal your first screen.

Source: https://repgem.com/trip-splash-ios

Would love your feedback!

Inspired by the Trip.com app. The code is original and not affiliated with them.


r/SwiftUI • • 18h ago Bravo

A checklist I use when a SwiftUI List or ScrollView stutters

18 Upvotes

Most SwiftUI scroll jank I've debugged came from a short list of causes, not from SwiftUI being slow. Here's the order I check them in. Curious what others would add.

  1. Unstable identity. `ForEach(items, id: \.self)` on values that aren't unique, or ids created inside the view (`UUID()` in `body`), make SwiftUI treat rows as new on every update. Use a stable id from your model.
  2. Work inside `body`. Date formatters, sorting, filtering or image decoding in `body` run on every re-render. Move them into the model or cache the result.
  3. Observing too much. With `@Observable`, a view re-renders for the properties it reads. If every row reads half of a big shared model, one change can invalidate far more rows than you expect. Give each row only what it needs.
  4. Conditional modifiers that swap view types. An `if` that wraps a row in different modifiers changes its structural identity and resets its state. Prefer value-based modifiers, like `.opacity(isHidden ? 0 : 1)`.
  5. Images. Full-size images decoded on the main thread will drop frames. Downsample to the size you actually display.

Before changing anything, I profile on a real device with a release build, using Instruments (the SwiftUI template plus Time Profiler). `Self._printChanges()` in `body` is also handy for seeing why a view re-rendered. Debug builds and the simulator can point you at the wrong problem.

What's the most surprising cause of scroll jank you've run into?


r/SwiftUI • • 4h ago

Buttons in .confirmationDialog have a significant delay when triggered

2 Upvotes

When tapping a button in a .confirmationDialog (at least one tied to a .bottomBar ToolbarItem), a ridiculously long delay — about a full second after the dialog closes — occurs before the action triggers. This issue is present in some of Apple's apps, including Reminders, Shortcuts, and Notes, but notably not in the Photos app. It also occurs for .alert, though to a lesser degree. How can I eliminate this, preferably without dropping down to UIKit?

The problem has been present since iOS 26. I haven't checked whether it existed before then.

Example code:

struct ContentView: View {
     private var confirmationDialogPresented = false
     private var colorToggled = false
    
    var body: some View {
        NavigationStack {
            Color(colorToggled ? .blue : .red)
                .ignoresSafeArea()
                .toolbar {
                    ToolbarItem(placement: .bottomBar) {
                        Button("Placeholder", systemImage: "square") {
                            confirmationDialogPresented = true
                        }
                        .confirmationDialog("Placeholder", isPresented: $confirmationDialogPresented) {
                            Button("Placeholder") {
                                colorToggled.toggle()
                            }
                        }
                    }
                }
        }
    }
}

#Preview {
    ContentView()
}

r/SwiftUI • • 9h ago

We rewrote the entire Rust WGPU in Swift, and it looks fantastic. I call it SAGA

Thumbnail gallery
2 Upvotes