Skip to content

Commit

Permalink
ench: improve mobile support;
Browse files Browse the repository at this point in the history
  • Loading branch information
twiddli committed Apr 4, 2023
1 parent 1fc74bc commit a0cc52f
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions packages/client/components/reader/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useFullscreen, useUnmount } from 'react-use';

import Scroller from '@twiddly/scroller';

import { useBreakpoints } from '../../client/hooks/ui';
import {
useBodyEvent,
useEffectAction,
Expand All @@ -30,6 +31,8 @@ export class CanvasState {
isPanning = false;
isFullscreen = false;
isTabActive = true;
isMobile = false;
isTablet = false;

isAutoNavigating = false;

Expand Down Expand Up @@ -339,8 +342,12 @@ export class CanvasState {

const { dimensions } = this.adjustments;

const { width, height, contentWidth, contentHeight } =
this._scroller.getDimensions();
const {
width,
height,
contentWidth,
contentHeight,
} = this._scroller.getDimensions();

return (
width !== dimensions.width ||
Expand Down Expand Up @@ -589,8 +596,9 @@ export class CanvasState {
if (diffX < delta && diffY < delta) {
const childNumber = this.currentChild;

const deadSpaceX = container.clientWidth * 0.1;
const deadSpaceY = container.clientHeight * 0.1;
const deadFactor = this.isMobile ? 0.01 : 0.1;
const deadSpaceX = container.clientWidth * deadFactor;
const deadSpaceY = container.clientHeight * deadFactor;

console.debug({
deadSpaceX,
Expand Down Expand Up @@ -727,6 +735,13 @@ const Canvas = observer(function Canvas({
state.onEndReachedCallback = onEndReached;
}, [onEndReached, state]);

const { isMobileMax, isTablet } = useBreakpoints();

useEffectAction(() => {
state.isMobile = isMobileMax;
state.isTablet = isTablet;
}, [isMobileMax, isTablet]);

useRefEvent(
state.containerRef,
'wheel',
Expand Down Expand Up @@ -814,17 +829,15 @@ const Canvas = observer(function Canvas({
state.onMouseDown(e.nativeEvent);
},
[state]
)}
>
)}>
<div className="top-content text-center">{!!label && label}</div>

<div
ref={state.contentRef}
className={classNames(
'user-select-none reader-content no-scrollbar',
'column'
)}
>
)}>
{children}
</div>
</div>
Expand Down

0 comments on commit a0cc52f

Please sign in to comment.