Skip to content

Commit 73dd1d3

Browse files
committed
fix(mobile): fixed all docs header, remove doc card tags layout strategy (#8104)
close AF-1326
1 parent 24acce2 commit 73dd1d3

File tree

6 files changed

+53
-139
lines changed

6 files changed

+53
-139
lines changed

packages/frontend/mobile/src/components/app-tabs/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const AppTabs = () => {
5555
className={styles.tabItem}
5656
role="tab"
5757
aria-label={route.to.slice(1)}
58+
replaceHistory
5859
>
5960
<li>
6061
<route.Icon />

packages/frontend/mobile/src/components/app-tabs/styles.css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const appTabs = style({
1111
backgroundColor: cssVarV2('layer/background/secondary'),
1212
borderTop: `1px solid ${cssVarV2('layer/insideBorder/border')}`,
1313

14-
width: '100vw',
14+
width: '100dvw',
1515
height: globalVars.appTabHeight,
1616
padding: 16,
1717
gap: 15.5,

packages/frontend/mobile/src/components/doc-card/tag.css.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,12 @@ export const tags = style({
77
width: '100%',
88
display: 'flex',
99
flexWrap: 'wrap',
10-
alignItems: 'flex-start',
10+
alignItems: 'center',
1111
position: 'relative',
12-
13-
transition: 'height 0.23s',
14-
overflow: 'hidden',
12+
gap: 4,
1513
});
1614

1715
export const tag = style({
18-
visibility: 'hidden',
19-
position: 'absolute',
20-
// transition: 'all 0.23s',
21-
2216
padding: '0px 8px',
2317
borderRadius: 10,
2418
alignItems: 'center',
@@ -43,3 +37,8 @@ export const tag = style({
4337
marginRight: 4,
4438
},
4539
});
40+
41+
export const more = style({
42+
fontSize: 16,
43+
color: cssVarV2('icon/primary'),
44+
});
Lines changed: 7 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { observeResize } from '@affine/component';
21
import type { Tag } from '@affine/core/modules/tag';
32
import { TagService } from '@affine/core/modules/tag';
3+
import { MoreHorizontalIcon } from '@blocksuite/icons/rc';
44
import { useLiveData, useService } from '@toeverything/infra';
55
import { assignInlineVars } from '@vanilla-extract/dynamic';
6-
import { useCallback, useEffect, useRef } from 'react';
76

87
import * as styles from './tag.css';
98

@@ -23,121 +22,21 @@ const DocCardTag = ({ tag }: { tag: Tag }) => {
2322
);
2423
};
2524

26-
const GAP = 4;
27-
const MIN_WIDTH = 32;
28-
29-
const DocCardTagsRenderer = ({ tags, rows }: { tags: Tag[]; rows: number }) => {
30-
const ulRef = useRef<HTMLUListElement>(null);
31-
32-
// A strategy to layout tags
33-
const layoutTags = useCallback(
34-
(entry: ResizeObserverEntry) => {
35-
const availableWidth = entry.contentRect.width;
36-
const lis = Array.from(ulRef.current?.querySelectorAll('li') ?? []);
37-
38-
const tagGrid: Array<{
39-
x: number;
40-
y: number;
41-
w: number;
42-
el: HTMLLIElement;
43-
}> = [];
44-
45-
for (let i = 0; i < rows; i++) {
46-
let width = 0;
47-
let restSpace = availableWidth - width;
48-
while (restSpace >= MIN_WIDTH) {
49-
const li = lis.shift();
50-
if (!li) break;
51-
const liWidth = li.scrollWidth + 2; // 2 is for border
52-
let liDisplayWidth = Math.min(liWidth, restSpace);
53-
54-
restSpace = restSpace - liDisplayWidth - GAP;
55-
if (restSpace < MIN_WIDTH) {
56-
liDisplayWidth += restSpace;
57-
}
58-
59-
tagGrid.push({
60-
x: width,
61-
y: i * (22 + GAP),
62-
w: liDisplayWidth,
63-
el: li,
64-
});
65-
66-
width += liDisplayWidth + GAP;
67-
}
68-
}
69-
70-
const lastItem = tagGrid[tagGrid.length - 1];
71-
72-
tagGrid.forEach(({ el, x, y, w }) => {
73-
Object.assign(el.style, {
74-
width: `${w}px`,
75-
transform: `translate(${x}px, ${y}px)`,
76-
visibility: 'visible',
77-
});
78-
});
79-
80-
// hide rest
81-
lis.forEach(li =>
82-
Object.assign(li.style, {
83-
visibility: 'hidden',
84-
width: '0px',
85-
transform: `translate(0px, ${lastItem.y + 22 + GAP}px)`,
86-
})
87-
);
88-
89-
// update ul height
90-
// to avoid trigger resize immediately
91-
setTimeout(() => {
92-
if (ulRef.current) {
93-
ulRef.current.style.height = `${lastItem.y + 22}px`;
94-
}
95-
});
96-
},
97-
[rows]
98-
);
99-
100-
const prevEntryRef = useRef<ResizeObserverEntry | null>(null);
101-
useEffect(() => {
102-
tags; // make sure tags is in deps
103-
const ul = ulRef.current;
104-
if (!ul) return;
105-
106-
const dispose = observeResize(ul, entry => {
107-
if (entry.contentRect.width === prevEntryRef.current?.contentRect.width) {
108-
return;
109-
}
110-
111-
layoutTags(entry);
112-
prevEntryRef.current = entry;
113-
});
114-
return () => {
115-
dispose();
116-
prevEntryRef.current = null;
117-
};
118-
}, [layoutTags, tags]);
119-
25+
const DocCardTagsRenderer = ({ tags }: { tags: Tag[] }) => {
12026
return (
121-
<ul className={styles.tags} ref={ulRef} style={{ gap: GAP }}>
122-
{tags.map(tag => (
27+
<ul className={styles.tags}>
28+
{tags.slice(0, 2).map(tag => (
12329
<DocCardTag key={tag.id} tag={tag} />
12430
))}
125-
{/* TODO(@CatsJuice): more icon */}
126-
{/* <MoreHorizontalIcon /> */}
31+
{tags.length > 2 ? <MoreHorizontalIcon className={styles.more} /> : null}
12732
</ul>
12833
);
12934
};
13035

131-
export const DocCardTags = ({
132-
docId,
133-
rows = 2,
134-
}: {
135-
docId: string;
136-
rows?: number;
137-
}) => {
36+
export const DocCardTags = ({ docId }: { docId: string; rows?: number }) => {
13837
const tagService = useService(TagService);
13938
const tags = useLiveData(tagService.tagList.tagsByPageId$(docId));
14039

14140
if (!tags.length) return null;
142-
return <DocCardTagsRenderer tags={tags} rows={rows} />;
41+
return <DocCardTagsRenderer tags={tags} />;
14342
};
Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { IconButton, MobileMenu } from '@affine/component';
22
import { MoreHorizontalIcon } from '@blocksuite/icons/rc';
33

4-
import { header } from './style.css';
4+
import { header, headerSpace } from './style.css';
55
import { AllDocsTabs } from './tabs';
66

77
export interface AllDocsHeaderProps {
@@ -10,15 +10,18 @@ export interface AllDocsHeaderProps {
1010

1111
export const AllDocsHeader = ({ operations }: AllDocsHeaderProps) => {
1212
return (
13-
<header className={header}>
14-
<AllDocsTabs />
15-
<div>
16-
{operations ? (
17-
<MobileMenu items={operations}>
18-
<IconButton icon={<MoreHorizontalIcon />} />
19-
</MobileMenu>
20-
) : null}
21-
</div>
22-
</header>
13+
<>
14+
<header className={header}>
15+
<AllDocsTabs />
16+
<div>
17+
{operations ? (
18+
<MobileMenu items={operations}>
19+
<IconButton icon={<MoreHorizontalIcon />} />
20+
</MobileMenu>
21+
) : null}
22+
</div>
23+
</header>
24+
<div className={headerSpace} />
25+
</>
2326
);
2427
};

packages/frontend/mobile/src/views/all-docs/style.css.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
import { cssVarV2 } from '@toeverything/theme/v2';
22
import { style } from '@vanilla-extract/css';
33

4-
export const header = style({
5-
display: 'flex',
6-
alignItems: 'center',
7-
justifyContent: 'space-between',
8-
gap: 16,
9-
padding: '16px 16px 0px 16px',
4+
const headerContentHeight = 56;
5+
const headerPaddingTop = 16;
106

11-
position: 'sticky',
12-
top: 0,
13-
backgroundColor: cssVarV2('layer/background/secondary'),
14-
zIndex: 1,
7+
const basicHeader = style({
8+
width: '100%',
9+
height: headerContentHeight + headerPaddingTop,
1510
});
11+
export const header = style([
12+
basicHeader,
13+
{
14+
display: 'flex',
15+
alignItems: 'center',
16+
justifyContent: 'space-between',
17+
gap: 16,
18+
padding: `${headerPaddingTop}px 16px 0px 16px`,
19+
20+
position: 'fixed',
21+
top: 0,
22+
backgroundColor: cssVarV2('layer/background/secondary'),
23+
zIndex: 1,
24+
},
25+
]);
26+
export const headerSpace = style([basicHeader]);
27+
1628
export const tabs = style({
17-
height: 56,
29+
height: headerContentHeight,
1830
gap: 16,
1931
display: 'flex',
2032
alignItems: 'center',

0 commit comments

Comments
 (0)