2021-05-28 05:36:55 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
2023-05-18 13:17:41 +02:00
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
2021-05-28 05:36:55 -07:00
|
|
|
|
2024-01-26 11:51:08 -08:00
|
|
|
import { forwardRef, useRef } from 'react';
|
2024-01-14 18:29:51 -05:00
|
|
|
import { Box, SxProps, Theme } from '@mui/material';
|
2023-06-05 01:42:39 +02:00
|
|
|
import { IReaderSettings } from '@/typings';
|
2024-01-14 18:29:51 -05:00
|
|
|
import { SpinnerImage } from '@/components/util/SpinnerImage';
|
2024-01-26 11:51:08 -08:00
|
|
|
import { imageStyle } from '@/components/reader/Page';
|
2021-05-28 05:36:55 -07:00
|
|
|
|
|
|
|
|
interface IProps {
|
2023-02-06 10:06:33 +01:00
|
|
|
index: number;
|
|
|
|
|
image1src: string;
|
|
|
|
|
image2src: string;
|
2024-01-14 18:29:51 -05:00
|
|
|
onImageLoad?: () => void;
|
2023-02-06 10:06:33 +01:00
|
|
|
settings: IReaderSettings;
|
2021-05-28 05:36:55 -07:00
|
|
|
}
|
|
|
|
|
|
2023-10-28 00:32:02 +02:00
|
|
|
export const DoublePage = forwardRef((props: IProps, ref: any) => {
|
2024-01-14 18:29:51 -05:00
|
|
|
const { image1src, image2src, index, onImageLoad, settings } = props;
|
|
|
|
|
|
|
|
|
|
const imgRef = useRef<HTMLImageElement>(null);
|
2024-01-26 11:51:08 -08:00
|
|
|
const baseImgStyle = imageStyle(settings);
|
|
|
|
|
const imgStyle = {
|
|
|
|
|
...baseImgStyle,
|
|
|
|
|
width: settings.fitPageToWindow ? baseImgStyle.width : `calc(${baseImgStyle.width} * 0.5)`,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const spinnerStyle: SxProps<Theme> = {
|
|
|
|
|
...imgStyle,
|
|
|
|
|
height: '100vh',
|
|
|
|
|
width: '50%',
|
|
|
|
|
backgroundColor: '#525252',
|
|
|
|
|
};
|
2021-05-28 05:36:55 -07:00
|
|
|
|
|
|
|
|
return (
|
2021-12-04 10:24:16 +03:30
|
|
|
<Box
|
|
|
|
|
ref={ref}
|
|
|
|
|
sx={{
|
|
|
|
|
display: 'flex',
|
2024-02-13 01:53:10 +01:00
|
|
|
flexDirection: settings.readerType === 'DoubleLTR' ? 'row' : 'row-reverse',
|
2021-12-04 10:24:16 +03:30
|
|
|
justifyContent: 'center',
|
2024-01-26 11:51:08 -08:00
|
|
|
width: '100%',
|
2021-12-04 10:24:16 +03:30
|
|
|
}}
|
|
|
|
|
>
|
2024-01-14 18:29:51 -05:00
|
|
|
<SpinnerImage
|
|
|
|
|
src={image1src}
|
|
|
|
|
onImageLoad={onImageLoad}
|
|
|
|
|
alt={`Page #${index}`}
|
|
|
|
|
imgRef={imgRef}
|
|
|
|
|
spinnerStyle={spinnerStyle}
|
2024-01-26 11:51:08 -08:00
|
|
|
imgStyle={imgStyle}
|
2024-01-14 18:29:51 -05:00
|
|
|
/>
|
|
|
|
|
<SpinnerImage
|
|
|
|
|
src={image2src}
|
|
|
|
|
onImageLoad={onImageLoad}
|
|
|
|
|
alt={`Page #${index + 1}`}
|
|
|
|
|
imgRef={imgRef}
|
|
|
|
|
spinnerStyle={{
|
|
|
|
|
...spinnerStyle,
|
2024-01-26 11:51:08 -08:00
|
|
|
width: 'calc(50% - 5px)',
|
2024-01-14 18:29:51 -05:00
|
|
|
marginLeft: '5px',
|
|
|
|
|
}}
|
2024-01-26 11:51:08 -08:00
|
|
|
imgStyle={imgStyle}
|
2024-01-14 18:29:51 -05:00
|
|
|
/>
|
2021-12-04 10:24:16 +03:30
|
|
|
</Box>
|
2021-05-28 05:36:55 -07:00
|
|
|
);
|
|
|
|
|
});
|