fix(mobile): scroll optimization (#8362)

close AF-1421, AF-1418, AF-1423, AF-1358
This commit is contained in:
CatsJuice
2024-09-24 03:51:09 +00:00
parent e02d450e4f
commit 9eae3de1ae
10 changed files with 69 additions and 43 deletions

View File

@@ -25,9 +25,13 @@ export const useThemeColorMeta = (color: string) => {
const meta = getMeta(); const meta = getMeta();
const old = meta.content; const old = meta.content;
meta.content = color; meta.content = color;
// also modify document background (for over scroll bounce effect)
const oldBg = document.documentElement.style.backgroundColor;
document.documentElement.style.backgroundColor = color;
return () => { return () => {
meta.content = old; meta.content = old;
document.documentElement.style.backgroundColor = oldBg;
}; };
}, [color]); }, [color]);
}; };

View File

@@ -161,7 +161,9 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
data-disabled={disabled || undefined} data-disabled={disabled || undefined}
data-size={size} data-size={size}
data-variant={variant} data-variant={variant}
data-no-hover={withoutHover || undefined} data-no-hover={
withoutHover || BUILD_CONFIG.isMobileEdition || undefined
}
data-mobile={BUILD_CONFIG.isMobileEdition} data-mobile={BUILD_CONFIG.isMobileEdition}
onClick={handleClick} onClick={handleClick}
> >

View File

@@ -96,8 +96,8 @@ export function useNavigateHelper() {
); );
const openPage = useCallback( const openPage = useCallback(
(workspaceId: string, pageId: string) => { (workspaceId: string, pageId: string, logic?: RouteLogic) => {
return jumpToPage(workspaceId, pageId); return jumpToPage(workspaceId, pageId, logic);
}, },
[jumpToPage] [jumpToPage]
); );

View File

@@ -15,7 +15,10 @@ import {
import { type LoaderFunction, useSearchParams } from 'react-router-dom'; import { type LoaderFunction, useSearchParams } from 'react-router-dom';
import { AppFallback } from '../../components/affine/app-container'; 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 { WorkspaceNavigator } from '../../components/workspace-selector';
import { AuthService } from '../../modules/cloud'; import { AuthService } from '../../modules/cloud';
import { import {
@@ -102,7 +105,7 @@ export const Component = ({
const lastId = localStorage.getItem('last_workspace_id'); const lastId = localStorage.getItem('last_workspace_id');
const openWorkspace = list.find(w => w.id === lastId) ?? list[0]; const openWorkspace = list.find(w => w.id === lastId) ?? list[0];
openPage(openWorkspace.id, defaultIndexRoute); openPage(openWorkspace.id, defaultIndexRoute, RouteLogic.REPLACE);
} }
}, [ }, [
createCloudWorkspace, createCloudWorkspace,

View File

@@ -65,41 +65,50 @@ export const PageHeader = forwardRef<HTMLDivElement, PageHeaderProps>(
}, [backAction]); }, [backAction]);
return ( return (
<SafeArea <>
top <SafeArea
ref={ref} top
className={clsx(styles.root, className)} ref={ref}
data-testid="mobile-page-header" className={clsx(styles.root, className)}
{...attrs} data-testid="mobile-page-header"
> {...attrs}
<header className={styles.inner}> >
<section <header className={styles.inner}>
className={clsx(styles.prefix, prefixClassName)} <section
style={prefixStyle} className={clsx(styles.prefix, prefixClassName)}
> style={prefixStyle}
{back ? ( >
<IconButton {back ? (
size={24} <IconButton
style={{ padding: 10 }} size={24}
onClick={handleRouteBack} style={{ padding: 10 }}
icon={<ArrowLeftSmallIcon />} onClick={handleRouteBack}
/> icon={<ArrowLeftSmallIcon />}
) : null} />
{prefix} ) : null}
</section> {prefix}
</section>
<section className={clsx(styles.content, { center: centerContent })}> <section
{children} className={clsx(styles.content, { center: centerContent })}
</section> >
{children}
</section>
<section <section
className={clsx(styles.suffix, suffixClassName)} className={clsx(styles.suffix, suffixClassName)}
style={suffixStyle} style={suffixStyle}
> >
{suffix} {suffix}
</section> </section>
</header> </header>
</SafeArea> </SafeArea>
{/* Spacer */}
<SafeArea top>
<div className={styles.headerSpacer} />
</SafeArea>
</>
); );
} }
); );

View File

@@ -3,13 +3,16 @@ import { style } from '@vanilla-extract/css';
export const root = style({ export const root = style({
width: '100%', width: '100%',
position: 'sticky', position: 'fixed',
top: 0, top: 0,
zIndex: 1, zIndex: 1,
backgroundColor: cssVarV2('layer/background/secondary'), backgroundColor: cssVarV2('layer/background/secondary'),
}); });
export const headerSpacer = style({
height: 44,
});
export const inner = style({ export const inner = style({
minHeight: 44, height: 44,
padding: '0 6px', padding: '0 6px',
display: 'flex', display: 'flex',
alignItems: 'center', alignItems: 'center',

View File

@@ -3,7 +3,8 @@ import { cssVarV2 } from '@toeverything/theme/v2';
import { style } from '@vanilla-extract/css'; import { style } from '@vanilla-extract/css';
export const root = style({ export const root = style({
maxHeight: 'calc(100dvh - 100px)', maxHeight:
'calc(100dvh - 100px - env(safe-area-inset-bottom) - env(safe-area-inset-top))',
display: 'flex', display: 'flex',
flexDirection: 'column', flexDirection: 'column',
}); });

View File

@@ -116,7 +116,9 @@ export const SelectorMenu = ({ onClose }: { onClose?: () => void }) => {
title="Cloud Sync" title="Cloud Sync"
list={cloudWorkspaces} list={cloudWorkspaces}
/> />
<div className={styles.divider} /> {cloudWorkspaces.length && localWorkspaces.length ? (
<div className={styles.divider} />
) : null}
<WorkspaceList <WorkspaceList
onClose={onClose} onClose={onClose}
title="Local Storage" title="Local Storage"

View File

@@ -11,7 +11,7 @@ export const root = style({
export const header = style({ export const header = style({
background: cssVarV2('layer/background/primary'), background: cssVarV2('layer/background/primary'),
position: 'sticky', position: 'fixed',
top: 0, top: 0,
zIndex: 1, zIndex: 1,
}); });

View File

@@ -14,11 +14,13 @@ globalStyle(':root', {
globalStyle('body', { globalStyle('body', {
height: 'auto', height: 'auto',
minHeight: '100dvh', minHeight: '100dvh',
overflowY: 'unset',
}); });
globalStyle('body:has(#app-tabs)', { globalStyle('body:has(#app-tabs)', {
paddingBottom: globalVars.appTabHeight, paddingBottom: globalVars.appTabHeight,
}); });
globalStyle('html', { globalStyle('html', {
height: '100dvh',
overflowY: 'auto', overflowY: 'auto',
background: cssVarV2('layer/background/secondary'), background: cssVarV2('layer/background/secondary'),
}); });