-
Notifications
You must be signed in to change notification settings - Fork 4.8k
fix(taro-components-advanced): 修复VirtualWaterfall组件设置renderTop/Bottom后onScrollToLower/Upper无法触发的问题 #17697
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
base: main
Are you sure you want to change the base?
Conversation
Walkthrough本次变更修改了 Changes
Assessment against linked issues
Poem
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. ✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 (1)
packages/taro-components-advanced/src/components/virtual-waterfall/react/wrapper.ts (1)
31-35
: 改进了渲染节点的实现方式,修复了事件触发问题这个修改解决了 PR 中描述的核心问题。通过始终返回一个包含两个元素的数组(自定义渲染组件和边界检测元素),确保了即使用户提供了自定义的 renderTop/Bottom,边界检测元素仍然存在且 ID 正确,从而使 onScrollToLower/Upper 事件能够正常触发。
这种实现方式与 virtual-list 组件类似,是一个经过验证的解决方案。
不过有一个小的代码风格建议:
- const expands = [renderExpand && React.createElement(renderExpand), React.createElement(innerElement!, props)] + const expands = [ + renderExpand ? React.createElement(renderExpand) : null, + React.createElement(innerElement!, props) + ]使用三元运算符可能会使代码更易读,并明确表示当 renderExpand 不存在时返回 null。虽然在 React 渲染中,false、null 和 undefined 都会被忽略,但使用 null 是更常见的做法。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/taro-components-advanced/src/components/virtual-waterfall/react/wrapper.ts
(1 hunks)
🔇 Additional comments (1)
packages/taro-components-advanced/src/components/virtual-waterfall/react/wrapper.ts (1)
24-30
: 样式属性现在无条件应用在修改前,style 属性可能根据 renderExpand 是否存在而有条件地应用。现在无论 renderExpand 是否存在,都会应用这个隐藏样式。这确保了边界检测元素始终保持隐藏状态。
这个 PR 做了什么?
修复了@taro-components-advanced包React版本的VirtualWaterfall组件中,当设置了renderBottom/renderTop属性时,onScrollToLower/onScrollToUpper事件无法被正确触发的问题。
这个 PR 是什么类型?
这个 PR 涉及以下平台:
错误原因
VirtualWaterfall组件当用户提供renderBottom属性时,底部的检测节点会被用户的自定义内容替代,在
getRenderExpandNodes
函数中,该节点会被创建并设置id为${sid}-${direction}
,但如果是用户自定义的组件,该组件会被Taro自动分配id,覆盖掉该id。在函数
boundaryDetectionHelper
中,通过observer监听了该id对应的节点,这导致当使用renderBottom时,无法监听到onScrollToLower事件,onScrollToUpper同理。错误验证
手动设置VirtualWaterfall组件的id,并设置renderBottom的根节点id为
${id}-bottom
。发现onScrollToLower事件能正常触发了。但onScrollToLower(我的应用里是loadMore)只能触发一次,原因如下。
observe该id的
boundaryDetectionHelper
只会在初始化的时候设置一次,自定义的renderBottom会在触发一次数据更新后卸载,需要显示时重新挂载,不传renderBottom时使用的innerElement不会被卸载。解决方案
效仿另一个组件virtual-list,如果设置了renderBottom/renderTop,函数
getRenderExpandNodes
中会同时返回默认的监听组件和自定义的组件,并保证顺序正确。Summary by CodeRabbit