@istmx/skills 1.1.0 → 2.0.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/CODE_OF_CONDUCT.md +47 -0
- package/LICENSE +30 -0
- package/README.md +48 -22
- package/bin/cli.js +130 -119
- package/istm-animate/SKILL.md +28 -58
- package/istm-animate/core/motion-principles/SKILL.md +284 -0
- package/istm-animate/core/motion-principles/references/designers.md +127 -0
- package/istm-animate/core/motion-principles/references/easing-guide.md +231 -0
- package/istm-animate/core/motion-principles/references/enter-exit-recipes.md +466 -0
- package/istm-animate/frameworks/canvas-generative/SKILL.md +325 -0
- package/istm-animate/frameworks/canvas-generative/references/algorithms.md +925 -0
- package/istm-animate/frameworks/css-native/SKILL.md +319 -0
- package/istm-animate/frameworks/css-native/references/modern-css.md +465 -0
- package/istm-animate/frameworks/framer-motion/SKILL.md +187 -0
- package/istm-animate/frameworks/framer-motion/references/api.md +312 -0
- package/istm-animate/frameworks/gsap/SKILL.md +188 -0
- package/istm-animate/frameworks/gsap/references/core.md +218 -0
- package/istm-animate/frameworks/gsap/references/plugins.md +371 -0
- package/istm-animate/frameworks/gsap/references/scrolltrigger.md +325 -0
- package/istm-animate/frameworks/gsap/references/timeline.md +218 -0
- package/istm-animate/frameworks/threejs-r3f/SKILL.md +243 -0
- package/istm-animate/frameworks/threejs-r3f/references/scene-setup.md +392 -0
- package/istm-animate/frameworks/threejs-r3f/references/shaders.md +446 -0
- package/istm-animate/mobile/android/compose-graphics/SKILL.md +503 -0
- package/istm-animate/mobile/android/compose-graphics/references/agsl-recipes.md +356 -0
- package/istm-animate/mobile/android/compose-graphics/references/canvas-generative.md +282 -0
- package/istm-animate/mobile/android/compose-graphics/references/m3-expressive-deep.md +303 -0
- package/istm-animate/mobile/android/compose-motion/SKILL.md +359 -0
- package/istm-animate/mobile/android/compose-motion/references/gestures-compose.md +273 -0
- package/istm-animate/mobile/android/compose-motion/references/recomposition-and-anim.md +196 -0
- package/istm-animate/mobile/android/compose-motion/references/shared-transitions.md +281 -0
- package/istm-animate/mobile/android/compose-multiplatform/SKILL.md +311 -0
- package/istm-animate/mobile/android/compose-multiplatform/references/cmp-interop.md +288 -0
- package/istm-animate/mobile/android/compose-multiplatform/references/cmp-platform-quirks.md +156 -0
- package/istm-animate/mobile/apple/swiftui-graphics/SKILL.md +408 -0
- package/istm-animate/mobile/apple/swiftui-graphics/references/canvas-swiftui.md +239 -0
- package/istm-animate/mobile/apple/swiftui-graphics/references/liquid-glass-deep.md +252 -0
- package/istm-animate/mobile/apple/swiftui-graphics/references/metal-recipes.md +382 -0
- package/istm-animate/mobile/apple/swiftui-motion/SKILL.md +379 -0
- package/istm-animate/mobile/apple/swiftui-motion/references/gestures-swiftui.md +336 -0
- package/istm-animate/mobile/apple/swiftui-motion/references/phase-keyframe-deep.md +231 -0
- package/istm-animate/mobile/apple/swiftui-motion/references/springs-cheatsheet.md +129 -0
- package/istm-animate/references/animate.md +199 -0
- package/istm-animate/references/audit.md +115 -0
- package/istm-animate/references/design-engineering.md +674 -0
- package/istm-animate/references/improve.md +101 -0
- package/istm-animate/references/opportunities.md +132 -0
- package/istm-animate/references/plan-template.md +73 -0
- package/istm-animate/references/recipes.md +324 -0
- package/istm-animate/references/review.md +112 -0
- package/istm-animate/references/standards.md +187 -0
- package/istm-animate/references/vocabulary.md +173 -0
- package/istm-architecture/SKILL.md +10 -1
- package/istm-awwward-designer/SKILL.md +28 -20
- package/istm-design/SKILL.md +31 -58
- package/istm-design/core/design-audit/SKILL.md +248 -0
- package/istm-design/core/desktop-principles/SKILL.md +363 -0
- package/istm-design/core/desktop-principles/references/keyboard-patterns.md +137 -0
- package/istm-design/core/desktop-principles/references/multi-window.md +105 -0
- package/istm-design/core/mobile-principles/SKILL.md +289 -0
- package/istm-design/core/mobile-principles/references/accessibility-mobile.md +175 -0
- package/istm-design/core/mobile-principles/references/gestures-deep.md +220 -0
- package/istm-design/core/ui-ux-pro-max/SKILL.md +392 -0
- package/istm-design/core/ui-ux-pro-max/UPSTREAM.md +23 -0
- package/istm-design/core/ui-ux-pro-max/data/app-interface.csv +31 -0
- package/istm-design/core/ui-ux-pro-max/data/charts.csv +26 -0
- package/istm-design/core/ui-ux-pro-max/data/colors.csv +193 -0
- package/istm-design/core/ui-ux-pro-max/data/google-fonts.csv +1924 -0
- package/istm-design/core/ui-ux-pro-max/data/icons.csv +106 -0
- package/istm-design/core/ui-ux-pro-max/data/landing.csv +35 -0
- package/istm-design/core/ui-ux-pro-max/data/motion.csv +17 -0
- package/istm-design/core/ui-ux-pro-max/data/products.csv +193 -0
- package/istm-design/core/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/angular.csv +51 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/astro.csv +54 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/avalonia.csv +57 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/javafx.csv +76 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/laravel.csv +51 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/nuxt-ui.csv +71 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/threejs.csv +54 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/uno.csv +60 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/uwp.csv +56 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/winui.csv +60 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/wpf.csv +57 -0
- package/istm-design/core/ui-ux-pro-max/data/styles.csv +85 -0
- package/istm-design/core/ui-ux-pro-max/data/typography.csv +75 -0
- package/istm-design/core/ui-ux-pro-max/data/ui-reasoning.csv +162 -0
- package/istm-design/core/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/istm-design/core/ui-ux-pro-max/references/pro-rules.md +109 -0
- package/istm-design/core/ui-ux-pro-max/references/quick-reference.md +240 -0
- package/istm-design/core/ui-ux-pro-max/scripts/core.py +464 -0
- package/istm-design/core/ui-ux-pro-max/scripts/design_system.py +1371 -0
- package/istm-design/core/ui-ux-pro-max/scripts/search.py +162 -0
- package/istm-design/core/ui-ux-pro-max/scripts/tests/test_core.py +134 -0
- package/istm-design/core/ui-ux-pro-max/scripts/validate_data.py +114 -0
- package/istm-design/references/apple-design.md +282 -0
- package/istm-design/references/generation-guide.md +209 -0
- package/istm-design/references/pick-ui-library.md +77 -0
- package/istm-design/references/picker.md +197 -0
- package/istm-design/references/prototype.md +90 -0
- package/istm-design/references/schema.md +366 -0
- package/istm-workflow/istm-audit/SKILL.md +7 -7
- package/istm-workflow/istm-audit/agent-prompt.md +20 -20
- package/istm-workflow/istm-audit/modes/area.md +1 -1
- package/istm-workflow/istm-audit/modes/greenfield.md +4 -4
- package/istm-workflow/istm-audit/modes/tool-skills.md +1 -1
- package/istm-workflow/istm-check/SKILL.md +10 -10
- package/istm-workflow/istm-check/modes/review.md +9 -9
- package/istm-workflow/istm-check/modes/verify.md +19 -19
- package/istm-workflow/istm-check/review-agent-prompt.md +2 -2
- package/istm-workflow/istm-check/review-guide.md +4 -4
- package/istm-workflow/istm-craft/SKILL.md +20 -11
- package/istm-workflow/istm-craft/agent-modes/architecture.md +1 -1
- package/istm-workflow/istm-craft/agent-prompt.md +8 -8
- package/istm-workflow/istm-craft/internal/after-subagent.md +11 -11
- package/istm-workflow/istm-craft/internal/design-conversation.md +9 -9
- package/istm-workflow/istm-craft/internal/tool-discovery.md +2 -2
- package/istm-workflow/istm-craft/spec-template.md +18 -18
- package/istm-workflow/istm-debug/SKILL.md +6 -6
- package/istm-workflow/istm-develop/SKILL.md +31 -16
- package/istm-workflow/istm-develop/checklist.md +1 -1
- package/istm-workflow/istm-develop/flow/build.md +21 -21
- package/istm-workflow/istm-develop/flow/git.md +4 -4
- package/istm-workflow/istm-develop/logical-guide.md +5 -5
- package/istm-workflow/istm-develop/ui/implementation.md +2 -2
- package/istm-workflow/istm-develop/ui-guide.md +3 -3
- package/istm-workflow/istm-document/SKILL.md +6 -6
- package/istm-workflow/istm-document/templates/postmortem.md +1 -1
- package/istm-workflow/istm-scope/SKILL.md +20 -20
- package/istm-workflow/istm-scope/modes/add.md +1 -1
- package/istm-workflow/istm-scope/modes/plan-brownfield.md +2 -2
- package/istm-workflow/istm-scope/modes/plan-greenfield.md +4 -4
- package/istm-workflow/istm-scope/modes/plan-monorepo.md +3 -3
- package/istm-workflow/istm-scope/modes/plan.md +16 -16
- package/istm-workflow/istm-scope/modes/replan.md +2 -2
- package/istm-workflow/istm-scope/scope-template.md +29 -29
- package/istm-workflow/istm-sync/SKILL.md +37 -25
- package/istm-workflow/istm-sync/agent-prompt.md +37 -19
- package/istm-workflow/istm-test/SKILL.md +12 -12
- package/istm-workflow/istm-test/modes/setup.md +6 -6
- package/istm-workflow/istm-test/writing-guide.md +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: mobile-principles
|
|
3
|
+
description: "Mobile-specific UX principles - touch targets, hover-less doctrine, thumb zones, safe areas, gestures, mobile perf budgets. Cross-platform (web mobile, iOS, Android)."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Mobile Principles
|
|
7
|
+
|
|
8
|
+
> Touch-first UX context. Loaded when mobile is detected (web mobile, iOS, Android).
|
|
9
|
+
> Concise rules here. Deep-dive in `references/`.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Touch Targets
|
|
14
|
+
|
|
15
|
+
| Platform | Minimum | Recommended | Spec |
|
|
16
|
+
|---|---|---|---|
|
|
17
|
+
| Apple iOS | 44pt | 44pt + 8pt spacing | Apple HIG |
|
|
18
|
+
| Android | 48dp | 48dp + 8dp spacing | Material Design |
|
|
19
|
+
| Web mobile | 44px | 44px + 8px spacing | WCAG 2.5.5 |
|
|
20
|
+
|
|
21
|
+
**Rule of thumb:** any tap target smaller than the platform minimum is a usability bug, period.
|
|
22
|
+
The hit area can extend beyond the visible glyph (use padding, `hitSlop`, or a transparent inner spacer), but the *interactive* surface must reach the minimum. Spacing matters as much as size: two 44pt buttons touching edges are still mistappable.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## No-Hover Doctrine
|
|
27
|
+
|
|
28
|
+
`:hover` does not exist on touch. Treating it as a primary trigger means hidden affordances on every phone. Anything reachable only by hover is, on mobile, simply gone. Visible-by-default is the rule; hover styles are a desktop *enhancement*, never a load-bearing interaction.
|
|
29
|
+
|
|
30
|
+
**CSS - gate hover styles behind a media query:**
|
|
31
|
+
```css
|
|
32
|
+
.card { opacity: 1; transform: translateY(0); }
|
|
33
|
+
|
|
34
|
+
@media (hover: hover) and (pointer: fine) {
|
|
35
|
+
.card { opacity: 0.85; }
|
|
36
|
+
.card:hover { opacity: 1; transform: translateY(-2px); }
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**SwiftUI - tap and long-press, no pseudo-hover:**
|
|
41
|
+
```swift
|
|
42
|
+
Image(systemName: "heart")
|
|
43
|
+
.onTapGesture { toggleLike() }
|
|
44
|
+
.contextMenu {
|
|
45
|
+
Button("Share", systemImage: "square.and.arrow.up", action: share)
|
|
46
|
+
Button("Report", systemImage: "flag", role: .destructive, action: report)
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**Compose - combinedClickable for tap + long-press:**
|
|
51
|
+
```kotlin
|
|
52
|
+
Box(
|
|
53
|
+
modifier = Modifier
|
|
54
|
+
.combinedClickable(
|
|
55
|
+
onClick = { toggleLike() },
|
|
56
|
+
onLongClick = { showContextMenu() },
|
|
57
|
+
)
|
|
58
|
+
) {
|
|
59
|
+
Icon(Icons.Default.Favorite, contentDescription = "Like")
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Thumb Zones (Hoober)
|
|
66
|
+
|
|
67
|
+
Steven Hoober's research shows portrait phone use is overwhelmingly one-handed or cradled, with the thumb pivoting from the bottom corner. The screen splits into reachable zones:
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
+------+----+------+
|
|
71
|
+
| HARD | OK | HARD | <- top: stretch, two-handed only
|
|
72
|
+
+------+----+------+
|
|
73
|
+
| OK | OK | OK | <- middle: comfortable
|
|
74
|
+
+------+----+------+
|
|
75
|
+
| EASY |EASY| EASY | <- bottom: natural thumb arc
|
|
76
|
+
+------+----+------+
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
- **Bottom third (EASY):** primary CTA, send, confirm, FAB, tab bar.
|
|
80
|
+
- **Middle (OK):** content, secondary actions.
|
|
81
|
+
- **Top (HARD):** back, close, search, profile - things the user expects to reach for, not hit by reflex.
|
|
82
|
+
|
|
83
|
+
**Rule:** primary CTA goes in the bottom half. Secondary, less-frequent or destructive actions go in the top. Never put a "Pay" button in the top-right corner of a phone screen.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Safe Areas
|
|
88
|
+
|
|
89
|
+
| Platform | API | Insets respected |
|
|
90
|
+
|---|---|---|
|
|
91
|
+
| Web | `env(safe-area-inset-top|right|bottom|left)` + `viewport-fit=cover` | notch, home indicator |
|
|
92
|
+
| SwiftUI | `.safeAreaInset(edge: ...)`, `safeAreaInsets` env | nav bar, tab bar, notch, home |
|
|
93
|
+
| Compose | `Modifier.windowInsetsPadding(WindowInsets.safeDrawing)` | system bars, IME, cutouts |
|
|
94
|
+
|
|
95
|
+
**Web:**
|
|
96
|
+
```html
|
|
97
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
|
98
|
+
```
|
|
99
|
+
```css
|
|
100
|
+
.fab {
|
|
101
|
+
position: fixed;
|
|
102
|
+
bottom: calc(env(safe-area-inset-bottom) + 16px);
|
|
103
|
+
right: calc(env(safe-area-inset-right) + 16px);
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**SwiftUI:**
|
|
108
|
+
```swift
|
|
109
|
+
ScrollView { content }
|
|
110
|
+
.safeAreaInset(edge: .bottom) {
|
|
111
|
+
PrimaryCTA().padding()
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Compose:**
|
|
116
|
+
```kotlin
|
|
117
|
+
Column(
|
|
118
|
+
modifier = Modifier
|
|
119
|
+
.fillMaxSize()
|
|
120
|
+
.windowInsetsPadding(WindowInsets.safeDrawing)
|
|
121
|
+
) { /* content */ }
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Reduced Motion (cross-platform unified)
|
|
127
|
+
|
|
128
|
+
| Platform | API |
|
|
129
|
+
|---|---|
|
|
130
|
+
| Web CSS | `@media (prefers-reduced-motion: reduce)` |
|
|
131
|
+
| Web JS | `window.matchMedia('(prefers-reduced-motion: reduce)')` |
|
|
132
|
+
| SwiftUI | `@Environment(\.accessibilityReduceMotion) var reduceMotion` |
|
|
133
|
+
| UIKit | `UIAccessibility.isReduceMotionEnabled` |
|
|
134
|
+
| Compose | Custom helper using `Settings.Global.ANIMATOR_DURATION_SCALE` (see code below; deep-dive in `references/accessibility-mobile.md`) |
|
|
135
|
+
|
|
136
|
+
**SwiftUI:**
|
|
137
|
+
```swift
|
|
138
|
+
struct Hero: View {
|
|
139
|
+
@Environment(\.accessibilityReduceMotion) var reduceMotion
|
|
140
|
+
@State private var shown = false
|
|
141
|
+
|
|
142
|
+
var body: some View {
|
|
143
|
+
Text("Welcome")
|
|
144
|
+
.opacity(shown ? 1 : 0)
|
|
145
|
+
.offset(y: shown ? 0 : (reduceMotion ? 0 : 20))
|
|
146
|
+
.animation(reduceMotion ? .none : .easeOut(duration: 0.3), value: shown)
|
|
147
|
+
.onAppear { shown = true }
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**UIKit:**
|
|
153
|
+
```swift
|
|
154
|
+
let duration = UIAccessibility.isReduceMotionEnabled ? 0 : 0.3
|
|
155
|
+
UIView.animate(withDuration: duration) {
|
|
156
|
+
view.alpha = 1
|
|
157
|
+
view.transform = .identity
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**Compose (helper pattern):**
|
|
162
|
+
```kotlin
|
|
163
|
+
@Composable
|
|
164
|
+
fun rememberReduceMotion(): Boolean {
|
|
165
|
+
val context = LocalContext.current
|
|
166
|
+
return remember {
|
|
167
|
+
Settings.Global.getFloat(
|
|
168
|
+
context.contentResolver,
|
|
169
|
+
Settings.Global.ANIMATOR_DURATION_SCALE,
|
|
170
|
+
1f,
|
|
171
|
+
) == 0f
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
val reduceMotion = rememberReduceMotion()
|
|
176
|
+
val spec = if (reduceMotion) snap() else tween<Float>(durationMillis = 300)
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
> Note: prefer `ValueAnimator.areAnimatorsEnabled()` (API 26+) - it returns `false` when the animator duration scale is 0, which the developer-options "Animation off" toggle, Battery Saver, and the user-facing "Remove animations" (Settings -> Accessibility) toggle all set. Deep dive in `references/accessibility-mobile.md`.
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## Mobile Gestures (canonical patterns)
|
|
184
|
+
|
|
185
|
+
The five gestures users already know. Reusing them is free UX; reinventing them is friction.
|
|
186
|
+
|
|
187
|
+
- **Swipe-back:** iOS edge-swipe from the left to pop the navigation stack. Never override; mirror it on Android via predictive back (Android 14+).
|
|
188
|
+
- **Pull-to-refresh:** downward drag at the top of a scroll surface to refetch. Standard on feeds, mail, lists.
|
|
189
|
+
- **Drag-to-dismiss:** modal sheets and image viewers close when dragged downward past a threshold (typically 100-150pt).
|
|
190
|
+
- **Pinch-to-zoom:** two-finger spread/pinch on images, maps, and zoomable canvases. Respect minimum/maximum scale.
|
|
191
|
+
- **Swipe actions on rows:** horizontal swipe on a list row to reveal contextual actions (delete, archive, mark read). Leading vs trailing swipe = different action sets.
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## Mobile Performance Budgets
|
|
196
|
+
|
|
197
|
+
- **Cold start:** <2s on mid-range devices. Baselines: Android Pixel 4a, iPhone SE (2nd gen). If your app takes 4s on a Pixel 4a, it takes 8s on a low-end device users actually own.
|
|
198
|
+
- **Frame budget:** 16.67ms per frame at 60fps, 8.33ms at 120fps (ProMotion / high-refresh Android). Anything synchronous on the main thread above that = jank.
|
|
199
|
+
- **Binary size:** target <30MB APK and <50MB IPA before adding heavy media libs. Lottie/Rive add 500KB to 2MB. Watch your asset folders; PNGs over WebP / vector are the usual culprit.
|
|
200
|
+
- **Battery:** no continuous CPU activity in the background. Coalesce work, use platform schedulers (`WorkManager` on Android, `BGTaskScheduler` on iOS), avoid wake-locks unless the user explicitly asked for foreground media.
|
|
201
|
+
- **Network:** respect connection hints. Web: `Save-Data` request header and `navigator.connection.saveData`. iOS: `URLSessionConfiguration.allowsCellularAccess` and `NWPathMonitor` for cellular vs Wi-Fi. Android: `ConnectivityManager` + `NetworkCapabilities` to detect metered networks.
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## Anti-Patterns (BAD / GOOD)
|
|
206
|
+
|
|
207
|
+
### 1. Hover as the only reveal
|
|
208
|
+
|
|
209
|
+
```css
|
|
210
|
+
/* BAD - on mobile the action button literally never appears */
|
|
211
|
+
.card .actions { opacity: 0; }
|
|
212
|
+
.card:hover .actions { opacity: 1; }
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
```css
|
|
216
|
+
/* GOOD - visible by default, hover is a desktop enhancement */
|
|
217
|
+
.card .actions { opacity: 1; }
|
|
218
|
+
|
|
219
|
+
@media (hover: hover) and (pointer: fine) {
|
|
220
|
+
.card .actions { opacity: 0; transition: opacity 0.15s ease-out; }
|
|
221
|
+
.card:hover .actions { opacity: 1; }
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### 2. Sub-minimum touch targets
|
|
226
|
+
|
|
227
|
+
```kotlin
|
|
228
|
+
// BAD - 32dp icon button, mistappable, fails Material guideline
|
|
229
|
+
IconButton(
|
|
230
|
+
onClick = onDelete,
|
|
231
|
+
modifier = Modifier.size(32.dp),
|
|
232
|
+
) { Icon(Icons.Default.Delete, contentDescription = "Delete") }
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
```kotlin
|
|
236
|
+
// GOOD - 48dp minimum even when the visible icon is 24dp
|
|
237
|
+
IconButton(
|
|
238
|
+
onClick = onDelete,
|
|
239
|
+
modifier = Modifier.size(48.dp),
|
|
240
|
+
) {
|
|
241
|
+
Icon(
|
|
242
|
+
Icons.Default.Delete,
|
|
243
|
+
contentDescription = "Delete",
|
|
244
|
+
modifier = Modifier.size(24.dp),
|
|
245
|
+
)
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### 3. Ignoring safe area insets
|
|
250
|
+
|
|
251
|
+
```swift
|
|
252
|
+
// BAD - the CTA sits under the home indicator on every modern iPhone
|
|
253
|
+
VStack {
|
|
254
|
+
Spacer()
|
|
255
|
+
Button("Continue", action: next)
|
|
256
|
+
.frame(maxWidth: .infinity)
|
|
257
|
+
.padding()
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
```swift
|
|
262
|
+
// GOOD - safeAreaInset keeps the button reachable and visible
|
|
263
|
+
ScrollView { content }
|
|
264
|
+
.safeAreaInset(edge: .bottom) {
|
|
265
|
+
Button("Continue", action: next)
|
|
266
|
+
.frame(maxWidth: .infinity)
|
|
267
|
+
.padding()
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## Quick Reference: Loading sub-skills
|
|
274
|
+
|
|
275
|
+
| Need | Load |
|
|
276
|
+
|---|---|
|
|
277
|
+
| Gesture deep-dive | `references/gestures-deep.md` |
|
|
278
|
+
| Mobile a11y deep-dive | `references/accessibility-mobile.md` |
|
|
279
|
+
| Compose-specific anim | `../compose-motion/SKILL.md` |
|
|
280
|
+
| SwiftUI-specific anim | `../swiftui-motion/SKILL.md` |
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
## Sources
|
|
285
|
+
|
|
286
|
+
- Steven Hoober, "Designing for Touch" (mobile thumb zones research)
|
|
287
|
+
- Apple Human Interface Guidelines (iOS): https://developer.apple.com/design/human-interface-guidelines/
|
|
288
|
+
- Material Design (Android): https://m3.material.io/foundations/layout/canonical-layouts/overview
|
|
289
|
+
- WCAG 2.5.5 Target Size: https://www.w3.org/WAI/WCAG21/Understanding/target-size.html
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# Mobile Accessibility (deep-dive)
|
|
2
|
+
|
|
3
|
+
Mobile accessibility patterns. Screen readers, dynamic type, contrast, motor accommodations.
|
|
4
|
+
Cross-platform reference for SwiftUI, Compose, and the mobile web. Backs up the parent SKILL.md's reduced-motion section with the Android 14+ nuance.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Screen readers
|
|
9
|
+
|
|
10
|
+
### VoiceOver (iOS / macOS)
|
|
11
|
+
|
|
12
|
+
VoiceOver reads `accessibilityLabel`, then `accessibilityValue`, then `accessibilityHint`. Traits (`accessibilityAddTraits`) tell it the element's role.
|
|
13
|
+
|
|
14
|
+
```swift
|
|
15
|
+
struct VolumeSlider: View {
|
|
16
|
+
@Binding var value: Double // 0...1
|
|
17
|
+
|
|
18
|
+
var body: some View {
|
|
19
|
+
CustomTrack(value: value)
|
|
20
|
+
.accessibilityElement()
|
|
21
|
+
.accessibilityLabel("Volume")
|
|
22
|
+
.accessibilityValue("\(Int(value * 100)) percent")
|
|
23
|
+
.accessibilityHint("Swipe up or down to adjust")
|
|
24
|
+
.accessibilityAddTraits(.isAdjustable)
|
|
25
|
+
.accessibilityAdjustableAction { direction in
|
|
26
|
+
switch direction {
|
|
27
|
+
case .increment: value = min(1, value + 0.1)
|
|
28
|
+
case .decrement: value = max(0, value - 0.1)
|
|
29
|
+
@unknown default: break
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### TalkBack (Android Compose)
|
|
37
|
+
|
|
38
|
+
Compose builds a semantics tree from modifiers. `clearAndSetSemantics` replaces children's semantics (use it when a custom composable should be announced as one element). `traversalIndex` controls reading order.
|
|
39
|
+
|
|
40
|
+
```kotlin
|
|
41
|
+
Box(
|
|
42
|
+
modifier = Modifier
|
|
43
|
+
.size(48.dp)
|
|
44
|
+
.clickable(onClick = onToggle)
|
|
45
|
+
.clearAndSetSemantics {
|
|
46
|
+
contentDescription = if (liked) "Liked, double tap to unlike" else "Not liked, double tap to like"
|
|
47
|
+
role = Role.Button
|
|
48
|
+
stateDescription = if (liked) "On" else "Off"
|
|
49
|
+
},
|
|
50
|
+
) {
|
|
51
|
+
Icon(if (liked) Icons.Filled.Favorite else Icons.Outlined.FavoriteBorder, contentDescription = null)
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Web (mobile)
|
|
56
|
+
|
|
57
|
+
ARIA on mobile is the same API as desktop, just delivered to VoiceOver/TalkBack instead of NVDA/JAWS. No major divergence.
|
|
58
|
+
|
|
59
|
+
```html
|
|
60
|
+
<div role="slider" aria-label="Volume"
|
|
61
|
+
aria-valuemin="0" aria-valuemax="100" aria-valuenow="60"
|
|
62
|
+
aria-describedby="vol-help" tabindex="0"></div>
|
|
63
|
+
<p id="vol-help" class="visually-hidden">Swipe up or down to adjust</p>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Dynamic type / font scaling
|
|
69
|
+
|
|
70
|
+
**SwiftUI** - system styles scale. Custom fonts opt in via `UIFontMetrics` or `dynamicTypeSize`.
|
|
71
|
+
|
|
72
|
+
```swift
|
|
73
|
+
Text("Hello").font(.body) // scales
|
|
74
|
+
|
|
75
|
+
Text("Custom").font(.custom("Inter-Regular", size: 17, relativeTo: .body))
|
|
76
|
+
.dynamicTypeSize(.xSmall ... .accessibility3)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Compose** - use Material typography; read `LocalDensity.current.fontScale` for extreme sizes.
|
|
80
|
+
|
|
81
|
+
```kotlin
|
|
82
|
+
val fontScale = LocalDensity.current.fontScale
|
|
83
|
+
Text(
|
|
84
|
+
text = "Headline",
|
|
85
|
+
style = MaterialTheme.typography.headlineSmall,
|
|
86
|
+
maxLines = if (fontScale > 1.3f) 3 else 2,
|
|
87
|
+
)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Web** - relative units, cap with `clamp()`.
|
|
91
|
+
|
|
92
|
+
```css
|
|
93
|
+
:root { font-size: 100%; }
|
|
94
|
+
h1 { font-size: clamp(1.5rem, 4vw + 1rem, 2.5rem); }
|
|
95
|
+
p { font-size: 1rem; line-height: 1.5; }
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Contrast (WCAG 2.2 AA)
|
|
101
|
+
|
|
102
|
+
| Element | Ratio |
|
|
103
|
+
|---|---|
|
|
104
|
+
| Normal text (<18pt or <14pt bold) | 4.5:1 |
|
|
105
|
+
| Large text (>=18pt or >=14pt bold) | 3:1 |
|
|
106
|
+
| Non-text UI components, icons, focus rings | 3:1 |
|
|
107
|
+
|
|
108
|
+
Tools: Stark plugin (Figma), Xcode Accessibility Inspector (Audit tab), Android Accessibility Scanner. Never rely on color alone (WCAG 1.4.1): pair it with an icon, label, or pattern.
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Motor accommodations
|
|
113
|
+
|
|
114
|
+
**iOS** - detect alternative input methods:
|
|
115
|
+
|
|
116
|
+
```swift
|
|
117
|
+
if UIAccessibility.isAssistiveTouchRunning {
|
|
118
|
+
// increase tap targets, slow auto-dismiss, avoid time-limited gestures
|
|
119
|
+
}
|
|
120
|
+
// also: isSwitchControlRunning, isVoiceOverRunning
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Android - reduce motion (the nuance).** The reliable system-wide signal is `ValueAnimator.areAnimatorsEnabled()` (API 26+): it returns `false` when the animator duration scale is 0, which the developer-options "Animation off" toggle, Battery Saver, and the user-facing Settings -> Accessibility -> Remove animations toggle all set. `Settings.Global.ANIMATOR_DURATION_SCALE == 0f` reads the same value directly (use it as the pre-API-26 fallback).
|
|
124
|
+
|
|
125
|
+
```kotlin
|
|
126
|
+
@Composable
|
|
127
|
+
fun rememberReduceMotion(): Boolean {
|
|
128
|
+
val context = LocalContext.current
|
|
129
|
+
return remember {
|
|
130
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
131
|
+
!ValueAnimator.areAnimatorsEnabled() // API 26+: reflects animator duration scale == 0
|
|
132
|
+
} else {
|
|
133
|
+
Settings.Global.getFloat( // fallback for API < 26
|
|
134
|
+
context.contentResolver,
|
|
135
|
+
Settings.Global.ANIMATOR_DURATION_SCALE,
|
|
136
|
+
1f,
|
|
137
|
+
) == 0f
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Switch Access works if you respect standard focusable semantics (`Modifier.focusable()`, proper traversal order). Avoid time-limited gestures; provide a button alternative.
|
|
144
|
+
|
|
145
|
+
**Web:**
|
|
146
|
+
|
|
147
|
+
```css
|
|
148
|
+
@media (prefers-reduced-motion: reduce) {
|
|
149
|
+
*, *::before, *::after {
|
|
150
|
+
animation-duration: 0.001ms !important;
|
|
151
|
+
transition-duration: 0.001ms !important;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Large click targets (44px min, WCAG 2.5.5), no hover-only affordances, no drag-only interactions without a button fallback.
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## Testing checklist
|
|
161
|
+
|
|
162
|
+
- [ ] VoiceOver and TalkBack pass: every interactive element announced with a clear label and role.
|
|
163
|
+
- [ ] Dynamic Type at 200% (iOS xxxLarge / Android fontScale 2.0): no truncation, no overlap.
|
|
164
|
+
- [ ] Contrast pass: 4.5:1 normal text, 3:1 large text and non-text components.
|
|
165
|
+
- [ ] All interactive elements have labels (no unlabeled icon button).
|
|
166
|
+
- [ ] No information conveyed by color alone.
|
|
167
|
+
- [ ] All gestures have a non-gesture alternative (button, menu, keyboard equivalent).
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## Sources
|
|
172
|
+
|
|
173
|
+
- Apple Accessibility: https://developer.apple.com/accessibility/
|
|
174
|
+
- Android Accessibility: https://developer.android.com/guide/topics/ui/accessibility
|
|
175
|
+
- WCAG 2.2: https://www.w3.org/TR/WCAG22/
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# Gestures Deep Dive
|
|
2
|
+
|
|
3
|
+
Deep dive on gestures across mobile platforms. Covers conflict resolution, momentum, and complex composition.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Platform-specific gesture APIs
|
|
8
|
+
|
|
9
|
+
### Web - Pointer Events
|
|
10
|
+
|
|
11
|
+
The Pointer Events API unifies mouse, touch, and stylus into one event model. Use it instead of `touchstart`/`mousedown` to avoid double-handling on hybrid devices. CSS `touch-action` is the first lever: set it to `none` only on surfaces you fully own (drawing canvas, custom pan), or `pan-y` to keep vertical scroll while reserving horizontal pans.
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
// Element CSS: touch-action: none;
|
|
15
|
+
let startX = 0, startY = 0, dragging = false;
|
|
16
|
+
el.addEventListener('pointerdown', (e) => {
|
|
17
|
+
dragging = true;
|
|
18
|
+
startX = e.clientX; startY = e.clientY;
|
|
19
|
+
el.setPointerCapture(e.pointerId); // route move/up to el even if pointer leaves
|
|
20
|
+
});
|
|
21
|
+
el.addEventListener('pointermove', (e) => {
|
|
22
|
+
if (!dragging) return;
|
|
23
|
+
el.style.transform = `translate(${e.clientX - startX}px, ${e.clientY - startY}px)`;
|
|
24
|
+
});
|
|
25
|
+
el.addEventListener('pointerup', (e) => {
|
|
26
|
+
dragging = false;
|
|
27
|
+
el.releasePointerCapture(e.pointerId);
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
For multi-touch (pinch, rotate) and momentum, prefer a maintained library: `@use-gesture/react` (React-friendly, handles inertia) or Hammer.js (framework-agnostic, recognizes pinch, rotate, swipe, press).
|
|
32
|
+
|
|
33
|
+
### SwiftUI - Gesture composition
|
|
34
|
+
|
|
35
|
+
SwiftUI exposes `DragGesture`, `LongPressGesture`, `MagnifyGesture` (iOS 17+, was `MagnificationGesture`), `RotateGesture` (iOS 17+, was `RotationGesture`), and `TapGesture`. Combine via `.simultaneousGesture()`, `.highPriorityGesture()`, or operators (`SequenceGesture`, `SimultaneousGesture`, `ExclusiveGesture`).
|
|
36
|
+
|
|
37
|
+
```swift
|
|
38
|
+
struct DragToReveal: View {
|
|
39
|
+
@State private var offset: CGSize = .zero
|
|
40
|
+
|
|
41
|
+
var body: some View {
|
|
42
|
+
let press = LongPressGesture(minimumDuration: 0.2)
|
|
43
|
+
let drag = DragGesture()
|
|
44
|
+
.onChanged { offset = $0.translation }
|
|
45
|
+
.onEnded { _ in withAnimation(.spring) { offset = .zero } }
|
|
46
|
+
|
|
47
|
+
return Card()
|
|
48
|
+
.offset(offset)
|
|
49
|
+
.gesture(press.sequenced(before: drag))
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`.sequenced(before:)` is the canonical "press, then drag" pattern: the drag only starts once the long-press has fired. Used by reorderable lists and draggable home-screen icons.
|
|
55
|
+
|
|
56
|
+
### Compose - Modifier-based gestures
|
|
57
|
+
|
|
58
|
+
Compose splits gestures into high-level modifiers (`Modifier.draggable`, `Modifier.scrollable`, `Modifier.transformable`) and a low-level pointer-input DSL (`detectDragGestures`, `detectTapGestures`, `awaitPointerEventScope`).
|
|
59
|
+
|
|
60
|
+
```kotlin
|
|
61
|
+
@Composable
|
|
62
|
+
fun CustomLongPressDrag(onCommit: (Offset) -> Unit) {
|
|
63
|
+
var offset by remember { mutableStateOf(Offset.Zero) }
|
|
64
|
+
Box(Modifier
|
|
65
|
+
.offset { IntOffset(offset.x.toInt(), offset.y.toInt()) }
|
|
66
|
+
.pointerInput(Unit) {
|
|
67
|
+
awaitPointerEventScope {
|
|
68
|
+
while (true) {
|
|
69
|
+
val down = awaitFirstDown()
|
|
70
|
+
val longPress = awaitLongPressOrCancellation(down.id) ?: continue
|
|
71
|
+
drag(longPress.id) { it.consume(); offset += it.positionChange() }
|
|
72
|
+
onCommit(offset)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
For 90% of cases, use `Modifier.draggable` (1D) or `Modifier.transformable` (pan + zoom + rotate). Drop to `awaitPointerEventScope` only for custom state machines.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Gesture conflicts and resolution
|
|
85
|
+
|
|
86
|
+
Two gestures can claim the same pointer stream. The system picks one, or runs them in parallel. Three recurring conflicts:
|
|
87
|
+
|
|
88
|
+
- **Vertical scroll vs horizontal swipe.** Whichever direction crosses the threshold first wins; the other is locked out for that sequence. iOS `UICollectionView` and Compose `LazyColumn` both implement this. Align with it.
|
|
89
|
+
- **Long-press vs drag.** Finger up before press threshold (~500ms) = tap; after = drag armed. SwiftUI: `LongPressGesture.sequenced(before: DragGesture)`. Compose: `detectDragGesturesAfterLongPress`.
|
|
90
|
+
- **Native back-swipe vs custom horizontal pan.** iOS reserves the left ~20pt edge for `UINavigationController` pop; the custom gesture must yield, otherwise navigation breaks. Bind your gesture to a non-edge area or filter pointer-downs by x.
|
|
91
|
+
|
|
92
|
+
**SwiftUI conflict resolution with `GestureMask`:**
|
|
93
|
+
|
|
94
|
+
```swift
|
|
95
|
+
ScrollView {
|
|
96
|
+
ForEach(items) { item in
|
|
97
|
+
Row(item)
|
|
98
|
+
.simultaneousGesture(
|
|
99
|
+
DragGesture(minimumDistance: 20)
|
|
100
|
+
.onChanged(handleSwipeAction),
|
|
101
|
+
including: .gesture // run our gesture, but let the ScrollView still handle vertical scroll
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`including: .gesture` keeps the parent ScrollView's vertical scroll alive while the row's horizontal swipe is detected.
|
|
108
|
+
|
|
109
|
+
**Compose conflict resolution with `nestedScroll`:**
|
|
110
|
+
|
|
111
|
+
```kotlin
|
|
112
|
+
val connection = remember {
|
|
113
|
+
object : NestedScrollConnection {
|
|
114
|
+
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
|
|
115
|
+
// Consume vertical drag for header collapse before the inner list scrolls
|
|
116
|
+
return Offset(0f, collapseHeader(available.y))
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
Box(Modifier.nestedScroll(connection)) { CollapsibleHeader(); LazyColumn { /* ... */ } }
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`NestedScrollConnection` is the contract between an outer container and an inner scrollable: `onPreScroll` runs before the child consumes, `onPostScroll` after. Used by collapsing toolbars, pull-to-refresh, sheet drag.
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Momentum and fling
|
|
128
|
+
|
|
129
|
+
When the finger lifts mid-gesture, content should decelerate naturally, not stop dead.
|
|
130
|
+
|
|
131
|
+
**SwiftUI** - `DragGesture.Value.predictedEndTranslation` is the system's estimate of the landing point if released now. Project it and animate with a spring.
|
|
132
|
+
|
|
133
|
+
```swift
|
|
134
|
+
.onEnded { value in
|
|
135
|
+
let projected = value.predictedEndTranslation.height
|
|
136
|
+
let target = abs(projected) > 100 ? sign(projected) * sheetMaxOffset : 0
|
|
137
|
+
withAnimation(.interpolatingSpring(stiffness: 200, damping: 25)) { offset = target }
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
iOS 17+ also exposes `.gestureVelocity` for raw velocity, which composes nicely with `phaseAnimator`.
|
|
142
|
+
|
|
143
|
+
**Compose** - `Animatable.animateDecay()` with `splineBasedDecay()` reproduces the Android system fling curve.
|
|
144
|
+
|
|
145
|
+
```kotlin
|
|
146
|
+
val offset = remember { Animatable(0f) }
|
|
147
|
+
val flingSpec = rememberSplineBasedDecay<Float>()
|
|
148
|
+
|
|
149
|
+
Modifier.pointerInput(Unit) {
|
|
150
|
+
detectDragGestures(
|
|
151
|
+
onDrag = { c, d -> scope.launch { offset.snapTo(offset.value + d.x) }; c.consume() },
|
|
152
|
+
onDragEnd = { scope.launch { offset.animateDecay(velocity, flingSpec) } },
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Web** - Two routes. For native snapping, `scroll-snap-type: y mandatory` + `scroll-snap-align: start` on children: the browser handles fling and snap. For custom canvases, capture velocity at `pointerup` and decay it in a `requestAnimationFrame` loop until below ~0.1 px/frame.
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Pull-to-refresh canonical implementation
|
|
162
|
+
|
|
163
|
+
The simplest gesture on the surface, still the most botched. Use the platform primitives, stop reimplementing.
|
|
164
|
+
|
|
165
|
+
**Compose - Material 3 1.3+:**
|
|
166
|
+
|
|
167
|
+
```kotlin
|
|
168
|
+
@Composable
|
|
169
|
+
fun Feed(items: List<Item>, onRefresh: suspend () -> Unit) {
|
|
170
|
+
var isRefreshing by remember { mutableStateOf(false) }
|
|
171
|
+
val scope = rememberCoroutineScope()
|
|
172
|
+
PullToRefreshBox(
|
|
173
|
+
isRefreshing = isRefreshing,
|
|
174
|
+
onRefresh = { scope.launch { isRefreshing = true; onRefresh(); isRefreshing = false } },
|
|
175
|
+
) {
|
|
176
|
+
LazyColumn { items(items) { Row(it) } }
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
**SwiftUI - iOS 15+:**
|
|
182
|
+
|
|
183
|
+
```swift
|
|
184
|
+
List(items) { Row($0) }.refreshable { await viewModel.refresh() }
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
`.refreshable` propagates through the environment - inner `List` or `ScrollView` (iOS 16+) inherits the closure. Spinner, threshold, and haptic are platform-managed.
|
|
188
|
+
|
|
189
|
+
**Web - custom transform with overscroll-behavior:**
|
|
190
|
+
|
|
191
|
+
```js
|
|
192
|
+
// Container CSS: overflow-y:auto; overscroll-behavior: contain;
|
|
193
|
+
let startY = 0, pulled = 0, pulling = false;
|
|
194
|
+
scroll.addEventListener('pointerdown', (e) => {
|
|
195
|
+
if (scroll.scrollTop === 0) { startY = e.clientY; pulling = true; }
|
|
196
|
+
});
|
|
197
|
+
scroll.addEventListener('pointermove', (e) => {
|
|
198
|
+
if (!pulling) return;
|
|
199
|
+
pulled = Math.max(0, e.clientY - startY);
|
|
200
|
+
scroll.style.transform = `translateY(${Math.min(pulled * 0.5, 80)}px)`;
|
|
201
|
+
});
|
|
202
|
+
scroll.addEventListener('pointerup', async () => {
|
|
203
|
+
if (!pulling) return;
|
|
204
|
+
pulling = false;
|
|
205
|
+
scroll.style.transition = 'transform 0.2s';
|
|
206
|
+
scroll.style.transform = 'translateY(0)';
|
|
207
|
+
if (pulled > 60) await refresh();
|
|
208
|
+
setTimeout(() => scroll.style.transition = '', 200);
|
|
209
|
+
});
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
`overscroll-behavior: contain` blocks Safari's native bounce-to-reload and chained scroll, leaving you in control. An `IntersectionObserver` on a sentinel above the list can swap the manual pointer math for "trigger when the sentinel becomes fully visible".
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## Sources
|
|
217
|
+
|
|
218
|
+
- Apple HIG, Gestures: https://developer.apple.com/design/human-interface-guidelines/gestures
|
|
219
|
+
- Material Design, Gestures: https://m3.material.io/foundations/interaction/gestures
|
|
220
|
+
- W3C Pointer Events: https://www.w3.org/TR/pointerevents/
|