Awesome-omni-skills swiftui-view-refactor
SwiftUI View Refactor workflow skill. Use this skill when the user needs Refactor SwiftUI views into smaller components with stable, explicit data flow and the operator should preserve the upstream workflow, copied support files, and provenance before merging or handing off.
git clone https://github.com/diegosouzapw/awesome-omni-skills
T=$(mktemp -d) && git clone --depth=1 https://github.com/diegosouzapw/awesome-omni-skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/swiftui-view-refactor" ~/.claude/skills/diegosouzapw-awesome-omni-skills-swiftui-view-refactor && rm -rf "$T"
skills/swiftui-view-refactor/SKILL.mdSwiftUI View Refactor
Overview
This public intake copy packages
plugins/antigravity-awesome-skills-claude/skills/swiftui-view-refactor from https://github.com/sickn33/antigravity-awesome-skills into the native Omni Skills editorial shape without hiding its origin.
Use it when the operator needs the upstream workflow, support files, and repository context to stay intact while the public validator and private enhancer continue their normal downstream flow.
This intake keeps the copied upstream files intact and uses
metadata.json plus ORIGIN.md as the provenance anchor for review.
SwiftUI View Refactor
Imported source sections that did not map cleanly to the public headings are still preserved below or in the support files. Notable imported sections: Notes, Large-view handling, Limitations.
When to Use This Skill
Use this section as the trigger filter. It should make the activation boundary explicit before the operator loads files, runs commands, or opens a pull request.
- When cleaning up a large SwiftUI view or splitting long body implementations.
- When you need smaller subviews, explicit dependency injection, or better Observation usage.
- Use when the request clearly matches the imported source intent: Refactor SwiftUI views into smaller components with stable, explicit data flow.
- Use when the operator should preserve upstream workflow detail instead of rewriting the process from scratch.
- Use when provenance needs to stay visible in the answer, PR, or review packet.
- Use when copied upstream references, examples, or scripts materially improve the answer.
Operating Table
| Situation | Start here | Why it matters |
|---|---|---|
| First-time use | | Confirms repository, branch, commit, and imported path before touching the copied workflow |
| Provenance review | | Gives reviewers a plain-language audit trail for the imported source |
| Workflow execution | | Starts with the smallest copied file that materially changes execution |
| Supporting context | | Adds the next most relevant copied source file without loading the entire package |
| Handoff decision | | Helps the operator switch to a stronger native skill when the task drifts |
Workflow
This workflow is intentionally editorial and operational at the same time. It keeps the imported source useful to the operator while still satisfying the public intake standards that feed the downstream enhancer flow.
- Reorder the view to match the ordering rules.
- Remove inline actions and side effects from body; move business logic into services/models and keep only thin orchestration in the view.
- Shorten long bodies by extracting dedicated subview types; avoid rebuilding the screen out of many computed some View helpers.
- Ensure stable view structure: avoid top-level if-based branch swapping; move conditions to localized sections/modifiers.
- If a view model exists or is explicitly required, replace optional view models with a non-optional @State view model initialized in init.
- Confirm Observation usage: @State for root @Observable models on iOS 17+, legacy wrappers only when the deployment target requires them.
- Keep behavior intact: do not change layout or business logic unless requested.
Imported Workflow Notes
Imported: Workflow
- Reorder the view to match the ordering rules.
- Remove inline actions and side effects from
; move business logic into services/models and keep only thin orchestration in the view.body - Shorten long bodies by extracting dedicated subview types; avoid rebuilding the screen out of many computed
helpers.some View - Ensure stable view structure: avoid top-level
-based branch swapping; move conditions to localized sections/modifiers.if - If a view model exists or is explicitly required, replace optional view models with a non-optional
view model initialized in@State
.init - Confirm Observation usage:
for root@State
models on iOS 17+, legacy wrappers only when the deployment target requires them.@Observable - Keep behavior intact: do not change layout or business logic unless requested.
Imported: Overview
Refactor SwiftUI views toward small, explicit, stable view types. Default to vanilla SwiftUI: local state in the view, shared dependencies in the environment, business logic in services/models, and view models only when the request or existing code clearly requires one.
Imported: Notes
- Prefer small, explicit view types over large conditional blocks and large computed
properties.some View - Keep computed view builders below
and non-view computed vars abovebody
.init - A good SwiftUI refactor should make the view read top-to-bottom as data flow plus layout, not as mixed layout and imperative logic.
- For MV-first guidance and rationale, see
.references/mv-patterns.md
Examples
Example 1: Ask for the upstream workflow directly
Use @swiftui-view-refactor to handle <task>. Start from the copied upstream workflow, load only the files that change the outcome, and keep provenance visible in the answer.
Explanation: This is the safest starting point when the operator needs the imported workflow, but not the entire repository.
Example 2: Ask for a provenance-grounded review
Review @swiftui-view-refactor against metadata.json and ORIGIN.md, then explain which copied upstream files you would load first and why.
Explanation: Use this before review or troubleshooting when you need a precise, auditable explanation of origin and file selection.
Example 3: Narrow the copied support files before execution
Use @swiftui-view-refactor for <task>. Load only the copied references, examples, or scripts that change the outcome, and name the files explicitly before proceeding.
Explanation: This keeps the skill aligned with progressive disclosure instead of loading the whole copied package by default.
Example 4: Build a reviewer packet
Review @swiftui-view-refactor using the copied upstream files plus provenance, then summarize any gaps before merge.
Explanation: This is useful when the PR is waiting for human review and you want a repeatable audit packet.
Best Practices
Treat the generated public skill as a reviewable packaging layer around the upstream repository. The goal is to keep provenance explicit and load only the copied source material that materially improves execution.
- Enforce this ordering unless the existing file has a stronger local convention you must preserve.
- Environment
- private/public let
- @State / other stored properties
- computed var (non-view)
- init
- body
Imported Operating Notes
Imported: Core Guidelines
1) View ordering (top → bottom)
- Enforce this ordering unless the existing file has a stronger local convention you must preserve.
- Environment
/privatepubliclet
/ other stored properties@State- computed
(non-view)var initbody- computed view builders / other view helpers
- helper / async functions
2) Default to MV, not MVVM
- Views should be lightweight state expressions and orchestration points, not containers for business logic.
- Favor
,@State
,@Environment
,@Query
,.task
, and.task(id:)
before reaching for a view model.onChange - Inject services and shared models via
; keep domain logic in services/models, not in the view body.@Environment - Do not introduce a view model just to mirror local view state or wrap environment dependencies.
- If a screen is getting large, split the UI into subviews before inventing a new view model layer.
3) Strongly prefer dedicated subview types over computed some View
helpers
some View- Flag
properties that are longer than roughly one screen or contain multiple logical sections.body - Prefer extracting dedicated
types for non-trivial sections, especially when they have state, async work, branching, or deserve their own preview.View - Keep computed
helpers rare and small. Do not build an entire screen out ofsome View
-style fragments.private var header: some View - Pass small, explicit inputs (data, bindings, callbacks) into extracted subviews instead of handing down the entire parent state.
- If an extracted subview becomes reusable or independently meaningful, move it to its own file.
Prefer:
var body: some View { List { HeaderSection(title: title, subtitle: subtitle) FilterSection( filterOptions: filterOptions, selectedFilter: $selectedFilter ) ResultsSection(items: filteredItems) FooterSection() } } private struct HeaderSection: View { let title: String let subtitle: String var body: some View { VStack(alignment: .leading, spacing: 6) { Text(title).font(.title2) Text(subtitle).font(.subheadline) } } } private struct FilterSection: View { let filterOptions: [FilterOption] @Binding var selectedFilter: FilterOption var body: some View { ScrollView(.horizontal, showsIndicators: false) { HStack { ForEach(filterOptions, id: \.self) { option in FilterChip(option: option, isSelected: option == selectedFilter) .onTapGesture { selectedFilter = option } } } } } }
Avoid:
var body: some View { List { header filters results footer } } private var header: some View { VStack(alignment: .leading, spacing: 6) { Text(title).font(.title2) Text(subtitle).font(.subheadline) } }
3b) Extract actions and side effects out of body
body- Do not keep non-trivial button actions inline in the view body.
- Do not bury business logic inside
,.task
,.onAppear
, or.onChange
..refreshable - Prefer calling small private methods from the view, and move real business logic into services/models.
- The body should read like UI, not like a view controller.
Button("Save", action: save) .disabled(isSaving) .task(id: searchText) { await reload(for: searchText) } private func save() { Task { await saveAsync() } } private func reload(for searchText: String) async { guard !searchText.isEmpty else { results = [] return } await searchService.search(searchText) }
4) Keep a stable view tree (avoid top-level conditional view swapping)
- Avoid
or computed views that return completely different root branches viabody
.if/else - Prefer a single stable base view with conditions inside sections/modifiers (
,overlay
,opacity
,disabled
, etc.).toolbar - Root-level branch swapping causes identity churn, broader invalidation, and extra recomputation.
Prefer:
var body: some View { List { documentsListContent } .toolbar { if canEdit { editToolbar } } }
Avoid:
var documentsListView: some View { if canEdit { editableDocumentsList } else { readOnlyDocumentsList } }
5) View model handling (only if already present or explicitly requested)
- Treat view models as a legacy or explicit-need pattern, not the default.
- Do not introduce a view model unless the request or existing code clearly calls for one.
- If a view model exists, make it non-optional when possible.
- Pass dependencies to the view via
, then create the view model in the view'sinit
.init - Avoid
patterns and other delayed setup workarounds.bootstrapIfNeeded
Example (Observation-based):
@State private var viewModel: SomeViewModel init(dependency: Dependency) { _viewModel = State(initialValue: SomeViewModel(dependency: dependency)) }
6) Observation usage
- For
reference types on iOS 17+, store them as@Observable
in the owning view.@State - Pass observables down explicitly; avoid optional state unless the UI genuinely needs it.
- If the deployment target includes iOS 16 or earlier, use
at the owner and@StateObject
when injecting legacy observable models.@ObservedObject
Troubleshooting
Problem: The operator skipped the imported context and answered too generically
Symptoms: The result ignores the upstream workflow in
plugins/antigravity-awesome-skills-claude/skills/swiftui-view-refactor, fails to mention provenance, or does not use any copied source files at all.
Solution: Re-open metadata.json, ORIGIN.md, and the most relevant copied upstream files. Load only the files that materially change the answer, then restate the provenance before continuing.
Problem: The imported workflow feels incomplete during review
Symptoms: Reviewers can see the generated
SKILL.md, but they cannot quickly tell which references, examples, or scripts matter for the current task.
Solution: Point at the exact copied references, examples, scripts, or assets that justify the path you took. If the gap is still real, record it in the PR instead of hiding it.
Problem: The task drifted into a different specialization
Symptoms: The imported skill starts in the right place, but the work turns into debugging, architecture, design, security, or release orchestration that a native skill handles better. Solution: Use the related skills section to hand off deliberately. Keep the imported provenance visible so the next skill inherits the right context instead of starting blind.
Related Skills
- Use when the work is better handled by that native specialization after this imported skill establishes context.@supply-chain-risk-auditor
- Use when the work is better handled by that native specialization after this imported skill establishes context.@sveltekit
- Use when the work is better handled by that native specialization after this imported skill establishes context.@swift-concurrency-expert
- Use when the work is better handled by that native specialization after this imported skill establishes context.@swiftui-expert-skill
Additional Resources
Use this support matrix and the linked files below as the operator packet for this imported skill. They should reflect real copied source material, not generic scaffolding.
| Resource family | What it gives the reviewer | Example path |
|---|---|---|
| copied reference notes, guides, or background material from upstream | |
| worked examples or reusable prompts copied from upstream | |
| upstream helper scripts that change execution or validation | |
| routing or delegation notes that are genuinely part of the imported package | |
| supporting assets or schemas copied from the source package | |
Imported Reference Notes
Imported: Large-view handling
When a SwiftUI view file exceeds ~300 lines, split it aggressively. Extract meaningful sections into dedicated
View types instead of hiding complexity in many computed properties. Use private extensions with // MARK: - comments for actions and helpers, but do not treat extensions as a substitute for breaking a giant screen into smaller view types. If an extracted subview is reused or independently meaningful, move it into its own file.
Imported: Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.