Skip to content
StackD

· Arnau López

How I turned a running React app into editable Figma layers

A designer joined one of my projects, an iPhone app built with React Native. She needed every screen in Figma. The app had around 45 screens and no up to date design file, because the code had moved on from the first mockups a long time ago.

There were two obvious options and I didn't like either. Screenshots look right, but in Figma they're flat pictures: you can't change a text or move a button. Rebuilding every screen by hand gives clean layers, but it takes days, and it's already out of date the next time the code changes.

So I tried a third option: read the layout from the app while it runs, and rebuild it as Figma layers.

The idea

The final layout only exists when the code runs. Styles come from a theme, change with the screen size and depend on the data. So instead of reading the source files, I open the app in a browser (Expo can run it on the web), and for every element I read what the browser actually drew:

  • its size and position
  • its colours, corner radius, border and shadow
  • its text, with font, size, weight and line height
  • its flex layout: direction, gap, padding and alignment

That goes into a JSON tree, one file per screen. Then a small Figma plugin walks the tree and creates the layers.

const cs = getComputedStyle(el)
const r = el.getBoundingClientRect()
node = {
  x: r.left, y: r.top, w: r.width, h: r.height,
  bg: cs.backgroundColor,
  radius: cs.borderTopLeftRadius,
  flex: { dir: cs.flexDirection, gap: cs.rowGap, pad: cs.paddingTop },
}

Flexbox maps to auto-layout

This is what makes it work. React Native lays everything out with flexbox, and Figma's auto-layout is flexbox with other names. A View with flexDirection: 'row' and gap: 12becomes a horizontal auto-layout frame with 12 spacing. A child that stretches to the full width becomes “fill container”.

I don't trust the CSS alone, though. Margins and absolute positions can make the real gaps different from the gap property. So the plugin measures where the children really are, and only uses auto-layout when they sit in a line with an even gap. If they don't, the frame keeps its children where they were. The screen still looks right, it's just less tidy to edit.

Layers named like the code

A Figma file full of layers called “Frame 342” is hard to work with. In a development build, React keeps its component tree on each DOM element, so the capture can find which component drew it. The button becomes BigButton, the mascot becomes LiveBot, the input becomes TextField. A designer can now talk about the same pieces as the developer.

What Figma can't rebuild

Some things don't exist as layers in Figma: a canvas (the app draws a few animations with Skia), 3D CSS transforms (the book covers tilt in 3D), and blur. For those, the capture takes a picture of just that area and places it as an image in the right spot. Everything around it stays editable.

Flat rotations and linear gradients do map, so they come through as real Figma properties.

The small things that took the longest

  • Intro animations. The first captures caught screens halfway through fading in. Turning on “reduce motion” in the browser made the app skip them, because it already respected that setting.
  • The notch. On the web the safe area is zero, so a floating tab bar covered the titles. Chrome can emulate the iPhone's safe area, and then every header sat where it does on the phone.
  • Long screens. To get the whole scroll in one frame, the viewport grows to the height of the screen's main scroll. Only the main one: a time picker is a small scroller too, and once it stretched a screen to twice its height.
  • Images. Photos came in at their original size, 5 MB for one picture. Shrinking each one to twice the size it's shown at brought it down to 47 KB.
  • Screens that need another account. Half of the app is the older person's phone, which only works when it's paired. Instead of touching real data, the capture answers that side's requests inside the browser with made-up data. Nothing reaches the server.

Was it worth it?

The first screen took a few hours. After that, each new screen is one command. The file now has 28 screens in sections, in English, at iPhone size, with editable text and auto-layout. When the code changes, I capture the screen again instead of redrawing it.

It's not perfect. A few pieces come in as pictures, and a hand-made Figma file would have cleaner components. But it starts from what the app really is, not from what the mockups said a few months ago.

The same thought is behind StackD: every component comes as React code and a Figma file that match, so design and code don't drift apart.