Fix reader width (#567)

* Fix reader width

The margin: auto on the Box container for the image was preventing 100% width
to actually mean 100%.

Now that 100% is actually possible, I think fitPageToWindow makes more
sense as a default. Additionally, since the image can fill 100% of the
page, it can cover the ReaderNavBar, so set the z-index of the
ReaderNavBar so it's rendered on top of the image and clickable.

Signed-off-by: Chance Zibolski <chance.zibolski@gmail.com>

* Support configuring reader width for DoublePage readers

Signed-off-by: Chance Zibolski <chance.zibolski@gmail.com>

* Fix single page of DoublePageReader not being able to take up full width

In case the parent container is flex row, the container does not automatically take up 100% of the available width, thus, the page also was not able to take up 100% of the width

* Fix applying reader width to double pages

The set reader width can't be applied to each page of the double pages because otherwise it will already take up 100% of the available width with the setting only being at 50%.

Instead, the set width has to be divided by 2, so that both pages take up the set reader width

* Prevent double page spinner from being larger than 100% of the available width

* Update width styling of the page spinner

* Always center pages in the middle of the screen

* Take up full height fitting page to window height

---------

Signed-off-by: Chance Zibolski <chance.zibolski@gmail.com>
Co-authored-by: schroda <50052685+schroda@users.noreply.github.com>
This commit is contained in:
Chance Zibolski
2024-01-26 11:51:08 -08:00
committed by GitHub
parent e0c5e0521d
commit 4d75474b39
10 changed files with 63 additions and 57 deletions

View File

@@ -8,13 +8,15 @@
import { useState, useEffect, forwardRef, useRef } from 'react';
import Box from '@mui/material/Box';
import { useTheme } from '@mui/material/styles';
import { useMediaQuery } from '@mui/material';
import { IReaderSettings, ReaderType } from '@/typings';
import { SpinnerImage } from '@/components/util/SpinnerImage';
export const isFillsPageReaderType = (readerType: ReaderType): boolean =>
['DoubleRTL', 'DoubleLTR', 'ContinuesHorizontalLTR', 'ContinuesHorizontalRTL'].includes(readerType);
export const isHorizontalReaderType = (readerType: ReaderType): boolean =>
['ContinuesHorizontalLTR', 'ContinuesHorizontalRTL'].includes(readerType);
function imageStyle(settings: IReaderSettings): any {
export function imageStyle(settings: IReaderSettings): any {
const [dimensions, setDimensions] = useState({
height: window.innerHeight,
width: window.innerWidth,
@@ -32,27 +34,26 @@ function imageStyle(settings: IReaderSettings): any {
window.removeEventListener('resize', handleResize);
};
}, []);
if (settings.fitPageToWindow || isFillsPageReaderType(settings.readerType)) {
const isHorizontal = isHorizontalReaderType(settings.readerType);
if (settings.fitPageToWindow || isHorizontal) {
return {
display: 'block',
marginLeft: '7px',
marginRight: '7px',
marginLeft: isHorizontal ? '7px' : 0,
marginRight: isHorizontal ? '7px' : 0,
width: 'auto',
minHeight: '99vh',
minHeight: '100vh',
height: 'auto',
maxHeight: '99vh',
maxHeight: '100vh',
objectFit: 'contain',
};
}
return {
display: 'block',
marginBottom: settings.readerType === 'ContinuesVertical' ? '15px' : 0,
minWidth: '10vw',
width: dimensions.width < dimensions.height ? '100vw' : `${settings.readerWidth}%`,
maxWidth: '100%',
marginLeft: 'auto',
marginRight: 'auto',
objectFit: 'contain',
};
}
@@ -66,12 +67,19 @@ interface IProps {
export const Page = forwardRef((props: IProps, ref: any) => {
const { src, index, onImageLoad, settings } = props;
const theme = useTheme();
const isMobileWidth = useMediaQuery(theme.breakpoints.down('md'));
const imgRef = useRef<HTMLImageElement>(null);
const imgStyle = imageStyle(settings);
const isDoublePageReader = ['DoubleRTL', 'DoubleLTR'].includes(settings.readerType);
return (
<Box ref={ref} sx={{ margin: 'auto' }}>
<Box
ref={ref}
sx={{ display: 'flex', justifyContent: 'center', minWidth: isDoublePageReader ? '100%' : undefined }}
>
<SpinnerImage
src={src}
onImageLoad={onImageLoad}
@@ -80,7 +88,7 @@ export const Page = forwardRef((props: IProps, ref: any) => {
spinnerStyle={{
...imgStyle,
height: '100vh',
width: '70vw',
width: isMobileWidth ? '100vw' : 'calc(100% * 0.5)',
backgroundColor: '#525252',
}}
imgStyle={imgStyle}