From 8f5215abfd952cb1ba514bbcb5ce56bf9a41e967 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Fri, 6 Sep 2024 15:28:35 +0200 Subject: [PATCH] ReaderView: Fix a couple of edge-cases in onReaderFooterVisibilityChange (#12466) Namely, it trips a `recalculate` that snaps `visible_area` to `page_area` edges (depending on zoom/reading direction), while we do *NOT* actually want to move the view, just increase/decrease its height ;). (This *might* happen more reliably than it used to since https://github.com/koreader/koreader/pull/11425 & https://github.com/koreader/koreader/pull/11557) Also deal with scroll mode while I'm here, as recalculate doesn't affect scroll mode at all, since that uses an *array* of on-screen pages, each with their own visible_area, page_area & state. Fix #12454 --- frontend/apps/reader/modules/readerview.lua | 25 ++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index b07d01e18..94e4e6e3f 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -999,10 +999,29 @@ function ReaderView:onReaderFooterVisibilityChange() if not self.footer.settings.reclaim_height then -- NOTE: Mimic what onSetFullScreen does, since, without reclaim, toggling the footer affects the available area, -- so we need to recompute the full layout. + -- NOTE: ReaderView:recalculate will snap visible_area to page_area edges (depending on zoom direction). + -- We don't actually want to move here, so save & restore our current visible_area *coordinates*... + local x, y = self.visible_area.x, self.visible_area.y self.ui:handleEvent(Event:new("SetDimensions", Screen:getSize())) - -- NOTE: Scroll mode's behavior after this might be suboptimal (until next page), - -- but I'm not familiar enough with it to make it behave... - -- (e.g., RedrawCurrentPage & co will snap to the top of the "current" page). + self.visible_area.x = x + self.visible_area.y = y + + -- Now, for scroll mode, ReaderView:recalculate does *not* affect any of the actual page_states, + -- so we'll fudge the bottom page's visible area ourselves, + -- so as not to leave a blank area behind the footer when hiding it... + -- This might cause the next scroll to scroll a footer height's *less* than expected, + -- but that should be hardly noticeable, and since we scroll less, it won't skip over anything. + if self.page_scroll then + local bottom_page = self.page_states[#self.page_states] + -- Not sure if this can ever be `nil`... + if bottom_page then + if self.footer_visible then + bottom_page.visible_area.h = bottom_page.visible_area.h - self.footer:getHeight() + else + bottom_page.visible_area.h = bottom_page.visible_area.h + self.footer:getHeight() + end + end + end end end end