Skip to content

Updated “Reached End” experience#368

Merged
amitojsingh merged 2 commits into
devfrom
fix-start-after-end
Jan 2, 2026
Merged

Updated “Reached End” experience#368
amitojsingh merged 2 commits into
devfrom
fix-start-after-end

Conversation

@amitojsingh

Copy link
Copy Markdown
Collaborator

Updated “Reached End” experience

When a user reaches the end of a Bani, the next time they open the same Bani it should start from the beginning.

What changed

  • Refactored currentElementId handling to use a ref, improving consistency and avoiding unnecessary re-renders.
  • Improved saveScrollPosition to dispatch the correct element ID more reliably.
  • Updated WebView message handling to detect “end of document” state and handle it gracefully during scroll.
  • Removed redundant currentElementId state updates to simplify logic and streamline the codebase.

- Updated currentElementId handling to utilize a ref for better performance and consistency.
- Enhanced saveScrollPosition logic to ensure accurate element ID dispatching.
- Modified WebView message handling to account for reaching the end of the document, improving user experience during scrolling.
- Cleaned up unnecessary state updates related to currentElementId for a more streamlined codebase.
@amitojsingh amitojsingh changed the title Refactor ReaderScreen to improve scroll position management Updated “Reached End” experience Dec 25, 2025
@amitojsingh amitojsingh self-assigned this Dec 25, 2025
Comment thread src/ReaderScreen/index.jsx Outdated
dispatch(actions.setPosition(elementIdToSave, id));
}
}, [dispatch, id, currentElementId]);
}, [dispatch, id, currentElementIdRef.current]);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Refs don't trigger re-render, so this callback won't trigger when currentElementIdRef changes

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment thread src/ReaderScreen/index.jsx Outdated
webViewRef.current.postMessage(JSON.stringify(scrollMessage));
}
}, [currentElementId]);
}, [currentElementIdRef.current]);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same here.
It won't trigger re-render, so this callback won't trigger when currentElementIdRef changes

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment thread src/ReaderScreen/index.jsx Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Navigation can also come as one of the side-effects here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment thread src/ReaderScreen/utils/gutkaScript.js Outdated
if (elementId && !hasReachedEnd) {
window.ReactNativeWebView.postMessage("scroll-elementId-" + elementId);
}
else if (hasReachedEnd) {

Copy link
Copy Markdown
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 code indentation here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment thread src/ReaderScreen/index.jsx Outdated
@@ -59,11 +58,11 @@ const Reader = ({ navigation, route }) => {
// Save element ID when leaving screen or app goes to background
const saveScrollPosition = useCallback(() => {
// Prefer element ID if available, otherwise fall back to currentElementId state

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This state doesn't exist anymore, so the comment can be removed

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@amitojsingh
amitojsingh merged commit e498596 into dev Jan 2, 2026
3 checks passed
@amitojsingh
amitojsingh deleted the fix-start-after-end branch January 2, 2026 19:03
smanjot27 pushed a commit to manjotkaur27/sundar-gutka-react that referenced this pull request Mar 28, 2026
* Refactor ReaderScreen to improve scroll position management

- Updated currentElementId handling to utilize a ref for better performance and consistency.
- Enhanced saveScrollPosition logic to ensure accurate element ID dispatching.
- Modified WebView message handling to account for reaching the end of the document, improving user experience during scrolling.
- Cleaned up unnecessary state updates related to currentElementId for a more streamlined codebase.

* fix: reviews
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants