fix(view):修复单页浏览时缩放计算布局错误的问题。
This commit is contained in:
parent
39accb3cb7
commit
a80e8eb74f
|
@ -13,12 +13,16 @@ export const ComicView: FC = () => {
|
|||
const files = useFileListStore(sortedFilesSelector());
|
||||
const viewMode = useZoomState.use.viewMode();
|
||||
const updateViewHeight = useZoomState.use.updateViewHeight();
|
||||
const [containerRef, { height }] = useMeasure();
|
||||
const updateViewWidth = useZoomState.use.updateViewWidth();
|
||||
const [containerRef, { height, width }] = useMeasure();
|
||||
const firstFileId = useMemo(() => head(files)?.id ?? '', [files, files.length]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
updateViewHeight(height);
|
||||
}, [height]);
|
||||
useLayoutEffect(() => {
|
||||
updateViewWidth(width);
|
||||
}, [width]);
|
||||
|
||||
return (
|
||||
<Box w="100%" h="100%" sx={{ overflow: 'hidden' }} ref={containerRef}>
|
||||
|
|
|
@ -10,8 +10,8 @@ import { useZoomState } from '../states/zoom';
|
|||
export const SingleView: FC = () => {
|
||||
const files = useFileListStore.use.files();
|
||||
const actives = useFileListStore.use.actives();
|
||||
const zoom = useZoomState.use.currentZoom();
|
||||
const viewHeight = useZoomState.use.viewHeight();
|
||||
const { currentZoom: zoom, viewHeight, viewWidth } = useZoomState();
|
||||
const maxImageWidth = useMemo(() => viewWidth * (zoom / 100), [viewWidth, zoom]);
|
||||
const updateActives = useFileListStore.use.updateActiveFiles();
|
||||
const ebus = useContext<EventEmitter>(EventBusContext);
|
||||
const [pageConRef, { width: pageConWidth }] = useMeasure();
|
||||
|
@ -21,9 +21,9 @@ export const SingleView: FC = () => {
|
|||
}, [files, actives]);
|
||||
const largerThanView = useMemo(() => {
|
||||
if (isNil(activeFile)) return false;
|
||||
let imageHeightAfterZoom = activeFile?.height * (zoom / 100);
|
||||
let imageHeightAfterZoom = activeFile?.height * (maxImageWidth / activeFile?.width);
|
||||
return gt(imageHeightAfterZoom, viewHeight);
|
||||
}, [activeFile, viewHeight, zoom]);
|
||||
}, [activeFile, viewHeight, maxImageWidth]);
|
||||
const handlePaginationAction = useCallback(
|
||||
(event: BaseSyntheticEvent) => {
|
||||
let middle = pageConWidth / 2;
|
||||
|
@ -62,7 +62,7 @@ export const SingleView: FC = () => {
|
|||
height: largerThanView ? '100%' : viewHeight
|
||||
}}
|
||||
>
|
||||
<img src={activeFile.path} style={{ width: `${zoom}%` }} />
|
||||
<img src={activeFile.path} style={{ width: maxImageWidth }} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
@ -6,11 +6,13 @@ interface ZoomState {
|
|||
currentZoom: number;
|
||||
viewMode: 'single' | 'continuation';
|
||||
viewHeight: number;
|
||||
viewWidth: number;
|
||||
}
|
||||
|
||||
type ZoomActions = {
|
||||
zoom: SyncObjectCallback<number>;
|
||||
updateViewHeight: SyncObjectCallback<number>;
|
||||
updateViewWidth: SyncObjectCallback<number>;
|
||||
switchViewMode: SyncObjectCallback<'single' | 'continuation'>;
|
||||
};
|
||||
|
||||
|
@ -18,7 +20,8 @@ const initialState: ZoomState = {
|
|||
autoFit: false,
|
||||
currentZoom: 80,
|
||||
viewMode: 'continuation',
|
||||
viewHeight: 0
|
||||
viewHeight: 0,
|
||||
viewWidth: 0
|
||||
};
|
||||
|
||||
export const useZoomState = createStoreHook<ZoomState & ZoomActions>(set => ({
|
||||
|
@ -33,6 +36,11 @@ export const useZoomState = createStoreHook<ZoomState & ZoomActions>(set => ({
|
|||
df.viewHeight = height;
|
||||
});
|
||||
},
|
||||
updateViewWidth(width) {
|
||||
set(df => {
|
||||
df.viewWidth = width;
|
||||
});
|
||||
},
|
||||
switchViewMode(mode) {
|
||||
set(df => {
|
||||
df.viewMode = mode;
|
||||
|
|
Loading…
Reference in New Issue
Block a user