Skip to content

Commit

Permalink
fix(mobile): scroll optimization (toeverything#8362)
Browse files Browse the repository at this point in the history
close AF-1421, AF-1418, AF-1423, AF-1358
  • Loading branch information
CatsJuice committed Sep 24, 2024
1 parent e02d450 commit 9eae3de
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 43 deletions.
4 changes: 4 additions & 0 deletions packages/frontend/component/src/hooks/use-theme-color-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ export const useThemeColorMeta = (color: string) => {
const meta = getMeta();
const old = meta.content;
meta.content = color;
// also modify document background (for over scroll bounce effect)
const oldBg = document.documentElement.style.backgroundColor;
document.documentElement.style.backgroundColor = color;

return () => {
meta.content = old;
document.documentElement.style.backgroundColor = oldBg;
};
}, [color]);
};
Expand Down
4 changes: 3 additions & 1 deletion packages/frontend/component/src/ui/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
data-disabled={disabled || undefined}
data-size={size}
data-variant={variant}
data-no-hover={withoutHover || undefined}
data-no-hover={
withoutHover || BUILD_CONFIG.isMobileEdition || undefined
}
data-mobile={BUILD_CONFIG.isMobileEdition}
onClick={handleClick}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ export function useNavigateHelper() {
);

const openPage = useCallback(
(workspaceId: string, pageId: string) => {
return jumpToPage(workspaceId, pageId);
(workspaceId: string, pageId: string, logic?: RouteLogic) => {
return jumpToPage(workspaceId, pageId, logic);
},
[jumpToPage]
);
Expand Down
7 changes: 5 additions & 2 deletions packages/frontend/core/src/desktop/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import {
import { type LoaderFunction, useSearchParams } from 'react-router-dom';

import { AppFallback } from '../../components/affine/app-container';
import { useNavigateHelper } from '../../components/hooks/use-navigate-helper';
import {
RouteLogic,
useNavigateHelper,
} from '../../components/hooks/use-navigate-helper';
import { WorkspaceNavigator } from '../../components/workspace-selector';
import { AuthService } from '../../modules/cloud';
import {
Expand Down Expand Up @@ -102,7 +105,7 @@ export const Component = ({
const lastId = localStorage.getItem('last_workspace_id');

const openWorkspace = list.find(w => w.id === lastId) ?? list[0];
openPage(openWorkspace.id, defaultIndexRoute);
openPage(openWorkspace.id, defaultIndexRoute, RouteLogic.REPLACE);
}
}, [
createCloudWorkspace,
Expand Down
75 changes: 42 additions & 33 deletions packages/frontend/core/src/mobile/components/page-header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,41 +65,50 @@ export const PageHeader = forwardRef<HTMLDivElement, PageHeaderProps>(
}, [backAction]);

return (
<SafeArea
top
ref={ref}
className={clsx(styles.root, className)}
data-testid="mobile-page-header"
{...attrs}
>
<header className={styles.inner}>
<section
className={clsx(styles.prefix, prefixClassName)}
style={prefixStyle}
>
{back ? (
<IconButton
size={24}
style={{ padding: 10 }}
onClick={handleRouteBack}
icon={<ArrowLeftSmallIcon />}
/>
) : null}
{prefix}
</section>
<>
<SafeArea
top
ref={ref}
className={clsx(styles.root, className)}
data-testid="mobile-page-header"
{...attrs}
>
<header className={styles.inner}>
<section
className={clsx(styles.prefix, prefixClassName)}
style={prefixStyle}
>
{back ? (
<IconButton
size={24}
style={{ padding: 10 }}
onClick={handleRouteBack}
icon={<ArrowLeftSmallIcon />}
/>
) : null}
{prefix}
</section>

<section className={clsx(styles.content, { center: centerContent })}>
{children}
</section>
<section
className={clsx(styles.content, { center: centerContent })}
>
{children}
</section>

<section
className={clsx(styles.suffix, suffixClassName)}
style={suffixStyle}
>
{suffix}
</section>
</header>
</SafeArea>
<section
className={clsx(styles.suffix, suffixClassName)}
style={suffixStyle}
>
{suffix}
</section>
</header>
</SafeArea>

{/* Spacer */}
<SafeArea top>
<div className={styles.headerSpacer} />
</SafeArea>
</>
);
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import { style } from '@vanilla-extract/css';

export const root = style({
width: '100%',
position: 'sticky',
position: 'fixed',
top: 0,
zIndex: 1,
backgroundColor: cssVarV2('layer/background/secondary'),
});
export const headerSpacer = style({
height: 44,
});
export const inner = style({
minHeight: 44,
height: 44,
padding: '0 6px',
display: 'flex',
alignItems: 'center',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { cssVarV2 } from '@toeverything/theme/v2';
import { style } from '@vanilla-extract/css';

export const root = style({
maxHeight: 'calc(100dvh - 100px)',
maxHeight:
'calc(100dvh - 100px - env(safe-area-inset-bottom) - env(safe-area-inset-top))',
display: 'flex',
flexDirection: 'column',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ export const SelectorMenu = ({ onClose }: { onClose?: () => void }) => {
title="Cloud Sync"
list={cloudWorkspaces}
/>
<div className={styles.divider} />
{cloudWorkspaces.length && localWorkspaces.length ? (
<div className={styles.divider} />
) : null}
<WorkspaceList
onClose={onClose}
title="Local Storage"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const root = style({

export const header = style({
background: cssVarV2('layer/background/primary'),
position: 'sticky',
position: 'fixed',
top: 0,
zIndex: 1,
});
Expand Down
2 changes: 2 additions & 0 deletions packages/frontend/core/src/mobile/styles/mobile.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ globalStyle(':root', {
globalStyle('body', {
height: 'auto',
minHeight: '100dvh',
overflowY: 'unset',
});
globalStyle('body:has(#app-tabs)', {
paddingBottom: globalVars.appTabHeight,
});
globalStyle('html', {
height: '100dvh',
overflowY: 'auto',
background: cssVarV2('layer/background/secondary'),
});
Expand Down

0 comments on commit 9eae3de

Please sign in to comment.