Skip to content

feat: skeleton 骨架屏#1465

Open
lqr131115 wants to merge 2 commits intoant-design:masterfrom
lqr131115:feat/skeleton
Open

feat: skeleton 骨架屏#1465
lqr131115 wants to merge 2 commits intoant-design:masterfrom
lqr131115:feat/skeleton

Conversation

@lqr131115
Copy link
Contributor

@lqr131115 lqr131115 commented Jan 30, 2026

First of all, thank you for your contribution! :-)

Please makes sure that these checkboxes are checked before submitting your PR, thank you!

  • Make sure that you follow antd's code convention.
  • Run npm run lint and fix those errors before submitting in order to keep consistent code style.
  • Rebase before creating a PR to keep commit history clear.
  • Add some descriptions and refer relative issues for you PR.

Extra checklist:

if isBugFix :

  • Make sure that you add at least one unit test for the bug which you had fixed.

elif isNewFeature :

  • Update API docs for the component.
  • Update/Add demo to demonstrate new feature.
  • Update TypeScript definition for the component.
  • Add unit tests for the feature.

Summary by CodeRabbit

  • 新功能
    • 新增骨架屏组件,含基础、Title 与 Paragraph 变体,支持动画与自定义样式,已集成至组件库并在示例中可见
  • 文档
    • 新增中/英文使用文档与演示示例
  • 测试
    • 添加骨架组件演示测试
  • 杂项
    • 新增主题色 token,示例列表已包含骨架项

@coderabbitai
Copy link

coderabbitai bot commented Jan 30, 2026

📝 Walkthrough

Walkthrough

新增完整的 Skeleton(骨架屏)组件系统,包括主组件及子组件 Title、Paragraph,类型定义、样式与主题变量、文档、示例与测试,并将组件与类型导出到库的公共 API。

Changes

Cohort / File(s) Summary
核心实现
components/skeleton/Skeleton.tsx, components/skeleton/SkeletonTitle.tsx, components/skeleton/SkeletonParagraph.tsx
新增 Skeleton 主组件及 Title/Paragraph 子组件,支持可选脉冲动画、主题样式合并及 memo 包装导出。
导出与入口
components/skeleton/index.tsx, components/index.tsx, components/types.ts
将 Skeleton 作为默认导出并附加静态属性 TitleParagraph,同时在全局 types 中重新导出相关类型。
类型定义
components/skeleton/PropsType.tsx
新增 SkeletonPropsSkeletonTitlePropsSkeletonParagraphProps 的 TypeScript 类型定义(包含 animated、style、styles、lineCount 等字段)。
样式与主题
components/skeleton/style/index.tsx, components/style/themes/default.tsx
新增 SkeletonStyle 接口与样式工厂,主题中添加 skeleton_background_color 配置。
文档与示例
components/skeleton/index.en-US.md, components/skeleton/index.zh-CN.md, components/skeleton/demo/basic.md, components/skeleton/demo/basic.tsx
新增中英文文档与演示示例,展示用法与 API。
测试与集成
components/skeleton/__tests__/demo.test.js, rn-kitchen-sink/demoList.js
添加 demo 测试文件并在演示列表中注册 Skeleton demo。

Sequence Diagram

sequenceDiagram
    participant Consumer as 消费者代码
    participant Skeleton as Skeleton 组件
    participant Theme as useTheme()
    participant Style as SkeletonStyle
    participant Animated as Animated API

    Consumer->>Skeleton: render(props)
    Skeleton->>Theme: 请求主题
    Theme-->>Skeleton: 返回 Theme 对象
    Skeleton->>Style: 合并主题样式与自定义 styles
    Style-->>Skeleton: 返回样式对象

    alt props.animated === true
        Skeleton->>Animated: 创建/配置 Animated.Value 与 timing 循环
        Animated->>Animated: 执行动画循环(opacity 0→1→0.25→1)
        Animated-->>Skeleton: 提供 Animated.View
        Skeleton->>Consumer: 渲染 Animated.View 骨架行/块
    else props.animated === false
        Skeleton->>Consumer: 渲染静态 View 骨架行/块
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Poem

🐰 新骨架来报到,轻声踩着节拍,
闪烁脉冲像心跳,主题样式暖洋洋,
Title 与 Paragraph 并肩站,演示与文档都在旁,
兔兔鼓掌庆贺这次小小改动。

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题'feat: skeleton 骨架屏'清晰、简洁地反映了主要变更——添加新的Skeleton骨架屏组件功能,与变更集的核心内容完全相关。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @lqr131115, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new Skeleton component, designed to enhance user experience during content loading by providing visual placeholders. The component offers both basic and animated loading states, along with specialized Title and Paragraph sub-components to mimic common content layouts. It is fully integrated with the existing styling system and includes comprehensive documentation and examples.

Highlights

  • New Skeleton Component: Introduces a Skeleton component for displaying loading placeholders, enhancing user experience during content loading.
  • Sub-components for Structure: Includes Skeleton.Title and Skeleton.Paragraph sub-components to mimic common content structures like headings and text blocks.
  • Animation Support: The Skeleton component supports an animated prop, providing a subtle loading animation to indicate active loading.
  • Custom Styling and Theming: Allows for custom styling through style and styles props, and integrates a new skeleton_background_color into the default theme.
  • Comprehensive Integration: The new component comes with full API documentation (English and Chinese), a practical demo, and unit tests, ensuring robust integration and usability.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new Skeleton component, including Skeleton.Title and Skeleton.Paragraph, to be used as a loading placeholder. The implementation includes an animated state and allows for customization. The changes are well-structured, with new components, styles, types, documentation, and tests. I've found a couple of areas for improvement: one is a potential bug where extra props are not passed down correctly in the Skeleton component, and the other is a minor code simplification in the Skeleton.Paragraph component. Overall, this is a great addition.

@lqr131115
Copy link
Contributor Author

lqr131115 commented Jan 30, 2026

@1uokun cc 👨‍💻

2026-01-30.16.55.43.mov

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@components/skeleton/Skeleton.tsx`:
- Around line 50-54: InternalSkeleton is spreading restProps into
AnimatedSkeleton which only expects style and animated, causing unknown props to
be forwarded and RN prop-type warnings; either stop forwarding restProps from
InternalSkeleton (only pass style and animated) or expand AnimatedSkeleton's
props to extend React Native ViewProps (update AnimatedSkeleton prop types to
include ViewProps and ensure it forwards allowed view props). Locate the spread
usage in InternalSkeleton (restProps -> AnimatedSkeleton) and fix by removing
the spread or by updating the AnimatedSkeleton/AnimatedSkeletonProps type and
internal forwarding logic to accept and pass through ViewProps safely.

In `@components/skeleton/SkeletonTitle.tsx`:
- Around line 7-23: The code currently merges customStyles twice (once here in
InternalSkeletonTitle via useTheme and again inside InternalSkeleton), so stop
forwarding the raw styles down: remove the styles={customStyles} prop from the
InternalSkeleton call in InternalSkeletonTitle (and do the same in
SkeletonParagraph) so the component only uses the already-merged
themeStyles.skeletonTitle for styling; keep useTheme(SkeletonStyles, styles:
customStyles) in InternalSkeletonTitle and let InternalSkeleton consume just the
merged style props, avoiding the double-merge.
🧹 Nitpick comments (4)
components/skeleton/index.en-US.md (1)

9-12: 考虑调整标题层级以符合 Markdown 最佳实践。

静态分析工具提示第 10 行的 ### Rule 标题应该使用 ## 而非 ###,因为在此之前没有出现过 ## 级别的标题。不过如果这是项目文档的统一风格,可以忽略此建议。

📝 可选的修复方案
-### Rule
+## Rules
components/skeleton/index.tsx (1)

5-6: 冗余的类型断言

as typeof InternalSkeletonTitleas typeof InternalSkeletonParagraph 是多余的,因为变量已经具有正确的类型。可以简化为直接赋值。

♻️ 建议的简化
-const Title = InternalSkeletonTitle as typeof InternalSkeletonTitle
-const Paragraph = InternalSkeletonParagraph as typeof InternalSkeletonParagraph
+const Title = InternalSkeletonTitle
+const Paragraph = InternalSkeletonParagraph
components/skeleton/demo/basic.tsx (1)

5-35: 建议使用函数式组件

Demo 使用了 class 组件,但项目中的 Skeleton 组件本身使用的是函数式组件和 Hooks。为保持代码风格一致性,建议将 demo 改为函数式组件。

♻️ 建议的重构
-class SkeletonExample extends React.Component {
-  render() {
-    return (
+const SkeletonExample: React.FC = () => {
+  return (
       <View style={{ padding: 16, backgroundColor: '#fff' }}>
         {/* ... 内容保持不变 ... */}
       </View>
-    )
-  }
+  )
 }
components/skeleton/SkeletonParagraph.tsx (1)

22-22: typeof 检查可简化

由于 TypeScript 类型已确保 lineCountnumber | undefined,且第 11 行已设置默认值 4,因此 typeof lineCount === 'number' 的检查是冗余的。可以简化为直接使用 Math.max

♻️ 建议的简化
-  const _lineCount = typeof lineCount === 'number' ? Math.max(lineCount, 1) : 4
+  const _lineCount = Math.max(lineCount, 1)

@1uokun
Copy link
Collaborator

1uokun commented Feb 2, 2026

建议新增 <Skeleton.Provider> 组件实现全局共享的动画实例 @lqr131115

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants