Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(picker): 删除3D环绕效果 #2815

Open
wants to merge 3 commits into
base: feat_v3.x
Choose a base branch
from

Conversation

oasis-cloud
Copy link
Collaborator

@oasis-cloud oasis-cloud commented Dec 2, 2024

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

💡 需求背景和解决方案

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • fork仓库代码是否为最新避免文件冲突
  • Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

  • 新功能

    • 移除了日期选择器和选择器组件中的三维效果属性,简化了用户界面。
  • 文档

    • 更新了日期选择器和选择器组件的文档,移除了与三维效果相关的描述和示例。

Copy link

coderabbitai bot commented Dec 2, 2024

Walkthrough

此拉取请求主要涉及对DatePickerPicker组件的多个文件进行修改,重点是删除threeDimensional属性。该属性在多个测试用例和组件实现中被移除,表明该功能不再被支持或使用。相应地,相关的文档也进行了更新,以反映这一变化,确保文档与代码保持一致。

Changes

文件路径 变更摘要
src/packages/datepicker/__test__/datepicker.spec.tsx 移除了多个测试用例中的threeDimensional属性。
src/packages/datepicker/datepicker.taro.tsx DatePickerProps接口和defaultProps中移除了threeDimensional属性。
src/packages/datepicker/datepicker.tsx DatePickerProps接口、defaultPropspickerProps中移除了threeDimensional属性。
src/packages/datepicker/demos/h5/demo1.tsx DatePicker实例中移除了threeDimensional属性。
src/packages/datepicker/demos/taro/demo1.tsx DatePicker实例中移除了threeDimensional属性。
src/packages/datepicker/doc.en-US.md 在文档中添加了threeDimensional属性,类型为boolean,默认值为true
src/packages/datepicker/doc.md 在文档中添加了threeDimensional属性,类型为boolean,默认值为true
src/packages/datepicker/doc.taro.md 在文档中添加了threeDimensional属性,类型为boolean,默认值为true
src/packages/datepicker/doc.zh-TW.md 在文档中添加了threeDimensional属性,类型为boolean,默认值为true
src/packages/picker/demo.taro.tsx 移除了对Demo5的导入和相关的JSX元素。
src/packages/picker/demo.tsx 移除了对Demo5的导入和相关的JSX元素。
src/packages/picker/demos/h5/demo5.tsx Picker组件中移除了threeDimensional属性。
src/packages/picker/demos/taro/demo5.tsx Picker组件中移除了threeDimensional属性。
src/packages/picker/doc.en-US.md 移除了文档中关于threeDimensional属性的描述。
src/packages/picker/doc.md 移除了文档中关于threeDimensional属性的描述。
src/packages/picker/doc.taro.md 移除了文档中关于threeDimensional属性的描述。
src/packages/picker/doc.zh-TW.md 移除了文档中关于threeDimensional属性的描述。
src/packages/picker/picker.taro.tsx PickerProps接口和defaultProps中移除了threeDimensional属性。
src/packages/picker/picker.tsx PickerProps接口和defaultProps中移除了threeDimensional属性。
src/packages/picker/pickerpanel.taro.tsx PickerPanelProps接口中移除了threeDimensional属性。
src/packages/picker/pickerpanel.tsx PickerPanelProps接口中移除了threeDimensional属性。

Suggested labels

3.x

Suggested reviewers

  • xiaoyatong

兔子在草地上欢快跳,
三维效果已不再需要,
日期选择更简洁明了,
代码清晰如春日的朝,
让我们一起欢庆这变更,
兔子舞动着小脚丫,
未来更美好,乐无边。 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the 3.x label Dec 2, 2024
@oasis-cloud oasis-cloud marked this pull request as draft December 2, 2024 12:24
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: 1

🧹 Outside diff range and nitpick comments (3)
src/packages/picker/pickerpanel.taro.tsx (2)

274-287: 建议优化渲染性能

当前实现正确但可以通过以下方式进行优化:

  1. 考虑使用虚拟列表来优化长列表的渲染性能
  2. 可以将固定的样式抽离到CSS中,减少内联样式的使用

建议参考以下实现:

+const ITEM_STYLE = {
+  height: '36px',
+  lineHeight: '36px',
+}

 {options.map((item, index) => {
   return (
     <View
       className="nut-picker-roller-item-title"
       key={item.value ? item.value : index}
-      style={{
-        height: `${lineSpacing.current}px`,
-        lineHeight: `${lineSpacing.current}px`,
-      }}
+      style={{
+        ...ITEM_STYLE,
+        height: `${lineSpacing.current}px`,
+        lineHeight: `${lineSpacing.current}px`,
+      }}
     >

Line range hint 1-294: 建议加强错误处理机制

为提高组件的健壮性,建议在以下几个关键位置添加错误处理:

  1. 触摸事件处理中添加try-catch
  2. 在ref获取失败时提供合理的降级处理
  3. 在options为空时提供友好的提示

建议在关键函数中添加错误处理,例如:

 const getReference = async () => {
+  try {
     const refe = await getRectByTaro(listRef?.current)
     lineSpacing.current = refe.height ? refe.height : 36
+  } catch (error) {
+    console.error('获取元素尺寸失败:', error)
+    lineSpacing.current = 36
+  }
 }
src/packages/picker/pickerpanel.tsx (1)

263-272: 建议增加无障碍访问支持

当前实现可以通过以下方式优化无障碍访问体验:

  1. 为选项添加 role="option" 属性
  2. 为当前选中项添加 aria-selected="true"
  3. 添加适当的 aria-label 描述

建议按如下方式修改代码:

 {options.map((item, index) => {
   return (
     <div
       className="nut-picker-roller-item-title"
       key={item.value ? item.value : index}
+      role="option"
+      aria-selected={currIndex === index + 1}
+      aria-label={`选项 ${item.text}`}
     >
       <>{item.text}</>
     </div>
   )
 })}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1fa8c82 and db45df8.

📒 Files selected for processing (21)
  • src/packages/datepicker/__test__/datepicker.spec.tsx (0 hunks)
  • src/packages/datepicker/datepicker.taro.tsx (0 hunks)
  • src/packages/datepicker/datepicker.tsx (0 hunks)
  • src/packages/datepicker/demos/h5/demo1.tsx (0 hunks)
  • src/packages/datepicker/demos/taro/demo1.tsx (0 hunks)
  • src/packages/datepicker/doc.en-US.md (0 hunks)
  • src/packages/datepicker/doc.md (0 hunks)
  • src/packages/datepicker/doc.taro.md (0 hunks)
  • src/packages/datepicker/doc.zh-TW.md (0 hunks)
  • src/packages/picker/demo.taro.tsx (0 hunks)
  • src/packages/picker/demo.tsx (0 hunks)
  • src/packages/picker/demos/h5/demo5.tsx (0 hunks)
  • src/packages/picker/demos/taro/demo5.tsx (0 hunks)
  • src/packages/picker/doc.en-US.md (0 hunks)
  • src/packages/picker/doc.md (0 hunks)
  • src/packages/picker/doc.taro.md (0 hunks)
  • src/packages/picker/doc.zh-TW.md (0 hunks)
  • src/packages/picker/picker.taro.tsx (0 hunks)
  • src/packages/picker/picker.tsx (0 hunks)
  • src/packages/picker/pickerpanel.taro.tsx (2 hunks)
  • src/packages/picker/pickerpanel.tsx (2 hunks)
💤 Files with no reviewable changes (19)
  • src/packages/datepicker/doc.en-US.md
  • src/packages/picker/demos/taro/demo5.tsx
  • src/packages/datepicker/doc.md
  • src/packages/datepicker/demos/taro/demo1.tsx
  • src/packages/datepicker/doc.zh-TW.md
  • src/packages/datepicker/doc.taro.md
  • src/packages/picker/demos/h5/demo5.tsx
  • src/packages/datepicker/test/datepicker.spec.tsx
  • src/packages/datepicker/demos/h5/demo1.tsx
  • src/packages/picker/doc.md
  • src/packages/picker/doc.taro.md
  • src/packages/datepicker/datepicker.tsx
  • src/packages/picker/picker.taro.tsx
  • src/packages/datepicker/datepicker.taro.tsx
  • src/packages/picker/picker.tsx
  • src/packages/picker/doc.en-US.md
  • src/packages/picker/doc.zh-TW.md
  • src/packages/picker/demo.tsx
  • src/packages/picker/demo.taro.tsx
🔇 Additional comments (2)
src/packages/picker/pickerpanel.taro.tsx (1)

270-270: 样式简化改动符合预期!

移除3D环绕效果后,统一使用 touchTileStyle() 来处理滚动变换,使代码更加清晰。

src/packages/picker/pickerpanel.tsx (1)

259-259: 样式更改符合预期!

移除3D效果后,统一使用 touchTileStyle() 来处理滚动动画,使代码更加简洁清晰。

Comment on lines +259 to +272
style={touchTileStyle()}
onTransitionEnd={stopMomentum}
>
{/* 3D 效果 */}
{threeDimensional &&
options.map((item, index) => {
return (
<div
className={`nut-picker-roller-item ${
isHidden(index + 1) && 'nut-picker-roller-item-hidden'
}`}
style={{
transform: `rotate3d(1, 0, 0, ${
-rotation * (index + 1)
}deg) translate3d(0px, 0px, 104px)`,
}}
key={item.value ? item.value : index}
>
<>{item.text}</>
</div>
)
})}
{/* 平铺 */}
{!threeDimensional &&
options.map((item, index) => {
return (
<div
className="nut-picker-roller-item-title"
key={item.value ? item.value : index}
>
<>{item.text}</>
</div>
)
})}
{options.map((item, index) => {
return (
<div
className="nut-picker-roller-item-title"
key={item.value ? item.value : index}
>
<>{item.text}</>
</div>
)
})}
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

需要更新测试用例和文档

基于验证结果:

  1. 在 properties.json 中仍存在 3D 效果相关的配置项
  2. 测试用例中没有针对 3D 效果的测试,但需要更新以反映新的交互方式
  3. 文档中没有明确提到 3D 效果相关的内容

建议:

  • 从 properties.json 中移除 threeDimensional 相关配置
  • 更新测试用例以验证新的滚动交互
  • 确保视觉测试覆盖新的滚动效果
🔗 Analysis chain

请确认视觉回归测试的更新

由于移除了3D效果,建议:

  1. 更新相关的视觉回归测试用例
  2. 确保文档中已移除所有关于3D效果的描述
  3. 验证在不同机型上的滚动效果是否正常
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查是否还有其他文件包含 threeDimensional 相关代码
rg -l "threeDimensional" .

# 检查文档中是否还有 3D 相关描述
rg -l "3D|三维|环绕" "src/packages/picker/doc*.md"

Length of output: 169


Script:

#!/bin/bash
# 检查 picker 相关的文档文件
fd "doc.*\.md" src/packages/picker/

# 检查 properties.json 中的 threeDimensional 相关内容
cat scripts/properties.json | grep -A 5 -B 5 "threeDimensional"

# 检查测试文件中是否包含相关测试用例
fd ".*test.*\.(ts|tsx|js|jsx)" src/packages/picker/

# 检查是否有视觉测试相关的配置文件
fd ".*\.(test|spec)\.(ts|tsx|js|jsx)" -e storybook -e cypress -e screenshot

Length of output: 745


Script:

#!/bin/bash
# 检查文档中的3D效果相关描述
cat src/packages/picker/doc.md
cat src/packages/picker/doc.en-US.md
cat src/packages/picker/doc.zh-TW.md
cat src/packages/picker/doc.taro.md

# 检查是否存在视觉测试相关目录
fd -t d "(test|__test__|cypress|screenshot|storybook)"

Length of output: 12916


Script:

#!/bin/bash
# 检查 picker 组件的测试文件内容
cat src/packages/picker/__tests__/*

# 检查 properties.json 中是否还有其他与 3D 效果相关的配置
cat scripts/properties.json | jq '.[] | select(.第二列 | contains("3D"))'

Length of output: 5367

@oasis-cloud oasis-cloud marked this pull request as ready for review December 3, 2024 02:36
Copy link

codecov bot commented Dec 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.10%. Comparing base (9332996) to head (76788d0).
Report is 24 commits behind head on feat_v3.x.

Additional details and impacted files
@@              Coverage Diff              @@
##           feat_v3.x    #2815      +/-   ##
=============================================
+ Coverage      83.99%   84.10%   +0.10%     
=============================================
  Files            220      273      +53     
  Lines          17885    18065     +180     
  Branches        2679     2681       +2     
=============================================
+ Hits           15023    15194     +171     
- Misses          2857     2866       +9     
  Partials           5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@irisSong irisSong left a comment

Choose a reason for hiding this comment

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

单测覆盖,migrate-from更新

Copy link
Collaborator

@irisSong irisSong left a comment

Choose a reason for hiding this comment

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

单测覆盖,migrate-from更新

return (
<View
className={`nut-picker-roller-item ${
isHidden(index + 1) && 'nut-picker-roller-item-hidden'
Copy link
Collaborator

Choose a reason for hiding this comment

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

3d环绕的样式也需要删除

@oasis-cloud oasis-cloud requested a review from irisSong December 5, 2024 09:08
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: 0

🧹 Outside diff range and nitpick comments (1)
src/packages/picker/pickerpanel.tsx (1)

250-259: 建议添加无障碍访问支持

为了提高组件的可访问性,建议添加适当的ARIA属性:

 <div
   className="nut-picker-roller-item-title"
   key={item.value ? item.value : index}
+  role="option"
+  aria-selected={currIndex === index + 1}
 >
   <>{item.text}</>
 </div>

这样可以:

  1. 让屏幕阅读器能够正确识别选项
  2. 提供更好的无障碍体验
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between de7bade and 76788d0.

📒 Files selected for processing (3)
  • migrate-from-v2.md (1 hunks)
  • src/packages/picker/pickerpanel.taro.tsx (2 hunks)
  • src/packages/picker/pickerpanel.tsx (2 hunks)
🔇 Additional comments (8)
migrate-from-v2.md (2)

444-444: 确认移除 Picker 组件的 3D 效果

这项更改与当前 PR 的目标一致,移除了 Picker 组件中的 3D 环绕效果。这种简化有助于提升组件的性能和可维护性。


Line range hint 1-1000: 文档结构清晰,迁移指南完整

该迁移指南详细记录了从 v2 到 v3 版本的所有重要变更,包括:

  • 清晰的升级步骤说明
  • 完整的 API 变更列表
  • 按组件类别组织的变更说明

建议在合并此 PR 后,确保该文档与其他相关文档保持同步更新。

src/packages/picker/pickerpanel.tsx (2)

246-247: 样式应用逻辑简化,代码更清晰!

移除3D效果后,样式应用变得更加直接和统一,提高了代码的可维护性。


Line range hint 1-270: 请确认是否完全清理了所有3D效果相关的配置

基于之前的审查发现,建议进一步确认:

  1. properties.json 中是否还存在 3D 效果相关的配置项
  2. 文档是否已更新以反映移除 3D 效果的变化
  3. 相关的测试用例是否已更新
#!/bin/bash
# 检查是否还有其他文件包含 threeDimensional 相关代码
rg -l "threeDimensional" .

# 检查文档中是否还有 3D 相关描述
rg -l "3D|三维|环绕" "src/packages/picker/doc*.md"

# 检查 properties.json 中的配置
cat scripts/properties.json | grep -A 5 -B 5 "threeDimensional"
src/packages/picker/pickerpanel.taro.tsx (4)

3-6: 导入语句重新排序符合最佳实践

React hooks的导入顺序调整更加合理,便于维护。


261-274: 确认扁平化渲染逻辑的完整性

移除3D效果后,选项渲染逻辑已简化为扁平化展示。建议:

  1. 确保所有选项的可见性和交互性
  2. 验证选项切换的过渡动画是否流畅

建议添加以下测试场景:

  • 快速滑动时的性能表现
  • 边界条件下的滚动行为
  • 不同数量选项时的显示效果

Line range hint 281-281: 样式清理建议

响应之前的评审意见,建议进一步检查并清理以下内容:

  1. 相关的CSS/Less文件中的3D样式
  2. 主题文件中的相关变量
  3. 动画相关的过渡效果

257-257: 建议检查样式兼容性

在移除3D效果后,touchTileStyle函数仍保留了transform属性。建议验证在不同设备上的滚动表现是否一致。

✅ Verification successful

Let me check the touchTileStyle function implementation to understand what transform properties are being used.


transform 样式实现兼容

经过验证,touchTileStyle 函数仅使用了 translate3d 进行垂直方向的滚动变换,这是一个广泛支持且性能良好的变换方式。目前的实现:

  • 仅包含必要的垂直位移变换
  • 使用了标准的 cubic-bezier 缓动函数
  • 没有使用可能导致兼容性问题的 3D 效果
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查其他组件中是否还存在3D相关样式
rg -g '*.less' -g '*.scss' -g '*.css' '3[dD]|transform.*rotate|perspective'

Length of output: 9521


Script:

#!/bin/bash
# Check touchTileStyle implementation
ast-grep --pattern 'touchTileStyle'

Length of output: 337


Script:

#!/bin/bash
# Check the implementation details of touchTileStyle function
ast-grep --pattern $'const touchTileStyle = () => {
  $$$
}'

Length of output: 961

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

Successfully merging this pull request may close these issues.

2 participants