figma2mobile-local 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +288 -0
- package/integrity.json +4 -0
- package/loader.cjs +383 -0
- package/main.obf.cjs +1 -0
- package/package.json +30 -0
- package/plugin/dist/code.js +1 -0
- package/plugin/manifest.json +15 -0
- package/plugin/src/ui.html +682 -0
- package/skills/figma-mobile-implementation/SKILL.md +193 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: figma-mobile-implementation
|
|
3
|
+
description: Use when building an Android or iOS screen from a Figma design through the figma-mobile MCP server, and when checking that the running app actually matches the design. Covers the read order, the asset step, and the export/capture/compare verification loop.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Figma to a mobile screen, verified against the real app
|
|
7
|
+
|
|
8
|
+
The MCP server measures and reports. It does not decide architecture, does not write
|
|
9
|
+
Compose or SwiftUI, and does not tell you what to change. That is this skill's job, and
|
|
10
|
+
yours.
|
|
11
|
+
|
|
12
|
+
## Read the design
|
|
13
|
+
|
|
14
|
+
1. `ui_status` first, always. It reports whether the plugin is connected, which session is
|
|
15
|
+
active, and whether writing is allowed.
|
|
16
|
+
- **Multiple Figma tabs open (multiple sessions):** each open file is its own session with
|
|
17
|
+
its own `sessionId`. When more than one is connected, every tool call MUST pass
|
|
18
|
+
`sessionId` or it fails with `AMBIGUOUS_SESSION`. Read `sessions[]` from `ui_status`
|
|
19
|
+
(each carries `fileName`) to pick the right one, and thread that `sessionId` through
|
|
20
|
+
every import/read/export/verify call for that screen.
|
|
21
|
+
2. `ui_import_source` to pull the selected frame. Keep the returned `irId` and reuse it -
|
|
22
|
+
re-importing every turn is the most common way to waste tokens here.
|
|
23
|
+
- **Many screens at once:** don't rely on live selection (one target at a time). Use
|
|
24
|
+
`ui_import_batch` with `nodeIds` (a list of Figma links/ids) and/or `container` (a
|
|
25
|
+
Section/Page/Frame whose child frames become screens). It returns one `irId` **per
|
|
26
|
+
screen** — never a merged IR — so you can read, build, and run the visual-verify loop on
|
|
27
|
+
each screen independently, including in parallel subagents. `failed[]` lists any id that
|
|
28
|
+
was not a screen; keep going with the rest.
|
|
29
|
+
3. `ui_read_ir detail="compact"` for the structure. **Not** `detail="summary"` - the
|
|
30
|
+
summary is a flat id-to-label index for finding a node, it has no hierarchy, and
|
|
31
|
+
building UI from it produces flat, wrong output.
|
|
32
|
+
4. `ui_read_layout` when the Figma file is grouped badly - absolute children, nested
|
|
33
|
+
wrappers, meaningless layer names. It returns geometric hints with confidence and
|
|
34
|
+
numeric evidence. Hints, not instructions: you decide whether a "row" becomes a `Row`,
|
|
35
|
+
a `LazyRow`, or something else entirely.
|
|
36
|
+
5. `ui_get_node` to drill into one node instead of re-reading the screen.
|
|
37
|
+
6. `ui_read_raw` only when you suspect the IR itself is wrong. It is the escape hatch back
|
|
38
|
+
to the raw Figma measurements, and it is expensive. Do not make it your default read.
|
|
39
|
+
|
|
40
|
+
Read `figmaType` as a node's identity. `role` is a guess the server keeps for export
|
|
41
|
+
decisions - do not build UI from it.
|
|
42
|
+
|
|
43
|
+
### Consume the style, or a node that reads fine still renders wrong
|
|
44
|
+
|
|
45
|
+
The compact IR carries everything you render from, but only if you act on it:
|
|
46
|
+
|
|
47
|
+
- **`assetRef` present -> that node is an asset, never text or a shape.** Its `text` field
|
|
48
|
+
is a private-use codepoint (an SF Symbols / Material Symbols glyph) that no platform has
|
|
49
|
+
a font for - draw it yourself and you get a `?` box. Import that node as an asset target,
|
|
50
|
+
`ui_export_assets`, and reference the exported file. This is the single biggest source of
|
|
51
|
+
empty / tofu icons.
|
|
52
|
+
- **`fillOpacity < 1`** - multiply it into the colour alpha. Skip it and an 8%-white glass
|
|
53
|
+
tile becomes an opaque slab.
|
|
54
|
+
- **`fillCount > 1` / `strokeCount > 1`** - Figma stacks that many paint layers; the IR
|
|
55
|
+
carries only the first. Pull the full stack from `ui_get_node(detail="style")` and render
|
|
56
|
+
every layer.
|
|
57
|
+
- **`effectsRef` -> `ir.tokens.effects[ref]`** is a list. Stacked `INNER_SHADOW` layers
|
|
58
|
+
*are* the material (glass, neumorphism) - render all of them. A flat `fill` with no
|
|
59
|
+
effects is a rectangle; multi-fill + translucent + stacked inner shadows is one composite
|
|
60
|
+
surface, not a coloured box.
|
|
61
|
+
- **`strokeAlign`** (INSIDE/OUTSIDE/CENTER) and **`fillScaleMode`** (FILL/FIT/CROP/TILE)
|
|
62
|
+
change drawn size and image framing. Not optional.
|
|
63
|
+
|
|
64
|
+
## Assets
|
|
65
|
+
|
|
66
|
+
`ui_export_assets` writes PNG / VectorDrawable / imageset files and returns paths. Read
|
|
67
|
+
`vectorDrawable.{pathCount,xmlBytes,complexity}` in the reply rather than trusting a
|
|
68
|
+
boolean: it tells you whether the XML is worth using or whether the PNG fallback was the
|
|
69
|
+
right call. Every node carrying an `assetRef` goes through here - do not hand-draw it.
|
|
70
|
+
|
|
71
|
+
## Validate the structure before you finalize
|
|
72
|
+
|
|
73
|
+
`ui_validate { irId }` checks the IR against mobile rules: touch targets, text size,
|
|
74
|
+
colour contrast, clipping overflow, safe areas, missing a11y labels, bottom-nav overlap,
|
|
75
|
+
hardcoded widths. Run it once before you call a screen done - it catches the class of
|
|
76
|
+
mistake that a pixel diff cannot see because both the design and the app share it.
|
|
77
|
+
|
|
78
|
+
## Write the code
|
|
79
|
+
|
|
80
|
+
Yours entirely. Choose the architecture, decide what becomes a reusable Composable or
|
|
81
|
+
View, decide whether a style is inlined or pulled into the project's theme. The IR's
|
|
82
|
+
`elements` map tells you which node bodies repeat byte-for-byte - useful input for that
|
|
83
|
+
decision, not the decision itself.
|
|
84
|
+
|
|
85
|
+
### Reuse existing components, don't invent them
|
|
86
|
+
|
|
87
|
+
The MCP does not map Figma components to your code — it never says "use AppButton". That
|
|
88
|
+
decision is yours:
|
|
89
|
+
|
|
90
|
+
- Before hand-building a Button / Card / TextField, look in the target repo for an existing
|
|
91
|
+
design-system component that fits. If one clearly does, use it: pass only its public props
|
|
92
|
+
(text, variant, state, enabled, icon/image slot, value, visibility) and let the component
|
|
93
|
+
own its internal width / radius / font / padding. Do not re-specify those from the IR.
|
|
94
|
+
- If nothing clearly fits, build from native primitives using the MCP facts. Do NOT guess a
|
|
95
|
+
component name that may not exist — a wrong import is worse than honest primitives.
|
|
96
|
+
- `componentRef` in the IR only tells you "this node is an instance of Figma component X". It
|
|
97
|
+
is a signal to go look in the repo, not an instruction to use any particular class.
|
|
98
|
+
- If a component you picked keeps failing the visual diff around its region, re-check the
|
|
99
|
+
reference image and `ui_read_raw`, and consider falling back to native primitives.
|
|
100
|
+
|
|
101
|
+
### Placing exported assets — copy the paths verbatim, do NOT flatten
|
|
102
|
+
|
|
103
|
+
`ui_export_assets` writes into its own asset store (`outDir` in the response), not into your
|
|
104
|
+
project. Each written file carries a `path` under `platforms.<platform>.files[]` that ALREADY
|
|
105
|
+
encodes the correct resource folder. Copy every file to `app/src/main/<path>` keeping that
|
|
106
|
+
path byte-for-byte. The MCP does not dictate a destination beyond the resource-folder
|
|
107
|
+
structure it already put in `path`; do not invent one.
|
|
108
|
+
|
|
109
|
+
Android — the folder is not optional, it is the density/type contract; never collapse to a
|
|
110
|
+
bare `res/drawable/`:
|
|
111
|
+
- PNG → `res/drawable-<density>/name.png` (`3x` = `drawable-xxhdpi`, plus `mdpi/hdpi/xhdpi/
|
|
112
|
+
xxxhdpi` when `density_buckets`). The `-<density>` suffix MUST stay; a `xxhdpi` PNG dropped
|
|
113
|
+
into plain `drawable/` renders at the wrong size on every device.
|
|
114
|
+
- VectorDrawable → `res/drawable/name.xml` (density-independent, no suffix — and it is `.xml`,
|
|
115
|
+
never a `drawable-*` bucket).
|
|
116
|
+
- Large background → `res/drawable-nodpi/name.png`; launcher → `res/mipmap-<density>/`.
|
|
117
|
+
- Reference it as `assetMap.android.reference` (`R.drawable.<name>`) — the same base name for
|
|
118
|
+
the XML and every PNG bucket, which is how Android resolves per-density at runtime.
|
|
119
|
+
|
|
120
|
+
iOS — copy the whole `.imageset` folder (`Contents.json` + `@1x/@2x/@3x`) into your asset
|
|
121
|
+
catalog; reference with `assetMap.ios.reference` (`Image("<name>")`).
|
|
122
|
+
|
|
123
|
+
If a file lands anywhere other than the `path` the tool reported, that is an agent placement
|
|
124
|
+
bug, not an MCP one — re-copy from `outDir` preserving `path`.
|
|
125
|
+
|
|
126
|
+
### Native layout rules — translate the facts, don't eyeball them
|
|
127
|
+
|
|
128
|
+
The IR carries `layoutMode`, `layoutSizing`, `layoutPositioning`, `constraints` and bounds.
|
|
129
|
+
Map them mechanically; guessing from the picture is how spacing drifts.
|
|
130
|
+
|
|
131
|
+
**Android / Compose:**
|
|
132
|
+
- vertical auto-layout → `Column`; horizontal → `Row`; overlapping / `layoutPositioning=ABSOLUTE`
|
|
133
|
+
children → `Box`.
|
|
134
|
+
- `layoutSizing = FILL` → `fillMaxWidth` / `fillMaxHeight`; `HUG` → `wrapContent`;
|
|
135
|
+
`FIXED` → `.size(...)` / `.width().height()`.
|
|
136
|
+
- Do NOT use absolute offsets unless the node is `layoutPositioning=ABSOLUTE`. Everything else
|
|
137
|
+
is flow layout + arrangement/spacing from the auto-layout gap.
|
|
138
|
+
- Text: set fontSize, lineHeight, fontWeight, letterSpacing and color — all are in the IR.
|
|
139
|
+
- Mind modifier order: size → padding → background → clip, matching what Figma shows.
|
|
140
|
+
- Use `WindowInsets.safeDrawing` (or the specific inset) for safe area, not a hardcoded top pad.
|
|
141
|
+
- Decorative / complex vector → an exported asset from the assetMap, not hand-drawn shapes.
|
|
142
|
+
Existing repo component chosen by the agent wins; the MCP provides no component mapping.
|
|
143
|
+
|
|
144
|
+
**iOS / SwiftUI:**
|
|
145
|
+
- vertical → `VStack`; horizontal → `HStack`; overlap → `ZStack`.
|
|
146
|
+
- `FILL` → `.frame(maxWidth: .infinity)` (or `maxHeight`); `HUG` → intrinsic / `.fixedSize()`
|
|
147
|
+
when needed; `FIXED` → `.frame(width:height:)`.
|
|
148
|
+
- Text: set font, lineSpacing, tracking and color; alignment leading/center/trailing from
|
|
149
|
+
`textAlignHorizontal`.
|
|
150
|
+
- Safe area explicit (`.safeAreaInset` / respect the safe area, don't fight it).
|
|
151
|
+
- Images via `Image("name")` from the exported imageset. Existing repo component chosen by the
|
|
152
|
+
agent wins; the MCP provides no component mapping.
|
|
153
|
+
|
|
154
|
+
## Verify against the running app
|
|
155
|
+
|
|
156
|
+
An IR read correctly still becomes a wrong screen. Safe area, spacing, text size, corner
|
|
157
|
+
radius and icon size are the usual suspects, and none of them show up until you look at
|
|
158
|
+
pixels.
|
|
159
|
+
|
|
160
|
+
1. Build and run the app. Navigate to the screen yourself - `ui_capture_device_screen`
|
|
161
|
+
captures what is on screen, it does not drive the app.
|
|
162
|
+
2. Wait for the screen to settle. Animations mid-flight produce noise, not findings.
|
|
163
|
+
3. `ui_export_reference_image { irId }`
|
|
164
|
+
4. `ui_capture_device_screen { platform, irId }`
|
|
165
|
+
5. `ui_compare_images { referenceImagePath, actualImagePath, irId }` - pass `irId` or
|
|
166
|
+
regions come back with no node ids, which is most of the value gone.
|
|
167
|
+
6. Read the result:
|
|
168
|
+
- `regions[].nodeIds` - which nodes sit under each differing area. Start here.
|
|
169
|
+
- `diffOverlayPath` - open it. The shape of a difference usually says more than its
|
|
170
|
+
number.
|
|
171
|
+
- `normalize.maskedBands` - what was excluded. A difference hiding under a mask will
|
|
172
|
+
never be reported.
|
|
173
|
+
- `warnings` - `VIEWPORT_MISMATCH` means the device and the design are not the same
|
|
174
|
+
shape; fix that before reading anything else into the numbers.
|
|
175
|
+
7. Fix the nodes named in `regions`, rebuild, and run 2-6 again.
|
|
176
|
+
|
|
177
|
+
### When to stop
|
|
178
|
+
|
|
179
|
+
Suggested: `mismatchRatio < 0.02` and no single region above `0.4`.
|
|
180
|
+
|
|
181
|
+
These are this skill's thresholds, not the server's - the server deliberately has no
|
|
182
|
+
opinion about pass or fail. Tighten them for a screen that has to be pixel-exact; loosen
|
|
183
|
+
them for one with device-dependent text.
|
|
184
|
+
|
|
185
|
+
### What the numbers are not
|
|
186
|
+
|
|
187
|
+
`mismatchRatio` is the share of compared block area that differs after masking. It is not
|
|
188
|
+
a similarity percentage and not an accuracy score. Two screens can differ by 1% of area
|
|
189
|
+
and still be badly wrong if that 1% is the primary button.
|
|
190
|
+
|
|
191
|
+
The server never classifies a difference as "spacing" or "font size". Pixels do not carry
|
|
192
|
+
that information, and a confident wrong label sends you to fix the wrong line. Look at the
|
|
193
|
+
overlay, look at the nodes, decide yourself.
|