-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat(swipe-action): 优化滑动操作组件 #7051
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: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,6 +97,15 @@ export const SwipeAction = forwardRef<SwipeActionRef, SwipeActionProps>( | |
| draggingRef.current = false | ||
| } | ||
|
|
||
| function open(side: SideType) { | ||
| if (side === 'right') { | ||
| api.start({ x: -getRightWidth() }) | ||
| } else { | ||
| api.start({ x: getLeftWidth() }) | ||
| } | ||
| p.onActionsReveal?.(side) | ||
| } | ||
|
|
||
| const bind = useDrag( | ||
| state => { | ||
| dragCancelRef.current = state.cancel | ||
|
|
@@ -161,34 +170,32 @@ export const SwipeAction = forwardRef<SwipeActionRef, SwipeActionProps>( | |
|
|
||
| useImperativeHandle(ref, () => ({ | ||
| show: (side: SideType = 'right') => { | ||
| if (side === 'right') { | ||
| api.start({ | ||
| x: -getRightWidth(), | ||
| }) | ||
| } else if (side === 'left') { | ||
| api.start({ | ||
| x: getLeftWidth(), | ||
| }) | ||
| } | ||
| p.onActionsReveal?.(side) | ||
| open(side) | ||
| }, | ||
| close, | ||
| })) | ||
|
|
||
| useEffect(() => { | ||
| if (!props.closeOnTouchOutside) return | ||
| function handle(e: Event) { | ||
| if (x.get() === 0) { | ||
| return | ||
| const root = rootRef.current | ||
| if (!root) return | ||
| function onTouchOutside(e: Event) { | ||
| if (x.get() === 0) return | ||
| if (!root.contains(e.target as Node)) { | ||
| close() | ||
| } | ||
| const root = rootRef.current | ||
| if (root && !root.contains(e.target as Node)) { | ||
| } | ||
| function onFocusOutside(e: FocusEvent) { | ||
| if (x.get() === 0) return | ||
| if (!root.contains(e.relatedTarget as Node)) { | ||
| close() | ||
| } | ||
| } | ||
| document.addEventListener('touchstart', handle) | ||
| document.addEventListener('touchstart', onTouchOutside) | ||
| root.addEventListener('focusout', onFocusOutside) | ||
| return () => { | ||
| document.removeEventListener('touchstart', handle) | ||
| document.removeEventListener('touchstart', onTouchOutside) | ||
| root.removeEventListener('focusout', onFocusOutside) | ||
| } | ||
| }, [props.closeOnTouchOutside]) | ||
|
Comment on lines
178
to
200
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
|
|
@@ -233,6 +240,9 @@ export const SwipeAction = forwardRef<SwipeActionRef, SwipeActionProps>( | |
| <div | ||
| className={`${classPrefix}-actions ${classPrefix}-actions-left`} | ||
| ref={leftRef} | ||
| onFocus={() => { | ||
| if (x.get() !== getLeftWidth()) open('left') | ||
| }} | ||
|
Comment on lines
+243
to
+245
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| > | ||
| {props.leftActions.map(renderAction)} | ||
| </div> | ||
|
|
@@ -262,6 +272,9 @@ export const SwipeAction = forwardRef<SwipeActionRef, SwipeActionProps>( | |
| <div | ||
| className={`${classPrefix}-actions ${classPrefix}-actions-right`} | ||
| ref={rightRef} | ||
| onFocus={() => { | ||
| if (x.get() !== -getRightWidth()) open('right') | ||
| }} | ||
|
Comment on lines
+275
to
+277
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| > | ||
| {props.rightActions.map(renderAction)} | ||
| </div> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.