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

fix: 修改jd小程序高版本弹幕不滚动问题 #2612

Merged
merged 2 commits into from
Sep 27, 2024

Conversation

irisSong
Copy link
Collaborator

@irisSong irisSong commented Sep 24, 2024

🤔 这个变动的性质是?

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

  • 新功能

    • Barrage 组件中新增了 interval 属性,设置为 100,指定了弹幕效果的时间间隔。
  • 改进

    • 改进了 InternalBarrage 组件的定时和动画处理,增强了代码结构和清晰度。

Copy link

coderabbitai bot commented Sep 24, 2024

Walkthrough

此次更改涉及 InternalBarrage 组件和 Demo1 组件的修改。InternalBarrage 组件引入了新的定时器管理逻辑,重构了动画处理和样式设置方法。Demo1 组件则新增了 interval 属性,以指定弹幕效果的时间间隔。这些修改改善了代码结构和功能实现。

Changes

文件路径 更改摘要
src/packages/barrage/barrage.taro.tsx 引入 domTimer 管理定时器,添加 clearDomTimeoutsetStyle 方法,重构了 runplay 函数以改善动画和样式处理。
src/packages/barrage/demos/taro/demo1.tsx Barrage 组件中新增 interval 属性,设置为 100

Suggested labels

size/XS

🐰 在代码的草地上,
新增属性如花儿绽放,
定时器跳跃,动画飞舞,
结构清晰,逻辑明亮,
兔子欢跳,庆祝更改,
代码如春,生机盎然! 🌼


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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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.

Copy link

codecov bot commented Sep 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.95%. Comparing base (33208c7) to head (e14baca).
Report is 2 commits behind head on next.

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #2612   +/-   ##
=======================================
  Coverage   82.95%   82.95%           
=======================================
  Files         219      219           
  Lines       17908    17908           
  Branches     2547     2547           
=======================================
  Hits        14856    14856           
  Misses       3047     3047           
  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: 1

Outside diff range and nitpick comments (1)
src/packages/barrage/barrage.taro.tsx (1)

138-141: 注意事件监听器的清理以防止内存泄漏

在为 el 添加 animationend 事件监听器后,没有在适当的时候移除监听器。虽然浏览器通常会在元素被移除时清理事件监听器,但为了保险起见,建议在回调函数中手动移除事件监听器,防止可能的内存泄漏。

可以在回调函数中移除事件监听器:

const onAnimationEnd = () => {
  (barrageContainer.current as HTMLDivElement).removeChild(el)
  el.removeEventListener('animationend', onAnimationEnd)
}
el.addEventListener('animationend', onAnimationEnd)
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 33208c7 and e14baca.

Files selected for processing (2)
  • src/packages/barrage/barrage.taro.tsx (4 hunks)
  • src/packages/barrage/demos/taro/demo1.tsx (1 hunks)
Additional comments not posted (1)
src/packages/barrage/demos/taro/demo1.tsx (1)

23-28: 请确认新添加的 interval 属性的影响

新增的 interval={100} 属性可能会影响弹幕的滚动速度或显示频率。请确保:

  1. 这个值(100)是经过测试和验证的,能够解决高版本弹幕不滚动的问题。
  2. 考虑添加注释说明这个属性的作用和选择这个值的原因。
  3. 更新相关文档,说明这个新属性的用途和默认值。

为了验证这个改动的影响,可以运行以下脚本:

这将帮助我们了解是否需要在其他地方也添加 interval 属性。

Verification successful

interval 属性添加已确认无其他影响

通过检查代码库,确定此次在 demo1.tsx 中新增的 interval={100} 属性仅影响该示例,不会对其他部分产生影响。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查 Barrage 组件的其他使用情况,确保改动不会影响其他地方

# 测试:搜索 Barrage 组件的其他使用实例
rg --type typescript --type tsx 'Barrage' -g '!**/demo1.tsx'

Length of output: 95


Script:

#!/bin/bash
# 描述:检查 Barrage 组件的其他使用情况,确保改动不会影响其他地方

# 测试:搜索 Barrage 组件的其他使用实例
rg --type ts --type tsx 'Barrage' -g '!**/demo1.tsx'

Length of output: 80


Script:

#!/bin/bash
# 描述:检查 Barrage 组件的其他使用情况,确保改动不会影响其他地方

# 测试:搜索 Barrage 组件的其他使用实例,排除 demo1.tsx
rg 'Barrage' -g '*.ts' -g '*.tsx' -g '!**/demo1.tsx'

Length of output: 2133

Comment on lines +119 to +141
const setStyle = async (el: HTMLElement, currentIndex: number) => {
try {
if (el) {
const refe = await getRectByTaro(el)
const width = refe.width
const height = refe.height
el.classList.add('move')
const elScrollDuration = Math.round(
(width / barrageCWidth.current) * duration
)
times.current[currentIndex] = elScrollDuration
el.style.animationDuration = `${duration + elScrollDuration}ms`
el.style.top = `${currentIndex * (height + gapY) + 20}px`
el.style.width = `${width}px`
}
} catch (error) {
console.log('异常自动流转到下一个', error)
;(barrageContainer.current as HTMLDivElement).removeChild(el)
}
el.addEventListener('animationend', () => {
;(barrageContainer.current as HTMLDivElement).removeChild(el)
})
}
Copy link

Choose a reason for hiding this comment

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

建议在 React 组件中避免直接操作 DOM

setStyle 函数中,直接对 DOM 元素进行了操作,例如使用 el.classList.add 和直接修改 el.style。在 React 中,直接操作 DOM 可能导致组件状态和界面不同步,增加维护难度。建议使用 React 的状态和属性来控制组件的渲染,或者使用 refuseEffect 相结合的方式安全地操作 DOM。

可以考虑将需要的样式和类名通过状态管理,并在渲染时使用 classNamestyle 属性进行控制,这样可以保持 React 的声明式编程风格,提高代码的可读性和可维护性。

@oasis-cloud oasis-cloud merged commit 69d3c19 into jdf2e:next Sep 27, 2024
5 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Sep 27, 2024
20 tasks
@irisSong irisSong deleted the next-barrage branch January 7, 2025 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants