Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reader width #567

Merged
merged 8 commits into from
Jan 26, 2024
14 changes: 9 additions & 5 deletions src/components/navbar/ReaderNavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ import { useTranslation } from 'react-i18next';
import { AllowedMetadataValueTypes, ChapterOffset, IReaderSettings, TChapter, TManga } from '@/typings';
import { ReaderSettingsOptions } from '@/components/reader/ReaderSettingsOptions';

const Root = styled('div')(({ theme }) => ({
const Root = styled('div')({
zIndex: 10,
});

const NavContainer = styled('div')(({ theme }) => ({
top: 0,
left: 0,
width: '300px',
Expand Down Expand Up @@ -198,9 +202,9 @@ export function ReaderNavBar(props: IProps) {
};

return (
<>
<Root>
<Slide direction="right" in={drawerOpen} timeout={200} appear={false} mountOnEnter unmountOnExit>
<Root
<NavContainer
sx={{
position: 'fixed',
}}
Expand Down Expand Up @@ -374,7 +378,7 @@ export function ReaderNavBar(props: IProps) {
</Tooltip>
</ChapterNavigation>
</Navigation>
</Root>
</NavContainer>
</Slide>
<Zoom in={!drawerOpen}>
<Fade in={!hideOpenButton}>
Expand All @@ -392,6 +396,6 @@ export function ReaderNavBar(props: IProps) {
</Tooltip>
</Fade>
</Zoom>
</>
</Root>
);
}
38 changes: 13 additions & 25 deletions src/components/reader/DoublePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,11 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

import { CSSProperties, forwardRef, useRef } from 'react';
import { forwardRef, useRef } from 'react';
import { Box, SxProps, Theme } from '@mui/material';
import { IReaderSettings } from '@/typings';
import { SpinnerImage } from '@/components/util/SpinnerImage';

const imgStyles: CSSProperties = {
display: 'block',
marginBottom: 0,
width: 'auto',
minHeight: '99vh',
height: 'auto',
maxHeight: '99vh',
objectFit: 'contain',
};

const spinnerStyle: SxProps<Theme> = {
...imgStyles,
width: 'calc((100vw - 300px) * 0.5)',
backgroundColor: '#525252',
};
import { imageStyle } from '@/components/reader/Page';

interface IProps {
index: number;
Expand All @@ -39,18 +24,22 @@ export const DoublePage = forwardRef((props: IProps, ref: any) => {
const { image1src, image2src, index, onImageLoad, settings } = props;

const imgRef = useRef<HTMLImageElement>(null);
const imgStyle = imageStyle(settings);

const spinnerStyle: SxProps<Theme> = {
...imgStyle,
height: '100vh',
width: '70vw',
backgroundColor: '#525252',
};

return (
<Box
ref={ref}
sx={{
display: 'flex',
flexDirection: settings.readerType === 'DoubleLTR' ? 'row' : 'row-reverse',
justifyContent: 'center',
margin: '0 auto',
width: 'auto',
height: 'auto',
overflowX: 'scroll',
flexGrow: 1,
}}
>
<SpinnerImage
Expand All @@ -59,7 +48,7 @@ export const DoublePage = forwardRef((props: IProps, ref: any) => {
alt={`Page #${index}`}
imgRef={imgRef}
spinnerStyle={spinnerStyle}
imgStyle={imgStyles}
imgStyle={imgStyle}
/>
<SpinnerImage
src={image2src}
Expand All @@ -68,10 +57,9 @@ export const DoublePage = forwardRef((props: IProps, ref: any) => {
imgRef={imgRef}
spinnerStyle={{
...spinnerStyle,
width: 'calc((100vw - 300px - 5px) * 0.5)',
marginLeft: '5px',
}}
imgStyle={imgStyles}
imgStyle={imgStyle}
/>
</Box>
);
Expand Down
21 changes: 10 additions & 11 deletions src/components/reader/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import Box from '@mui/material/Box';
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,
Expand All @@ -32,11 +32,12 @@ 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',
chancez marked this conversation as resolved.
Show resolved Hide resolved
marginRight: '7px',
marginLeft: isHorizontal ? '7px' : 0,
marginRight: isHorizontal ? '7px' : 0,
width: 'auto',
minHeight: '99vh',
height: 'auto',
Expand All @@ -46,13 +47,11 @@ function imageStyle(settings: IReaderSettings): any {
}

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',
};
}

Expand All @@ -71,7 +70,7 @@ export const Page = forwardRef((props: IProps, ref: any) => {
const imgStyle = imageStyle(settings);

return (
<Box ref={ref} sx={{ margin: 'auto' }}>
<Box ref={ref} sx={{ display: 'flex', justifyContent: 'center' }}>
<SpinnerImage
src={src}
onImageLoad={onImageLoad}
Expand Down
4 changes: 2 additions & 2 deletions src/components/reader/ReaderSettingsOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import MenuItem from '@mui/material/MenuItem';
import { useTranslation } from 'react-i18next';
import { AllowedMetadataValueTypes, IReaderSettings } from '@/typings';
import { NumberSetting } from '@/components/settings/NumberSetting.tsx';
import { isFillsPageReaderType } from '@/components/reader/Page.tsx';
import { isHorizontalReaderType } from '@/components/reader/Page.tsx';

interface IProps extends IReaderSettings {
setSettingValue: (key: keyof IReaderSettings, value: AllowedMetadataValueTypes) => void;
Expand All @@ -30,7 +30,7 @@ export function ReaderSettingsOptions({
readerWidth,
}: IProps) {
const { t } = useTranslation();
const fitPageToWindowEligible = !isFillsPageReaderType(readerType);
const fitPageToWindowEligible = !isHorizontalReaderType(readerType);
return (
<List>
<ListItem>
Expand Down
1 change: 0 additions & 1 deletion src/components/reader/pager/DoublePagedPager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ export function DoublePagedPager(props: IReaderProps) {
margin: '0 auto',
width: 'auto',
height: 'auto',
overflowX: 'scroll',
}}
>
{getPagesToDisplay() === 2 ? (
Expand Down
6 changes: 3 additions & 3 deletions src/components/reader/pager/PagedPager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ export function PagedPager(props: IReaderProps) {
ref={selfRef}
sx={{
display: 'flex',
flexDirection: 'row',
flexDirection: 'column',
justifyContent: 'center',
margin: '0 auto',
width: '100%',
height: '100vh',
width: 'auto',
height: 'auto',
}}
onClick={clickControl}
>
Expand Down
3 changes: 2 additions & 1 deletion src/components/reader/pager/VerticalPager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ export function VerticalPager(props: IReaderProps) {
flexDirection: 'column',
justifyContent: 'center',
margin: '0 auto',
width: '100%',
width: 'auto',
height: 'auto',
userSelect: 'none',
}}
onClick={(e) => {
Expand Down
2 changes: 1 addition & 1 deletion src/util/readerSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const getDefaultSettings = (): IReaderSettings => ({
showPageNumber: true,
loadNextOnEnding: false,
skipDupChapters: true,
fitPageToWindow: false,
fitPageToWindow: true,
readerType: 'ContinuesVertical',
offsetFirstPage: false,
readerWidth: 100,
Expand Down
Loading