All skills
johnrogers avatar

/swiftui-advanced

@d62eb71

Use when implementing gesture composition (simultaneous, sequenced, exclusive), adaptive layouts (ViewThatFits, AnyLayout, size classes), or choosing architecture patterns (MVVM vs TCA vs vanilla, State-as-Bridge). Covers advanced SwiftUI patterns beyond basic views.

Use this Skill: https://skilld.dev/gh/johnrogers/claude-swift-engineering/swiftui-advanced

This session only. Nothing lands on disk.

referencesgestures.md

≈825 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Gesture Composition

Decision Tree

What interaction do you need?
- Single tap/click? -> Button (preferred) or TapGesture
- Drag/pan? -> DragGesture
- Hold before action? -> LongPressGesture
- Pinch to zoom? -> MagnificationGesture
- Two-finger rotate? -> RotationGesture

Multiple gestures together?
- Both at same time? -> .simultaneously
- One after another? -> .sequenced
- One OR the other? -> .exclusively

GestureState vs State

Use Case Type Why
Temporary feedback @GestureState Auto-resets when gesture ends
Final committed value @State Persists after gesture

Pattern 1: Draggable View

struct DraggableCard: View {
    @GestureState private var dragOffset = CGSize.zero  // Temporary
    @State private var position = CGSize.zero           // Permanent

    var body: some View {
        RoundedRectangle(cornerRadius: 12)
            .offset(x: position.width + dragOffset.width,
                    y: position.height + dragOffset.height)
            .gesture(
                DragGesture()
                    .updating($dragOffset) { value, state, _ in
                        state = value.translation
                    }
                    .onEnded { value in
                        withAnimation(.spring()) {
                            position.width += value.translation.width
                            position.height += value.translation.height
                        }
                    }
            )
    }
}

Pattern 2: Simultaneous Gestures

// Drag AND pinch-zoom at the same time
.gesture(
    DragGesture()
        .updating($dragOffset) { value, state, _ in state = value.translation }
        .simultaneously(with:
            MagnificationGesture()
                .updating($scale) { value, state, _ in state = value.magnification }
        )
)

Pattern 3: Sequenced Gestures

// Long press THEN drag (like iOS Home Screen reordering)
LongPressGesture(minimumDuration: 0.5)
    .onEnded { _ in isEditing = true }
    .sequenced(before:
        DragGesture()
            .updating($dragOffset) { value, state, _ in state = value.translation }
    )

Pattern 4: Exclusive Gestures

// Double-tap OR single-tap (not both)
TapGesture(count: 2)
    .onEnded { zoom() }
    .exclusively(before:
        TapGesture(count: 1)
            .onEnded { select() }
    )

Common Pitfalls

Using @State instead of @GestureState:

// WRONG - offset stays at last value
@State private var offset = CGSize.zero

// CORRECT - auto-resets when gesture ends
@GestureState private var offset = CGSize.zero

Gesture blocks ScrollView:

// WRONG - blocks scrolling
.gesture(DragGesture())

// CORRECT - allows both
.simultaneousGesture(DragGesture())

Using TapGesture instead of Button:

// WRONG - no accessibility
Text("Submit").onTapGesture { }

// CORRECT - proper semantics
Button("Submit") { }

Accessibility

Image("slider")
    .gesture(DragGesture().onChanged { ... })
    .accessibilityAdjustableAction { direction in
        switch direction {
        case .increment: volume += 5
        case .decrement: volume -= 5
        @unknown default: break
        }
    }

Source: SKILL.md on GitHub

1 warning16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill is a collection of reference documentation and code patterns for advanced SwiftUI development. No security issues, malicious code, or suspicious instructions were detected.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    5/5 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at d62eb71. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Dormantupdated 9 months ago

README badge

README badge for johnrogers/claude-swift-engineering/swiftui-advanced