diff --git a/src/components/Controller.tsx b/src/components/Controller.tsx index c072bd3..80ae279 100644 --- a/src/components/Controller.tsx +++ b/src/components/Controller.tsx @@ -159,7 +159,7 @@ const Controller = ({ onTap, children, horizontal = false }: ControllerProps) => {horizontal ? ( - + {children} ) : ( diff --git a/src/components/JMComicImage.tsx b/src/components/JMComicImage.tsx index 147fef5..7611a32 100644 --- a/src/components/JMComicImage.tsx +++ b/src/components/JMComicImage.tsx @@ -48,11 +48,11 @@ const JMComicImage = ({ uri, headers = {}, horizontal = false, onSuccess }: JMCo let prevDh: number = 0; step.forEach(({ dx, dy, sx, sy, sWidth, sHeight, dWidth, dHeight }, index) => { if (index <= 0) { - prevDy = Math.round(dy * container.scale * 1000) / 1000; + prevDy = dy * container.scale; } else { prevDy = prevDh + prevDy; } - prevDh = Math.round(dHeight * container.scale * 1000) / 1000; + prevDh = dHeight * container.scale; ctx.drawImage( image, diff --git a/src/components/Reader.tsx b/src/components/Reader.tsx index 01304c0..a6a818c 100644 --- a/src/components/Reader.tsx +++ b/src/components/Reader.tsx @@ -8,7 +8,6 @@ import Controller from '~/components/Controller'; import PageSlider, { PageSliderRef } from '~/components/PageSlider'; const windowWidth = Dimensions.get('window').width; -const windowHeight = Dimensions.get('window').height; const lastPageToastId = 'LAST_PAGE_TOAST_ID'; interface ReaderProps { @@ -35,13 +34,10 @@ const Reader = ({ const toast = useToast(); const [page, setPage] = useState(initPage); const [showExtra, setShowExtra] = useState(false); - const layout = useRef( - data.map((_, index) => ({ length: windowHeight, offset: index * windowHeight, index })) - ); const timeout = useRef(null); const flatListRef = useRef(null); const pageSliderRef = useRef(null); - const initialScrollIndex = Math.max(Math.min(initPage - 1, data.length - 1), 0); + const initialScrollIndex = Math.max(Math.min(page - 1, data.length - 1), 0); const toastRef = useRef(toast); const dataRef = useRef(data); toastRef.current = toast; @@ -75,31 +71,16 @@ const Reader = ({ }, 200); }, []); const renderVerticalItem = useCallback( - ({ item, index }: ListRenderItemInfo) => { + ({ item }: ListRenderItemInfo) => { const { uri, needUnscramble } = item; - const handleSuccess = (image: { width: number; height: number }) => { - const prevIndex = layout.current[index].index; - const prevLength = layout.current[index].length; - const newLayout = layout.current.map((curr) => { - if (curr.index < prevIndex) { - return curr; - } - return { - ...curr, - length: image.height, - offset: curr.offset - prevLength + image.height, - }; - }); - layout.current === newLayout; - }; return needUnscramble ? ( - + ) : ( - + ); }, - [headers, layout] + [headers] ); const renderHorizontalItem = useCallback( ({ item }: ListRenderItemInfo) => { @@ -117,7 +98,7 @@ const Reader = ({ }, [headers, toggleExtra] ); - const handleSliderChangeEndHor = useCallback((newStep: number) => { + const handleSliderChangeEnd = useCallback((newStep: number) => { const newPage = Math.floor(newStep); setPage(newPage); @@ -128,15 +109,6 @@ const Reader = ({ flatListRef.current?.scrollToOffset({ offset: 1, animated: false }); } }, []); - const handleSliderChangeEndVer = useCallback((newStep: number) => { - const newPage = Math.floor(newStep); - const offset = layout.current[newPage].offset; - - setPage(newPage); - flatListRef.current?.scrollToOffset({ - offset: offset <= 0 ? 1 : offset, - }); - }, []); const handleVertical = () => { onModeChange(false); @@ -210,12 +182,6 @@ const Reader = ({ /> {title} - {title} - {title} - {title} - {title} - {title} - {title} @@ -238,12 +204,14 @@ const Reader = ({ )} - + {horizontal && ( + + )} )}