@mmerterden/multi-agent-pipeline 16.18.0 → 16.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -0
- package/README.md +5 -5
- package/README.tr.md +2 -2
- package/docs/FIGMA_PIPELINE.md +1 -1
- package/docs/adr/0001-three-model-triage.md +4 -2
- package/docs/architecture.md +2 -2
- package/docs/ecosystem.md +13 -11
- package/docs/features.md +2 -2
- package/index.js +1 -1
- package/install/_common.mjs +25 -1
- package/install/_dev-only-files.mjs +2 -2
- package/install/_mcp-register.mjs +4 -3
- package/install/_plugin-skills.mjs +1 -3
- package/install/copilot.mjs +18 -9
- package/install/index.mjs +2 -4
- package/install/templates/copilot-instructions.md +7 -7
- package/package.json +1 -1
- package/pipeline/claude-md-template.md +2 -2
- package/pipeline/commands/multi-agent/SKILL.md +5 -5
- package/pipeline/commands/multi-agent/complaint-analysis/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/design-check/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/help/SKILL.md +2 -2
- package/pipeline/commands/multi-agent/local-autopilot/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/review/SKILL.md +27 -14
- package/pipeline/commands/multi-agent/review-analysis/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/store-ready/SKILL.md +2 -2
- package/pipeline/commands/multi-agent/sync/SKILL.md +2 -2
- package/pipeline/commands/sim-test.md +54 -15
- package/pipeline/lib/credential-inventory.sh +15 -2
- package/pipeline/lib/credential-store-resolver.sh +14 -4
- package/pipeline/lib/credential-store.sh +8 -2
- package/pipeline/lib/extract-conventions.sh +1 -14
- package/pipeline/lib/fetch-confluence.sh +12 -4
- package/pipeline/lib/fetch-crashlytics.sh +11 -8
- package/pipeline/lib/fetch-document.sh +1 -1
- package/pipeline/lib/fetch-figma-annotations.sh +7 -5
- package/pipeline/lib/fetch-fortify.sh +5 -3
- package/pipeline/lib/fetch-graylog.sh +5 -3
- package/pipeline/lib/figma-mcp-refresh.sh +1 -1
- package/pipeline/lib/figma-screenshot.sh +27 -24
- package/pipeline/lib/figma-token.sh +8 -4
- package/pipeline/lib/issue-fetcher.sh +0 -1
- package/pipeline/lib/jira-publish.sh +7 -5
- package/pipeline/lib/md2confluence-v3.py +13 -7
- package/pipeline/lib/multi-repo-pipeline.sh +18 -8
- package/pipeline/lib/plan-todos.sh +11 -0
- package/pipeline/lib/post-pr-review.sh +9 -2
- package/pipeline/lib/repo-cache.sh +18 -10
- package/pipeline/lib/review-watch.sh +60 -14
- package/pipeline/lib/shadow-git.sh +8 -4
- package/pipeline/lib/vercel-deploy.sh +2 -2
- package/pipeline/multi-agent-refs/_dev-context.md +5 -2
- package/pipeline/multi-agent-refs/analysis/locked.md +4 -4
- package/pipeline/multi-agent-refs/analysis/render.md +1 -1
- package/pipeline/multi-agent-refs/cross-cli-contract.md +1 -1
- package/pipeline/multi-agent-refs/outside-the-pipeline.md +6 -6
- package/pipeline/multi-agent-refs/phases/log-format.md +1 -1
- package/pipeline/multi-agent-refs/phases/modes.md +1 -1
- package/pipeline/multi-agent-refs/phases/phase-0-init.md +4 -2
- package/pipeline/multi-agent-refs/phases/phase-1-analysis.md +3 -3
- package/pipeline/multi-agent-refs/phases/phase-2-planning.md +5 -5
- package/pipeline/multi-agent-refs/phases/phase-4-review.md +21 -16
- package/pipeline/multi-agent-refs/tracker-contract.md +1 -1
- package/pipeline/rules/figma-pipeline.md +18 -72
- package/pipeline/rules/outside-the-pipeline.md +4 -3
- package/pipeline/schemas/agent-state.schema.json +1 -1
- package/pipeline/schemas/token-budget.json +1 -1
- package/pipeline/scripts/_stack-routing.mjs +1 -1
- package/pipeline/scripts/agent-guard.py +102 -21
- package/pipeline/scripts/anonymize-findings.mjs +7 -6
- package/pipeline/scripts/build-skills-index.mjs +14 -3
- package/pipeline/scripts/cost-budget-check.mjs +5 -3
- package/pipeline/scripts/cost-lib.sh +0 -15
- package/pipeline/scripts/diff-explain.mjs +22 -12
- package/pipeline/scripts/gc-refs.sh +6 -2
- package/pipeline/scripts/gc-tmp.sh +1 -1
- package/pipeline/scripts/gc-worktrees.sh +1 -1
- package/pipeline/scripts/gen-mode-dispatch.mjs +3 -3
- package/pipeline/scripts/github-ssh-setup.sh +7 -2
- package/pipeline/scripts/graph-build.mjs +2 -2
- package/pipeline/scripts/jira-wiki-escape.mjs +2 -1
- package/pipeline/scripts/keychain.py +12 -11
- package/pipeline/scripts/learning-curve.mjs +1 -1
- package/pipeline/scripts/migrate-prefs.mjs +1 -1
- package/pipeline/scripts/output-quality-check.sh +3 -1
- package/pipeline/scripts/phase-tracker.sh +1 -1
- package/pipeline/scripts/phase0-exit-gate.mjs +2 -1
- package/pipeline/scripts/plan-coverage-gate.mjs +2 -1
- package/pipeline/scripts/pre-commit-check.sh +23 -13
- package/pipeline/scripts/prune-logs.sh +1 -1
- package/pipeline/scripts/render-agent-log-cost.sh +3 -1
- package/pipeline/scripts/render-cost-summary.sh +4 -2
- package/pipeline/scripts/render-work-summary.sh +5 -3
- package/pipeline/scripts/repo-map.mjs +3 -2
- package/pipeline/scripts/scan-skills.sh +6 -2
- package/pipeline/scripts/search-logs.sh +8 -6
- package/pipeline/scripts/sign-skills.sh +3 -1
- package/pipeline/scripts/smoke-cross-cli-behavior.sh +1 -1
- package/pipeline/scripts/triage-memory.mjs +25 -4
- package/pipeline/scripts/uninstall.mjs +20 -12
- package/pipeline/scripts/update-check.sh +2 -2
- package/pipeline/scripts/update-issue-progress.sh +6 -5
- package/pipeline/scripts/validate-analysis-doc.mjs +6 -6
- package/pipeline/scripts/verify-skills.sh +3 -1
- package/pipeline/scripts/worktree-finalize.sh +22 -10
- package/pipeline/skills/.skill-manifest.json +81 -57
- package/pipeline/skills/.skills-index.json +19 -19
- package/pipeline/skills/shared/README.md +8 -8
- package/pipeline/skills/shared/core/multi-agent/SKILL.md +7 -7
- package/pipeline/skills/shared/core/multi-agent-design-check/SKILL.md +1 -1
- package/pipeline/skills/shared/core/multi-agent-help/SKILL.md +2 -2
- package/pipeline/skills/shared/core/multi-agent-local/SKILL.md +1 -1
- package/pipeline/skills/shared/core/multi-agent-local-autopilot/SKILL.md +2 -2
- package/pipeline/skills/shared/core/multi-agent-review/SKILL.md +23 -14
- package/pipeline/skills/shared/core/multi-agent-sync/SKILL.md +2 -2
- package/pipeline/skills/shared/external/NOTICE-dimillian-skills.md +56 -0
- package/pipeline/skills/shared/external/accessibility-compliance-accessibility-audit/SKILL.md +0 -4
- package/pipeline/skills/shared/external/api-patterns/SKILL.md +12 -24
- package/pipeline/skills/shared/external/app-store-changelog/references/release-notes-guidelines.md +34 -0
- package/pipeline/skills/shared/external/app-store-changelog/scripts/collect_release_changes.sh +33 -0
- package/pipeline/skills/shared/external/architecture/SKILL.md +7 -9
- package/pipeline/skills/shared/external/debugging-strategies/SKILL.md +0 -4
- package/pipeline/skills/shared/external/fastapi-pro/SKILL.md +0 -1
- package/pipeline/skills/shared/external/github-actions-templates/SKILL.md +0 -14
- package/pipeline/skills/shared/external/hig-components-content/SKILL.md +13 -13
- package/pipeline/skills/shared/external/hig-components-layout/SKILL.md +16 -16
- package/pipeline/skills/shared/external/hig-components-status/SKILL.md +6 -6
- package/pipeline/skills/shared/external/hig-components-system/SKILL.md +13 -13
- package/pipeline/skills/shared/external/hig-foundations/SKILL.md +23 -23
- package/pipeline/skills/shared/external/hig-inputs/SKILL.md +18 -18
- package/pipeline/skills/shared/external/hig-patterns/SKILL.md +30 -30
- package/pipeline/skills/shared/external/hig-platforms/SKILL.md +11 -11
- package/pipeline/skills/shared/external/hig-technologies/SKILL.md +33 -33
- package/pipeline/skills/shared/external/ios-coding-standard/references/STANDARD.md +52 -52
- package/pipeline/skills/shared/external/ios-coding-standard/references/lint-local.sh +1 -1
- package/pipeline/skills/shared/external/ios-coding-standard/references/rules.yml +11 -11
- package/pipeline/skills/shared/external/ios-developer/SKILL.md +0 -1
- package/pipeline/skills/shared/external/ios-module-structure/SKILL.md +7 -3
- package/pipeline/skills/shared/external/localization-reuse-map/SKILL.md +9 -15
- package/pipeline/skills/shared/external/macos-spm-app-packaging/SKILL.md +0 -5
- package/pipeline/skills/shared/external/macos-spm-app-packaging/assets/templates/bootstrap/Package.swift +17 -0
- package/pipeline/skills/shared/external/macos-spm-app-packaging/assets/templates/bootstrap/Sources/MyApp/Resources/.keep +0 -0
- package/pipeline/skills/shared/external/macos-spm-app-packaging/assets/templates/bootstrap/Sources/MyApp/main.swift +11 -0
- package/pipeline/skills/shared/external/macos-spm-app-packaging/assets/templates/bootstrap/version.env +2 -0
- package/pipeline/skills/shared/external/macos-spm-app-packaging/assets/templates/build_icon.sh +49 -0
- package/pipeline/skills/shared/external/macos-spm-app-packaging/assets/templates/compile_and_run.sh +63 -0
- package/pipeline/skills/shared/external/macos-spm-app-packaging/assets/templates/launch.sh +28 -0
- package/pipeline/skills/shared/external/macos-spm-app-packaging/assets/templates/make_appcast.sh +82 -0
- package/pipeline/skills/shared/external/macos-spm-app-packaging/assets/templates/package_app.sh +206 -0
- package/pipeline/skills/shared/external/macos-spm-app-packaging/assets/templates/setup_dev_signing.sh +52 -0
- package/pipeline/skills/shared/external/macos-spm-app-packaging/assets/templates/sign-and-notarize.sh +52 -0
- package/pipeline/skills/shared/external/macos-spm-app-packaging/assets/templates/version.env +2 -0
- package/pipeline/skills/shared/external/macos-spm-app-packaging/references/packaging.md +17 -0
- package/pipeline/skills/shared/external/macos-spm-app-packaging/references/release.md +32 -0
- package/pipeline/skills/shared/external/macos-spm-app-packaging/references/scaffold.md +79 -0
- package/pipeline/skills/shared/external/monorepo-architect/SKILL.md +0 -1
- package/pipeline/skills/shared/external/nodejs-backend-patterns/SKILL.md +0 -4
- package/pipeline/skills/shared/external/swift-concurrency-expert/references/approachable-concurrency.md +63 -0
- package/pipeline/skills/shared/external/swift-concurrency-expert/references/swift-6-2-concurrency.md +272 -0
- package/pipeline/skills/shared/external/swift-concurrency-expert/references/swiftui-concurrency-tour-wwdc.md +33 -0
- package/pipeline/skills/shared/external/swiftui-performance-audit/references/code-smells.md +150 -0
- package/pipeline/skills/shared/external/swiftui-performance-audit/references/demystify-swiftui-performance-wwdc23.md +46 -0
- package/pipeline/skills/shared/external/swiftui-performance-audit/references/optimizing-swiftui-performance-instruments.md +29 -0
- package/pipeline/skills/shared/external/swiftui-performance-audit/references/profiling-intake.md +44 -0
- package/pipeline/skills/shared/external/swiftui-performance-audit/references/report-template.md +47 -0
- package/pipeline/skills/shared/external/swiftui-performance-audit/references/understanding-hangs-in-your-app.md +33 -0
- package/pipeline/skills/shared/external/swiftui-performance-audit/references/understanding-improving-swiftui-performance.md +52 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/app-wiring.md +201 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/async-state.md +96 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/components-index.md +46 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/controls.md +57 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/deeplinks.md +66 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/focus.md +90 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/form.md +97 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/grids.md +71 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/haptics.md +71 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/input-toolbar.md +51 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/lightweight-clients.md +93 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/list.md +86 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/loading-placeholders.md +38 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/macos-settings.md +71 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/matched-transitions.md +59 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/media.md +73 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/menu-bar.md +101 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/navigationstack.md +159 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/overlay.md +45 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/performance.md +62 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/previews.md +48 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/scroll-reveal.md +133 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/scrollview.md +87 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/searchable.md +71 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/sheets.md +155 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/split-views.md +72 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/tabview.md +114 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/theming.md +71 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/title-menus.md +93 -0
- package/pipeline/skills/shared/external/swiftui-ui-patterns/references/top-bar.md +49 -0
- package/pipeline/skills/shared/external/swiftui-view-refactor/references/mv-patterns.md +161 -0
- package/pipeline/skills/skills-index.md +8 -8
- package/pipeline/skills/shared/external/help-skills/SKILL.md +0 -166
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Optimizing SwiftUI Performance with Instruments (Summary)
|
|
2
|
+
|
|
3
|
+
Context: WWDC session introducing the next-generation SwiftUI Instrument in Instruments 26 and how to diagnose SwiftUI-specific bottlenecks.
|
|
4
|
+
|
|
5
|
+
## Key takeaways
|
|
6
|
+
|
|
7
|
+
- Profile SwiftUI issues with the SwiftUI template (SwiftUI instrument + Time Profiler + Hangs/Hitches).
|
|
8
|
+
- Long view body updates are a common bottleneck; use "Long View Body Updates" to identify slow bodies.
|
|
9
|
+
- Set inspection range on a long update and correlate with Time Profiler to find expensive frames.
|
|
10
|
+
- Keep work out of `body`: move formatting, sorting, image decoding, and other expensive work into cached or precomputed paths.
|
|
11
|
+
- Use Cause & Effect Graph to diagnose *why* updates occur; SwiftUI is declarative, so backtraces are often unhelpful.
|
|
12
|
+
- Avoid broad dependencies that trigger many updates (e.g., `@Observable` arrays or global environment reads).
|
|
13
|
+
- Prefer granular view models and scoped state so only the affected view updates.
|
|
14
|
+
- Environment values update checks still cost time; avoid placing fast-changing values (timers, geometry) in environment.
|
|
15
|
+
- Profile early and often during feature development to catch regressions.
|
|
16
|
+
|
|
17
|
+
## Suggested workflow (condensed)
|
|
18
|
+
|
|
19
|
+
1. Record a trace in Release mode using the SwiftUI template.
|
|
20
|
+
2. Inspect "Long View Body Updates" and "Other Long Updates."
|
|
21
|
+
3. Zoom into a long update, then inspect Time Profiler for hot frames.
|
|
22
|
+
4. Fix slow body work by moving heavy logic into precomputed/cache paths.
|
|
23
|
+
5. Use Cause & Effect Graph to identify unintended update fan-out.
|
|
24
|
+
6. Re-record and compare the update counts and hitch frequency.
|
|
25
|
+
|
|
26
|
+
## Example patterns from the session
|
|
27
|
+
|
|
28
|
+
- Caching formatted distance strings in a location manager instead of computing in `body`.
|
|
29
|
+
- Replacing a dependency on a global favorites array with per-item view models to reduce update fan-out.
|
package/pipeline/skills/shared/external/swiftui-performance-audit/references/profiling-intake.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Profiling intake and collection checklist
|
|
2
|
+
|
|
3
|
+
## Intent
|
|
4
|
+
|
|
5
|
+
Use this checklist when code review alone cannot explain the SwiftUI performance issue and you need runtime evidence from the user.
|
|
6
|
+
|
|
7
|
+
## Ask for first
|
|
8
|
+
|
|
9
|
+
- Exact symptom: CPU spike, dropped frames, memory growth, hangs, or excessive view updates.
|
|
10
|
+
- Exact interaction: scrolling, typing, initial load, navigation push/pop, animation, sheet presentation, or background refresh.
|
|
11
|
+
- Target device and OS version.
|
|
12
|
+
- Whether the issue was reproduced on a real device or only in Simulator.
|
|
13
|
+
- Build configuration: Debug or Release.
|
|
14
|
+
- Whether the user already has a baseline or before/after comparison.
|
|
15
|
+
|
|
16
|
+
## Default profiling request
|
|
17
|
+
|
|
18
|
+
Ask the user to:
|
|
19
|
+
- Run the app in a Release build when possible.
|
|
20
|
+
- Use the SwiftUI Instruments template.
|
|
21
|
+
- Reproduce the exact problematic interaction only long enough to capture the issue.
|
|
22
|
+
- Capture the SwiftUI timeline and Time Profiler together.
|
|
23
|
+
- Export the trace or provide screenshots of the key SwiftUI lanes and the Time Profiler call tree.
|
|
24
|
+
|
|
25
|
+
## Ask for these artifacts
|
|
26
|
+
|
|
27
|
+
- Trace export or screenshots of the relevant SwiftUI lanes
|
|
28
|
+
- Time Profiler call tree screenshot or export
|
|
29
|
+
- Device/OS/build configuration
|
|
30
|
+
- A short note describing what action was happening at the time of the capture
|
|
31
|
+
- If memory is involved, the memory graph or Allocations data if available
|
|
32
|
+
|
|
33
|
+
## When to ask for more
|
|
34
|
+
|
|
35
|
+
- Ask for a second capture if the first run mixes multiple interactions.
|
|
36
|
+
- Ask for a before/after pair if the user has already tried a fix.
|
|
37
|
+
- Ask for a device capture if the issue only appears in Simulator or if scrolling smoothness matters.
|
|
38
|
+
|
|
39
|
+
## Common traps
|
|
40
|
+
|
|
41
|
+
- Debug builds can distort SwiftUI timing and allocation behavior.
|
|
42
|
+
- Simulator traces can miss device-only rendering or memory issues.
|
|
43
|
+
- Mixed interactions in one capture make attribution harder.
|
|
44
|
+
- Screenshots without the reproduction note are much harder to interpret.
|
package/pipeline/skills/shared/external/swiftui-performance-audit/references/report-template.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Audit output template
|
|
2
|
+
|
|
3
|
+
## Intent
|
|
4
|
+
|
|
5
|
+
Use this structure when reporting SwiftUI performance findings so the user can quickly see the symptom, evidence, likely cause, and next validation step.
|
|
6
|
+
|
|
7
|
+
## Template
|
|
8
|
+
|
|
9
|
+
```markdown
|
|
10
|
+
## Summary
|
|
11
|
+
|
|
12
|
+
[One short paragraph on the most likely bottleneck and whether the conclusion is code-backed or trace-backed.]
|
|
13
|
+
|
|
14
|
+
## Findings
|
|
15
|
+
|
|
16
|
+
1. [Issue title]
|
|
17
|
+
- Symptom: [what the user sees]
|
|
18
|
+
- Likely cause: [root cause]
|
|
19
|
+
- Evidence: [code reference or profiling evidence]
|
|
20
|
+
- Fix: [specific change]
|
|
21
|
+
- Validation: [what to measure after the fix]
|
|
22
|
+
|
|
23
|
+
2. [Issue title]
|
|
24
|
+
- Symptom: ...
|
|
25
|
+
- Likely cause: ...
|
|
26
|
+
- Evidence: ...
|
|
27
|
+
- Fix: ...
|
|
28
|
+
- Validation: ...
|
|
29
|
+
|
|
30
|
+
## Metrics
|
|
31
|
+
|
|
32
|
+
| Metric | Before | After | Notes |
|
|
33
|
+
| --- | --- | --- | --- |
|
|
34
|
+
| CPU | [value] | [value] | [note] |
|
|
35
|
+
| Frame drops / hitching | [value] | [value] | [note] |
|
|
36
|
+
| Memory peak | [value] | [value] | [note] |
|
|
37
|
+
|
|
38
|
+
## Next step
|
|
39
|
+
|
|
40
|
+
[One concrete next action: apply a fix, capture a better trace, or validate on device.]
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Notes
|
|
44
|
+
|
|
45
|
+
- Order findings by impact, not by file order.
|
|
46
|
+
- Say explicitly when a conclusion is still a hypothesis.
|
|
47
|
+
- If no metrics are available, omit the table and say what should be measured next.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Understanding Hangs in Your App (Summary)
|
|
2
|
+
|
|
3
|
+
Context: Apple guidance on identifying hangs caused by long-running main-thread work and understanding the main run loop.
|
|
4
|
+
|
|
5
|
+
## Key concepts
|
|
6
|
+
|
|
7
|
+
- A hang is a noticeable delay in a discrete interaction (typically >100 ms).
|
|
8
|
+
- Hangs almost always come from long-running work on the main thread.
|
|
9
|
+
- The main run loop processes UI events, timers, and main-queue work sequentially.
|
|
10
|
+
|
|
11
|
+
## Main-thread work stages
|
|
12
|
+
|
|
13
|
+
- Event delivery to the correct view/handler.
|
|
14
|
+
- Your code: state updates, data fetch, UI changes.
|
|
15
|
+
- Core Animation commit to the render server.
|
|
16
|
+
|
|
17
|
+
## Why the main run loop matters
|
|
18
|
+
|
|
19
|
+
- Only the main thread can update UI safely.
|
|
20
|
+
- The run loop is the foundation that executes main-queue work.
|
|
21
|
+
- If the run loop is busy, it can't handle new events; this causes hangs.
|
|
22
|
+
|
|
23
|
+
## Diagnosing hangs
|
|
24
|
+
|
|
25
|
+
- Observe the main run loop's busy periods: healthy loops sleep most of the time.
|
|
26
|
+
- Hang detection typically flags busy periods >250 ms.
|
|
27
|
+
- The Hangs instrument can be configured to lower thresholds.
|
|
28
|
+
|
|
29
|
+
## Practical takeaways
|
|
30
|
+
|
|
31
|
+
- Keep main-thread work short; offload heavy work from event handlers.
|
|
32
|
+
- Avoid long-running tasks on the main dispatch queue or main actor.
|
|
33
|
+
- Use run loop behavior as a proxy for user-perceived responsiveness.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Understanding and Improving SwiftUI Performance (Summary)
|
|
2
|
+
|
|
3
|
+
Context: Apple guidance on diagnosing SwiftUI performance with Instruments and applying design patterns to reduce long or frequent updates.
|
|
4
|
+
|
|
5
|
+
## Core concepts
|
|
6
|
+
|
|
7
|
+
- SwiftUI is declarative; view updates are driven by state, environment, and observable data dependencies.
|
|
8
|
+
- View bodies must compute quickly to meet frame deadlines; slow or frequent updates lead to hitches.
|
|
9
|
+
- Instruments is the primary tool to find long-running updates and excessive update frequency.
|
|
10
|
+
|
|
11
|
+
## Instruments workflow
|
|
12
|
+
|
|
13
|
+
1. Profile via Product > Profile.
|
|
14
|
+
2. Choose the SwiftUI template and record.
|
|
15
|
+
3. Exercise the target interaction.
|
|
16
|
+
4. Stop recording and inspect the SwiftUI track + Time Profiler.
|
|
17
|
+
|
|
18
|
+
## SwiftUI timeline lanes
|
|
19
|
+
|
|
20
|
+
- Update Groups: overview of time SwiftUI spends calculating updates.
|
|
21
|
+
- Long View Body Updates: orange >500us, red >1000us.
|
|
22
|
+
- Long Platform View Updates: AppKit/UIKit hosting in SwiftUI.
|
|
23
|
+
- Other Long Updates: geometry/text/layout and other SwiftUI work.
|
|
24
|
+
- Hitches: frame misses where UI wasn't ready in time.
|
|
25
|
+
|
|
26
|
+
## Diagnose long view body updates
|
|
27
|
+
|
|
28
|
+
- Expand the SwiftUI track; inspect module-specific subtracks.
|
|
29
|
+
- Set Inspection Range and correlate with Time Profiler.
|
|
30
|
+
- Use call tree or flame graph to identify expensive frames.
|
|
31
|
+
- Repeat the update to gather enough samples for analysis.
|
|
32
|
+
- Filter to a specific update (Show Calls Made by `MySwiftUIView.body`).
|
|
33
|
+
|
|
34
|
+
## Diagnose frequent updates
|
|
35
|
+
|
|
36
|
+
- Use Update Groups to find long active groups without long updates.
|
|
37
|
+
- Set inspection range on the group and analyze update counts.
|
|
38
|
+
- Use Cause graph ("Show Causes") to see what triggers updates.
|
|
39
|
+
- Compare causes with expected data flow; prioritize the highest-frequency causes.
|
|
40
|
+
|
|
41
|
+
## Remediation patterns
|
|
42
|
+
|
|
43
|
+
- Move expensive work out of `body` and cache results.
|
|
44
|
+
- Use `Observable()` macro to scope dependencies to properties actually read.
|
|
45
|
+
- Avoid broad dependencies that fan out updates to many views.
|
|
46
|
+
- Reduce layout churn; isolate state-dependent subtrees from layout readers.
|
|
47
|
+
- Avoid storing closures that capture parent state; precompute child views.
|
|
48
|
+
- Gate frequent updates (e.g., geometry changes) by thresholds.
|
|
49
|
+
|
|
50
|
+
## Verification
|
|
51
|
+
|
|
52
|
+
- Re-record after changes to confirm reduced update counts and fewer hitches.
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# App wiring and dependency graph
|
|
2
|
+
|
|
3
|
+
## Intent
|
|
4
|
+
|
|
5
|
+
Show how to wire the app shell (TabView + NavigationStack + sheets) and install a global dependency graph (environment objects, services, streaming clients, SwiftData ModelContainer) in one place.
|
|
6
|
+
|
|
7
|
+
## Recommended structure
|
|
8
|
+
|
|
9
|
+
1) Root view sets up tabs, per-tab routers, and sheets.
|
|
10
|
+
2) A dedicated view modifier installs global dependencies and lifecycle tasks (auth state, streaming watchers, push tokens, data containers).
|
|
11
|
+
3) Feature views pull only what they need from the environment; feature-specific state stays local.
|
|
12
|
+
|
|
13
|
+
## Dependency selection
|
|
14
|
+
|
|
15
|
+
- Use `@Environment` for app-level services, shared clients, theme/configuration, and values that many descendants genuinely need.
|
|
16
|
+
- Prefer initializer injection for feature-local dependencies and models. Do not move a dependency into the environment just to avoid passing one or two arguments.
|
|
17
|
+
- Keep mutable feature state out of the environment unless it is intentionally shared across broad parts of the app.
|
|
18
|
+
- Use `@EnvironmentObject` only as a legacy fallback or when the project already standardizes on it for a truly shared object.
|
|
19
|
+
|
|
20
|
+
## Root shell example (generic)
|
|
21
|
+
|
|
22
|
+
```swift
|
|
23
|
+
@MainActor
|
|
24
|
+
struct AppView: View {
|
|
25
|
+
@State private var selectedTab: AppTab = .home
|
|
26
|
+
@State private var tabRouter = TabRouter()
|
|
27
|
+
|
|
28
|
+
var body: some View {
|
|
29
|
+
TabView(selection: $selectedTab) {
|
|
30
|
+
ForEach(AppTab.allCases) { tab in
|
|
31
|
+
let router = tabRouter.router(for: tab)
|
|
32
|
+
NavigationStack(path: tabRouter.binding(for: tab)) {
|
|
33
|
+
tab.makeContentView()
|
|
34
|
+
}
|
|
35
|
+
.withSheetDestinations(sheet: Binding(
|
|
36
|
+
get: { router.presentedSheet },
|
|
37
|
+
set: { router.presentedSheet = $0 }
|
|
38
|
+
))
|
|
39
|
+
.environment(router)
|
|
40
|
+
.tabItem { tab.label }
|
|
41
|
+
.tag(tab)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
.withAppDependencyGraph()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Minimal `AppTab` example:
|
|
50
|
+
|
|
51
|
+
```swift
|
|
52
|
+
@MainActor
|
|
53
|
+
enum AppTab: Identifiable, Hashable, CaseIterable {
|
|
54
|
+
case home, notifications, settings
|
|
55
|
+
var id: String { String(describing: self) }
|
|
56
|
+
|
|
57
|
+
@ViewBuilder
|
|
58
|
+
func makeContentView() -> some View {
|
|
59
|
+
switch self {
|
|
60
|
+
case .home: HomeView()
|
|
61
|
+
case .notifications: NotificationsView()
|
|
62
|
+
case .settings: SettingsView()
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@ViewBuilder
|
|
67
|
+
var label: some View {
|
|
68
|
+
switch self {
|
|
69
|
+
case .home: Label("Home", systemImage: "house")
|
|
70
|
+
case .notifications: Label("Notifications", systemImage: "bell")
|
|
71
|
+
case .settings: Label("Settings", systemImage: "gear")
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Router skeleton:
|
|
78
|
+
|
|
79
|
+
```swift
|
|
80
|
+
@MainActor
|
|
81
|
+
@Observable
|
|
82
|
+
final class RouterPath {
|
|
83
|
+
var path: [Route] = []
|
|
84
|
+
var presentedSheet: SheetDestination?
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
enum Route: Hashable {
|
|
88
|
+
case detail(id: String)
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Dependency graph modifier (generic)
|
|
93
|
+
|
|
94
|
+
Use a single modifier to install environment objects and handle lifecycle hooks when the active account/client changes. This keeps wiring consistent and avoids forgetting a dependency in call sites.
|
|
95
|
+
|
|
96
|
+
```swift
|
|
97
|
+
extension View {
|
|
98
|
+
func withAppDependencyGraph(
|
|
99
|
+
accountManager: AccountManager = .shared,
|
|
100
|
+
currentAccount: CurrentAccount = .shared,
|
|
101
|
+
currentInstance: CurrentInstance = .shared,
|
|
102
|
+
userPreferences: UserPreferences = .shared,
|
|
103
|
+
theme: Theme = .shared,
|
|
104
|
+
watcher: StreamWatcher = .shared,
|
|
105
|
+
pushNotifications: PushNotificationsService = .shared,
|
|
106
|
+
intentService: AppIntentService = .shared,
|
|
107
|
+
quickLook: QuickLook = .shared,
|
|
108
|
+
toastCenter: ToastCenter = .shared,
|
|
109
|
+
namespace: Namespace.ID? = nil,
|
|
110
|
+
isSupporter: Bool = false
|
|
111
|
+
) -> some View {
|
|
112
|
+
environment(accountManager)
|
|
113
|
+
.environment(accountManager.currentClient)
|
|
114
|
+
.environment(quickLook)
|
|
115
|
+
.environment(currentAccount)
|
|
116
|
+
.environment(currentInstance)
|
|
117
|
+
.environment(userPreferences)
|
|
118
|
+
.environment(theme)
|
|
119
|
+
.environment(watcher)
|
|
120
|
+
.environment(pushNotifications)
|
|
121
|
+
.environment(intentService)
|
|
122
|
+
.environment(toastCenter)
|
|
123
|
+
.environment(\.isSupporter, isSupporter)
|
|
124
|
+
.task(id: accountManager.currentClient.id) {
|
|
125
|
+
let client = accountManager.currentClient
|
|
126
|
+
if let namespace { quickLook.namespace = namespace }
|
|
127
|
+
currentAccount.setClient(client: client)
|
|
128
|
+
currentInstance.setClient(client: client)
|
|
129
|
+
userPreferences.setClient(client: client)
|
|
130
|
+
await currentInstance.fetchCurrentInstance()
|
|
131
|
+
watcher.setClient(client: client, instanceStreamingURL: currentInstance.instance?.streamingURL)
|
|
132
|
+
if client.isAuth {
|
|
133
|
+
watcher.watch(streams: [.user, .direct])
|
|
134
|
+
} else {
|
|
135
|
+
watcher.stopWatching()
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
.task(id: accountManager.pushAccounts.map(\.token)) {
|
|
139
|
+
pushNotifications.tokens = accountManager.pushAccounts.map(\.token)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Notes:
|
|
146
|
+
- The `.task(id:)` hooks respond to account/client changes, re-seeding services and watcher state.
|
|
147
|
+
- Keep the modifier focused on global wiring; feature-specific state stays within features.
|
|
148
|
+
- Adjust types (AccountManager, StreamWatcher, etc.) to match your project.
|
|
149
|
+
|
|
150
|
+
## SwiftData / ModelContainer
|
|
151
|
+
|
|
152
|
+
Install your `ModelContainer` at the root so all feature views share the same store. Keep the list minimal to the models that need persistence.
|
|
153
|
+
|
|
154
|
+
```swift
|
|
155
|
+
extension View {
|
|
156
|
+
func withModelContainer() -> some View {
|
|
157
|
+
modelContainer(for: [Draft.self, LocalTimeline.self, TagGroup.self])
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Why: a single container avoids duplicated stores per sheet or tab and keeps data consistent.
|
|
163
|
+
|
|
164
|
+
## Sheet routing (enum-driven)
|
|
165
|
+
|
|
166
|
+
Centralize sheets with a small enum and a helper modifier.
|
|
167
|
+
|
|
168
|
+
```swift
|
|
169
|
+
enum SheetDestination: Identifiable {
|
|
170
|
+
case composer
|
|
171
|
+
case settings
|
|
172
|
+
var id: String { String(describing: self) }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
extension View {
|
|
176
|
+
func withSheetDestinations(sheet: Binding<SheetDestination?>) -> some View {
|
|
177
|
+
sheet(item: sheet) { destination in
|
|
178
|
+
switch destination {
|
|
179
|
+
case .composer:
|
|
180
|
+
ComposerView().withEnvironments()
|
|
181
|
+
case .settings:
|
|
182
|
+
SettingsView().withEnvironments()
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Why: enum-driven sheets keep presentation centralized and testable; adding a new sheet means adding one enum case and one switch branch.
|
|
190
|
+
|
|
191
|
+
## When to use
|
|
192
|
+
|
|
193
|
+
- Apps with multiple packages/modules that share environment objects and services.
|
|
194
|
+
- Apps that need to react to account/client changes and rewire streaming/push safely.
|
|
195
|
+
- Any app that wants consistent TabView + NavigationStack + sheet wiring without repeating environment setup.
|
|
196
|
+
|
|
197
|
+
## Caveats
|
|
198
|
+
|
|
199
|
+
- Keep the dependency modifier slim; do not put feature state or heavy logic there.
|
|
200
|
+
- Ensure `.task(id:)` work is lightweight or cancelled appropriately; long-running work belongs in services.
|
|
201
|
+
- If unauthenticated clients exist, gate streaming/watch calls to avoid reconnect spam.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Async state and task lifecycle
|
|
2
|
+
|
|
3
|
+
## Intent
|
|
4
|
+
|
|
5
|
+
Use this pattern when a view loads data, reacts to changing input, or coordinates async work that should follow the SwiftUI view lifecycle.
|
|
6
|
+
|
|
7
|
+
## Core rules
|
|
8
|
+
|
|
9
|
+
- Use `.task` for load-on-appear work that belongs to the view lifecycle.
|
|
10
|
+
- Use `.task(id:)` when async work should restart for a changing input such as a query, selection, or identifier.
|
|
11
|
+
- Treat cancellation as a normal path for view-driven tasks. Check `Task.isCancelled` in longer flows and avoid surfacing cancellation as a user-facing error.
|
|
12
|
+
- Debounce or coalesce user-driven async work such as search before it fans out into repeated requests.
|
|
13
|
+
- Keep UI-facing models and mutations main-actor-safe; do background work in services, then publish the result back to UI state.
|
|
14
|
+
|
|
15
|
+
## Example: load on appear
|
|
16
|
+
|
|
17
|
+
```swift
|
|
18
|
+
struct DetailView: View {
|
|
19
|
+
let id: String
|
|
20
|
+
@State private var state: LoadState<Item> = .idle
|
|
21
|
+
@Environment(ItemClient.self) private var client
|
|
22
|
+
|
|
23
|
+
var body: some View {
|
|
24
|
+
content
|
|
25
|
+
.task {
|
|
26
|
+
await load()
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@ViewBuilder
|
|
31
|
+
private var content: some View {
|
|
32
|
+
switch state {
|
|
33
|
+
case .idle, .loading:
|
|
34
|
+
ProgressView()
|
|
35
|
+
case .loaded(let item):
|
|
36
|
+
ItemContent(item: item)
|
|
37
|
+
case .failed(let error):
|
|
38
|
+
ErrorView(error: error)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private func load() async {
|
|
43
|
+
state = .loading
|
|
44
|
+
do {
|
|
45
|
+
state = .loaded(try await client.fetch(id: id))
|
|
46
|
+
} catch is CancellationError {
|
|
47
|
+
return
|
|
48
|
+
} catch {
|
|
49
|
+
state = .failed(error)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Example: restart on input change
|
|
56
|
+
|
|
57
|
+
```swift
|
|
58
|
+
struct SearchView: View {
|
|
59
|
+
@State private var query = ""
|
|
60
|
+
@State private var results: [ResultItem] = []
|
|
61
|
+
@Environment(SearchClient.self) private var client
|
|
62
|
+
|
|
63
|
+
var body: some View {
|
|
64
|
+
List(results) { item in
|
|
65
|
+
Text(item.title)
|
|
66
|
+
}
|
|
67
|
+
.searchable(text: $query)
|
|
68
|
+
.task(id: query) {
|
|
69
|
+
try? await Task.sleep(for: .milliseconds(250))
|
|
70
|
+
guard !Task.isCancelled, !query.isEmpty else {
|
|
71
|
+
results = []
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
do {
|
|
75
|
+
results = try await client.search(query)
|
|
76
|
+
} catch is CancellationError {
|
|
77
|
+
return
|
|
78
|
+
} catch {
|
|
79
|
+
results = []
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## When to move work out of the view
|
|
87
|
+
|
|
88
|
+
- If the async flow spans multiple screens or must survive view dismissal, move it into a service or model.
|
|
89
|
+
- If the view is mostly coordinating app-level lifecycle or account changes, wire it at the app shell in `app-wiring.md`.
|
|
90
|
+
- If retry, caching, or offline policy becomes complex, keep the policy in the client/service and leave the view with simple state transitions.
|
|
91
|
+
|
|
92
|
+
## Pitfalls
|
|
93
|
+
|
|
94
|
+
- Do not start network work directly from `body`.
|
|
95
|
+
- Do not ignore cancellation for searches, typeahead, or rapidly changing selections.
|
|
96
|
+
- Avoid storing derived async state in multiple places when one source of truth is enough.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Components Index
|
|
2
|
+
|
|
3
|
+
Use this file to find component and cross-cutting guidance. Each entry lists when to use it.
|
|
4
|
+
|
|
5
|
+
## Available components
|
|
6
|
+
|
|
7
|
+
- TabView: `references/tabview.md` - Use when building a tab-based app or any tabbed feature set.
|
|
8
|
+
- NavigationStack: `references/navigationstack.md` - Use when you need push navigation and programmatic routing, especially per-tab history.
|
|
9
|
+
- Sheets and presentation: `references/sheets.md` - Use for local item-driven sheets, centralized modal routing, and sheet-specific action patterns.
|
|
10
|
+
- Form and Settings: `references/form.md` - Use for settings, grouped inputs, and structured data entry.
|
|
11
|
+
- macOS Settings: `references/macos-settings.md` - Use when building a macOS Settings window with SwiftUI's Settings scene.
|
|
12
|
+
- Split views and columns: `references/split-views.md` - Use for iPad/macOS multi-column layouts or custom secondary columns.
|
|
13
|
+
- List and Section: `references/list.md` - Use for feed-style content and settings rows.
|
|
14
|
+
- ScrollView and Lazy stacks: `references/scrollview.md` - Use for custom layouts, horizontal scrollers, or grids.
|
|
15
|
+
- Scroll-reveal detail surfaces: `references/scroll-reveal.md` - Use when a detail screen reveals secondary content or actions as the user scrolls or swipes between full-screen sections.
|
|
16
|
+
- Grids: `references/grids.md` - Use for icon pickers, media galleries, and tiled layouts.
|
|
17
|
+
- Theming and dynamic type: `references/theming.md` - Use for app-wide theme tokens, colors, and type scaling.
|
|
18
|
+
- Controls (toggles, pickers, sliders): `references/controls.md` - Use for settings controls and input selection.
|
|
19
|
+
- Input toolbar (bottom anchored): `references/input-toolbar.md` - Use for chat/composer screens with a sticky input bar.
|
|
20
|
+
- Top bar overlays (iOS 26+ and fallback): `references/top-bar.md` - Use for pinned selectors or pills above scroll content.
|
|
21
|
+
- Overlay and toasts: `references/overlay.md` - Use for transient UI like banners or toasts.
|
|
22
|
+
- Focus handling: `references/focus.md` - Use for chaining fields and keyboard focus management.
|
|
23
|
+
- Searchable: `references/searchable.md` - Use for native search UI with scopes and async results.
|
|
24
|
+
- Async images and media: `references/media.md` - Use for remote media, previews, and media viewers.
|
|
25
|
+
- Haptics: `references/haptics.md` - Use for tactile feedback tied to key actions.
|
|
26
|
+
- Matched transitions: `references/matched-transitions.md` - Use for smooth source-to-destination animations.
|
|
27
|
+
- Deep links and URL routing: `references/deeplinks.md` - Use for in-app navigation from URLs.
|
|
28
|
+
- Title menus: `references/title-menus.md` - Use for filter or context menus in the navigation title.
|
|
29
|
+
- Menu bar commands: `references/menu-bar.md` - Use when adding or customizing macOS/iPadOS menu bar commands.
|
|
30
|
+
- Loading & placeholders: `references/loading-placeholders.md` - Use for redacted skeletons, empty states, and loading UX.
|
|
31
|
+
- Lightweight clients: `references/lightweight-clients.md` - Use for small, closure-based API clients injected into stores.
|
|
32
|
+
|
|
33
|
+
## Cross-cutting references
|
|
34
|
+
|
|
35
|
+
- App wiring and dependency graph: `references/app-wiring.md` - Use to wire the app shell, install shared dependencies, and decide what belongs in the environment.
|
|
36
|
+
- Async state and task lifecycle: `references/async-state.md` - Use when a view loads data, reacts to changing input, or needs cancellation/debouncing guidance.
|
|
37
|
+
- Previews: `references/previews.md` - Use when adding `#Preview`, fixtures, mock environments, or isolated preview setup.
|
|
38
|
+
- Performance guardrails: `references/performance.md` - Use when a screen is large, scroll-heavy, frequently updated, or showing signs of avoidable re-renders.
|
|
39
|
+
|
|
40
|
+
## Planned components (create files as needed)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
## Adding entries
|
|
44
|
+
|
|
45
|
+
- Add the component file and link it here with a short "when to use" description.
|
|
46
|
+
- Keep each component reference short and actionable.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Controls (Toggle, Slider, Picker)
|
|
2
|
+
|
|
3
|
+
## Intent
|
|
4
|
+
|
|
5
|
+
Use native controls for settings and configuration screens, keeping labels accessible and state bindings clear.
|
|
6
|
+
|
|
7
|
+
## Core patterns
|
|
8
|
+
|
|
9
|
+
- Bind controls directly to `@State`, `@Binding`, or `@AppStorage`.
|
|
10
|
+
- Prefer `Toggle` for boolean preferences.
|
|
11
|
+
- Use `Slider` for numeric ranges and show the current value in a label.
|
|
12
|
+
- Use `Picker` for discrete choices; use `.pickerStyle(.segmented)` only for 2-4 options.
|
|
13
|
+
- Keep labels visible and descriptive; avoid embedding buttons inside controls.
|
|
14
|
+
|
|
15
|
+
## Example: toggles with sections
|
|
16
|
+
|
|
17
|
+
```swift
|
|
18
|
+
Form {
|
|
19
|
+
Section("Notifications") {
|
|
20
|
+
Toggle("Mentions", isOn: $preferences.notificationsMentionsEnabled)
|
|
21
|
+
Toggle("Follows", isOn: $preferences.notificationsFollowsEnabled)
|
|
22
|
+
Toggle("Boosts", isOn: $preferences.notificationsBoostsEnabled)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Example: slider with value text
|
|
28
|
+
|
|
29
|
+
```swift
|
|
30
|
+
Section("Font Size") {
|
|
31
|
+
Slider(value: $fontSizeScale, in: 0.5...1.5, step: 0.1)
|
|
32
|
+
Text("Scale: \(String(format: \"%.1f\", fontSizeScale))")
|
|
33
|
+
.font(.scaledBody)
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Example: picker for enums
|
|
38
|
+
|
|
39
|
+
```swift
|
|
40
|
+
Picker("Default Visibility", selection: $visibility) {
|
|
41
|
+
ForEach(Visibility.allCases, id: \.self) { option in
|
|
42
|
+
Text(option.title).tag(option)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Design choices to keep
|
|
48
|
+
|
|
49
|
+
- Group related controls in a `Form` section.
|
|
50
|
+
- Use `.disabled(...)` to reflect locked or inherited settings.
|
|
51
|
+
- Use `Label` inside toggles to combine icon + text when it adds clarity.
|
|
52
|
+
|
|
53
|
+
## Pitfalls
|
|
54
|
+
|
|
55
|
+
- Avoid `.pickerStyle(.segmented)` for large sets; use menu or inline styles instead.
|
|
56
|
+
- Don't hide labels for sliders; always show context.
|
|
57
|
+
- Avoid hard-coding colors for controls; use theme tint sparingly.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Deep links and navigation
|
|
2
|
+
|
|
3
|
+
## Intent
|
|
4
|
+
|
|
5
|
+
Route external URLs into in-app destinations while falling back to system handling when needed.
|
|
6
|
+
|
|
7
|
+
## Core patterns
|
|
8
|
+
|
|
9
|
+
- Centralize URL handling in the router (`handle(url:)`, `handleDeepLink(url:)`).
|
|
10
|
+
- Inject an `OpenURLAction` handler that delegates to the router.
|
|
11
|
+
- Use `.onOpenURL` for app scheme links and convert them to web URLs if needed.
|
|
12
|
+
- Let the router decide whether to navigate or open externally.
|
|
13
|
+
|
|
14
|
+
## Example: router entry points
|
|
15
|
+
|
|
16
|
+
```swift
|
|
17
|
+
@MainActor
|
|
18
|
+
final class RouterPath {
|
|
19
|
+
var path: [Route] = []
|
|
20
|
+
var urlHandler: ((URL) -> OpenURLAction.Result)?
|
|
21
|
+
|
|
22
|
+
func handle(url: URL) -> OpenURLAction.Result {
|
|
23
|
+
if isInternal(url) {
|
|
24
|
+
navigate(to: .status(id: url.lastPathComponent))
|
|
25
|
+
return .handled
|
|
26
|
+
}
|
|
27
|
+
return urlHandler?(url) ?? .systemAction
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
func handleDeepLink(url: URL) -> OpenURLAction.Result {
|
|
31
|
+
// Resolve federated URLs, then navigate.
|
|
32
|
+
navigate(to: .status(id: url.lastPathComponent))
|
|
33
|
+
return .handled
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Example: attach to a root view
|
|
39
|
+
|
|
40
|
+
```swift
|
|
41
|
+
extension View {
|
|
42
|
+
func withLinkRouter(_ router: RouterPath) -> some View {
|
|
43
|
+
self
|
|
44
|
+
.environment(
|
|
45
|
+
\.openURL,
|
|
46
|
+
OpenURLAction { url in
|
|
47
|
+
router.handle(url: url)
|
|
48
|
+
}
|
|
49
|
+
)
|
|
50
|
+
.onOpenURL { url in
|
|
51
|
+
router.handleDeepLink(url: url)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Design choices to keep
|
|
58
|
+
|
|
59
|
+
- Keep URL parsing and decision logic inside the router.
|
|
60
|
+
- Avoid handling deep links in multiple places; one entry point is enough.
|
|
61
|
+
- Always provide a fallback to `OpenURLAction` or `UIApplication.shared.open`.
|
|
62
|
+
|
|
63
|
+
## Pitfalls
|
|
64
|
+
|
|
65
|
+
- Don't assume the URL is internal; validate first.
|
|
66
|
+
- Avoid blocking UI while resolving remote links; use `Task`.
|