stop font size fluctuations showing in summary cards (#7092)

* stop summary cards from showing until font size settled

* note
This commit is contained in:
Matt Fiddaman
2026-03-06 23:00:41 +00:00
committed by GitHub
parent b727124603
commit a8ec84ceac
3 changed files with 33 additions and 8 deletions

View File

@@ -49,6 +49,7 @@ export function FormulaResult({
containerRef,
}: FormulaResultProps) {
const [fontSize, setFontSize] = useState<number>(initialFontSize);
const [hasSized, setHasSized] = useState(false);
const refDiv = useRef<HTMLDivElement>(null);
const previousFontSizeRef = useRef<number>(initialFontSize);
const format = useFormat();
@@ -89,7 +90,10 @@ export function FormulaResult({
height, // Ensure the text fits vertically by using the height as the limiting factor
);
setFontSize(calculatedFontSize);
if (calculatedFontSize > 0) {
setFontSize(calculatedFontSize);
setHasSized(true);
}
// Only call fontSizeChanged if the font size actually changed
if (
@@ -143,6 +147,7 @@ export function FormulaResult({
useEffect(() => {
if (fontSizeMode === 'static') {
setFontSize(staticFontSize);
setHasSized(true);
}
}, [fontSizeMode, staticFontSize]);
@@ -153,6 +158,8 @@ export function FormulaResult({
? theme.errorText
: theme.pageText;
const showContent = hasSized || fontSizeMode === 'static';
return (
<View style={{ flex: 1 }}>
{loading && <LoadingIndicator />}
@@ -175,9 +182,13 @@ export function FormulaResult({
color,
}}
>
<span aria-hidden="true">
<PrivacyFilter>{displayValue}</PrivacyFilter>
</span>
{!showContent ? (
<LoadingIndicator />
) : (
<span aria-hidden="true">
<PrivacyFilter>{displayValue}</PrivacyFilter>
</span>
)}
</View>
)}
</View>

View File

@@ -38,6 +38,7 @@ export function SummaryNumber({
}: SummaryNumberProps) {
const { t } = useTranslation();
const [fontSize, setFontSize] = useState<number>(initialFontSize);
const [hasSized, setHasSized] = useState(false);
const refDiv = useRef<HTMLDivElement>(null);
const format = useFormat();
const isNumericValue = Number.isFinite(value);
@@ -61,7 +62,10 @@ export function SummaryNumber({
height, // Ensure the text fits vertically by using the height as the limiting factor
);
setFontSize(calculatedFontSize);
if (calculatedFontSize > 0) {
setFontSize(calculatedFontSize);
setHasSized(true);
}
if (calculatedFontSize !== initialFontSize && fontSizeChanged) {
fontSizeChanged(calculatedFontSize);
@@ -107,9 +111,13 @@ export function SummaryNumber({
: theme.reportsNumberPositive,
}}
>
<FinancialText aria-hidden="true">
<PrivacyFilter>{displayAmount}</PrivacyFilter>
</FinancialText>
{!hasSized ? (
<LoadingIndicator />
) : (
<FinancialText aria-hidden="true">
<PrivacyFilter>{displayAmount}</PrivacyFilter>
</FinancialText>
)}
</View>
)}
</>

View File

@@ -0,0 +1,6 @@
---
category: Bugfixes
authors: [matt-fidd]
---
Stop font size fluctuations showing in summary cards