Skip to content

Commit d969690

Browse files
committed
fix(rntester): narrow measurements before formatting
1 parent 7abc1f8 commit d969690

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

‎packages/rn-tester/js/examples/Text/TextInlineViewBaselineExample.js‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const TALL_LINE_HEIGHT = 48;
2828
const FONT_FAMILY = 'Helvetica';
2929
const SERIF_FONT_FAMILY = 'TimesNewRomanPSMT';
3030
const SPACING = 8;
31+
const DISPLAY_DECIMAL_PLACES = 3;
3132

3233
type Sample = Readonly<{
3334
name: string,
@@ -108,8 +109,6 @@ function InlineViewBaselineSample({
108109
});
109110
}, [baseline]);
110111

111-
const error =
112-
baseline != null && bottom != null ? bottom - baseline : undefined;
113112
const content = (
114113
<>
115114
{'Hg '}
@@ -147,11 +146,11 @@ function InlineViewBaselineSample({
147146
allowFontScaling={false}
148147
testID={`${name}-metrics`}
149148
style={styles.metrics}>
150-
{error == null
151-
? baseline == null
152-
? 'Measuring...'
153-
: 'View measurement unavailable'
154-
: `baseline ${baseline?.toFixed(3)} | bottom ${bottom?.toFixed(3)} | error ${error.toFixed(3)} pt`}
149+
{baseline == null
150+
? 'Measuring...'
151+
: bottom == null
152+
? 'View measurement unavailable'
153+
: `baseline ${baseline.toFixed(DISPLAY_DECIMAL_PLACES)} | bottom ${bottom.toFixed(DISPLAY_DECIMAL_PLACES)} | error ${(bottom - baseline).toFixed(DISPLAY_DECIMAL_PLACES)} pt`}
155154
</RNTesterText>
156155
</View>
157156
);
@@ -171,7 +170,7 @@ export function TextInlineViewBaselineExample(): React.Node {
171170
sample.
172171
</RNTesterText>
173172
<RNTesterText allowFontScaling={false} style={styles.metrics}>
174-
{`One pixel: ${(1 / scale).toFixed(3)} pt | font scale: ${fontScale.toFixed(3)} (last sample only)`}
173+
{`One pixel: ${(1 / scale).toFixed(DISPLAY_DECIMAL_PLACES)} pt | font scale: ${fontScale.toFixed(DISPLAY_DECIMAL_PLACES)} (last sample only)`}
175174
</RNTesterText>
176175
{SAMPLES.map(sample => (
177176
<InlineViewBaselineSample key={sample.name} {...sample} />

0 commit comments

Comments
 (0)