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

feat(swipe): harmony #3039

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 Mar 4, 2025

Summary by CodeRabbit

  • New Features

    • 优化了滑动组件的交互响应和初始化,提升了整体使用流畅性。
    • 修改了输入组件的展示逻辑,确保一直显示,并改进了按钮中文本的显示效果。
  • Style

    • 调整了左右滑动区域的布局和定位,使视觉呈现更精准、更协调。

Copy link

coderabbitai bot commented Mar 4, 2025

Walkthrough

本次变更包括多个模块的调整:在配置文件中将 Swipe 组件的 "dd" 属性从 false 修改为 true;在获取元素尺寸的 hook 中增加了日志输出;在 Taro 示例中移除了对 harmony 的依赖并调整了组件渲染条件;同时对 Swipe 组件的样式、布局以及交互逻辑进行了优化,使用 useReady 替换了 useEffect 并引入了 useUuid,此外更新了工具函数 getRectByTaro 的参数和选择逻辑。

Changes

文件 更改摘要
src/config.json 将 Swipe 组件的 "dd" 属性值由 false 改为 true
src/hooks/use-client-rect.ts getRect 函数中添加了 console.log,用于输出元素及其边界矩形信息
src/packages/swipe/demos/taro/demo9.tsx,
src/packages/swipe/swipe.scss,
src/packages/swipe/swipe.taro.tsx
- demo 文件中移除了 harmony 导入,并简化了 InputNumber 组件的条件渲染(始终渲染),且更新了按钮内文本样式。
- 样式文件中注释掉了部分 flex 布局属性,添加了新的 transform 定位。
- Taro 组件中用 useReady 替换了 useEffect,引入了 useUuid 生成唯一 ID,并更新了触摸事件处理和宽度计算逻辑。
src/utils/get-rect-by-taro.ts 修改了函数签名,增加了 harmonyId 参数,并更新了通过 harmonyIdelement.uid 选择 DOM 元素的逻辑

Sequence Diagram(s)

sequenceDiagram
    participant S as Swipe 组件
    participant U as useUuid Hook
    participant R as useReady Hook
    participant G as getRectByTaro
    S->>U: 生成唯一 ID (uid, leftId, rightId)
    S->>R: 注册组件就绪回调
    R->>S: 就绪后触发回调
    S->>G: 请求获取 left/right 元素尺寸 (传入生成的 ID)
    G-->>S: 返回元素的尺寸信息
Loading

Possibly related PRs

Suggested reviewers

  • irisSong

Poem

嘟嘟小兔欢声跳,
代码更新日新潮。
配置、样式齐调整,
逻辑流转稳步跑。
日志、UUID传递好,
轻松调试不烦恼。
变更庆祝,快来瞧! 🐰


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b5dcefa and 4c18378.

📒 Files selected for processing (1)
  • src/config.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/config.json
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: test

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
🪧 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 generate docstrings to generate docstrings for this 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 3.x Target branch 3.x action:review This PR needs more reviews (less than 2 approvals) labels Mar 4, 2025
Copy link

codecov bot commented Mar 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.05%. Comparing base (4fd87f6) to head (4c18378).

Additional details and impacted files
@@            Coverage Diff             @@
##           feat_v3.x    #3039   +/-   ##
==========================================
  Coverage      86.05%   86.05%           
==========================================
  Files            281      281           
  Lines          18255    18256    +1     
  Branches        2749     2749           
==========================================
+ Hits           15709    15710    +1     
  Misses          2541     2541           
  Partials           5        5           

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

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

🧹 Nitpick comments (2)
src/config.json (1)

173-173: 代码格式优化

删除了多余的空行,保持代码风格的一致性。

src/packages/swipe/demos/taro/demo9.tsx (1)

49-49: 简化渲染逻辑

移除了条件渲染逻辑,改为直接渲染 InputNumber 组件,简化了代码并提高了组件在不同平台上的一致性。同时也移除了对 harmony 函数的依赖。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 827ab5c and b5dcefa.

📒 Files selected for processing (7)
  • src/config.json (2 hunks)
  • src/hooks/use-client-rect.ts (1 hunks)
  • src/packages/button/button.scss (1 hunks)
  • src/packages/swipe/demos/taro/demo9.tsx (2 hunks)
  • src/packages/swipe/swipe.scss (1 hunks)
  • src/packages/swipe/swipe.taro.tsx (5 hunks)
  • src/utils/get-rect-by-taro.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/hooks/use-client-rect.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (14)
src/packages/button/button.scss (1)

23-23: 样式增强: 避免按钮文本换行

添加 white-space: nowrap; 确保按钮内的文本不会因空间不足而换行,保持单行显示,提高了按钮的整体视觉一致性。

src/config.json (1)

1027-1027: 配置更新: Swipe 组件标记为 dd 支持

将 Swipe 组件的 "dd" 属性从 false 更改为 true,表明该组件现在支持 harmony 平台或特定功能。这与其他文件中的相关更改保持一致。

src/packages/swipe/demos/taro/demo9.tsx (1)

17-23: 样式增强: 确保按钮文本不换行

为文本组件添加了 whiteSpace: 'nowrap' 样式,与 button.scss 中的全局样式变更保持一致,确保按钮文字在任何情况下都保持单行显示。

src/utils/get-rect-by-taro.ts (2)

26-29: API 增强: 添加 harmonyId 参数

函数签名更新,增加了 harmonyId 可选参数,增强了函数的灵活性,允许通过外部传入标识符来选择元素。这种改进使函数更适合在 harmony 平台上使用。


37-37: 逻辑优化: 灵活的元素选择

使用 harmonyId || element.uid 表达式进行元素选择,优先使用传入的标识符,提高了函数的适应性和平台兼容性。

src/packages/swipe/swipe.scss (3)

23-25: 注释掉了Flex布局属性,确保与新的定位策略一致

这些注释掉的Flex属性表明组件正在从Flex布局转向使用transform定位方式来实现滑动效果。这种变化使得组件更加符合移动端和跨平台(特别是Harmony OS)的交互需求。


30-30: 为左侧元素添加了初始位置的transform

添加transform: translate(-100%, 0px)确保左侧滑动元素在初始状态下位于可视区域外部,实现了更自然的滑入效果。这种方法比使用定位属性更适合动画过渡。


34-36: 优化了右侧元素的定位方式

left: 100%改为使用right: 0pxtransform: translate(100%, 0px)的组合提高了定位精确性,确保右侧元素在初始状态下正确隐藏,并且在滑动时有一致的动画效果。这种实现方式更符合Swipe组件在各平台上的一致性需求。

src/packages/swipe/swipe.taro.tsx (6)

11-18: 引入了Taro生命周期钩子和UUID生成功能

添加了useReady钩子和useUuid函数,显著提升了组件在Taro环境中的初始化可靠性。useReady确保组件在完全准备好后再进行DOM操作,而useUuid提供唯一标识符以解决多实例场景下的元素选择问题。这些改进对Harmony OS兼容性至关重要。


80-82: 实现唯一标识符生成逻辑

使用useUuid()生成唯一ID并为左右滑动元素创建特定标识符,解决了多个Swipe组件同时存在时的DOM查询冲突问题。这种实现方式优雅且有效。


85-98: 使用useReady替代useEffect提高组件初始化可靠性

将元素宽度获取逻辑从useEffect移至useReady钩子中执行,确保了在Taro环境(特别是小程序和Harmony OS)中组件DOM完全准备就绪后再进行尺寸计算。这解决了之前可能存在的尺寸获取不准确的问题。


132-132: 优化transform样式表达式

移除了条件判断!harmony() ? 'px' : '',简化了样式生成逻辑,确保在所有平台上使用一致的像素单位。这种变更提高了代码可读性和维护性。


135-144: 增强了触摸事件中的元素尺寸获取逻辑

onTouchStart函数中集成了唯一ID参数,确保通过getRectByTaro函数精确获取正确元素的尺寸。这解决了可能存在的元素选择错误问题,提高了滑动交互的准确性。


235-235: 为滑动操作元素添加唯一ID属性

为左右操作区域添加了基于UUID的唯一ID属性,确保getRectByTaro可以准确定位到正确的DOM元素。这是整个改进方案中的关键一环,解决了在Harmony OS等环境中元素查询不准确的问题。

Copy link
Collaborator

@xiaoyatong xiaoyatong left a comment

Choose a reason for hiding this comment

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

swipe 打开按钮那个有点问题,其他ok,可先合并。

@@ -20,6 +20,7 @@
font-weight: $font-weight;
text-align: center;
cursor: pointer;
white-space: nowrap;
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个不建议处理,要保留可换行,特别是处理多语言时折行会较多。

@oasis-cloud oasis-cloud requested a review from xiaoyatong March 4, 2025 11:08
# Conflicts:
#	src/config.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Target branch 3.x action:review This PR needs more reviews (less than 2 approvals) size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants