Index of every page on this site: llms.txt
All skills
david-evans03 avatar

/react-native-nested-text-layout

@6465931
Run it yourself

Fixes broken line height, spacing, wrapping, and baselines when React Native copy is built from one Text (or Animated.Text) per character or word inside View rows and flexWrap. Use when debugging "wrong padding/margins/typography" on staggered or per-glyph text, typewriter effects, character fade-ins, or any pattern that maps strings to many sibling Text nodes inside flex containers.

  • 1 file
  • 3.4 KB
  • Updated 5 months ago
  • GitHub
Use this Skill: https://skilld.dev/gh/david-evans03/skills/react-native-nested-text-layout

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈105 tokens for metadata: the name and description. ≈763 when used: this file.

Description uses 5.3% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈420 characters, or 5.3%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

React Native: nested Text for inline / paragraph layout

When to suspect this issue

Symptoms often look like font or theme bugs but are really layout mode:

  • Line height or vertical rhythm looks wrong vs the same styles on a single Text
  • Wrapped lines have uneven gaps, odd baselines, or "extra" space above/below
  • letterSpacing or transforms look different from a normal paragraph
  • Tweaking lineHeight, padding, or margin helps only a little or not at all

Common trigger code: each glyph is its own Text / Animated.Text wrapped in View with flexDirection: "row" and flexWrap: "wrap" (sometimes one View per word).

That structure is flex layout of boxes, not the text layout engine. Breaks, baselines, and multi-line spacing will not match a real paragraph.

Fix: one parent Text, nested children

Put one outer Text (or Animated.Text if the whole block is animated) around the fragments. Nested Text / Animated.Text children lay out inline, share wrapping, and match normal typography.

  • Apply paragraph styles (fontSize, lineHeight, fontFamily, color, letterSpacing, textTransform, etc.) on the parent when possible; children inherit unless overridden.
  • Each animated character stays an Animated.Text child without duplicating full paragraph styles if inheritance is enough.

Do not use Fragment inside Text

React Native Text children must be Text nodes or strings. Build arrays with flatMap / spread instead of <>...</>.

Example shape (character stagger)

<Text style={paragraphStyle}>
  {words.flatMap((word, wordIndex) => {
    const keys = word.split("").map((char, i) => (
      <Animated.Text key={`${wordIndex}-${i}`} entering={/* ... */}>
        {char}
      </Animated.Text>
    ));
    if (wordIndex < words.length - 1) {
      return [
        ...keys,
        <Animated.Text key={`sp-${wordIndex}`} entering={/* ... */}>
          {"\u00A0"}
        </Animated.Text>,
      ];
    }
    return keys;
  })}
</Text>

Words can be precomputed with useMemo if needed; keep keys stable.

Related gotchas

  • Android: includeFontPadding on the parent Text can tighten vertical metrics if labels still look vertically padded.
  • Layout reservation: If a hidden placeholder and visible control differ in copy or line count (e.g. two button labels), height can shift when swapping; use the same final string (or explicit minHeight) for the placeholder.
  • Still wrong? After nested Text, if top inset looks off, check navigator header + SafeAreaView (e.g. double top inset with a transparent stack header), not typography.

Quick checklist

  1. Is per-character (or per-word-for-wrap) content inside Views + flexWrap? → Refactor to parent Text + nested Text / Animated.Text.
  2. Are paragraph styles on the parent so inheritance is consistent?
  3. No Fragment inside Text; use array / flatMap.
  4. Placeholder vs visible text: same dimensions?

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at 6465931. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 5 months ago

README badge

README badge for david-evans03/skills/react-native-nested-text-layout