形变验证码输入框
“Enter code”胶囊先挤压再弹开成 6 位验证码框,聚焦环弹簧跟随。输错时整行抖动、数字逐位下沉清空,输对则渐变为绿色 Verified。支持真实键盘输入。
灵感来自 @sucodeee 在 X 上发布的设计由 Now In Code 从零重建
Piece.tsxindex.ts
// Sign in to see the source. Free pieces need a free account.
Agent 提示词
Add the Now In Code component "morphing-verification-code-input" to this project. The full source is attached at the end of this prompt. Put the files under components/morphing-verification-code-input/, install the listed dependencies with `npx expo install`, and render it on a route I can open. Keep the timing and easing values documented in the source comments. Replace the sample copy and artwork with content from my app, or leave placeholders and list what I still need to supply. === Sign in to attach the source files ===
详情
- 平台
- iOS、Android、Web
- 依赖
- Expo SDK 54+
- 权限
- 免费
- 更新于
- 2026年10月7日
- 许可证
- 无限商业项目
- 原始设计
- @sucodeee(X)
你是设计者吗? 请求我们修改或下架此作品.
CLI 与 MCP 服务器 即将推出
在终端添加作品,或让智能体自行获取。在此之前,用“复制提示词”也能做到。 文档
功能说明
一个一次性验证码输入框,会随状态改变形状。起初是一个小药丸,标注 Enter code。点按后,它展开为一排六格,活动格带有一圈环形高亮和闪烁的光标。每个数字以短促的上升动画和从模糊到清晰的过渡进入。输入第六位后,这排格子挤压成一个带旋转指示器的 Verifying 药丸。错误验证码会使药丸左右抖动、变为粉色,数字从右到左依次掉出,环形高亮回到第一格。正确验证码则使药丸变为绿色,文字换成对勾和 Verified。隐藏的输入框负责键盘输入、粘贴和自动填充,同时提供循环演示和交互模式。
实现方式
纯 JavaScript 函数接收事件日志和时间,返回每个格子的状态、环形高亮、光标和药丸宽度,因此网页预览和 React Native 组件读取的是同一组数值。原生版本用 react-native-svg 渲染,并用 expo-blur 对整层做模糊。React Native 没有 CSS 滤镜,因此文字模糊通过一个幽灵 Text 加阴影半径来模拟。宽度变化先收缩再弹性展开,环形高亮以短弹簧跟随最后一个格子。requestAnimationFrame 循环驱动时钟。
适用场景
- 邮件或短信验证页面
- 成功与失败都需要明确反馈的双重验证或 PIN 码输入
- 在空闲、输入、加载和结果状态之间切换时需要自我变形的任何控件
依赖
react-native-svgexpo-blurreact-native标签
金融钱包飞入飞出浅色极简形变选择器登录注册弹簧状态切换输入框