fix(mobile): explorer node touch optimization (#8101)

close AF-1338
This commit is contained in:
CatsJuice
2024-09-05 02:18:28 +00:00
parent 416faba2bc
commit 06552a1120
5 changed files with 40 additions and 37 deletions

View File

@@ -73,10 +73,7 @@ export const mobileRoot = style([
padding: '0 16px',
selectors: {
'&[data-collapsible="true"]:hover': {
backgroundColor: 'transparent',
},
'&[data-collapsible="true"]:active': {
backgroundColor: cssVarV2('layer/background/hoverOverlay'),
backgroundColor: 'none',
},
},
},

View File

@@ -53,9 +53,11 @@ export const CategoryDivider = forwardRef(
/>
) : null}
</div>
<div className={styles.actions} onClick={e => e.stopPropagation()}>
{children}
</div>
{mobile ? null : (
<div className={styles.actions} onClick={e => e.stopPropagation()}>
{children}
</div>
)}
</div>
);
}

View File

@@ -78,7 +78,7 @@ export const CollapsibleSection = ({
ref={headerRef}
className={clsx(header, headerClassName)}
>
{mobile ? null : actions}
{actions}
</CategoryDivider>
<Collapsible.Content
data-testid="collapsible-section-content"

View File

@@ -189,7 +189,7 @@ export const mobileItemRoot = style([
gap: 12,
selectors: {
'&:hover': {
background: 'transparent',
background: 'none',
},
'&:active': {
background: cssVar('hoverColor'),

View File

@@ -138,19 +138,21 @@ export const ExplorerTreeNode = ({
AffineDNDData & { draggable: { __cid: string } }
>(
() => ({
canDrag: () => !mobile,
data: { ...dndData?.draggable, __cid: cid },
dragPreviewPosition: 'pointer-outside',
}),
[cid, dndData]
[cid, dndData, mobile]
);
const handleCanDrop = useMemo<DropTargetOptions<AffineDNDData>['canDrop']>(
() => args => {
if (mobile) return false;
if (!reorderable && args.treeInstruction?.type !== 'make-child') {
return false;
}
return (typeof canDrop === 'function' ? canDrop(args) : canDrop) ?? true;
},
[canDrop, reorderable]
[canDrop, mobile, reorderable]
);
const {
dropTargetRef,
@@ -347,33 +349,35 @@ export const ExplorerTreeNode = ({
</div>
{postfix}
<div
className={styles.postfix}
onClick={e => {
// prevent jump to page
e.stopPropagation();
e.preventDefault();
}}
>
{inlineOperations.map(({ view }, index) => (
<Fragment key={index}>{view}</Fragment>
))}
{menuOperations.length > 0 && (
<Menu
items={menuOperations.map(({ view }, index) => (
<Fragment key={index}>{view}</Fragment>
))}
>
<IconButton
size="16"
data-testid="explorer-tree-node-operation-button"
style={{ marginLeft: 4 }}
{mobile ? null : (
<div
className={styles.postfix}
onClick={e => {
// prevent jump to page
e.stopPropagation();
e.preventDefault();
}}
>
{inlineOperations.map(({ view }, index) => (
<Fragment key={index}>{view}</Fragment>
))}
{menuOperations.length > 0 && (
<Menu
items={menuOperations.map(({ view }, index) => (
<Fragment key={index}>{view}</Fragment>
))}
>
<MoreHorizontalIcon />
</IconButton>
</Menu>
)}
</div>
<IconButton
size="16"
data-testid="explorer-tree-node-operation-button"
style={{ marginLeft: 4 }}
>
<MoreHorizontalIcon />
</IconButton>
</Menu>
)}
</div>
)}
</div>
{renameable && (