-
Notifications
You must be signed in to change notification settings - Fork 13
Added Scroll bar for bani reader #361
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
base: dev
Are you sure you want to change the base?
Changes from 3 commits
aa892d0
6c95120
7aed587
664a810
54d7530
de86a0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ let isScrolling; | |
| let isManuallyScrolling = false; | ||
| let lastHighlightedElement = null; | ||
| let highlightTimeout = null; | ||
| let scrollbar = null; | ||
|
|
||
| const clearScrollTimeout=()=> { | ||
| if (autoScrollTimeout != null) { | ||
|
|
@@ -21,9 +22,27 @@ const clearScrollTimeout=()=> { | |
| autoScrollTimeout = null; | ||
| } | ||
|
|
||
| const scrollFunc=(e)=> { | ||
| const updateScrollbar = () => { | ||
| if (!scrollbar) return; | ||
| const maxScrollHeight = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight) - window.innerHeight; | ||
| if (maxScrollHeight <= 0) { | ||
| scrollbar.style.display = "none"; | ||
| return; | ||
| } | ||
| scrollbar.style.display = "block"; | ||
| const scrollPosition = Math.max(0, Math.min(1, (window.pageYOffset || 0) / maxScrollHeight)); | ||
| const thumbHeight = Math.max(30, (window.innerHeight / maxScrollHeight) * window.innerHeight); | ||
| const thumbElement = scrollbar.children[0]; | ||
| if (thumbElement) { | ||
| thumbElement.style.height = thumbHeight + "px"; | ||
| thumbElement.style.top = (scrollPosition * (window.innerHeight - thumbHeight)) + "px"; | ||
| } | ||
| } | ||
|
|
||
| const scrollFunc = (event) => { | ||
| curPosition = getScrollPercent(); | ||
| window.ReactNativeWebView.postMessage("scroll-" + curPosition); | ||
| updateScrollbar(); | ||
| if (window.scrollY == 0) { | ||
| window.ReactNativeWebView.postMessage("show"); | ||
| } | ||
|
|
@@ -101,20 +120,33 @@ window.addEventListener( | |
| false | ||
| ); | ||
|
|
||
| ${listener}.onload = () => { | ||
| // Use window.onload for Android reliability | ||
| window.onload = () => { | ||
| if (${theme.mode === "dark"}) { | ||
| //fade event | ||
| fadeInEffect(); | ||
| } | ||
|
|
||
| scrollToPosition(); | ||
| scrollToPosition(); | ||
|
|
||
| // Minimal scrollbar - works on Android and iOS | ||
| const existingScrollbar = document.getElementById("sb"); | ||
| if (existingScrollbar) existingScrollbar.remove(); | ||
| scrollbar = document.createElement("div"); | ||
| scrollbar.id = "sb"; | ||
| const scrollbarThumb = document.createElement("div"); | ||
| scrollbarThumb.id = "sb-t"; | ||
| scrollbar.appendChild(scrollbarThumb); | ||
| document.body.appendChild(scrollbar); | ||
| setTimeout(updateScrollbar, 100); | ||
| window.addEventListener("resize", updateScrollbar); | ||
|
||
| } | ||
|
|
||
|
|
||
| // Listen for scroll events | ||
| ${listener}.addEventListener( | ||
| "scroll", | ||
| (event)=> { | ||
| (scrollEvent) => { | ||
| // Clear our timeout throughout the scroll | ||
| window.clearTimeout(isScrolling); | ||
| // Set a timeout to run after scrolling ends | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,24 @@ const htmlTemplate = (backColor, fontFace, content, theme, savePosition) => `<!D | |
| .right{ | ||
| text-align:right | ||
| } | ||
| /* Minimal scrollbar */ | ||
| #sb { | ||
| position: fixed; | ||
| right: 0; | ||
| top: 0; | ||
| width: 6px; | ||
| height: 100vh; | ||
| z-index: 99999; | ||
| pointer-events: none; | ||
| } | ||
| #sb-t { | ||
| position: absolute; | ||
| right: 1; | ||
|
||
| width: 2px; | ||
| background: ${theme.colors.primaryText}; | ||
| border-radius: 4px; | ||
| min-height: 40px; | ||
| } | ||
| </style> | ||
| <script>${script(theme, savePosition)}</script> | ||
| </head> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add some explanation, on the purpose of this code, is this removing an existing div with id
#sband then adding another div with same idsb?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is added as defensive logic to handle cases where the screen may load multiple times, preventing duplicate scrollbars from being created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't add a condition that if this div exists, do not add another? Why do we need to remove and add?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed