swift-code-reviewer-skill 1.1.1 → 1.2.1
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 +44 -162
- package/README.md +91 -21
- package/SKILL.md +107 -725
- package/bin/install.js +87 -22
- package/package.json +16 -2
- package/references/companion-skills.md +70 -0
- package/skills/README.md +43 -0
- package/skills/swift-concurrency/NOTICE.md +18 -0
- package/skills/swift-concurrency/SKILL.md +235 -0
- package/skills/swift-concurrency/references/actors.md +640 -0
- package/skills/swift-concurrency/references/async-await-basics.md +249 -0
- package/skills/swift-concurrency/references/async-sequences.md +635 -0
- package/skills/swift-concurrency/references/core-data.md +533 -0
- package/skills/swift-concurrency/references/glossary.md +96 -0
- package/skills/swift-concurrency/references/linting.md +38 -0
- package/skills/swift-concurrency/references/memory-management.md +542 -0
- package/skills/swift-concurrency/references/migration.md +721 -0
- package/skills/swift-concurrency/references/performance.md +574 -0
- package/skills/swift-concurrency/references/sendable.md +578 -0
- package/skills/swift-concurrency/references/tasks.md +604 -0
- package/skills/swift-concurrency/references/testing.md +565 -0
- package/skills/swift-concurrency/references/threading.md +452 -0
- package/skills/swift-expert/NOTICE.md +18 -0
- package/skills/swift-expert/SKILL.md +226 -0
- package/skills/swift-expert/references/async-concurrency.md +363 -0
- package/skills/swift-expert/references/memory-performance.md +380 -0
- package/skills/swift-expert/references/protocol-oriented.md +357 -0
- package/skills/swift-expert/references/swiftui-patterns.md +294 -0
- package/skills/swift-expert/references/testing-patterns.md +402 -0
- package/skills/swift-testing/NOTICE.md +18 -0
- package/skills/swift-testing/SKILL.md +295 -0
- package/skills/swift-testing/references/async-testing.md +245 -0
- package/skills/swift-testing/references/dump-snapshot-testing.md +265 -0
- package/skills/swift-testing/references/fixtures.md +193 -0
- package/skills/swift-testing/references/integration-testing.md +189 -0
- package/skills/swift-testing/references/migration-xctest.md +301 -0
- package/skills/swift-testing/references/parameterized-tests.md +171 -0
- package/skills/swift-testing/references/snapshot-testing.md +201 -0
- package/skills/swift-testing/references/test-doubles.md +243 -0
- package/skills/swift-testing/references/test-organization.md +231 -0
- package/skills/swiftui-expert-skill/NOTICE.md +18 -0
- package/skills/swiftui-expert-skill/SKILL.md +281 -0
- package/skills/swiftui-expert-skill/references/accessibility-patterns.md +151 -0
- package/skills/swiftui-expert-skill/references/animation-advanced.md +403 -0
- package/skills/swiftui-expert-skill/references/animation-basics.md +284 -0
- package/skills/swiftui-expert-skill/references/animation-transitions.md +326 -0
- package/skills/swiftui-expert-skill/references/charts-accessibility.md +135 -0
- package/skills/swiftui-expert-skill/references/charts.md +602 -0
- package/skills/swiftui-expert-skill/references/image-optimization.md +203 -0
- package/skills/swiftui-expert-skill/references/latest-apis.md +464 -0
- package/skills/swiftui-expert-skill/references/layout-best-practices.md +266 -0
- package/skills/swiftui-expert-skill/references/liquid-glass.md +414 -0
- package/skills/swiftui-expert-skill/references/list-patterns.md +394 -0
- package/skills/swiftui-expert-skill/references/macos-scenes.md +318 -0
- package/skills/swiftui-expert-skill/references/macos-views.md +357 -0
- package/skills/swiftui-expert-skill/references/macos-window-styling.md +303 -0
- package/skills/swiftui-expert-skill/references/performance-patterns.md +403 -0
- package/skills/swiftui-expert-skill/references/scroll-patterns.md +293 -0
- package/skills/swiftui-expert-skill/references/sheet-navigation-patterns.md +363 -0
- package/skills/swiftui-expert-skill/references/state-management.md +417 -0
- package/skills/swiftui-expert-skill/references/view-structure.md +389 -0
- package/skills/swiftui-ui-patterns/NOTICE.md +18 -0
- package/skills/swiftui-ui-patterns/SKILL.md +95 -0
- package/skills/swiftui-ui-patterns/references/app-wiring.md +201 -0
- package/skills/swiftui-ui-patterns/references/async-state.md +96 -0
- package/skills/swiftui-ui-patterns/references/components-index.md +50 -0
- package/skills/swiftui-ui-patterns/references/controls.md +57 -0
- package/skills/swiftui-ui-patterns/references/deeplinks.md +66 -0
- package/skills/swiftui-ui-patterns/references/focus.md +90 -0
- package/skills/swiftui-ui-patterns/references/form.md +97 -0
- package/skills/swiftui-ui-patterns/references/grids.md +71 -0
- package/skills/swiftui-ui-patterns/references/haptics.md +71 -0
- package/skills/swiftui-ui-patterns/references/input-toolbar.md +51 -0
- package/skills/swiftui-ui-patterns/references/lightweight-clients.md +93 -0
- package/skills/swiftui-ui-patterns/references/list.md +86 -0
- package/skills/swiftui-ui-patterns/references/loading-placeholders.md +38 -0
- package/skills/swiftui-ui-patterns/references/macos-settings.md +71 -0
- package/skills/swiftui-ui-patterns/references/matched-transitions.md +59 -0
- package/skills/swiftui-ui-patterns/references/media.md +73 -0
- package/skills/swiftui-ui-patterns/references/menu-bar.md +101 -0
- package/skills/swiftui-ui-patterns/references/navigationstack.md +159 -0
- package/skills/swiftui-ui-patterns/references/overlay.md +45 -0
- package/skills/swiftui-ui-patterns/references/performance.md +62 -0
- package/skills/swiftui-ui-patterns/references/previews.md +48 -0
- package/skills/swiftui-ui-patterns/references/scroll-reveal.md +133 -0
- package/skills/swiftui-ui-patterns/references/scrollview.md +87 -0
- package/skills/swiftui-ui-patterns/references/searchable.md +71 -0
- package/skills/swiftui-ui-patterns/references/sheets.md +155 -0
- package/skills/swiftui-ui-patterns/references/split-views.md +72 -0
- package/skills/swiftui-ui-patterns/references/tabview.md +114 -0
- package/skills/swiftui-ui-patterns/references/theming.md +71 -0
- package/skills/swiftui-ui-patterns/references/title-menus.md +93 -0
- package/skills/swiftui-ui-patterns/references/top-bar.md +49 -0
- package/templates/agents/swift-code-reviewer.md +78 -0
- package/templates/commands/review.md +56 -0
|
@@ -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,50 @@
|
|
|
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
|
+
- Web content: create `references/webview.md` — Use for embedded web content or in-app browsing.
|
|
43
|
+
- Status composer patterns: create `references/composer.md` — Use for composition or editor workflows.
|
|
44
|
+
- Text input and validation: create `references/text-input.md` — Use for forms, validation, and text-heavy input.
|
|
45
|
+
- Design system usage: create `references/design-system.md` — Use when applying shared styling rules.
|
|
46
|
+
|
|
47
|
+
## Adding entries
|
|
48
|
+
|
|
49
|
+
- Add the component file and link it here with a short “when to use” description.
|
|
50
|
+
- 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`.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Focus handling and field chaining
|
|
2
|
+
|
|
3
|
+
## Intent
|
|
4
|
+
|
|
5
|
+
Use `@FocusState` to control keyboard focus, chain fields, and coordinate focus across complex forms.
|
|
6
|
+
|
|
7
|
+
## Core patterns
|
|
8
|
+
|
|
9
|
+
- Use an enum to represent focusable fields.
|
|
10
|
+
- Set initial focus in `onAppear`.
|
|
11
|
+
- Use `.onSubmit` to move focus to the next field.
|
|
12
|
+
- For dynamic lists of fields, use an enum with associated values (e.g., `.option(Int)`).
|
|
13
|
+
|
|
14
|
+
## Example: single field focus
|
|
15
|
+
|
|
16
|
+
```swift
|
|
17
|
+
struct AddServerView: View {
|
|
18
|
+
@State private var server = ""
|
|
19
|
+
@FocusState private var isServerFieldFocused: Bool
|
|
20
|
+
|
|
21
|
+
var body: some View {
|
|
22
|
+
Form {
|
|
23
|
+
TextField("Server", text: $server)
|
|
24
|
+
.focused($isServerFieldFocused)
|
|
25
|
+
}
|
|
26
|
+
.onAppear { isServerFieldFocused = true }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Example: chained focus with enum
|
|
32
|
+
|
|
33
|
+
```swift
|
|
34
|
+
struct EditTagView: View {
|
|
35
|
+
enum FocusField { case title, symbol, newTag }
|
|
36
|
+
@FocusState private var focusedField: FocusField?
|
|
37
|
+
|
|
38
|
+
var body: some View {
|
|
39
|
+
Form {
|
|
40
|
+
TextField("Title", text: $title)
|
|
41
|
+
.focused($focusedField, equals: .title)
|
|
42
|
+
.onSubmit { focusedField = .symbol }
|
|
43
|
+
|
|
44
|
+
TextField("Symbol", text: $symbol)
|
|
45
|
+
.focused($focusedField, equals: .symbol)
|
|
46
|
+
.onSubmit { focusedField = .newTag }
|
|
47
|
+
}
|
|
48
|
+
.onAppear { focusedField = .title }
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Example: dynamic focus for variable fields
|
|
54
|
+
|
|
55
|
+
```swift
|
|
56
|
+
struct PollView: View {
|
|
57
|
+
enum FocusField: Hashable { case option(Int) }
|
|
58
|
+
@FocusState private var focused: FocusField?
|
|
59
|
+
@State private var options: [String] = ["", ""]
|
|
60
|
+
@State private var currentIndex = 0
|
|
61
|
+
|
|
62
|
+
var body: some View {
|
|
63
|
+
ForEach(options.indices, id: \.self) { index in
|
|
64
|
+
TextField("Option \(index + 1)", text: $options[index])
|
|
65
|
+
.focused($focused, equals: .option(index))
|
|
66
|
+
.onSubmit { addOption(at: index) }
|
|
67
|
+
}
|
|
68
|
+
.onAppear { focused = .option(0) }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private func addOption(at index: Int) {
|
|
72
|
+
options.append("")
|
|
73
|
+
currentIndex = index + 1
|
|
74
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
|
|
75
|
+
focused = .option(currentIndex)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Design choices to keep
|
|
82
|
+
|
|
83
|
+
- Keep focus state local to the view that owns the fields.
|
|
84
|
+
- Use focus changes to drive UX (validation messages, helper UI).
|
|
85
|
+
- Pair with `.scrollDismissesKeyboard(...)` when using ScrollView/Form.
|
|
86
|
+
|
|
87
|
+
## Pitfalls
|
|
88
|
+
|
|
89
|
+
- Don’t store focus state in shared objects; it is view-local.
|
|
90
|
+
- Avoid aggressive focus changes during animation; delay if needed.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Form
|
|
2
|
+
|
|
3
|
+
## Intent
|
|
4
|
+
|
|
5
|
+
Use `Form` for structured settings, grouped inputs, and action rows. This pattern keeps layout, spacing, and accessibility consistent for data entry screens.
|
|
6
|
+
|
|
7
|
+
## Core patterns
|
|
8
|
+
|
|
9
|
+
- Wrap the form in a `NavigationStack` only when it is presented in a sheet or standalone view without an existing navigation context.
|
|
10
|
+
- Group related controls into `Section` blocks.
|
|
11
|
+
- Use `.scrollContentBackground(.hidden)` plus a custom background color when you need design-system colors.
|
|
12
|
+
- Apply `.formStyle(.grouped)` for grouped styling when appropriate.
|
|
13
|
+
- Use `@FocusState` to manage keyboard focus in input-heavy forms.
|
|
14
|
+
|
|
15
|
+
## Example: settings-style form
|
|
16
|
+
|
|
17
|
+
```swift
|
|
18
|
+
@MainActor
|
|
19
|
+
struct SettingsView: View {
|
|
20
|
+
@Environment(Theme.self) private var theme
|
|
21
|
+
|
|
22
|
+
var body: some View {
|
|
23
|
+
NavigationStack {
|
|
24
|
+
Form {
|
|
25
|
+
Section("General") {
|
|
26
|
+
NavigationLink("Display") { DisplaySettingsView() }
|
|
27
|
+
NavigationLink("Haptics") { HapticsSettingsView() }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
Section("Account") {
|
|
31
|
+
Button("Edit profile") { /* open sheet */ }
|
|
32
|
+
.buttonStyle(.plain)
|
|
33
|
+
}
|
|
34
|
+
.listRowBackground(theme.primaryBackgroundColor)
|
|
35
|
+
}
|
|
36
|
+
.navigationTitle("Settings")
|
|
37
|
+
.navigationBarTitleDisplayMode(.inline)
|
|
38
|
+
.scrollContentBackground(.hidden)
|
|
39
|
+
.background(theme.secondaryBackgroundColor)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Example: modal form with validation
|
|
46
|
+
|
|
47
|
+
```swift
|
|
48
|
+
@MainActor
|
|
49
|
+
struct AddRemoteServerView: View {
|
|
50
|
+
@Environment(\.dismiss) private var dismiss
|
|
51
|
+
@Environment(Theme.self) private var theme
|
|
52
|
+
|
|
53
|
+
@State private var server: String = ""
|
|
54
|
+
@State private var isValid = false
|
|
55
|
+
@FocusState private var isServerFieldFocused: Bool
|
|
56
|
+
|
|
57
|
+
var body: some View {
|
|
58
|
+
NavigationStack {
|
|
59
|
+
Form {
|
|
60
|
+
TextField("Server URL", text: $server)
|
|
61
|
+
.keyboardType(.URL)
|
|
62
|
+
.textInputAutocapitalization(.never)
|
|
63
|
+
.autocorrectionDisabled()
|
|
64
|
+
.focused($isServerFieldFocused)
|
|
65
|
+
.listRowBackground(theme.primaryBackgroundColor)
|
|
66
|
+
|
|
67
|
+
Button("Add") {
|
|
68
|
+
guard isValid else { return }
|
|
69
|
+
dismiss()
|
|
70
|
+
}
|
|
71
|
+
.disabled(!isValid)
|
|
72
|
+
.listRowBackground(theme.primaryBackgroundColor)
|
|
73
|
+
}
|
|
74
|
+
.formStyle(.grouped)
|
|
75
|
+
.navigationTitle("Add Server")
|
|
76
|
+
.navigationBarTitleDisplayMode(.inline)
|
|
77
|
+
.scrollContentBackground(.hidden)
|
|
78
|
+
.background(theme.secondaryBackgroundColor)
|
|
79
|
+
.scrollDismissesKeyboard(.immediately)
|
|
80
|
+
.toolbar { CancelToolbarItem() }
|
|
81
|
+
.onAppear { isServerFieldFocused = true }
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Design choices to keep
|
|
88
|
+
|
|
89
|
+
- Prefer `Form` over custom stacks for settings and input screens.
|
|
90
|
+
- Keep rows tappable by using `.contentShape(Rectangle())` and `.buttonStyle(.plain)` on row buttons.
|
|
91
|
+
- Use list row backgrounds to keep section styling consistent with your theme.
|
|
92
|
+
|
|
93
|
+
## Pitfalls
|
|
94
|
+
|
|
95
|
+
- Avoid heavy custom layouts inside a `Form`; it can lead to spacing issues.
|
|
96
|
+
- If you need highly custom layouts, prefer `ScrollView` + `VStack`.
|
|
97
|
+
- Don’t mix multiple background strategies; pick either default Form styling or custom colors.
|