FreeMIT License

Morph Text — Per-Character Text Transitions & Rolling Numbers for React Native & Expo

Text that changes beautifully in React Native: shared letters glide to their new places, removed ones leave and new ones rise in, never overlapping. Odometer numbers formatted by Intl, and a button that morphs through loading, success and error. Persian and Arabic stay joined.

by UpFork, built by Ramin ValadanMobile componentUpdated 14 Oct 2026

Watch0
Preview of Morph Text — Per-Character Text Transitions & Rolling Numbers for React Native & Expo

Code

15 files · 4 packages

// Which pieces of the old text are the same pieces in the new one. A longest common subsequence,
// but among the equally long ones it takes the one with the fewest separate runs, then the one
// whose pieces travel least: "letter" → "better" keeps "etter" together, and a repeated letter
// matches the copy nearest to it.

/**
 * Pairs of indices (old, new) that stay, in order. `before` and `after` are where each piece sits
 * (any unit, as long as both use the same one): they break ties between repeated pieces.
 */
export function matchTokens(
  a: readonly string[],
  b: readonly string[],
  before: readonly number[],
  after: readonly number[],
): Array<[number, number]> {
  const n = a.length;
  const m = b.length;
  if (n === 0 || m === 0) return [];

  // Score: matches first, then fewer runs, then less travel. Two states per cell: whether the
  // last step was a match on the diagonal (so the next match continues the run).
  const MATCH = 1_000_000;
  const RUN = 1_000;
  const width = m + 1;
  const free = new Float64Array((n + 1) * width).fill(-Infinity); // last step was not a match
  const run = new Float64Array((n + 1) * width).fill(-Infinity); // last step matched (i-1, j-1)
  // How each cell was reached: 0 skip old, 1 skip new, 2 match from free, 3 match from run.
  const fromFree = new Uint8Array((n + 1) * width);
  const fromRun = new Uint8Array((n + 1) * width);
  free[0] = 0;

  for (let i = 0; i <= n; i++) {
    for (let j = 0; j <= m; j++) {
      const k = i * width + j;
      if (i > 0 || j > 0) {
        // Arriving without a match: skip a[i-1] or b[j-1] from either state.
        let best = -Infinity;
        let how = 0;
        if (i > 0) {
          const up = Math.max(free[k - width], run[k - width]);
          if (up > best) {
            best = up;
            how = 0;
          }
        }
        if (j > 0) {
          const left = Math.max(free[k - 1], run[k - 1]);
          if (left > best) {
            best = left;
            how = 1;
          }
        }
        free[k] = best;
        fromFree[k] = how;
      }
      if (i > 0 && j > 0 && a[i - 1] === b[j - 1]) {
        const d = k - width - 1;
        const travel = Math.min(999, Math.abs(before[i - 1] - after[j - 1]));
        const startRun = free[d] + MATCH - RUN - travel;
        const keepRun = run[d] + MATCH - travel;
        if (keepRun >= startRun) {
          run[k] = keepRun;
          fromRun[k] = 3;
        } else {
          run[k] = startRun;
          fromRun[k] = 2;
        }
      }
    }
  }

  const pairs: Array<[number, number]> = [];
  let i = n;
  let j = m;
  let inRun = run[n * width + m] > free[n * width + m];
  while (i > 0 || j > 0) {
    const k = i * width + j;
    if (inRun) {
      pairs.push([i - 1, j - 1]);
      inRun = fromRun[k] === 3;
      i--;
      j--;
    } else {
      const how = fromFree[k];
      if (how === 0) {
        inRun = run[k - width] > free[k - width];
        i--;
      } else {
        inRun = run[k - 1] > free[k - 1];
        j--;
      }
    }
  }
  return pairs.reverse();
}
15 files4 packages

About

Morph Text is the detail that makes an app feel expensive: labels, numbers and buttons that change in place instead of blinking.

  • MorphText. "Follow" becomes "Following" by keeping "Follow" and bringing in "ing". Letters both strings share glide to their new places, removed ones shrink and fade, new ones rise in with a stagger, and the width springs to fit. An arrival waits for its spot to clear, so no letter is ever drawn over another, in any frame.
  • Every script. Emoji, flags and accents move as one piece. Persian, Arabic and the Indic scripts move by word, so joined letters keep their shapes; right-to-left text is laid out right to left.
  • MorphNumber. An odometer for prices, counters and balances: each digit rolls by its place, "999" becomes "1,000" with "1," sliding in, and Intl formats currency, percent, compact and decimals. Optional green and red trend flashes.
  • MorphButton. Return a promise from onPress and the pill shrinks around a spinner, then draws a check with its success label, or shakes with an error, and goes back by itself. Solid, tinted and outline; accent, neutral and danger; three sizes; haptics.
  • Calm and accessible. One readable label for screen readers, announcements on change, reduced motion respected, light and dark, every label at 4.5:1 or better.

Three complete demos: a creator's profile and shop with follow, subscribe, add to bag and a swap card; a live portfolio with ticking prices; and one greeting in five languages.

Reviews and bugs

0 reviews · 0 bugs

Ship it0With fixes0Skip0· 0 reviews

0 bugs0 open0 fixed

Members who have it review it and report its bugs. Sign in

No reviews or bugs yet.

Installation

React Native · Expo SDK 57

Built withExpo HapticsReanimatedSVGSafe Area Context

  1. 01

    Copy the files into your app

    • components/morph-text/diff.ts
    • components/morph-text/easing.ts
    • components/morph-text/format.ts
    • components/morph-text/icons.tsx
    • components/morph-text/index.ts
    • components/morph-text/measure.tsx
    • components/morph-text/morph-button.tsx
    • components/morph-text/morph-number.tsx
    • components/morph-text/morph-text.tsx
    • components/morph-text/piece.tsx
    • components/morph-text/plan.ts
    • components/morph-text/segment.ts
    • components/morph-text/timeline.ts
    • lib/demo-icons.tsx
    • lib/use-scheme.ts
    • demos/ (3 screens showing it in use)

    At your app’s root, the folders side by side as they are: the files import each other by relative paths.

  2. 02

    Install the packages with Expo

    npx expo install expo-haptics react-native-reanimated react-native-svg react-native-worklets
  3. 03

    And what the demos use

    npx expo install react-native-safe-area-context
  4. 04

    See it in your app

    Make demos/buttons.tsx your app’s App.tsx:

    import Buttons from './demos/buttons';
    
    export default function App() {
      return <Buttons scheme="light" />;
    }
    

UpFork installs every revision just so into a fresh Expo app (SDK 57), type-checks it and builds it for the web before it goes on sale. An AI assistant can do it for you through UpFork’s MCP server: Install mobile components has both ways.

Before you buy

Everything you need to know

How this mobile component gets from the preview into your project, and what buyers ask most.

How to use it

From the preview to your project

  1. 01

    Try it in the preview

    Switch between light and dark, and resize it to phone and tablet widths, before you decide.

  2. 02

    Get it

    Free products are yours with a free account. Paid ones settle in USDT on TRON, sent straight to the wallet on your order.

  3. 03

    Install it

    Components go into your project with one shadcn command, dependencies included. Everything else downloads with a checksum.

  4. 04

    Make it yours

    It's your code now: rename it, restyle it and wire in your real data.

  5. 05

    Or hand it to your AI

    Copy the prompt and let your coding assistant place it in your project, following your conventions.

Building with an AI assistant?

Copy a ready-made prompt with the code, its dependencies and a demo, and your assistant can put it in place for you.

Copy AI prompt

Selling your own work?

Get approved once, then publish components, templates and mobile components, paid in USDT straight to your own wallet.