Skip to content

Commit 1da4aa1

Browse files
committed
test
1 parent aaa64ff commit 1da4aa1

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

frontends/android/BitBoxApp/app/src/main/java/ch/shiftcrypto/bitboxapp/MainActivity.java

+27
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public class MainActivity extends AppCompatActivity {
7777

7878
private String location = "";
7979

80+
private int currentZoom;
81+
8082
// This is for the file picker dialog invoked by file upload forms in the WebView.
8183
// Used by e.g. MoonPay's KYC forms.
8284
private ValueCallback<Uri[]> filePathCallback;
@@ -221,12 +223,37 @@ public void run() {
221223
// For MoonPay WebRTC camera access.
222224
vw.getSettings().setMediaPlaybackRequiresUserGesture(false);
223225

226+
// Retrieve the current text zoom setting to adjust the base font size in the WebView.
227+
currentZoom = vw.getSettings().getTextZoom();
228+
224229
vw.setWebViewClient(new WebViewClient() {
225230
@Override
226231
public void onPageFinished(WebView view, String url) {
227232
// The url is not correctly updated when navigating to a new page. This allows to
228233
// know the current location and to block external requests on that base.
229234
view.evaluateJavascript("window.location.pathname", path -> location = path);
235+
236+
// Calculate the base font size for html as a percentage.
237+
// This percentage dynamically adjusts to ensure 1rem = 10px, scaled according to the current zoom level.
238+
double baseFontSizePercentage = 62.5 * (currentZoom / 100.0);
239+
240+
// The default body font size in rem, which is independent of the zoom level.
241+
// This size does not scale dynamically with zoom adjustments and is fixed at 1.6rem.
242+
double defaultFontSizeREM = 1.6;
243+
244+
// Set the base font-size on the html element dynamically and apply a fixed font size to the body.
245+
// Also, set a custom data attribute 'data-test' to the calculated base font size percentage for potential debugging.
246+
String cssSetup = "document.documentElement.style.fontSize = '" + baseFontSizePercentage + "%';" +
247+
"document.body.style.fontSize = '" + defaultFontSizeREM + "rem';" +
248+
"document.body.setAttribute('data-test', '" + baseFontSizePercentage + "%');";
249+
250+
// Reset the WebView's text zoom to 100% to ensure that the scaling is controlled via CSS
251+
// and not by the WebView's default scaling behavior.
252+
view.getSettings().setTextZoom(100);
253+
254+
// Execute the CSS setup in the WebView.
255+
view.evaluateJavascript(cssSetup, null);
256+
230257
}
231258
@Override
232259
public WebResourceResponse shouldInterceptRequest(final WebView view, WebResourceRequest request) {

frontends/web/src/components/layout/header.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ const Header = ({
4545
}
4646
return false;
4747
};
48+
const test = document.body.getAttribute('data-test');
49+
const width = window.screen.width;
4850

4951
return (
5052
<div className={[style.container, sidebarStatus ? style[sidebarStatus] : ''].join(' ')}>
@@ -62,6 +64,9 @@ const Header = ({
6264
<a href="#" onClick={toggle} className={[style.guideIcon, guideShown ? style.disabled : ''].join(' ')}>
6365
<GuideActive />
6466
{t('guide.toggle.open')}
67+
<sup>
68+
({test} {width}px)
69+
</sup>
6570
</a>
6671
</span>
6772
)

0 commit comments

Comments
 (0)