-
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 1 commit
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 sb = null; | ||
|
|
||
| const clearScrollTimeout=()=> { | ||
| if (autoScrollTimeout != null) { | ||
|
|
@@ -21,9 +22,21 @@ const clearScrollTimeout=()=> { | |
| autoScrollTimeout = null; | ||
| } | ||
|
|
||
| const updateSB=()=> { | ||
| if(!sb) return; | ||
| const h=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight)-window.innerHeight; | ||
| if(h<=0){sb.style.display="none";return;} | ||
| sb.style.display="block"; | ||
| const p=Math.max(0,Math.min(1,(window.pageYOffset||0)/h)); | ||
| const th=Math.max(30,(window.innerHeight/h)*window.innerHeight); | ||
| const t=sb.children[0]; | ||
| if(t){t.style.height=th+"px";t.style.top=(p*(window.innerHeight-th))+"px";} | ||
| } | ||
|
|
||
| const scrollFunc=(e)=> { | ||
| curPosition = getScrollPercent(); | ||
| window.ReactNativeWebView.postMessage("scroll-" + curPosition); | ||
| updateSB(); | ||
| if (window.scrollY == 0) { | ||
| window.ReactNativeWebView.postMessage("show"); | ||
| } | ||
|
|
@@ -101,13 +114,26 @@ 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 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
| const existing=document.getElementById("sb"); | ||
| if(existing) existing.remove(); | ||
| sb=document.createElement("div"); | ||
| sb.id="sb"; | ||
| const st=document.createElement("div"); | ||
| st.id="sb-t"; | ||
| sb.appendChild(st); | ||
| document.body.appendChild(sb); | ||
| setTimeout(updateSB,100); | ||
| window.addEventListener("resize",updateSB); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,11 @@ 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.
This feels very congested and difficult to read. Can you please fix the indentation and use proper variable names, instead of single letter variables.
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