139 large font error: WebView Font Persistence & Chapter 5C Layout Shift Fix + Dynamic Scaling for Chapter Icon and Paragraph Bar #150
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
1. Overview
This PR addresses two intertwined UX issues affecting font scaling and layout consistency inside the WebView.
1.1 Issues Fixed
Font size not persisting between page navigations.
Layout shift occurring in specific sections — notably
Chapter 5 → Subchapter C (“Special clinical situations”)
where content shifts left after increasing font size, leaving the page, and returning.
Visual elements not scaling consistently with text, specifically:
ic_chapter_icon
The decorative vertical bar generated by .uk-paragraph::before
All fixes are implemented entirely at runtime in BodyFragment without modifying any CSS files.
2. Issues in Detail
2.1 Font Persistence + Layout Shift
Previously the app mixed:
WebView page zoom (onZoomOut()), and
textZoom (CSS text scaling)
This combination caused conflicts, unpredictable reflow behavior, and improper restoration of layout when revisiting pages.
Result:
2.2 Inconsistent Visual Scaling
The chapter icon (ic_chapter_icon) remained a fixed size while text scaled via textZoom.
The decorative line (.uk-paragraph::before):
-Used fixed rem units
-Did not follow the textZoom scaling
-Misaligned at larger sizes
-Overlapped the following text at smaller sizes
3. Solution
3.1 Use Only textZoom + Reapply on Page Load
Disable WebView page zoom
Reapply updates after navigation
-Ensures consistent, correct scaling every time a page loads.
3.2 Scale All Visual Elements at Runtime
All adjustments happen dynamically using JavaScript + injected <style> blocks.
4. Implementation Details
4.1 Chapter Icon Scaling (ic_chapter_icon)
Determine scaling based on the selected font size.
Locate chapter icons with:
-img[src*="ic_chapter.svg"]
Add the class .ic_chapter_icon for consistent targeting.
-Inject late <style> with !important:
Apply:
-Inline width/height
-HTML attributes (width="", height="") as a fallback
Ensure parent wrapper reserves enough space:
-Prevents flex-based clipping at larger font sizes.
4.2 Decorative Line Scaling (.uk-paragraph::before)
-Inject a runtime <style id="uk-paragraph-override"> with:
Height
Width
Top offset
Border radius
All values computed in px based on the same scale factor used to compute text size.
Fixes issues where:
-The line misaligns at large sizes
-The line overlaps text at smaller sizes
5.1 app/src/main/java/.../BodyFragment.kt
setupWebView()
Commented out onZoomOut() to eliminate page zoom.
Added updateFont() inside WebViewClient.onPageFinished(...) so scaling is reapplied on each navigation.
updateFont()
Read saved font preference.
Apply via webView.settings.textZoom.
Compute a scaleFactor derived from the font size.
Inject JavaScript to:
Detect chapter icons → add .ic_chapter_icon
Create/update <style id="chapter-icon-override">
Apply inline and HTML-attribute sizing
Adjust icon wrapper to fix layout clipping
Create/update <style id="uk-paragraph-override"> for scaling paragraph bars