@rootnative/loupe 0.0.0-alpha.0 → 0.0.0-alpha.2

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.
@@ -0,0 +1,186 @@
1
+ ---
2
+ name: loupe
3
+ description: Check the layout of a mobile app on an Android emulator or device with the loupe tools, and get numbers in dp, not guesses from a screenshot. Use it when you check or fix how a screen looks in portrait or landscape, light or dark, LTR or RTL, near the system bars, the cutout, or the screen edges.
4
+ ---
5
+
6
+ # loupe
7
+
8
+ loupe drives an Android emulator or device and measures each screen of your
9
+ app. It gives you exact numbers: element frames, safe areas, cutouts, and
10
+ edges. Use them to say "pass" or "fail" with evidence.
11
+
12
+ Each loupe tool gives JSON. Each input field has a description in the tool's
13
+ schema, so this skill doesn't repeat them. loupe works on Android 11
14
+ (API level 30) and later.
15
+
16
+ ## Ask the user first
17
+
18
+ - Ask before you start an emulator. Don't start one on your own.
19
+ - Ask before you open an app or a link on a device, unless the user asked
20
+ for that run.
21
+ - On a real phone, give `app` in each call. loupe then reads the screen
22
+ only while that app is in front, so it never shows you another app.
23
+ - Don't change a setting that the user didn't ask for. `rotate` and
24
+ `theme` change the device, and `expo-rtl` changes the app.json of the
25
+ app. Put back what you changed: after `expo-rtl on`, run `expo-rtl off`.
26
+ `sweep` puts the orientation and the theme back itself.
27
+
28
+ ## Before the first check
29
+
30
+ 1. Run `devices`. Only a device in the state `ready` takes commands.
31
+ 2. When two or more devices are ready, give `device` (the serial or the
32
+ AVD name) in each call.
33
+ 3. Give `app` in each call that reads or touches the screen. For Expo Go,
34
+ it's `host.exp.exponent`.
35
+ 4. Run one loupe call at a time on a device. Two touches at the same time
36
+ lose events. The MCP server already runs its calls one after the other.
37
+
38
+ ## An app in Expo Go
39
+
40
+ 1. The user runs `npx expo start` in the folder of the app. loupe doesn't
41
+ start Metro. Give `port` when Metro doesn't use 8081.
42
+ 2. Open the app with `expo-open` and a route, for example `/settings`. It
43
+ warms the bundle, closes Expo Go's onboarding sheet and developer menu,
44
+ and waits until the app shows: on the route when the app has the probe,
45
+ else until the screen has text, a label or a touch and keeps still.
46
+ Then give `app` `host.exp.exponent` in each call. An animation that
47
+ never stops, or a long one, hides a screen from loupe: `expo-open`
48
+ then gives `not_idle`. A link to the root can start the animation
49
+ again, so open another route.
50
+ 3. After an edit of the app's code, run `expo-warm`, and compare its
51
+ `sha256` with the one before the edit. The same hash means that Metro
52
+ didn't see the edit. Ask the user to restart Metro with
53
+ `npx expo start --clear`.
54
+ 4. To start the app again from a clean state, run `expo-reload`. It stops
55
+ Expo Go and opens the app again, on the route that the probe shows.
56
+ With no probe, it opens the root: give `route` for another screen.
57
+ Run it also after a Metro restart or a new package: until then, Expo Go
58
+ keeps the old JavaScript.
59
+ 5. To see the app in RTL, run `expo-rtl on`. It writes `supportsRTL` and
60
+ `forcesRTL` in the app's app.json, keeps the file as it was, and opens
61
+ the app again in RTL. When you're done, run `expo-rtl off`: it puts
62
+ app.json back.
63
+
64
+ ## Units
65
+
66
+ - Each position and size is in dp, from the top-left corner of the
67
+ current orientation.
68
+ - Each reading gives `scale`: the pixels in one dp.
69
+ - Each screenshot is upright, in each orientation.
70
+
71
+ ## Check one screen
72
+
73
+ 1. Open the screen with `open-url` and its deep link (in Expo Go, with
74
+ `expo-open`). Give `waitText` (a text on that screen) or `waitStill`, so
75
+ the call ends when the screen is there.
76
+ 2. Run `check`. Read `passed`, then the findings of each rule that failed.
77
+ 3. Run `rotate` with `landscape-left`, then `check` again.
78
+ 4. Run `rotate` with `landscape-right`, then `check` again. A cutout on one
79
+ side shows only in one of the two landscapes.
80
+ 5. Run `rotate` with `portrait` to put the device back.
81
+
82
+ Take a `screenshot` when you want to see the screen, but decide with
83
+ `check`. Over MCP, the result of `screenshot` also holds the image. Give
84
+ `scale` (for example 0.5) or `crop` to make it smaller.
85
+
86
+ ## Check many screens: sweep
87
+
88
+ Give `sweep` one `url` for each screen. Add `orientation`
89
+ (`portrait,landscape-left`) and `theme` (`light,dark`) to check each
90
+ screen in each of them. Add `scroll` to check each screen again after one
91
+ scroll down. For a long list, add `reloadEvery` (for example 10) with
92
+ `app`: loupe stops the app before each 10th link, so stacked screens
93
+ don't slow it down. A restarted screen has `reloaded` in the report. In
94
+ Expo Go, add `direction` (`ltr,rtl`) to check each screen in both layout
95
+ directions. loupe sets each direction once, in app.json, and puts app.json
96
+ back at the end. Each variant name then ends with its direction:
97
+ `portrait-light-rtl`.
98
+
99
+ - The result lists each screen that failed, with each finding and its
100
+ numbers. You don't need to check those screens again.
101
+ - A sweep writes to `out` (`loupe-sweep` by default): `report.json`, a
102
+ screenshot of each screen, and a contact sheet of each variant. A red
103
+ frame on the contact sheet marks a screen that failed. Over MCP, the
104
+ result also holds each contact sheet as an image.
105
+ - A screen that loupe can't open or check gets its error in the report,
106
+ and the sweep goes on.
107
+ - A sweep can take minutes. Over MCP, it sends its progress after each
108
+ screen. When you cancel it, it stops before the next screen and puts
109
+ the orientation and the theme back. It then writes no report.
110
+
111
+ ## The rules
112
+
113
+ `check` runs each rule by default. Give `rules` (a comma list) to run
114
+ fewer.
115
+
116
+ | Rule | Fails when | What to look at |
117
+ |---|---|---|
118
+ | `inset` | An element with text, a label, or a touch sits under a system bar or the cutout, or outside the safe area. | The edge in the finding. In landscape, the left and the right insets can differ. A full-screen scrim doesn't count. |
119
+ | `overflow` | An element at a screen edge is shorter than the elements like it in its row or column: the edge cuts it. | The row or the column of the element. Let it wrap or scroll, or make its items smaller. |
120
+ | `centred` | A text with an element on each side is more than 4 dp from the centre of its container. | Centre the text in the whole bar, not in the space between the side items. Name a text with `centred`, `centredLabel`, or `centredId` to check it. |
121
+ | `touch-target` | An element that you can press is smaller than 48 × 48 dp. | From 40 dp, loupe gives a warning, not a finding: the tree doesn't show `hitSlop`. Look in the code for a `hitSlop` that makes it 48 dp. |
122
+ | `mirrored` | In RTL, an element sits where LTR puts it. | It runs only with `mirrorOf` (see below). |
123
+
124
+ To check `mirrored`:
125
+
126
+ 1. Show the screen in LTR. Run `ui` with `out` set to a file.
127
+ 2. Show the same screen in RTL, in the same orientation. In Expo Go, run
128
+ `expo-rtl on` with the route of the screen.
129
+ 3. Run `check` with `mirrorOf` set to that file.
130
+ 4. In Expo Go, run `expo-rtl off` when you're done.
131
+
132
+ ## Read a result
133
+
134
+ - `passed` is false when a rule failed. A failed check is still a
135
+ success: the data has each finding. The CLI exits with 1 for it.
136
+ - Each finding has the `element`, a `message`, and `details` in dp.
137
+ - `safeAreaSource` says where the safe area came from: `probe` (the app's
138
+ own numbers) or `dumpsys` (the system's numbers).
139
+ - A `warnings` line says where loupe isn't sure. Read it before you decide.
140
+ - After a fix, reload the app and check the same screen again, in the same
141
+ orientation.
142
+
143
+ ## The probe
144
+
145
+ `@rootnative/loupe-probe` gives loupe the app's own safe area, layout
146
+ direction, colour scheme, and route. Render `<LoupeProbe route={path} />`
147
+ once, inside your `SafeAreaProvider`. It renders nothing in a release
148
+ build. Without it, loupe takes the safe area from Android.
149
+
150
+ ## Errors
151
+
152
+ A failed call has an error `code` and a `message`. The message says what
153
+ to do. The codes:
154
+
155
+ | Code | What to do |
156
+ |---|---|
157
+ | `no_device` | Ask the user to start an emulator or to connect a phone. |
158
+ | `device_ambiguous` | Run `devices`, then give `device`. |
159
+ | `device_unavailable` | The device is offline, not authorized, or still booting. Wait, or ask the user. |
160
+ | `tool_missing` | loupe can't find adb. Ask the user to set `ANDROID_HOME`. |
161
+ | `tool_failed` | adb or Metro failed. Read the message: for a bundle, it gives Metro's error. |
162
+ | `app_not_in_front` | Another app or a dialog is in front. Run `dismiss` for a dialog or a sheet, or `foreground` for the app. |
163
+ | `not_idle` | The screen didn't keep still long enough to read it. Run `wait` with `still`, then try again. An animation that never stops, or a long one, keeps a screen from loupe: take a screenshot, wait until it ends, or open another route. |
164
+ | `element_not_found` | Run `ui`, find the element, and give its exact text, label, or id. |
165
+ | `element_ambiguous` | More than one element matches. Give its `id`. |
166
+ | `orientation_locked` | The app sets its own orientation. Check the orientations it allows. |
167
+ | `timeout` | The screen didn't get there in time. The message says whether the action ran. |
168
+ | `no_handler` | No app on the device opens that link. With no Expo Go, ask the user to install it: press "a" in `npx expo start`. |
169
+ | `no_server` | Nothing answers on the port, or it isn't Metro. Ask the user to run `npx expo start`, or give `port`. |
170
+ | `invalid_input` | Fix the input. The message names the field. |
171
+ | `unsupported` | loupe can't do this on this device or API level, or with this server. The message says why. |
172
+ | `cancelled` | The call was cancelled. loupe stopped at a safe point. |
173
+
174
+ ## The CLI
175
+
176
+ The CLI has the same commands: run `loupe <command> --help`. A field such
177
+ as `waitText` is the flag `--wait-text`. When you read the output through a
178
+ pipe, it's JSON: `{ "ok": true, "command": …, "data": … }`, or `"ok": false`
179
+ with `"error": { "code": …, "message": … }`. Exit codes: 0 passed, 1
180
+ failed, 2 a wrong command or flag, 130 cancelled.
181
+
182
+ ## Don't
183
+
184
+ - Don't decide pass or fail from a screenshot when a rule gives numbers.
185
+ - Don't run two loupe calls at the same time on one device.
186
+ - Don't leave the device turned or in another theme.