Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ReaderScreen/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ const Reader = ({ navigation, route }) => {
<WebView
key={webViewKey}
webviewDebuggingEnabled
showsVerticalScrollIndicator={false}
showsHorizontalScrollIndicator={false}
javaScriptEnabled
originWhitelist={["*"]}
onLoadStart={handleLoadStart}
Expand Down
30 changes: 28 additions & 2 deletions src/ReaderScreen/utils/gutkaScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let isScrolling;
let isManuallyScrolling = false;
let lastHighlightedElement = null;
let highlightTimeout = null;
let sb = null;

const clearScrollTimeout=()=> {
if (autoScrollTimeout != null) {
Expand All @@ -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";}
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}

const scrollFunc=(e)=> {
curPosition = getScrollPercent();
window.ReactNativeWebView.postMessage("scroll-" + curPosition);
updateSB();
if (window.scrollY == 0) {
window.ReactNativeWebView.postMessage("show");
}
Expand Down Expand Up @@ -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
Copy link
Collaborator

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 #sb and then adding another div with same id sb?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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);
}


Expand Down
5 changes: 5 additions & 0 deletions src/ReaderScreen/utils/gutkahtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix the indentation here as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

#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>
Expand Down
Loading