deonmenezes/mobile-app-skill / skills/swiftui-expert-skill
swiftui-expert-skill
VerifiedUse when writing, reviewing, or refactoring SwiftUI code for iOS or macOS, including state and `@Observable` data flow, view composition, resizable layouts, safe areas, display scale, performance, lists, environment, localization, animation, Liquid Glass, and API migration. Also use for iPhone Duo, foldable, or large-display layouts (`NavigationSplitView` on large displays, iPhone tab sidebar, two-column reflow, foldable grids, `ArrangementView`, `ReservedRegion`), hinge effects, vertical bars, `@State` initialization or synthesized-property diagnostics, `@ContentBuilder` ambiguity, `reorderable` drag/drop, custom `AsyncImage` `URLSession`, swipe actions outside List, item-bound `alert`/`confirmationDialog`, `ToolbarOverflowMenu`, `AnimatableValues`, Document APIs (`Document`/`DocumentReader`), and Instruments `.trace` capture or analysis.
references/modifier-patterns.md
View on GitHub# SwiftUI Modifier and Identity Patterns
Use this reference when a modifier is conditional or when modifier composition changes a view's structural identity.
## Avoid Conditional `.if` Modifiers
Do not create an `@ViewBuilder` extension that switches between `transform(self)` and `self`. Its branches produce different view types, so toggling the condition can replace the subtree, reset state, and break animations.
```swift
// AVOID
extension View {
@ViewBuilder
func `if`<Content: View>(
_ condition: Bool,
transform: (Self) -> Content
) -> some View {
if condition { transform(self) } else { self }
}
}
```
When two states describe the same view, keep one structural identity and vary the modifier's value:
```swift
Text("Hello")
.foregroundStyle(isHighlighted ? .red : .primary)
.opacity(isEnabled ? 1 : 0.5)
```
Use `if` when the branches genuinely represent different views or when content is truly optional. Do not silently refactor an existing `.if` modifier during unrelated work; call out the identity risk and keep the behavioral change focused.
## Use `AnyShapeStyle` When Style Types Differ
Some `ShapeStyle` branches do not unify in a ternary. Preserve the view's identity by erasing the styles, not the view:
```swift
Text("Status")
.foregroundStyle(
isActive
? AnyShapeStyle(.primary)
: AnyShapeStyle(.tint)
)
```
`AnyShapeStyle` is an appropriate value-type eraser and does not have the structural-identity cost of `AnyView`. Add it only when the original ternary does not compile; many combinations involving `Color`, such as `.yellow` and `.primary`, already unify.
## Prefer No-Effect Values for Visual State
For visibility or styling changes where the same view should retain state, prefer an always-present modifier with a no-effect value:
```swift
DetailsView()
.opacity(isVisible ? 1 : 0)
```
Opacity keeps the view in layout and accessibility by default. Use conditional inclusion when hidden content should be removed from layout, interaction, or accessibility.
## Checklist
- [ ] Conditional styling changes modifier values instead of branching the whole view
- [ ] Existing `.if` helpers are reported as focused identity risks, not rewritten incidentally
- [ ] `AnyShapeStyle` is used only when different style types fail to unify
- [ ] `AnyView` is not introduced to solve a modifier type mismatch
- [ ] Visibility behavior intentionally accounts for layout, hit testing, and accessibility
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |