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(Fab): add dragstart and dragend events #3388

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/fab/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ y-bounds | Array | - | Typescript:`Array<string \| number>` | N
name | params | description
-- | -- | --
click | `({e: Event})` | \-
drag-end | `(e: TouchEvent)` | \-
drag-start | `(e: TouchEvent)` | \-

### CSS Variables

Expand Down
2 changes: 2 additions & 0 deletions src/fab/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ y-bounds | Array | - | 设置垂直方向边界限制,示例:[48, 48] 或 ['
名称 | 参数 | 描述
-- | -- | --
click | `({e: Event})` | 悬浮按钮点击事件
drag-end | `(e: TouchEvent)` | 结束拖拽时触发
drag-start | `(e: TouchEvent)` | 开始拖拽时触发

### CSS Variables

Expand Down
3 changes: 2 additions & 1 deletion src/fab/__test__/__snapshots__/demo.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ exports[`Fab Fab draggable demo works fine 1`] = `
]
}}"
bind:click="handleClick"
bind:move="handleMove"
bind:dragend="handleDragEnd"
bind:dragstart="handleDragStart"
/>
</draggable>
`;
11 changes: 8 additions & 3 deletions src/fab/_example/draggable/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
Component({
methods: {
handleClick(e) {
console.log(e);
console.log('handleClick: ', e);
},
handleMove(e) {
console.log(e);

handleDragStart(e) {
console.log('handleDragStart: ', e);
},

handleDragEnd(e) {
console.log('handleDragEnd: ', e);
},
},
});
5 changes: 3 additions & 2 deletions src/fab/_example/draggable/index.wxml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<t-fab
icon="gesture-press"
text="拖我"
bind:click="handleClick"
bind:move="handleMove"
aria-label="增加"
usingCustomNavbar
draggable
y-bounds="{{[0, 32]}}"
bind:click="handleClick"
bind:dragstart="handleDragStart"
bind:dragend="handleDragEnd"
></t-fab>
10 changes: 10 additions & 0 deletions src/fab/fab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export default class Fab extends SuperComponent {
onTplButtonTap(e) {
this.triggerEvent('click', e);
},

onStart(e) {
this.triggerEvent('dragstart', e.detail.e);
},

onMove(e) {
const { yBounds } = this.properties;
const { distanceTop } = this.data;
Expand All @@ -64,6 +69,11 @@ export default class Fab extends SuperComponent {
moveStyle: `right: ${right}px; bottom: ${bottom}px;`,
});
},

onEnd(e) {
this.triggerEvent('dragend', e.detail.e);
},

computedSize() {
if (!this.properties.draggable) return;
const insChild = this.selectComponent('#draggable');
Expand Down
2 changes: 2 additions & 0 deletions src/fab/template/draggable.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
id="draggable"
style="right: 16px; bottom: 32px; {{_._style([style, customStyle, moveStyle])}}"
direction="{{draggable === true ? 'all' : draggable}}"
bind:start="onStart"
bind:move="onMove"
bind:end="onEnd"
>
<template is="button" data="{{...buttonData}}" />
</t-draggable>
Expand Down
Loading