BeforeAfter

BeforeAfter is an animated before after component for React Native and React, from the dissolve library. Before / after image comparison with a draggable divider and haptic ticks.

Compare two versions of an image. Drag the round handle, or anywhere on the frame, or tap to send the divider there. The before layer is clipped to the left of the divider without relayout, and the pills fade as the divider reaches them.

Install

React Native

Install the engine once per app and wrap the root layout in <DissolveProvider> (see Installation), then copy the component into components/dissolve:

npx expo install dissolve-ui @shopify/react-native-skia react-native-reanimated react-native-worklets react-native-gesture-handler expo-haptics
npx dissolve-ui add before-after --native
npx shadcn@latest add https://dissolve.rselmi.com/r/native/before-after.json

React

Needs React 19 and react-dom, nothing else: no engine, no provider, no Tailwind. Works in the Next.js App Router.

npx dissolve-ui add before-after --web
npx shadcn@latest add https://dissolve.rselmi.com/r/before-after.json

Usage

BeforeAfter.tsx (React Native)
import { Image } from 'expo-image';
import { BeforeAfter } from '@/components/dissolve/before-after';

<BeforeAfter
  height={320}
  initial={0.42}
  afterLabel="Vivid"
  renderBefore={({ width, height }) => <Image source={raw} style={{ width, height }} />}
  renderAfter={({ width, height }) => <Image source={edited} style={{ width, height }} />}
/>
BeforeAfter.tsx (React)
import { BeforeAfter } from '@/components/dissolve/before-after';

<BeforeAfter
  height={320}
  initial={0.42}
  afterLabel="Vivid"
  renderBefore={({ width, height }) => <img src={raw} style={{ width, height }} />}
  renderAfter={({ width, height }) => <img src={edited} style={{ width, height }} />}
/>

Props

PropTypeDefaultDescription
before / afterReactNodeThe two versions, left and right of the divider.
renderBefore / renderAfter(size) => ReactNodeRender props given the frame size, for images that need explicit dimensions.
initialnumber0.5Initial divider position, 0 (all after) to 1 (all before).
heightnumber320Frame height.
beforeLabelstring'Before'Left pill.
afterLabelstring'After'Right pill.
labelsbooleantrueShows the two pills.
onChange(value: number) => voidDivider position (0..1) when a drag or a tap settles.
hapticsbooleantrueA tick at the middle, a light impact at both edges.
classNamestring'rounded-[20px] bg-dissolve-surface-2'Frame: radius, placeholder background, margins.
handleClassNamestringRound handle.
dividerClassNamestringDivider line.
pillClassNamestringBefore and After pills.
pillTextClassNamestring'text-[12px] font-semibold text-white'Pill labels.

Source

Previous: CardStack · Next: ThinkingOrb · All components

dissolve is MIT licensed. Source on GitHub, package on npm. This page as markdown. For AI agents: llms.txt.