Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/app/record.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ function Recording({ controller }: { controller: SessionController }) {
const target = state.labelTargetId ? data.moments.find((m) => m.id === state.labelTargetId) ?? null : null;
const bands = recordingBands(target !== null);
const sinceValue = sinceLast === null ? '—' : formatElapsed(sinceLast);
const since = sinceTimerFonts(clockFont, { ...sinceBox, label: sinceHeading, value: sinceValue });
// Destructured: Reanimated's dev Babel plugin warns about any `x.value` in an
// inline style, mistaking it for a shared value read.
const { label: sinceLabelFont, value: sinceValueFont } = sinceTimerFonts(clockFont, {
...sinceBox,
label: sinceHeading,
value: sinceValue,
});

const milestone = (code: RowMilestoneCode | Extract<MilestoneCode, 'RESUSCITATE'>) => {
controller.markMilestone(code);
Expand Down Expand Up @@ -139,13 +145,13 @@ function Recording({ controller }: { controller: SessionController }) {
{/* Sized by sinceTimerFonts, not adjustsFontSizeToFit, which on
iOS collapsed the value to a few points in this flex box. */}
<Text
style={[styles.timerLabel, { fontSize: since.label, lineHeight: Math.round(since.label * 1.2) }]}
style={[styles.timerLabel, { fontSize: sinceLabelFont, lineHeight: Math.round(sinceLabelFont * 1.2) }]}
numberOfLines={1}
maxFontSizeMultiplier={1}>
{sinceHeading}
</Text>
<Text
style={[styles.timerValue, type.tabular, { fontSize: since.value, lineHeight: Math.round(since.value * 1.1) }]}
style={[styles.timerValue, type.tabular, { fontSize: sinceValueFont, lineHeight: Math.round(sinceValueFont * 1.1) }]}
numberOfLines={1}
maxFontSizeMultiplier={1}>
{sinceValue}
Expand Down
44 changes: 44 additions & 0 deletions tests/inlineStyleWarning.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { transformFileSync, transformSync } from '@babel/core';
import { readFileSync, readdirSync, statSync } from 'fs';
import { join } from 'path';

// In development builds the Reanimated / worklets Babel plugin rewrites any
// `x.value` inside an inline `style` object into a console.warn("It looks like
// you might be using shared value's .value inside reanimated inline style"),
// even when x is a plain object. record.tsx did that with sinceTimerFonts()'s
// `value` font size. This compiles every component with the project's own
// babel.config.js and fails if the plugin injected the warning anywhere.

const ROOT = join(__dirname, '..');
const MARKER = 'getUseOfValueInStyleWarning';

function tsxFiles(dir: string): string[] {
return readdirSync(dir).flatMap((name) => {
const p = join(dir, name);
if (statSync(p).isDirectory()) return tsxFiles(p);
return p.endsWith('.tsx') ? [p] : [];
});
}

const OPTIONS = { cwd: ROOT, envName: 'development', babelrc: false, configFile: join(ROOT, 'babel.config.js') };

/** Compiled output of a file, or of `code` as if it lived at `filename`. */
const compile = (filename: string, code?: string) =>
(code === undefined ? transformFileSync(filename, OPTIONS) : transformSync(code, { ...OPTIONS, filename }))?.code ?? '';

describe('Reanimated inline style warning', () => {
// Positive control: the old record.tsx line. If the plugin stops running in
// this config, this fails instead of every file below passing vacuously.
it('detects the pattern record.tsx used to have', () => {
const record = join(ROOT, 'src', 'app', 'record.tsx');
const old = readFileSync(record, 'utf8').replace('fontSize: sinceValueFont,', 'fontSize: fonts.value,');
expect(old).toContain('fonts.value');
expect(compile(record, old)).toContain(MARKER);
});

const files = tsxFiles(join(ROOT, 'src'));

it.each(files.map((f) => [f.slice(ROOT.length + 1), f]))('%s compiles without the warning', (_, file) => {
expect(compile(file)).not.toContain(MARKER);
});
});
Loading