✨ 巧用等待状态,让产品响应更丝滑——《999 个小技巧,让你 Vibe 的产品更有质感》017 在实际运行的产品中,等待不可避免。如何把等待合理地告知用户,会影响用户的情绪和操作的流畅度,有时甚至应该先给出反馈,再根据结果更正。今天介绍几种常见的交互模式: Spinner:按钮搭配 Toast,适合几秒内就能完成的操作,如刷新、同步。点击后按钮图标原地旋转,结束后用 Toast 告知结果,轻量,也不打断操作。 Skeleton:页面结构已知时,先显示骨架,再换成真实内容。用户能提前知道内容会出现在哪里,内容到达后原位替换,页面不跳动。常见于信息流、图表等内容面积较大的场景。 Progress:明确告知用户进度和最终结果,常见于上传、导入、诊断等耗时任务。可以用 Toast 或通知卡片呈现,也可以嵌在页面或表单中。 Optimistic:严格来说,这是一种策略而非模式。对于大概率成功、也容易退回的操作,先显示结果,再在后台保存;保存失败时,把改动退回原处,说明原因,并提供重试。 另外,300ms 以内的等待通常不显示单独的加载状态,否则它刚出现就消失,看起来像闪了一下。 附一条 Prompt(比较长,如果你需要):它会先找出你的产品里所有需要等待的地方,逐个判断该用哪种方式,列出表格由你决定;确认后,再按视频中的效果改造 ⬇️
枯白啃设计

图标设计师 / 设计工程师

Prompt(3/3) - Progress in a notification: 344px wide, 24px corners, 14px padding (16px on the right), at the top right. A 32px icon tile centred on the words beside it, holding the file's type as a two-tone filled icon at 18px, the title (Importing tasks.csv), the count and time left in one line (568 of 1,240 rows · About 2s left), and a 4px bar in the accent on the accent at 10%; no row of buttons: the card opens what it is about, and a close mark on hover cancels. It comes down 56px onto the page out of a 4px blur and from 96% over 420ms. When it is done, the same card changes in place: the old words blur out over 160ms and the new ones in over 420ms (Imported 1,240 tasks, Added to Backlog.), the bar folds away and the tile turns solid green with a heavy white check, the same 18px. It then stays until opened or closed. - Optimistic: a 20px checkbox in the task icon's place, shown on hover and filled green when ticked; totals roll to the new figure over 320ms; Saving with a 12px spinner, then Saved with a check, at the start of the row's last column, in 12px grey. When a save fails the row shakes 6px, twice, over 360ms, the reason in red takes the place of the row's counts, and Retry takes the place of Saving, until it is fixed. - AI answer: steps at 13px with a 16px spinner that turns into a check; the answer at 15/24; the caret 2px wide in the accent; Retry and Copy at the end. 5. How to build it, by platform These are suggestions; check them against my stack and its versions, and prefer what the product already uses. - Web: the delay and minimum as one hook or helper, for example useDelayedFlag(loading, 300, 500). React: Suspense with a skeleton fallback, startTransition to keep the old content while the new loads, useOptimistic or a mutation's onMutate with a rollback; React Query or SWR keep the previous data while they refetch. Read streamed answers from fetch with a ReadableStream, or the AI SDK's useChat. Draw the band as one gradient fixed to the list, moved by background-position, and stop it under prefers-reduced-motion. - iOS: .redacted(reason: .placeholder) for skeletons, ProgressView for progress, Task cancellation for Cancel, optimistic changes in the view model with a rollback, AsyncSequence for streamed text. - Android: a shimmer brush over placeholder shapes in Compose, LinearProgressIndicator with a value, Paging's LoadState for lists, optimistic state in the ViewModel with a rollback, Flow for streamed text. - Flutter: the real widgets as placeholders under a shimmer (or Skeletonizer), LinearProgressIndicator(value:), a Stream for streamed text. - Rust and other native desktops (egui, iced, GPUI, Tauri): the same states in the UI model, with the 300 and 500ms timers in the update loop. 6. Check - Throttle the network (Slow 4G) and time every wait: nothing shows a separate loader under 300ms, nothing flashes, nothing moves the layout when the data comes. - Turn the network off during an optimistic change: it goes back, says why, and Retry works. - Cancel a long job, and leave the page during one: nothing is lost, nothing keeps spinning. - A screen reader hears loading and done; reduced motion has no moving band; light and dark both checked; existing tests still pass.
登录并发表评论

评论 · 0