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: 解决移动端下,树形结构展开、收起交互失效的问题。 #3005

Closed
wants to merge 2 commits into from
Closed
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
38 changes: 29 additions & 9 deletions packages/s2-core/src/cell/corner-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
getResizeAreaAttrs,
shouldAddResizeArea,
} from '../utils/interaction/resize';
import { isMobile } from '../utils/is-mobile';
import { HeaderCell } from './header-cell';

export class CornerCell extends HeaderCell<CornerHeaderConfig> {
Expand Down Expand Up @@ -55,6 +56,11 @@ export class CornerCell extends HeaderCell<CornerHeaderConfig> {
this.update();
}

private onTreeIconClick(isCollapsed: boolean) {
this.spreadsheet.facet.resetScrollY();
this.spreadsheet.emit(S2Event.ROW_CELL_ALL_COLLAPSED__PRIVATE, isCollapsed);
}

/**
* 绘制折叠展开的 icon
*/
Expand All @@ -73,23 +79,37 @@ export class CornerCell extends HeaderCell<CornerHeaderConfig> {
values(collapseFields!).filter(Boolean).length === rootRowNodes.length ||
rootRowNodes.every((node) => node.isCollapsed);
const isCollapsed = isAllCollapsed;
let offsetXY = 0;
let offsetWH = 0;

// 移动端的时候,将icon变化,从而增加触发交互的面积
if (isMobile()) {
offsetXY = size / 4;
offsetWH = size / 2!;
}

this.treeIcon = renderTreeIcon({
group: this,
iconCfg: {
x: area.x,
y: this.getIconPosition().y,
width: size,
height: size,
x: area.x - offsetXY,
y: this.getIconPosition().y - offsetXY,
width: size + offsetWH,
height: size + offsetWH,
fill,
},
isCollapsed,
onClick: () => {
this.spreadsheet.facet.resetScrollY();
this.spreadsheet.emit(
S2Event.ROW_CELL_ALL_COLLAPSED__PRIVATE,
isCollapsed,
);
if (isMobile()) {
return;
}

this.onTreeIconClick(isCollapsed);
},
onTouchEnd: () => {
/**
* 移动端时,绑定展开、收起事件
*/
this.onTreeIconClick(isCollapsed);
},
});
}
Expand Down
38 changes: 29 additions & 9 deletions packages/s2-core/src/cell/row-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,28 +155,48 @@ export class RowCell extends HeaderCell<RowHeaderConfig> {

const iconX = x + contentIndent;
const iconY = this.getIconPosition().y;
let offsetXY = 0;
let offsetWH = 0;

// 移动端的时候,将icon变化,从而增加触发交互的面积
if (isMobile()) {
offsetXY = size / 4;
offsetWH = size / 2!;
}

this.treeIcon = renderTreeIcon({
group: this,
iconCfg: {
x: iconX,
y: iconY,
width: size!,
height: size!,
x: iconX - offsetXY,
Copy link
Member

@lijinke666 lijinke666 Dec 12, 2024

Choose a reason for hiding this comment

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

这个热区的处理建议在基类 HeaderCell 上抽一个公用方法, 和上面 corner-cell 公用

y: iconY - offsetXY,
width: size + offsetWH,
height: size + offsetWH,
fill,
},
isCollapsed,
onClick: () => {
Copy link
Member

Choose a reason for hiding this comment

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

这里不需要像 corner-cell 一样处理吗?

this.onTreeIconClick();
},
onTouchEnd: () => {
/**
* 移动端时,绑定展开、收起事件
*/
this.emitCollapseEvent();
},
});

/**
Copy link
Member

Choose a reason for hiding this comment

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

直接删掉吧, 不需要注释 L#188-L#199

* 这里不能将整个单元格作为热区
* 否则会导致emitCollapseEvent回调执行两次,
* 还会影响到绑定到整个单元格的其他事件,比如ToolTop.show
* 树形结构的展开、收起操作,在移动端下失效
*/
// 移动端, 点击热区为整个单元格
if (isMobile()) {
this.addEventListener('click', () => {
this.emitCollapseEvent();
});
}
// if (isMobile()) {
// this.addEventListener('click', () => {
// this.emitCollapseEvent();
// });
// }
}

protected drawTreeLeafNodeAlignDot() {
Expand Down
7 changes: 6 additions & 1 deletion packages/s2-core/src/utils/g-renders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ export function renderTreeIcon(options: {
isCollapsed?: boolean | null;
iconCfg: Omit<GuiIconCfg, 'name'>;
onClick?: () => void;
onTouchEnd?: () => void;
}) {
const { group, iconCfg, isCollapsed, onClick } = options;
const { group, iconCfg, isCollapsed, onClick, onTouchEnd } = options;
const iconShape = renderIcon(group, {
...iconCfg,
name: isCollapsed ? 'Plus' : 'Minus',
Expand All @@ -142,5 +143,9 @@ export function renderTreeIcon(options: {
iconShape.addEventListener('click', onClick);
}

if (isFunction(onTouchEnd)) {
iconShape.addEventListener('touchend', onTouchEnd);
}

return iconShape;
}
Loading