-
Notifications
You must be signed in to change notification settings - Fork 269
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(drag): add the ability to support onDrag, onDragStart, onDragEnd callbacks #2418
Conversation
Walkthrough在此次更改中,主要为拖拽组件新增了事件处理程序: Changes
Poem
Recent review detailsConfiguration used: CodeRabbit UI Files selected for processing (2)
Files skipped from review as they are similar to previous changes (2)
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## next #2418 +/- ##
==========================================
+ Coverage 85.98% 86.01% +0.02%
==========================================
Files 217 217
Lines 22833 22855 +22
Branches 2542 2545 +3
==========================================
+ Hits 19633 19658 +25
+ Misses 3195 3192 -3
Partials 5 5 ☔ View full report in Codecov by Sentry. |
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: 4
src/packages/drag/drag.tsx
Outdated
onDragStart && first && onDragStart() | ||
onDrag && onDrag({ offset: [x, y] }) | ||
onDragEnd && last && onDragEnd({ offset: [x, y] }) |
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.
优化可选链使用
在调用 onDragStart
, onDrag
, 和 onDragEnd
时,建议使用可选链操作符以确保安全调用。
- onDragStart && first && onDragStart()
- onDrag && onDrag({ offset: [x, y] })
- onDragEnd && last && onDragEnd({ offset: [x, y] })
+ first && onDragStart?.()
+ onDrag?.({ offset: [x, y] })
+ last && onDragEnd?.({ offset: [x, y] })
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
onDragStart && first && onDragStart() | |
onDrag && onDrag({ offset: [x, y] }) | |
onDragEnd && last && onDragEnd({ offset: [x, y] }) | |
first && onDragStart?.() | |
onDrag?.({ offset: [x, y] }) | |
last && onDragEnd?.({ offset: [x, y] }) |
Tools
Biome
[error] 90-90: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
src/packages/drag/drag.taro.tsx
Outdated
onDragStart && onDragStart() | ||
const touches = e.touches[0] | ||
axisCache.current = { x: touches.clientX, y: touches.clientY } |
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.
优化可选链使用
在调用 onDragStart
, onDrag
, 和 onDragEnd
时,建议使用可选链操作符以确保安全调用。
- onDragStart && onDragStart()
+ onDragStart?.()
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
onDragStart && onDragStart() | |
const touches = e.touches[0] | |
axisCache.current = { x: touches.clientX, y: touches.clientY } | |
onDragStart?.() | |
const touches = e.touches[0] | |
axisCache.current = { x: touches.clientX, y: touches.clientY } |
Tools
Biome
[error] 89-89: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
src/packages/drag/drag.taro.tsx
Outdated
onDrag && | ||
onDrag({ | ||
offset: [translateX.current, translateY.current], | ||
}) |
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.
优化可选链使用
在调用 onDrag
时,建议使用可选链操作符以确保安全调用。
- onDrag &&
- onDrag({
- offset: [translateX.current, translateY.current],
- })
+ onDrag?.({
+ offset: [translateX.current, translateY.current],
+ })
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
onDrag && | |
onDrag({ | |
offset: [translateX.current, translateY.current], | |
}) | |
onDrag?.({ | |
offset: [translateX.current, translateY.current], | |
}) |
Tools
Biome
[error] 102-105: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
src/packages/drag/drag.taro.tsx
Outdated
onDragEnd && | ||
onDragEnd({ | ||
offset: [translateX.current, translateY.current], | ||
}) | ||
if (direction !== 'y' && attract && dragRef.current) { |
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.
优化可选链使用
在调用 onDragEnd
时,建议使用可选链操作符以确保安全调用。
- onDragEnd &&
- onDragEnd({
- offset: [translateX.current, translateY.current],
- })
+ onDragEnd?.({
+ offset: [translateX.current, translateY.current],
+ })
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
onDragEnd && | |
onDragEnd({ | |
offset: [translateX.current, translateY.current], | |
}) | |
if (direction !== 'y' && attract && dragRef.current) { | |
onDragEnd?.({ | |
offset: [translateX.current, translateY.current], | |
}) | |
if (direction !== 'y' && attract && dragRef.current) { |
Tools
Biome
[error] 127-131: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
新增支持onDrag,onDragStart,onDragEnd回调函数的能力
Summary by CodeRabbit
Drag
组件添加了拖拽事件处理功能,包括onDragStart
、onDrag
和onDragEnd
。