Skip to content

Commit c52fe0e

Browse files
committed
Merge branch 'frontend-responsive-fontsize-android'
2 parents eaa2958 + 06d2c23 commit c52fe0e

File tree

133 files changed

+953
-948
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+953
-948
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Sort backups from newest to oldest in manage backups
1010
- Android: fix display of external links from Bitrefill
1111
- fix language sometimes not persistent across app restarts
12+
- Android: make the UI work with responsive font sizes and adhere to OS font size settings
1213

1314
## v4.49.0
1415
- Bundle BitBox02 Nova firmware version v9.24.0

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,46 @@ public class WebViewClient extends android.webkit.WebViewClient {
1414
private final String baseUrl;
1515
private final AssetManager assets;
1616
private final Application appContext;
17+
private final int initialZoom;
1718

18-
public WebViewClient(String baseUrl, AssetManager assets, Application appContext) {
19+
public WebViewClient(String baseUrl, AssetManager assets, Application appContext, int initialZoom) {
1920
this.assets = assets;
2021
this.appContext = appContext;
2122
this.baseUrl = baseUrl;
23+
this.initialZoom = initialZoom;
2224
}
2325
@Override
2426
public void onPageFinished(WebView view, String url) {
2527
super.onPageFinished(view, url);
28+
29+
// Calculate the base font size for html as a percentage.
30+
// This percentage dynamically adjusts to ensure 1rem = 10px, scaled according to the current zoom level.
31+
double baseFontSizePercentage = 62.5 * ((double) initialZoom / 100.0);
32+
33+
// The default body font size in rem, which is independent of the zoom level.
34+
// This size does not scale dynamically with zoom adjustments and is fixed at 1.6rem.
35+
double defaultFontSizeREM = 1.6;
36+
37+
// Reset the WebView's text zoom to 100% to ensure that the scaling is controlled via CSS
38+
// and not by the WebView's default scaling behavior.
39+
view.getSettings().setTextZoom(100);
40+
41+
String cssSetupInjected =
42+
"(function() {" +
43+
" function applyCss() {" +
44+
" document.documentElement.style.fontSize='" + baseFontSizePercentage + "%';" +
45+
" document.body.style.fontSize='" + defaultFontSizeREM + "rem';" +
46+
" }" +
47+
" if (document.readyState === 'complete' || document.readyState === 'interactive') {" +
48+
" applyCss();" +
49+
" } else {" +
50+
" document.addEventListener('DOMContentLoaded', applyCss);" +
51+
" }" +
52+
"})();";
53+
54+
// Execute the CSS setup in the WebView.
55+
view.evaluateJavascript(cssSetupInjected, null);
56+
2657
// override the default readText method, that doesn't work
2758
// because of read permission denied.
2859
view.evaluateJavascript(

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ public void initialize(WebView webView) {
9494
settings.setDomStorageEnabled(true);
9595
settings.setMediaPlaybackRequiresUserGesture(false);
9696
// webView.setWebContentsDebuggingEnabled(true); // enable remote debugging in chrome://inspect/#devices
97-
webView.setWebViewClient(new WebViewClient(BASE_URL, activity.getAssets(), activity.getApplication()));
97+
// Retrieve the current text zoom setting to adjust the base font size in the WebView.
98+
int initialZoom = webView.getSettings().getTextZoom();
99+
webView.setWebViewClient(new WebViewClient(BASE_URL, activity.getAssets(), activity.getApplication(), initialZoom));
98100
webView.setWebChromeClient(webChromeClient);
99101
webView.addJavascriptInterface(new JavascriptBridge(activity), "android");
100102
webView.loadUrl(BASE_URL + "index.html");

frontends/web/src/components/actionable-item/actionable-item.module.css

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
.container {
2-
--size-default: 14px;
32
align-items: center;
43
background-color: var(--background-secondary);
54
border: none;
65
color: var(--color-default);
76
display: flex;
87
font-size: var(--size-default);
98
justify-content: space-between;
10-
line-height: 1.571428;
119
padding: 16px;
1210
text-align: left;
1311
width: 100%;

frontends/web/src/components/amount/amount-with-unit.module.css

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
.rates {
22
cursor: default;
3-
line-height: 1;
43
margin: 0;
54
max-width: 100%;
65
white-space: nowrap;
76
}
87

98
.unit {
109
font-weight: 400;
10+
flex-grow: 0;
11+
flex-shrink: 0;
1112
color: var(--color-secondary);
1213
font-variant: normal;
1314
position: relative;
1415
cursor: default;
1516
}
1617

1718
.availableFiatAmount {
18-
color: var(--color-default);
19-
padding-right: var(--space-quarter) !important;
19+
align-items: baseline;
20+
display: inline-flex;
21+
flex-grow: 0;
22+
justify-content: flex-start;
23+
gap: 0.4ch;
2024
text-align: right;
2125
}
2226

@@ -43,9 +47,4 @@
4347
.fiatRow {
4448
bottom: 0;
4549
}
46-
47-
.availableFiatAmount,
48-
.availableFiatUnit {
49-
line-height: 24px;
50-
}
5150
}

frontends/web/src/components/amount/amount-with-unit.tsx

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import style from './amount-with-unit.module.css';
2424

2525
type TAmountWithUnitProps = {
2626
amount: TAmountWithConversions | undefined;
27-
tableRow?: boolean;
2827
enableRotateUnit?: boolean;
2928
sign?: string;
3029
alwaysShowAmounts?: boolean;
@@ -34,12 +33,11 @@ type TAmountWithUnitProps = {
3433

3534
export const AmountWithUnit = ({
3635
amount,
37-
tableRow,
3836
enableRotateUnit: rotateUnit,
3937
sign,
4038
convertToFiat,
4139
alwaysShowAmounts = false,
42-
unitClassName = ''
40+
unitClassName = '',
4341
}: TAmountWithUnitProps) => {
4442
const { rotateDefaultCurrency, defaultCurrency, rotateBtcUnit } = useContext(RatesContext);
4543

@@ -64,35 +62,27 @@ export const AmountWithUnit = ({
6462
}
6563

6664
const enableClick = rotateUnit && (convertToFiat || isBitcoinCoin(amount.unit));
67-
const formattedAmount = !!displayedAmount ?
68-
(
69-
<Amount
70-
alwaysShowAmounts={alwaysShowAmounts}
71-
amount={displayedAmount}
72-
unit={displayedUnit}
73-
onMobileClick={enableClick ? onClick : undefined}
74-
/>
75-
) : '---';
76-
77-
const amountUnit = <AmountUnit unit={displayedUnit} rotateUnit={enableClick ? onClick : undefined} className={unitClassName}/>;
7865

79-
if (tableRow) {
80-
return (
81-
<tr className={style.fiatRow}>
82-
<td className={style.availableFiatAmount}>{formattedAmount}</td>
83-
<td>{amountUnit}</td>
84-
</tr>
85-
);
86-
}
8766
return (
8867
<span className={`
8968
${style.rates || ''}
69+
${style.availableFiatAmount || ''}
9070
${!displayedAmount && style.notAvailable || ''}
9171
`.trim()}>
9272
{!!displayedAmount ? sign : ''}
93-
{formattedAmount}
73+
{!!displayedAmount ? (
74+
<Amount
75+
alwaysShowAmounts={alwaysShowAmounts}
76+
amount={displayedAmount}
77+
unit={displayedUnit}
78+
onMobileClick={enableClick ? onClick : undefined}
79+
/>
80+
) : '---'}
9481
{' '}
95-
{amountUnit}
82+
<AmountUnit
83+
unit={displayedUnit}
84+
rotateUnit={enableClick ? onClick : undefined}
85+
className={unitClassName}/>
9686
</span>
9787
);
9888
};

frontends/web/src/components/amount/amount.module.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
.amount {
2+
align-items: baseline;
3+
display: inline-flex;
4+
display: flow-root; /* flow-root seems to work better on all-account. keeping inline-flex as fallback */
25
flex-shrink: 1;
6+
flex-basis: auto;
7+
flex-grow: 0;
38
font-variant: tabular-nums;
9+
max-width: 100%;
410
overflow: hidden;
511
text-overflow: ellipsis;
612
}

frontends/web/src/components/amount/conversion-amount.module.css

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@
1414
.txPrefix,
1515
.txUnit {
1616
color: var(--color-secondary);
17-
font-size: 14px;
18-
line-height: 1.285714;
17+
font-size: var(--size-small);
1918
white-space: nowrap;
2019
}
2120

2221
.txConversionAmount .txUnit {
23-
font-size: 12px;
22+
font-size: var(--size-smaller);
2423
flex-shrink: 0;
24+
max-width: 100%;
2525
}
2626

2727
.txSmallInlineIcon img {
28-
max-height: 15px;
29-
max-width: 15px;
28+
max-height: 1.5rem;
29+
max-width: 1.5rem;
3030
vertical-align: text-bottom;
3131
}
3232
.txConversionAmount .txSmallInlineIcon {

frontends/web/src/components/aopp/aopp.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@
4242
}
4343
@media (min-width: 1200px) {
4444
.message {
45-
--size-default: 18px;
45+
--size-default: 1.8rem;
4646
}
4747
}

frontends/web/src/components/badge/badge.module.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
border-radius: var(--space-half);
33
border: 1px solid;
44
display: inline-block;
5-
font-size: var(--size-small);
5+
font-size: var(--size-smaller);
66
flex-shrink: 0;
77
line-height: 1;
88
padding: var(--space-eight) 10px;
@@ -19,7 +19,7 @@
1919
}
2020

2121
.badgeIcon {
22-
max-width: 10px;
22+
max-width: 1rem;
2323
}
2424

2525
.withChildren .badgeIcon {
@@ -28,7 +28,7 @@
2828

2929
@media (max-width: 382px) {
3030
.badge {
31-
font-size: 10px;
31+
font-size: var(--size-xsmall);
3232
}
3333
}
3434

0 commit comments

Comments
 (0)