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,71 @@
|
|
|
1
|
+
# Grids
|
|
2
|
+
|
|
3
|
+
## Intent
|
|
4
|
+
|
|
5
|
+
Use `LazyVGrid` for icon pickers, media galleries, and dense visual selections where items align in columns.
|
|
6
|
+
|
|
7
|
+
## Core patterns
|
|
8
|
+
|
|
9
|
+
- Use `.adaptive` columns for layouts that should scale across device sizes.
|
|
10
|
+
- Use multiple `.flexible` columns when you want a fixed column count.
|
|
11
|
+
- Keep spacing consistent and small to avoid uneven gutters.
|
|
12
|
+
- Use `GeometryReader` inside grid cells when you need square thumbnails.
|
|
13
|
+
|
|
14
|
+
## Example: adaptive icon grid
|
|
15
|
+
|
|
16
|
+
```swift
|
|
17
|
+
let columns = [GridItem(.adaptive(minimum: 120, maximum: 1024))]
|
|
18
|
+
|
|
19
|
+
LazyVGrid(columns: columns, spacing: 6) {
|
|
20
|
+
ForEach(icons) { icon in
|
|
21
|
+
Button {
|
|
22
|
+
select(icon)
|
|
23
|
+
} label: {
|
|
24
|
+
ZStack(alignment: .bottomTrailing) {
|
|
25
|
+
Image(icon.previewName)
|
|
26
|
+
.resizable()
|
|
27
|
+
.aspectRatio(contentMode: .fit)
|
|
28
|
+
.cornerRadius(6)
|
|
29
|
+
if icon.isSelected {
|
|
30
|
+
Image(systemName: "checkmark.seal.fill")
|
|
31
|
+
.padding(4)
|
|
32
|
+
.tint(.green)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
.buttonStyle(.plain)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Example: fixed 3-column media grid
|
|
42
|
+
|
|
43
|
+
```swift
|
|
44
|
+
LazyVGrid(
|
|
45
|
+
columns: [
|
|
46
|
+
.init(.flexible(minimum: 100), spacing: 4),
|
|
47
|
+
.init(.flexible(minimum: 100), spacing: 4),
|
|
48
|
+
.init(.flexible(minimum: 100), spacing: 4),
|
|
49
|
+
],
|
|
50
|
+
spacing: 4
|
|
51
|
+
) {
|
|
52
|
+
ForEach(items) { item in
|
|
53
|
+
GeometryReader { proxy in
|
|
54
|
+
ThumbnailView(item: item)
|
|
55
|
+
.frame(width: proxy.size.width, height: proxy.size.width)
|
|
56
|
+
}
|
|
57
|
+
.aspectRatio(1, contentMode: .fit)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Design choices to keep
|
|
63
|
+
|
|
64
|
+
- Use `LazyVGrid` for large collections; avoid non-lazy grids for big sets.
|
|
65
|
+
- Keep tap targets full-bleed using `.contentShape(Rectangle())` when needed.
|
|
66
|
+
- Prefer adaptive grids for settings pickers and flexible layouts.
|
|
67
|
+
|
|
68
|
+
## Pitfalls
|
|
69
|
+
|
|
70
|
+
- Avoid heavy overlays in every grid cell; it can be expensive.
|
|
71
|
+
- Don’t nest grids inside other grids without a clear reason.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Haptics
|
|
2
|
+
|
|
3
|
+
## Intent
|
|
4
|
+
|
|
5
|
+
Use haptics sparingly to reinforce user actions (tab selection, refresh, success/error) and respect user preferences.
|
|
6
|
+
|
|
7
|
+
## Core patterns
|
|
8
|
+
|
|
9
|
+
- Centralize haptic triggers in a `HapticManager` or similar utility.
|
|
10
|
+
- Gate haptics behind user preferences and hardware support.
|
|
11
|
+
- Use distinct types for different UX moments (selection vs. notification vs. refresh).
|
|
12
|
+
|
|
13
|
+
## Example: simple haptic manager
|
|
14
|
+
|
|
15
|
+
```swift
|
|
16
|
+
@MainActor
|
|
17
|
+
final class HapticManager {
|
|
18
|
+
static let shared = HapticManager()
|
|
19
|
+
|
|
20
|
+
enum HapticType {
|
|
21
|
+
case buttonPress
|
|
22
|
+
case tabSelection
|
|
23
|
+
case dataRefresh(intensity: CGFloat)
|
|
24
|
+
case notification(UINotificationFeedbackGenerator.FeedbackType)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private let selectionGenerator = UISelectionFeedbackGenerator()
|
|
28
|
+
private let impactGenerator = UIImpactFeedbackGenerator(style: .heavy)
|
|
29
|
+
private let notificationGenerator = UINotificationFeedbackGenerator()
|
|
30
|
+
|
|
31
|
+
private init() { selectionGenerator.prepare() }
|
|
32
|
+
|
|
33
|
+
func fire(_ type: HapticType, isEnabled: Bool) {
|
|
34
|
+
guard isEnabled else { return }
|
|
35
|
+
switch type {
|
|
36
|
+
case .buttonPress:
|
|
37
|
+
impactGenerator.impactOccurred()
|
|
38
|
+
case .tabSelection:
|
|
39
|
+
selectionGenerator.selectionChanged()
|
|
40
|
+
case let .dataRefresh(intensity):
|
|
41
|
+
impactGenerator.impactOccurred(intensity: intensity)
|
|
42
|
+
case let .notification(style):
|
|
43
|
+
notificationGenerator.notificationOccurred(style)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Example: usage
|
|
50
|
+
|
|
51
|
+
```swift
|
|
52
|
+
Button("Save") {
|
|
53
|
+
HapticManager.shared.fire(.notification(.success), isEnabled: preferences.hapticsEnabled)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
TabView(selection: $selectedTab) { /* tabs */ }
|
|
57
|
+
.onChange(of: selectedTab) { _, _ in
|
|
58
|
+
HapticManager.shared.fire(.tabSelection, isEnabled: preferences.hapticTabSelectionEnabled)
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Design choices to keep
|
|
63
|
+
|
|
64
|
+
- Haptics should be subtle and not fire on every tiny interaction.
|
|
65
|
+
- Respect user preferences (toggle to disable).
|
|
66
|
+
- Keep haptic triggers close to the user action, not deep in data layers.
|
|
67
|
+
|
|
68
|
+
## Pitfalls
|
|
69
|
+
|
|
70
|
+
- Avoid firing multiple haptics in quick succession.
|
|
71
|
+
- Do not assume haptics are available; check support.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Input toolbar (bottom anchored)
|
|
2
|
+
|
|
3
|
+
## Intent
|
|
4
|
+
|
|
5
|
+
Use a bottom-anchored input bar for chat, composer, or quick actions without fighting the keyboard.
|
|
6
|
+
|
|
7
|
+
## Core patterns
|
|
8
|
+
|
|
9
|
+
- Use `.safeAreaInset(edge: .bottom)` to anchor the toolbar above the keyboard.
|
|
10
|
+
- Keep the main content in a `ScrollView` or `List`.
|
|
11
|
+
- Drive focus with `@FocusState` and set initial focus when needed.
|
|
12
|
+
- Avoid embedding the input bar inside the scroll content; keep it separate.
|
|
13
|
+
|
|
14
|
+
## Example: scroll view + bottom input
|
|
15
|
+
|
|
16
|
+
```swift
|
|
17
|
+
@MainActor
|
|
18
|
+
struct ConversationView: View {
|
|
19
|
+
@FocusState private var isInputFocused: Bool
|
|
20
|
+
|
|
21
|
+
var body: some View {
|
|
22
|
+
ScrollViewReader { _ in
|
|
23
|
+
ScrollView {
|
|
24
|
+
LazyVStack {
|
|
25
|
+
ForEach(messages) { message in
|
|
26
|
+
MessageRow(message: message)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
.padding(.horizontal, .layoutPadding)
|
|
30
|
+
}
|
|
31
|
+
.safeAreaInset(edge: .bottom) {
|
|
32
|
+
InputBar(text: $draft)
|
|
33
|
+
.focused($isInputFocused)
|
|
34
|
+
}
|
|
35
|
+
.scrollDismissesKeyboard(.interactively)
|
|
36
|
+
.onAppear { isInputFocused = true }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Design choices to keep
|
|
43
|
+
|
|
44
|
+
- Keep the input bar visually separated from the scrollable content.
|
|
45
|
+
- Use `.scrollDismissesKeyboard(.interactively)` for chat-like screens.
|
|
46
|
+
- Ensure send actions are reachable via keyboard return or a clear button.
|
|
47
|
+
|
|
48
|
+
## Pitfalls
|
|
49
|
+
|
|
50
|
+
- Avoid placing the input view inside the scroll stack; it will jump with content.
|
|
51
|
+
- Avoid nested scroll views that fight for drag gestures.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Lightweight Clients (Closure-Based)
|
|
2
|
+
|
|
3
|
+
Use this pattern to keep networking or service dependencies simple and testable without introducing a full view model or heavy DI framework. It works well for SwiftUI apps where you want a small, composable API surface that can be swapped in previews/tests.
|
|
4
|
+
|
|
5
|
+
## Intent
|
|
6
|
+
- Provide a tiny "client" type made of async closures.
|
|
7
|
+
- Keep business logic in a store or feature layer, not the view.
|
|
8
|
+
- Enable easy stubbing in previews/tests.
|
|
9
|
+
|
|
10
|
+
## Minimal shape
|
|
11
|
+
```swift
|
|
12
|
+
struct SomeClient {
|
|
13
|
+
var fetchItems: (_ limit: Int) async throws -> [Item]
|
|
14
|
+
var search: (_ query: String, _ limit: Int) async throws -> [Item]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
extension SomeClient {
|
|
18
|
+
static func live(baseURL: URL = URL(string: "https://example.com")!) -> SomeClient {
|
|
19
|
+
let session = URLSession.shared
|
|
20
|
+
return SomeClient(
|
|
21
|
+
fetchItems: { limit in
|
|
22
|
+
// build URL, call session, decode
|
|
23
|
+
},
|
|
24
|
+
search: { query, limit in
|
|
25
|
+
// build URL, call session, decode
|
|
26
|
+
}
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage pattern
|
|
33
|
+
```swift
|
|
34
|
+
@MainActor
|
|
35
|
+
@Observable final class ItemsStore {
|
|
36
|
+
enum LoadState { case idle, loading, loaded, failed(String) }
|
|
37
|
+
|
|
38
|
+
var items: [Item] = []
|
|
39
|
+
var state: LoadState = .idle
|
|
40
|
+
private let client: SomeClient
|
|
41
|
+
|
|
42
|
+
init(client: SomeClient) {
|
|
43
|
+
self.client = client
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
func load(limit: Int = 20) async {
|
|
47
|
+
state = .loading
|
|
48
|
+
do {
|
|
49
|
+
items = try await client.fetchItems(limit)
|
|
50
|
+
state = .loaded
|
|
51
|
+
} catch {
|
|
52
|
+
state = .failed(error.localizedDescription)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
```swift
|
|
59
|
+
struct ContentView: View {
|
|
60
|
+
@Environment(ItemsStore.self) private var store
|
|
61
|
+
|
|
62
|
+
var body: some View {
|
|
63
|
+
List(store.items) { item in
|
|
64
|
+
Text(item.title)
|
|
65
|
+
}
|
|
66
|
+
.task { await store.load() }
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
```swift
|
|
72
|
+
@main
|
|
73
|
+
struct MyApp: App {
|
|
74
|
+
@State private var store = ItemsStore(client: .live())
|
|
75
|
+
|
|
76
|
+
var body: some Scene {
|
|
77
|
+
WindowGroup {
|
|
78
|
+
ContentView()
|
|
79
|
+
.environment(store)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Guidance
|
|
86
|
+
- Keep decoding and URL-building in the client; keep state changes in the store.
|
|
87
|
+
- Make the store accept the client in `init` and keep it private.
|
|
88
|
+
- Avoid global singletons; use `.environment` for store injection.
|
|
89
|
+
- If you need multiple variants (mock/stub), add `static func mock(...)`.
|
|
90
|
+
|
|
91
|
+
## Pitfalls
|
|
92
|
+
- Don’t put UI state in the client; keep state in the store.
|
|
93
|
+
- Don’t capture `self` or view state in the client closures.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# List and Section
|
|
2
|
+
|
|
3
|
+
## Intent
|
|
4
|
+
|
|
5
|
+
Use `List` for feed-style content and settings-style rows where built-in row reuse, selection, and accessibility matter.
|
|
6
|
+
|
|
7
|
+
## Core patterns
|
|
8
|
+
|
|
9
|
+
- Prefer `List` for long, vertically scrolling content with repeated rows.
|
|
10
|
+
- Use `Section` headers to group related rows.
|
|
11
|
+
- Pair with `ScrollViewReader` when you need scroll-to-top or jump-to-id.
|
|
12
|
+
- Use `.listStyle(.plain)` for modern feed layouts.
|
|
13
|
+
- Use `.listStyle(.grouped)` for multi-section discovery/search pages where section grouping helps.
|
|
14
|
+
- Apply `.scrollContentBackground(.hidden)` + a custom background when you need a themed surface.
|
|
15
|
+
- Use `.listRowInsets(...)` and `.listRowSeparator(.hidden)` to tune row spacing and separators.
|
|
16
|
+
- Use `.environment(\\.defaultMinListRowHeight, ...)` to control dense list layouts.
|
|
17
|
+
|
|
18
|
+
## Example: feed list with scroll-to-top
|
|
19
|
+
|
|
20
|
+
```swift
|
|
21
|
+
@MainActor
|
|
22
|
+
struct TimelineListView: View {
|
|
23
|
+
@Environment(\.selectedTabScrollToTop) private var selectedTabScrollToTop
|
|
24
|
+
@State private var scrollToId: String?
|
|
25
|
+
|
|
26
|
+
var body: some View {
|
|
27
|
+
ScrollViewReader { proxy in
|
|
28
|
+
List {
|
|
29
|
+
ForEach(items) { item in
|
|
30
|
+
TimelineRow(item: item)
|
|
31
|
+
.id(item.id)
|
|
32
|
+
.listRowInsets(.init(top: 12, leading: 16, bottom: 6, trailing: 16))
|
|
33
|
+
.listRowSeparator(.hidden)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
.listStyle(.plain)
|
|
37
|
+
.environment(\\.defaultMinListRowHeight, 1)
|
|
38
|
+
.onChange(of: scrollToId) { _, newValue in
|
|
39
|
+
if let newValue {
|
|
40
|
+
proxy.scrollTo(newValue, anchor: .top)
|
|
41
|
+
scrollToId = nil
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
.onChange(of: selectedTabScrollToTop) { _, newValue in
|
|
45
|
+
if newValue == 0 {
|
|
46
|
+
withAnimation {
|
|
47
|
+
proxy.scrollTo(ScrollToView.Constants.scrollToTop, anchor: .top)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Example: settings-style list
|
|
57
|
+
|
|
58
|
+
```swift
|
|
59
|
+
@MainActor
|
|
60
|
+
struct SettingsView: View {
|
|
61
|
+
var body: some View {
|
|
62
|
+
List {
|
|
63
|
+
Section("General") {
|
|
64
|
+
NavigationLink("Display") { DisplaySettingsView() }
|
|
65
|
+
NavigationLink("Haptics") { HapticsSettingsView() }
|
|
66
|
+
}
|
|
67
|
+
Section("Account") {
|
|
68
|
+
Button("Sign Out", role: .destructive) {}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
.listStyle(.insetGrouped)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Design choices to keep
|
|
77
|
+
|
|
78
|
+
- Use `List` for dynamic feeds, settings, and any UI where row semantics help.
|
|
79
|
+
- Use stable IDs for rows to keep animations and scroll positioning reliable.
|
|
80
|
+
- Prefer `.contentShape(Rectangle())` on rows that should be tappable end-to-end.
|
|
81
|
+
- Use `.refreshable` for pull-to-refresh feeds when the data source supports it.
|
|
82
|
+
|
|
83
|
+
## Pitfalls
|
|
84
|
+
|
|
85
|
+
- Avoid heavy custom layouts inside a `List` row; use `ScrollView` + `LazyVStack` instead.
|
|
86
|
+
- Be careful mixing `List` and nested `ScrollView`; it can cause gesture conflicts.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Loading & Placeholders
|
|
2
|
+
|
|
3
|
+
Use this when a view needs a consistent loading state (skeletons, redaction, empty state) without blocking interaction.
|
|
4
|
+
|
|
5
|
+
## Patterns to prefer
|
|
6
|
+
|
|
7
|
+
- **Redacted placeholders** for list/detail content to preserve layout while loading.
|
|
8
|
+
- **ContentUnavailableView** for empty or error states after loading completes.
|
|
9
|
+
- **ProgressView** only for short, global operations (use sparingly in content-heavy screens).
|
|
10
|
+
|
|
11
|
+
## Recommended approach
|
|
12
|
+
|
|
13
|
+
1. Keep the real layout, render placeholder data, then apply `.redacted(reason: .placeholder)`.
|
|
14
|
+
2. For lists, show a fixed number of placeholder rows (avoid infinite spinners).
|
|
15
|
+
3. Switch to `ContentUnavailableView` when load finishes but data is empty.
|
|
16
|
+
|
|
17
|
+
## Pitfalls
|
|
18
|
+
|
|
19
|
+
- Don’t animate layout shifts during redaction; keep frames stable.
|
|
20
|
+
- Avoid nesting multiple spinners; use one loading indicator per section.
|
|
21
|
+
- Keep placeholder count small (3–6) to reduce jank on low-end devices.
|
|
22
|
+
|
|
23
|
+
## Minimal usage
|
|
24
|
+
|
|
25
|
+
```swift
|
|
26
|
+
VStack {
|
|
27
|
+
if isLoading {
|
|
28
|
+
ForEach(0..<3, id: \.self) { _ in
|
|
29
|
+
RowView(model: .placeholder())
|
|
30
|
+
}
|
|
31
|
+
.redacted(reason: .placeholder)
|
|
32
|
+
} else if items.isEmpty {
|
|
33
|
+
ContentUnavailableView("No items", systemImage: "tray")
|
|
34
|
+
} else {
|
|
35
|
+
ForEach(items) { item in RowView(model: item) }
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# macOS Settings
|
|
2
|
+
|
|
3
|
+
## Intent
|
|
4
|
+
|
|
5
|
+
Use this when building a macOS Settings window backed by SwiftUI's `Settings` scene.
|
|
6
|
+
|
|
7
|
+
## Core patterns
|
|
8
|
+
|
|
9
|
+
- Declare the Settings scene in the `App` and compile it only for macOS.
|
|
10
|
+
- Keep settings content in a dedicated root view (`SettingsView`) and drive values with `@AppStorage`.
|
|
11
|
+
- Use `TabView` to group settings sections when you have more than one category.
|
|
12
|
+
- Use `Form` inside each tab to keep controls aligned and accessible.
|
|
13
|
+
- Use `OpenSettingsAction` or `SettingsLink` for in-app entry points to the Settings window.
|
|
14
|
+
|
|
15
|
+
## Example: settings scene
|
|
16
|
+
|
|
17
|
+
```swift
|
|
18
|
+
@main
|
|
19
|
+
struct MyApp: App {
|
|
20
|
+
var body: some Scene {
|
|
21
|
+
WindowGroup {
|
|
22
|
+
ContentView()
|
|
23
|
+
}
|
|
24
|
+
#if os(macOS)
|
|
25
|
+
Settings {
|
|
26
|
+
SettingsView()
|
|
27
|
+
}
|
|
28
|
+
#endif
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Example: tabbed settings view
|
|
34
|
+
|
|
35
|
+
```swift
|
|
36
|
+
@MainActor
|
|
37
|
+
struct SettingsView: View {
|
|
38
|
+
@AppStorage("showPreviews") private var showPreviews = true
|
|
39
|
+
@AppStorage("fontSize") private var fontSize = 12.0
|
|
40
|
+
|
|
41
|
+
var body: some View {
|
|
42
|
+
TabView {
|
|
43
|
+
Form {
|
|
44
|
+
Toggle("Show Previews", isOn: $showPreviews)
|
|
45
|
+
Slider(value: $fontSize, in: 9...96) {
|
|
46
|
+
Text("Font Size (\(fontSize, specifier: "%.0f") pts)")
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
.tabItem { Label("General", systemImage: "gear") }
|
|
50
|
+
|
|
51
|
+
Form {
|
|
52
|
+
Toggle("Enable Advanced Mode", isOn: .constant(false))
|
|
53
|
+
}
|
|
54
|
+
.tabItem { Label("Advanced", systemImage: "star") }
|
|
55
|
+
}
|
|
56
|
+
.scenePadding()
|
|
57
|
+
.frame(maxWidth: 420, minHeight: 240)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Skip navigation
|
|
63
|
+
|
|
64
|
+
- Avoid wrapping `SettingsView` in a `NavigationStack` unless you truly need deep push navigation.
|
|
65
|
+
- Prefer tabs or sections; Settings is already presented as a separate window and should feel flat.
|
|
66
|
+
- If you must show hierarchical settings, use a single `NavigationSplitView` with a sidebar list of categories.
|
|
67
|
+
|
|
68
|
+
## Pitfalls
|
|
69
|
+
|
|
70
|
+
- Don’t reuse iOS-only settings layouts (full-screen stacks, toolbar-heavy flows).
|
|
71
|
+
- Avoid large custom view hierarchies inside `Form`; keep rows focused and accessible.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Matched transitions
|
|
2
|
+
|
|
3
|
+
## Intent
|
|
4
|
+
|
|
5
|
+
Use matched transitions to create smooth continuity between a source view (thumbnail, avatar) and a destination view (sheet, detail, viewer).
|
|
6
|
+
|
|
7
|
+
## Core patterns
|
|
8
|
+
|
|
9
|
+
- Use a shared `Namespace` and a stable ID for the source.
|
|
10
|
+
- Use `matchedTransitionSource` + `navigationTransition(.zoom(...))` on iOS 26+.
|
|
11
|
+
- Use `matchedGeometryEffect` for in-place transitions within a view hierarchy.
|
|
12
|
+
- Keep IDs stable across view updates (avoid random UUIDs).
|
|
13
|
+
|
|
14
|
+
## Example: media preview to full-screen viewer (iOS 26+)
|
|
15
|
+
|
|
16
|
+
```swift
|
|
17
|
+
struct MediaPreview: View {
|
|
18
|
+
@Namespace private var namespace
|
|
19
|
+
@State private var selected: MediaAttachment?
|
|
20
|
+
|
|
21
|
+
var body: some View {
|
|
22
|
+
ThumbnailView()
|
|
23
|
+
.matchedTransitionSource(id: selected?.id ?? "", in: namespace)
|
|
24
|
+
.sheet(item: $selected) { item in
|
|
25
|
+
MediaViewer(item: item)
|
|
26
|
+
.navigationTransition(.zoom(sourceID: item.id, in: namespace))
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Example: matched geometry within a view
|
|
33
|
+
|
|
34
|
+
```swift
|
|
35
|
+
struct ToggleBadge: View {
|
|
36
|
+
@Namespace private var space
|
|
37
|
+
@State private var isOn = false
|
|
38
|
+
|
|
39
|
+
var body: some View {
|
|
40
|
+
Button {
|
|
41
|
+
withAnimation(.spring) { isOn.toggle() }
|
|
42
|
+
} label: {
|
|
43
|
+
Image(systemName: isOn ? "eye" : "eye.slash")
|
|
44
|
+
.matchedGeometryEffect(id: "icon", in: space)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Design choices to keep
|
|
51
|
+
|
|
52
|
+
- Prefer `matchedTransitionSource` for cross-screen transitions.
|
|
53
|
+
- Keep source and destination sizes reasonable to avoid jarring scale changes.
|
|
54
|
+
- Use `withAnimation` for state-driven transitions.
|
|
55
|
+
|
|
56
|
+
## Pitfalls
|
|
57
|
+
|
|
58
|
+
- Don’t use unstable IDs; it breaks the transition.
|
|
59
|
+
- Avoid mismatched shapes (e.g., square to circle) unless the design expects it.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Media (images, video, viewer)
|
|
2
|
+
|
|
3
|
+
## Intent
|
|
4
|
+
|
|
5
|
+
Use consistent patterns for loading images, previewing media, and presenting a full-screen viewer.
|
|
6
|
+
|
|
7
|
+
## Core patterns
|
|
8
|
+
|
|
9
|
+
- Use `LazyImage` (or `AsyncImage`) for remote images with loading states.
|
|
10
|
+
- Prefer a lightweight preview component for inline media.
|
|
11
|
+
- Use a shared viewer state (e.g., `QuickLook`) to present a full-screen media viewer.
|
|
12
|
+
- Use `openWindow` for desktop/visionOS and a sheet for iOS.
|
|
13
|
+
|
|
14
|
+
## Example: inline media preview
|
|
15
|
+
|
|
16
|
+
```swift
|
|
17
|
+
struct MediaPreviewRow: View {
|
|
18
|
+
@Environment(QuickLook.self) private var quickLook
|
|
19
|
+
|
|
20
|
+
let attachments: [MediaAttachment]
|
|
21
|
+
|
|
22
|
+
var body: some View {
|
|
23
|
+
ScrollView(.horizontal, showsIndicators: false) {
|
|
24
|
+
HStack {
|
|
25
|
+
ForEach(attachments) { attachment in
|
|
26
|
+
LazyImage(url: attachment.previewURL) { state in
|
|
27
|
+
if let image = state.image {
|
|
28
|
+
image.resizable().aspectRatio(contentMode: .fill)
|
|
29
|
+
} else {
|
|
30
|
+
ProgressView()
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
.frame(width: 120, height: 120)
|
|
34
|
+
.clipped()
|
|
35
|
+
.onTapGesture {
|
|
36
|
+
quickLook.prepareFor(
|
|
37
|
+
selectedMediaAttachment: attachment,
|
|
38
|
+
mediaAttachments: attachments
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Example: global media viewer sheet
|
|
49
|
+
|
|
50
|
+
```swift
|
|
51
|
+
struct AppRoot: View {
|
|
52
|
+
@State private var quickLook = QuickLook.shared
|
|
53
|
+
|
|
54
|
+
var body: some View {
|
|
55
|
+
content
|
|
56
|
+
.environment(quickLook)
|
|
57
|
+
.sheet(item: $quickLook.selectedMediaAttachment) { selected in
|
|
58
|
+
MediaUIView(selectedAttachment: selected, attachments: quickLook.mediaAttachments)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Design choices to keep
|
|
65
|
+
|
|
66
|
+
- Keep previews lightweight; load full media in the viewer.
|
|
67
|
+
- Use shared viewer state so any view can open media without prop-drilling.
|
|
68
|
+
- Use a single entry point for the viewer (sheet/window) to avoid duplicates.
|
|
69
|
+
|
|
70
|
+
## Pitfalls
|
|
71
|
+
|
|
72
|
+
- Avoid loading full-size images in list rows; use resized previews.
|
|
73
|
+
- Don’t present multiple viewer sheets at once; keep a single source of truth.
|