@momo-kits/native-kits 0.169.13-beta.2 → 0.169.13-beta.3

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/CLAUDE.md CHANGED
@@ -22,15 +22,18 @@ Guidance for working in this repo. Keep it accurate — update it when structure
22
22
  - `navigation/` — `NavigationContainer.kt` (**canonical entry point**), `Navigator.kt`, `Navigation.kt`, `StackScreen.kt`, `bottomtab/`, `component/`, `tracking/`.
23
23
  - `const/` — design tokens: `Theme.kt`, `Colors.kt`, `Typography.kt`, `Spacing.kt`, `Radius.kt`.
24
24
  - `layout/`, `modifier/`, `utils/`.
25
+ - `sdui/` — `SduiView(spec, modifier, onError, maxApi)`: embeddable server-driven-UI renderer (JSON spec -> kit components). No host seams: output goes only through the view's MaxApi (`maxApi`, else `LocalMaxApi`) - tracking events via `track` (Trackify), errors/warnings via `logFile` (spec-level identifiers only, deduped, capped). CornerStone / PlatformWidget are not supported: like any unknown type they draw nothing and report `sdui_node_error` (`unsupported_type`); any other child-node failure (`expr_failed`, `unknown_token`, `invalid_action`) is reported the same way, never capped. There is no click/action event: spec authors track clicks with their own `trackEvent` action. Actions use `maxApi` or `LocalMaxApi`; only typed actions exist (`type`: `startFeatureCode` | `trackEvent` | `setState`, required), an action without `type` (or with fields the runtime does not read, e.g. `code`) fails structure validation (SPEC_SHAPE); the runtime skip-and-warn guards are defence only. SduiView draws a section only: screen-level top-level keys (`header`, `footer`, `tabs`, `onMount`, `actions`, ...) fail validation. Device storage (`storage` get/set, MaxApi getItem/setItem) is not supported: such action fields fail structure validation. Expressions (`SduiExpr.kt`) follow JavaScript semantics for every supported construct, with one nullish value (null: `undefined`/missing names convert like JS null; a null optional argument counts as omitted); derived `spec.data` keys (`"{expr}"`) are re-evaluated on every read (memo only within one `evalExpr`), so they track state and repeat locals. Version: `SduiView.VERSION` (semver, set by hand, sent as `sduiVersion` on every tracking event) - bump PATCH for a renderer fix, MINOR for a new node / prop / action, MAJOR when a spec that used to work no longer does; `SduiView.RENDER_VERSION` is the feature level checked against `meta.minRenderVersion`. Tests: `compose/src/androidUnitTest/.../sdui/` (read the gallery/block specs from `sample/shared/.../composeResources/files/sdui/`).
25
26
  - `platform/` — `Platform.kt` `expect` declarations, actualized in `androidMain` / `iosMain` (`Platform.android.kt`, `Platform.ios.kt`).
26
27
 
27
28
  ## Build & verify
28
29
 
29
- No unit-test suite is configured. Validate changes by compiling the relevant target(s); use the sample app for visual checks.
30
+ The only unit tests are the SDUI ones (`androidUnitTest`); validate everything else by compiling the relevant target(s) and use the sample app for visual checks (the **SDUI** entry lists every bundled spec).
30
31
 
31
32
  ```bash
32
33
  ./gradlew :compose:compileCommonMainKotlinMetadata # validate commonMain (fast, do this first)
33
34
  ./gradlew :compose:compileDebugKotlinAndroid # Android target
35
+ ./gradlew :compose:testDebugUnitTest # SDUI unit tests (537)
36
+ scripts/sdui-visual/run.sh baseline|check # SDUI visual regression on the emulator (see scripts/sdui-visual/README.md)
34
37
  ./gradlew :compose:linkDebugFrameworkIosSimulatorArm64 # iOS framework (slow)
35
38
  ./gradlew :sample:androidApp:installDebug # run demo on device/emulator
36
39
  ```
@@ -250,11 +250,7 @@ struct TabItemContent: View {
250
250
  }
251
251
  }
252
252
 
253
- /// Text badges keep 5 characters, then "..." ("Khám phá" -> "Khám...").
254
- private let badgeMaxChars = 5
255
-
256
- /// Badge value shown on a tab: nil hides it, "" is a dot, numbers cap at 99+ ("0" hides it, RN parity),
257
- /// text keeps its first 5 characters.
253
+ /// Badge value shown on a tab: nil hides it, "" is a dot, numbers cap at 99+ ("0" hides it, RN parity).
258
254
  func tabBadgeLabel(_ item: BottomTabItem) -> String? {
259
255
  guard let label = item.badgeLabel else { return item.showDot ? "" : nil }
260
256
  if label.isEmpty { return "" }
@@ -263,9 +259,7 @@ func tabBadgeLabel(_ item: BottomTabItem) -> String? {
263
259
  if value == 0 { return item.showDot ? "" : nil }
264
260
  return value > 99 ? "99+" : label
265
261
  }
266
- guard label.count > badgeMaxChars else { return label }
267
- let head = String(label.prefix(badgeMaxChars))
268
- return head.trimmingCharacters(in: .whitespaces) + "..."
262
+ return label
269
263
  }
270
264
 
271
265
  /// 24 icon, active and inactive tints cross-faded; badges hang off it: dot at 16/-2, label badge at
@@ -320,12 +314,8 @@ private struct TabBadge: View {
320
314
  .scaleSizeMaxRate(1)
321
315
  .padding(.horizontal, Spacing.XS)
322
316
  .frame(minWidth: 16, maxWidth: TabBarMetrics.badgeMaxWidth, minHeight: 16, maxHeight: 16)
323
- // the ring sits under the label: an overlay stroke would paint over the text
324
- .background(
325
- Capsule()
326
- .fill(isNumber ? theme.colors.error.primary : theme.colors.warning.primary)
327
- .overlay(Capsule().strokeBorder(theme.colors.background.surface, lineWidth: 1))
328
- )
317
+ .background(Capsule().fill(isNumber ? theme.colors.error.primary : theme.colors.warning.primary))
318
+ .overlay(Capsule().strokeBorder(theme.colors.background.surface, lineWidth: 1))
329
319
  }
330
320
  }
331
321
 
@@ -1,6 +1,6 @@
1
1
  Pod::Spec.new do |s|
2
2
  s.name = 'MoMoUIKits'
3
- s.version = '0.169.13-beta.2'
3
+ s.version = '0.169.13-beta.3'
4
4
  s.summary = 'MoMoUIKits for iOS'
5
5
  s.homepage = 'https://momo.vn'
6
6
  s.license = { :type => 'MIT' }
@@ -1,6 +1,6 @@
1
1
  Pod::Spec.new do |s|
2
2
  s.name = 'MoMoUIKitsDemo'
3
- s.version = '0.169.13-beta.2'
3
+ s.version = '0.169.13-beta.3'
4
4
  s.summary = 'Demo browser for MoMoUIKits SwiftUI components'
5
5
  s.homepage = 'https://momo.vn'
6
6
  s.license = { :type => 'MIT' }
@@ -89,18 +89,7 @@ private func ctaLottie(_ animation: LottieAnimation?, offset: CGFloat) -> some V
89
89
  }
90
90
  private let badges: [(String, String?)] = [
91
91
  ("Không", nil), ("Dot \"\"", ""), ("\"0\"", "0"), ("\"5\"", "5"),
92
- ("\"1999\"", "1999"), ("\"Mới\"", "Mới"),
93
- ]
94
-
95
- /// "Chữ dài" picks one of these at random on every tap.
96
- private let longBadges = [
97
- "Khuyến mãi lớn",
98
- "Khám phá ngay",
99
- "Ưu đãi cực sốc",
100
- "Quà tặng hấp dẫn",
101
- "Hoàn tiền mỗi ngày",
102
- "Siêu sale cuối tuần",
103
- "Thanh toán hóa đơn",
92
+ ("\"1999\"", "1999"), ("\"Mới\"", "Mới"), ("Chữ dài", "Khuyến mãi lớn"),
104
93
  ]
105
94
 
106
95
  struct BottomTabDemoContent: View {
@@ -186,12 +175,10 @@ private struct TabContent: View {
186
175
  Section(title: "Tab đang mở · \(name)") {
187
176
  IconOptions(title: "icon", icons: icons, value: tab.icon) { icon in updateTab { $0.icon = icon } }
188
177
  Options(title: "badgeLabel",
189
- hint: "\"\" là dot, \"0\" ẩn badge, số > 99 hiện 99+, chữ > 5 ký tự cắt thành 5 ký tự + \"...\"",
178
+ hint: "\"\" là dot, \"0\" ẩn badge, số > 99 hiện 99+, chữ dài bị cắt ở 58",
190
179
  options: badges.map { title, value in
191
180
  Option(title: title, selected: tab.badgeLabel == value) { updateTab { $0.badgeLabel = value } }
192
- } + [Option(title: "Chữ dài", selected: longBadges.contains(tab.badgeLabel ?? "")) {
193
- updateTab { $0.badgeLabel = longBadges.randomElement() }
194
- }])
181
+ })
195
182
  Options(title: "showDot",
196
183
  hint: "Hiện dot khi không có badgeLabel hoặc badgeLabel là \"0\"",
197
184
  options: yesNo(tab.showDot) { value in updateTab { $0.showDot = value } })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.169.13-beta.2",
3
+ "version": "0.169.13-beta.3",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "publish:local": "bash publish.sh local"
@@ -0,0 +1,65 @@
1
+ # File: scripts/sdui-visual/diff.py
2
+ # Created At: 2026-11-10 15:30:00 +07:00
3
+ # Created By: AI
4
+ # AI Agent: Claude Code
5
+ # Model: claude-opus-5-5
6
+ """Pixel-diff two capture folders. usage: diff.py <a> <b> <diffdir> [--noise <baseline2 dir>]
7
+ Status bar (top 110 px, demo-mode clock is fixed but kept out anyway) is excluded. With --noise, pixels that differed
8
+ between the two baseline runs of the same image are masked (inherent noise: animations, image loading)."""
9
+ import json, os, sys
10
+ from PIL import Image, ImageChops
11
+
12
+ STATUS = 110
13
+
14
+
15
+ def load(p):
16
+ return Image.open(p).convert("RGB")
17
+
18
+
19
+ def mask_of(a, b):
20
+ d = ImageChops.difference(a, b).convert("L").point(lambda v: 255 if v else 0)
21
+ return d
22
+
23
+
24
+ def main():
25
+ a, b, out = sys.argv[1:4]
26
+ noise_dir = sys.argv[sys.argv.index("--noise") + 1] if "--noise" in sys.argv else None
27
+ os.makedirs(out, exist_ok=True)
28
+ rows = []
29
+ names = sorted(set(os.listdir(a)) | set(os.listdir(b)))
30
+ for n in names:
31
+ if not n.endswith(".png"):
32
+ continue
33
+ if n not in os.listdir(a) or n not in os.listdir(b):
34
+ rows.append((n, "MISSING", -1, -1, -1)); continue
35
+ ia, ib = load(f"{a}/{n}"), load(f"{b}/{n}")
36
+ if ia.size != ib.size:
37
+ rows.append((n, "SIZE", -1, -1, -1)); continue
38
+ w, h = ia.size
39
+ d = mask_of(ia, ib)
40
+ d.paste(0, (0, 0, w, STATUS))
41
+ raw = d.width * d.height - d.histogram()[0]
42
+ masked = raw
43
+ if noise_dir and os.path.exists(f"{noise_dir}/{n}"):
44
+ nz = mask_of(ia, load(f"{noise_dir}/{n}"))
45
+ keep = ImageChops.subtract(d, nz)
46
+ masked = keep.width * keep.height - keep.histogram()[0]
47
+ else:
48
+ keep = d
49
+ total = w * (h - STATUS)
50
+ if raw:
51
+ vis = ib.copy()
52
+ red = Image.new("RGB", ib.size, (255, 0, 0))
53
+ vis.paste(red, (0, 0), keep if masked else d)
54
+ vis.save(f"{out}/{n}")
55
+ rows.append((n, "OK", raw, masked, 100.0 * masked / total))
56
+ zero = sum(1 for r in rows if r[1] == "OK" and r[3] == 0)
57
+ for r in rows:
58
+ if r[1] != "OK" or r[2]:
59
+ print(f"{r[0]:40s} {r[1]:7s} raw={r[2]} beyond_noise={r[3]} ({r[4]:.4f}%)")
60
+ print(f"images={len(rows)} zero_beyond_noise={zero} raw_zero={sum(1 for r in rows if r[1]=='OK' and r[2]==0)}")
61
+ json.dump(rows, open(f"{out}/summary.json", "w"), indent=0)
62
+ sys.exit(0 if zero == len(rows) else 1)
63
+
64
+
65
+ main()
@@ -0,0 +1,234 @@
1
+ # File: scripts/sdui-visual/drive.py
2
+ # Created At: 2026-11-10 15:30:00 +07:00
3
+ # Created By: AI
4
+ # AI Agent: Claude Code
5
+ # Model: claude-opus-5-5
6
+ """Drive the sample app: open every bundled SDUI spec, capture pages + interaction states.
7
+
8
+ usage: drive.py <outdir> [--plan plan.json] [--record plan.json] [--only a,b]
9
+ --record: discover page counts + tap coordinates and save them (baseline run)
10
+ --plan: replay exactly the page counts + taps from a recorded plan
11
+ (a spec missing from the plan is discovered on the fly, not saved)
12
+ """
13
+ import io, json, re, subprocess, sys, time, os
14
+ from PIL import Image, ImageChops
15
+
16
+ PKG = "com.myapplication.MyApplication"
17
+ ACT = "com.myapplication.MainActivity"
18
+ USAGE_KT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..",
19
+ "sample/shared/src/commonMain/kotlin/screens/SduiUsage.kt")
20
+
21
+
22
+ def spec_list(name):
23
+ """A spec list (GALLERY / BLOCKS / SHOWCASE) exactly as the sample app shows it, read from SduiUsage.kt."""
24
+ src = open(USAGE_KT, encoding="utf-8").read()
25
+ m = re.search(r"val " + name + r" = listOf\(([^)]*)\)", src)
26
+ if not m:
27
+ raise SystemExit(f"{name} list not found in {USAGE_KT}")
28
+ return re.findall(r'"([^"]+)"', m.group(1))
29
+
30
+
31
+ # same order as the app's list screen
32
+ ALL = spec_list("SHOWCASE") + spec_list("BLOCKS") + spec_list("GALLERY")
33
+ # specs with state-changing actions (setState) that can be driven by taps (inputs need typing: skipped)
34
+ TAPPABLE = ["button", "carousel", "check-box", "chip", "collapse", "icon-button", "information", "popup-notify", "popup-promotion",
35
+ "radio", "rating", "slider", "stepper", "steps", "suggest-action", "swipe", "switch", "tab-view", "title",
36
+ "touchable-opacity", "uploader", "community", "paylater_benefits", "paylater_history"]
37
+ MAX_TAPS = 4
38
+ SETTLE = 3.0
39
+
40
+
41
+ def sh(*a, capture=True):
42
+ return subprocess.run(["adb", *a], capture_output=capture, check=False).stdout
43
+
44
+
45
+ def shot():
46
+ return Image.open(io.BytesIO(sh("exec-out", "screencap", "-p"))).convert("RGB")
47
+
48
+
49
+ def dump():
50
+ for _ in range(3):
51
+ sh("shell", "uiautomator", "dump", "/sdcard/ui.xml")
52
+ x = sh("shell", "cat", "/sdcard/ui.xml").decode("utf-8", "replace")
53
+ if "<hierarchy" in x:
54
+ return x
55
+ time.sleep(0.5)
56
+ return ""
57
+
58
+
59
+ NODE = re.compile(r'<node [^>]*>')
60
+ def nodes(xml):
61
+ out = []
62
+ for m in NODE.finditer(xml):
63
+ s = m.group(0)
64
+ g = lambda k: (re.search(k + r'="([^"]*)"', s) or [None, ""])[1]
65
+ b = re.match(r'\[(\d+),(\d+)\]\[(\d+),(\d+)\]', g("bounds"))
66
+ if not b:
67
+ continue
68
+ x1, y1, x2, y2 = map(int, b.groups())
69
+ out.append(dict(text=g("text"), desc=g("content-desc"), clickable=g("clickable") == "true", b=(x1, y1, x2, y2)))
70
+ return out
71
+
72
+
73
+ def tap(x, y):
74
+ sh("shell", "input", "tap", str(x), str(y))
75
+
76
+
77
+ def swipe_up(dist=1000, dur=1200):
78
+ sh("shell", "input", "swipe", "540", "1900", "540", str(1900 - dist), str(dur))
79
+
80
+
81
+ def swipe_down(dist=1000, dur=300):
82
+ sh("shell", "input", "swipe", "540", "700", "540", str(700 + dist), str(dur))
83
+
84
+
85
+ def find_text(name, tries=14, up=True):
86
+ for _ in range(tries):
87
+ for n in nodes(dump()):
88
+ if n["text"] == name and 250 < (n["b"][1] + n["b"][3]) // 2 < 2250:
89
+ return n
90
+ if up:
91
+ swipe_up(700, 600)
92
+ else:
93
+ swipe_down(1500, 300)
94
+ time.sleep(0.6)
95
+ return None
96
+
97
+
98
+ def launch_to_list():
99
+ sh("shell", "am", "force-stop", PKG)
100
+ sh("shell", "am", "start", "-n", f"{PKG}/{ACT}")
101
+ time.sleep(4)
102
+ n = find_text("SDUI", tries=25)
103
+ if not n:
104
+ raise SystemExit("SDUI entry not found")
105
+ x1, y1, x2, y2 = n["b"]
106
+ tap((x1 + x2) // 2, (y1 + y2) // 2)
107
+ time.sleep(2)
108
+
109
+
110
+ def to_top():
111
+ for _ in range(6):
112
+ swipe_down(1600, 200)
113
+ time.sleep(0.8)
114
+
115
+
116
+ def open_spec(name):
117
+ to_top()
118
+ n = find_text(name, tries=14)
119
+ if not n:
120
+ raise RuntimeError(f"spec {name} not found in list")
121
+ x1, y1, x2, y2 = n["b"]
122
+ tap((x1 + x2) // 2, (y1 + y2) // 2)
123
+ time.sleep(SETTLE)
124
+
125
+
126
+ def back():
127
+ sh("shell", "input", "keyevent", "4")
128
+ time.sleep(1.2)
129
+
130
+
131
+ EXTRA = {
132
+ "carousel": [["hswipe", 900, 543, 150, 400], ["hswipe", 900, 543, 150, 400]],
133
+ "slider": [["hswipe", 257, 463, 500, 800]],
134
+ "swipe": [["hswipe", 900, 520, 300, 800], ["hswipe", 200, 770, 800, 800]],
135
+ }
136
+
137
+
138
+ def act(a):
139
+ if a[0] == "tap":
140
+ tap(a[1], a[2])
141
+ elif a[0] == "scroll":
142
+ swipe_up(); time.sleep(0.3)
143
+ elif a[0] == "hswipe":
144
+ sh("shell", "input", "swipe", str(a[1]), str(a[2]), str(a[3]), str(a[2]), str(a[4]))
145
+
146
+
147
+ def same(a, b):
148
+ return ImageChops.difference(a, b).getbbox() is None
149
+
150
+
151
+ def run(outdir, plan, record_path, only):
152
+ os.makedirs(outdir, exist_ok=True)
153
+ launch_to_list()
154
+ new_plan = {}
155
+ for name in ALL:
156
+ if only and name not in only:
157
+ continue
158
+ entry = (plan or {}).get(name)
159
+ t0 = time.time()
160
+ # ---- pages
161
+ open_spec(name)
162
+ pages = []
163
+ img = shot(); img.save(f"{outdir}/{name}-p0.png"); pages.append(img)
164
+ if entry is not None:
165
+ for p in range(1, entry["pages"]):
166
+ swipe_up(); time.sleep(1.5)
167
+ img = shot(); img.save(f"{outdir}/{name}-p{p}.png")
168
+ else:
169
+ for p in range(1, 10):
170
+ swipe_up(); time.sleep(1.5)
171
+ img = shot()
172
+ if same(img, pages[-1]):
173
+ break
174
+ img.save(f"{outdir}/{name}-p{p}.png"); pages.append(img)
175
+ npages = entry["pages"] if entry is not None else len(pages)
176
+ back()
177
+ # ---- interaction states
178
+ taps = []
179
+ if name in TAPPABLE:
180
+ open_spec(name)
181
+ if entry is not None:
182
+ taps = entry["taps"]
183
+ for k, a in enumerate(taps):
184
+ act(a)
185
+ if a[0] == "scroll":
186
+ if k + 1 < len(taps) and taps[k + 1][0] != "scroll":
187
+ time.sleep(1.5)
188
+ continue
189
+ time.sleep(1.8)
190
+ shot().save(f"{outdir}/{name}-tap{k}.png")
191
+ else:
192
+ k = 0
193
+ for pg in range(npages if npages > 1 else 1):
194
+ if pg > 0 and pg != npages - 1:
195
+ continue
196
+ if pg > 0:
197
+ for _ in range(npages - 1):
198
+ a = ["scroll"]; act(a); taps.append(a)
199
+ time.sleep(1.5)
200
+ seen = set(); n_here = 0
201
+ for n in [n for n in nodes(dump()) if n["clickable"] and n["b"][1] > 300 and n["b"][3] < 2250]:
202
+ c = ((n["b"][0] + n["b"][2]) // 2, (n["b"][1] + n["b"][3]) // 2)
203
+ if c in seen:
204
+ continue
205
+ seen.add(c)
206
+ a = ["tap", c[0], c[1]]; act(a); taps.append(a); time.sleep(1.8)
207
+ shot().save(f"{outdir}/{name}-tap{len(taps) - 1}.png")
208
+ n_here += 1
209
+ if n_here >= MAX_TAPS:
210
+ break
211
+ for a in EXTRA.get(name, []):
212
+ act(a); taps.append(a); time.sleep(1.8)
213
+ shot().save(f"{outdir}/{name}-tap{len(taps) - 1}.png")
214
+ back()
215
+ # a tap may have opened a popup / modal: make sure we are back on the list
216
+ if not find_text(name, tries=1):
217
+ back()
218
+ new_plan[name] = {"pages": npages, "taps": taps}
219
+ print(f"{name}: pages={npages} taps={len(taps)} ({time.time() - t0:.1f}s)", flush=True)
220
+ if record_path:
221
+ json.dump(new_plan, open(record_path, "w"), indent=1)
222
+
223
+
224
+ if __name__ == "__main__":
225
+ args = sys.argv[1:]
226
+ out = args[0]
227
+ plan = rec = None; only = None
228
+ if "--plan" in args:
229
+ plan = json.load(open(args[args.index("--plan") + 1]))
230
+ if "--record" in args:
231
+ rec = args[args.index("--record") + 1]
232
+ if "--only" in args:
233
+ only = set(args[args.index("--only") + 1].split(","))
234
+ run(out, plan, rec, only)
@@ -0,0 +1,713 @@
1
+ {
2
+ "paylater_benefits": {
3
+ "pages": 2,
4
+ "taps": [
5
+ [
6
+ "tap",
7
+ 985,
8
+ 490
9
+ ],
10
+ [
11
+ "tap",
12
+ 826,
13
+ 1983
14
+ ],
15
+ [
16
+ "scroll"
17
+ ],
18
+ [
19
+ "tap",
20
+ 826,
21
+ 1594
22
+ ],
23
+ [
24
+ "tap",
25
+ 819,
26
+ 1900
27
+ ],
28
+ [
29
+ "tap",
30
+ 975,
31
+ 1900
32
+ ]
33
+ ]
34
+ },
35
+ "paylater_bills": {
36
+ "pages": 1,
37
+ "taps": []
38
+ },
39
+ "paylater_history": {
40
+ "pages": 1,
41
+ "taps": [
42
+ [
43
+ "tap",
44
+ 540,
45
+ 475
46
+ ],
47
+ [
48
+ "tap",
49
+ 165,
50
+ 611
51
+ ],
52
+ [
53
+ "tap",
54
+ 411,
55
+ 611
56
+ ],
57
+ [
58
+ "tap",
59
+ 704,
60
+ 611
61
+ ]
62
+ ]
63
+ },
64
+ "paylater_overview": {
65
+ "pages": 2,
66
+ "taps": []
67
+ },
68
+ "buy_insurance": {
69
+ "pages": 1,
70
+ "taps": []
71
+ },
72
+ "community": {
73
+ "pages": 1,
74
+ "taps": [
75
+ [
76
+ "tap",
77
+ 146,
78
+ 460
79
+ ],
80
+ [
81
+ "tap",
82
+ 340,
83
+ 460
84
+ ],
85
+ [
86
+ "tap",
87
+ 557,
88
+ 460
89
+ ],
90
+ [
91
+ "tap",
92
+ 877,
93
+ 460
94
+ ]
95
+ ]
96
+ },
97
+ "pay_premium": {
98
+ "pages": 1,
99
+ "taps": []
100
+ },
101
+ "avatar": {
102
+ "pages": 1,
103
+ "taps": []
104
+ },
105
+ "badge-ribbon": {
106
+ "pages": 1,
107
+ "taps": []
108
+ },
109
+ "badge": {
110
+ "pages": 1,
111
+ "taps": []
112
+ },
113
+ "button": {
114
+ "pages": 2,
115
+ "taps": [
116
+ [
117
+ "tap",
118
+ 540,
119
+ 500
120
+ ],
121
+ [
122
+ "tap",
123
+ 540,
124
+ 709
125
+ ],
126
+ [
127
+ "tap",
128
+ 540,
129
+ 918
130
+ ],
131
+ [
132
+ "tap",
133
+ 540,
134
+ 1127
135
+ ],
136
+ [
137
+ "scroll"
138
+ ],
139
+ [
140
+ "tap",
141
+ 540,
142
+ 488
143
+ ],
144
+ [
145
+ "tap",
146
+ 540,
147
+ 697
148
+ ],
149
+ [
150
+ "tap",
151
+ 540,
152
+ 906
153
+ ],
154
+ [
155
+ "tap",
156
+ 540,
157
+ 1115
158
+ ]
159
+ ]
160
+ },
161
+ "card": {
162
+ "pages": 1,
163
+ "taps": []
164
+ },
165
+ "carousel": {
166
+ "pages": 1,
167
+ "taps": [
168
+ [
169
+ "hswipe",
170
+ 900,
171
+ 543,
172
+ 150,
173
+ 400
174
+ ],
175
+ [
176
+ "hswipe",
177
+ 900,
178
+ 543,
179
+ 150,
180
+ 400
181
+ ]
182
+ ]
183
+ },
184
+ "check-box": {
185
+ "pages": 1,
186
+ "taps": [
187
+ [
188
+ "tap",
189
+ 69,
190
+ 438
191
+ ],
192
+ [
193
+ "tap",
194
+ 69,
195
+ 538
196
+ ],
197
+ [
198
+ "tap",
199
+ 69,
200
+ 674
201
+ ],
202
+ [
203
+ "tap",
204
+ 69,
205
+ 784
206
+ ]
207
+ ]
208
+ },
209
+ "chip": {
210
+ "pages": 1,
211
+ "taps": [
212
+ [
213
+ "tap",
214
+ 121,
215
+ 483
216
+ ],
217
+ [
218
+ "tap",
219
+ 332,
220
+ 483
221
+ ],
222
+ [
223
+ "tap",
224
+ 112,
225
+ 647
226
+ ],
227
+ [
228
+ "tap",
229
+ 297,
230
+ 647
231
+ ]
232
+ ]
233
+ },
234
+ "collapse": {
235
+ "pages": 1,
236
+ "taps": [
237
+ [
238
+ "tap",
239
+ 540,
240
+ 490
241
+ ],
242
+ [
243
+ "tap",
244
+ 540,
245
+ 616
246
+ ],
247
+ [
248
+ "tap",
249
+ 540,
250
+ 742
251
+ ],
252
+ [
253
+ "tap",
254
+ 540,
255
+ 948
256
+ ]
257
+ ]
258
+ },
259
+ "divider": {
260
+ "pages": 1,
261
+ "taps": []
262
+ },
263
+ "icon-button": {
264
+ "pages": 1,
265
+ "taps": [
266
+ [
267
+ "tap",
268
+ 105,
269
+ 500
270
+ ],
271
+ [
272
+ "tap",
273
+ 252,
274
+ 500
275
+ ],
276
+ [
277
+ "tap",
278
+ 399,
279
+ 500
280
+ ],
281
+ [
282
+ "tap",
283
+ 546,
284
+ 500
285
+ ]
286
+ ]
287
+ },
288
+ "icon": {
289
+ "pages": 1,
290
+ "taps": []
291
+ },
292
+ "image-background": {
293
+ "pages": 1,
294
+ "taps": []
295
+ },
296
+ "image": {
297
+ "pages": 1,
298
+ "taps": []
299
+ },
300
+ "information": {
301
+ "pages": 1,
302
+ "taps": [
303
+ [
304
+ "tap",
305
+ 985,
306
+ 490
307
+ ],
308
+ [
309
+ "tap",
310
+ 540,
311
+ 597
312
+ ],
313
+ [
314
+ "tap",
315
+ 985,
316
+ 974
317
+ ],
318
+ [
319
+ "tap",
320
+ 985,
321
+ 1208
322
+ ]
323
+ ]
324
+ },
325
+ "input-drop-down": {
326
+ "pages": 1,
327
+ "taps": []
328
+ },
329
+ "input-money": {
330
+ "pages": 1,
331
+ "taps": []
332
+ },
333
+ "input-otp": {
334
+ "pages": 1,
335
+ "taps": []
336
+ },
337
+ "input-phone-number": {
338
+ "pages": 1,
339
+ "taps": []
340
+ },
341
+ "input-search": {
342
+ "pages": 1,
343
+ "taps": []
344
+ },
345
+ "input-text-area": {
346
+ "pages": 1,
347
+ "taps": []
348
+ },
349
+ "input": {
350
+ "pages": 2,
351
+ "taps": []
352
+ },
353
+ "item": {
354
+ "pages": 1,
355
+ "taps": []
356
+ },
357
+ "loader": {
358
+ "pages": 1,
359
+ "taps": []
360
+ },
361
+ "pagination": {
362
+ "pages": 1,
363
+ "taps": []
364
+ },
365
+ "popup-notify": {
366
+ "pages": 2,
367
+ "taps": [
368
+ [
369
+ "tap",
370
+ 333,
371
+ 733
372
+ ],
373
+ [
374
+ "tap",
375
+ 746,
376
+ 733
377
+ ],
378
+ [
379
+ "tap",
380
+ 540,
381
+ 1277
382
+ ],
383
+ [
384
+ "tap",
385
+ 540,
386
+ 1761
387
+ ],
388
+ [
389
+ "scroll"
390
+ ],
391
+ [
392
+ "tap",
393
+ 540,
394
+ 495
395
+ ],
396
+ [
397
+ "tap",
398
+ 540,
399
+ 979
400
+ ],
401
+ [
402
+ "tap",
403
+ 540,
404
+ 1100
405
+ ],
406
+ [
407
+ "tap",
408
+ 1006,
409
+ 688
410
+ ]
411
+ ]
412
+ },
413
+ "popup-promotion": {
414
+ "pages": 1,
415
+ "taps": [
416
+ [
417
+ "tap",
418
+ 540,
419
+ 1033
420
+ ],
421
+ [
422
+ "tap",
423
+ 541,
424
+ 1754
425
+ ]
426
+ ]
427
+ },
428
+ "progress-info": {
429
+ "pages": 2,
430
+ "taps": []
431
+ },
432
+ "radio": {
433
+ "pages": 1,
434
+ "taps": [
435
+ [
436
+ "tap",
437
+ 135,
438
+ 438
439
+ ],
440
+ [
441
+ "tap",
442
+ 135,
443
+ 538
444
+ ],
445
+ [
446
+ "tap",
447
+ 134,
448
+ 609
449
+ ],
450
+ [
451
+ "tap",
452
+ 209,
453
+ 820
454
+ ]
455
+ ]
456
+ },
457
+ "rating": {
458
+ "pages": 1,
459
+ "taps": [
460
+ [
461
+ "tap",
462
+ 51,
463
+ 472
464
+ ],
465
+ [
466
+ "tap",
467
+ 125,
468
+ 472
469
+ ],
470
+ [
471
+ "tap",
472
+ 199,
473
+ 472
474
+ ],
475
+ [
476
+ "tap",
477
+ 273,
478
+ 472
479
+ ]
480
+ ]
481
+ },
482
+ "screen": {
483
+ "pages": 1,
484
+ "taps": []
485
+ },
486
+ "scroll-view": {
487
+ "pages": 1,
488
+ "taps": []
489
+ },
490
+ "section": {
491
+ "pages": 1,
492
+ "taps": []
493
+ },
494
+ "skeleton": {
495
+ "pages": 1,
496
+ "taps": []
497
+ },
498
+ "slider": {
499
+ "pages": 1,
500
+ "taps": [
501
+ [
502
+ "hswipe",
503
+ 257,
504
+ 463,
505
+ 500,
506
+ 800
507
+ ]
508
+ ]
509
+ },
510
+ "stepper": {
511
+ "pages": 1,
512
+ "taps": [
513
+ [
514
+ "tap",
515
+ 90,
516
+ 485
517
+ ],
518
+ [
519
+ "tap",
520
+ 289,
521
+ 485
522
+ ],
523
+ [
524
+ "tap",
525
+ 489,
526
+ 485
527
+ ],
528
+ [
529
+ "tap",
530
+ 79,
531
+ 724
532
+ ]
533
+ ]
534
+ },
535
+ "steps": {
536
+ "pages": 2,
537
+ "taps": [
538
+ [
539
+ "scroll"
540
+ ]
541
+ ]
542
+ },
543
+ "suggest-action": {
544
+ "pages": 1,
545
+ "taps": [
546
+ [
547
+ "tap",
548
+ 852,
549
+ 506
550
+ ],
551
+ [
552
+ "tap",
553
+ 975,
554
+ 507
555
+ ],
556
+ [
557
+ "tap",
558
+ 852,
559
+ 727
560
+ ],
561
+ [
562
+ "tap",
563
+ 975,
564
+ 728
565
+ ]
566
+ ]
567
+ },
568
+ "swipe": {
569
+ "pages": 1,
570
+ "taps": [
571
+ [
572
+ "tap",
573
+ 964,
574
+ 521
575
+ ],
576
+ [
577
+ "tap",
578
+ 115,
579
+ 772
580
+ ],
581
+ [
582
+ "tap",
583
+ 262,
584
+ 772
585
+ ],
586
+ [
587
+ "hswipe",
588
+ 900,
589
+ 520,
590
+ 300,
591
+ 800
592
+ ],
593
+ [
594
+ "hswipe",
595
+ 200,
596
+ 770,
597
+ 800,
598
+ 800
599
+ ]
600
+ ]
601
+ },
602
+ "switch": {
603
+ "pages": 1,
604
+ "taps": [
605
+ [
606
+ "tap",
607
+ 89,
608
+ 464
609
+ ],
610
+ [
611
+ "tap",
612
+ 213,
613
+ 461
614
+ ],
615
+ [
616
+ "tap",
617
+ 89,
618
+ 672
619
+ ],
620
+ [
621
+ "tap",
622
+ 213,
623
+ 669
624
+ ]
625
+ ]
626
+ },
627
+ "tab-view": {
628
+ "pages": 1,
629
+ "taps": [
630
+ [
631
+ "tap",
632
+ 208,
633
+ 526
634
+ ],
635
+ [
636
+ "tap",
637
+ 540,
638
+ 526
639
+ ],
640
+ [
641
+ "tap",
642
+ 872,
643
+ 526
644
+ ],
645
+ [
646
+ "tap",
647
+ 152,
648
+ 762
649
+ ]
650
+ ]
651
+ },
652
+ "tag": {
653
+ "pages": 1,
654
+ "taps": []
655
+ },
656
+ "text": {
657
+ "pages": 1,
658
+ "taps": []
659
+ },
660
+ "title": {
661
+ "pages": 1,
662
+ "taps": [
663
+ [
664
+ "tap",
665
+ 989,
666
+ 992
667
+ ]
668
+ ]
669
+ },
670
+ "touchable-opacity": {
671
+ "pages": 1,
672
+ "taps": [
673
+ [
674
+ "tap",
675
+ 540,
676
+ 493
677
+ ]
678
+ ]
679
+ },
680
+ "trust-banner": {
681
+ "pages": 1,
682
+ "taps": []
683
+ },
684
+ "uploader": {
685
+ "pages": 1,
686
+ "taps": [
687
+ [
688
+ "tap",
689
+ 126,
690
+ 521
691
+ ],
692
+ [
693
+ "tap",
694
+ 126,
695
+ 772
696
+ ],
697
+ [
698
+ "tap",
699
+ 315,
700
+ 772
701
+ ],
702
+ [
703
+ "tap",
704
+ 373,
705
+ 714
706
+ ]
707
+ ]
708
+ },
709
+ "view": {
710
+ "pages": 1,
711
+ "taps": []
712
+ }
713
+ }
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env bash
2
+ # File: scripts/sdui-visual/run.sh
3
+ # Created At: 2026-11-10 15:30:00 +07:00
4
+ # Created By: AI
5
+ # AI Agent: Claude Code
6
+ # Model: claude-opus-5-5
7
+ #
8
+ # SDUI visual regression on the Android emulator: captures every SDUI spec of the sample app (pages + tap states)
9
+ # and pixel-diffs it against a baseline taken before a change.
10
+ #
11
+ # scripts/sdui-visual/run.sh baseline [--twice] capture the baseline (before changing code); --twice also learns noise
12
+ # scripts/sdui-visual/run.sh check capture again and diff against the baseline
13
+ # scripts/sdui-visual/run.sh record re-discover page counts + tap coordinates into plan.json
14
+ #
15
+ # Output: build/sdui-visual/{baseline,baseline2,check,diff}/ (git-ignored). Needs adb, the emulator, uv.
16
+ set -euo pipefail
17
+
18
+ MODE="${1:-}"
19
+ HERE="$(cd "$(dirname "$0")" && pwd)"
20
+ ROOT="$(cd "$HERE/../.." && pwd)"
21
+ OUT="$ROOT/build/sdui-visual"
22
+ AVD="${SDUI_AVD:-momo_api36}"
23
+ PY=(uv run -q --with pillow python)
24
+ STARTED_EMU=0
25
+
26
+ case "$MODE" in baseline|check|record) ;; *) sed -n '8,15p' "$0"; exit 2 ;; esac
27
+ mkdir -p "$OUT"
28
+
29
+ boot() {
30
+ if adb get-state >/dev/null 2>&1; then echo "using the attached device"; return; fi
31
+ local sdk="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-$HOME/Library/Android/sdk}}"
32
+ local emu="$sdk/emulator/emulator"
33
+ [ -x "$emu" ] || emu="$(command -v emulator || true)"
34
+ [ -n "$emu" ] || { echo "Android emulator not found (set ANDROID_HOME)"; exit 1; }
35
+ echo "booting $AVD (headless)"
36
+ "$emu" -avd "$AVD" -no-window -no-audio -no-snapshot -no-boot-anim >"$OUT/emulator.log" 2>&1 &
37
+ STARTED_EMU=1
38
+ local waited=0
39
+ until [ "$(adb shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')" = 1 ]; do
40
+ sleep 3; waited=$((waited + 3))
41
+ if [ "$waited" -ge 300 ]; then echo "emulator did not boot in 5 min, see $OUT/emulator.log"; exit 1; fi
42
+ done
43
+ sleep 5
44
+ }
45
+
46
+ prepare() {
47
+ # no animations, frozen status bar: captures must only differ when the app draws differently
48
+ for k in window_animation_scale transition_animation_scale animator_duration_scale; do adb shell settings put global "$k" 0; done
49
+ adb shell settings put global sysui_demo_allowed 1
50
+ local demo=(-a com.android.systemui.demo -e command)
51
+ adb shell am broadcast "${demo[@]}" enter >/dev/null
52
+ adb shell am broadcast "${demo[@]}" clock -e hhmm 1200 >/dev/null
53
+ adb shell am broadcast "${demo[@]}" battery -e level 100 -e plugged false >/dev/null
54
+ adb shell am broadcast "${demo[@]}" network -e wifi show -e level 4 -e mobile hide >/dev/null
55
+ adb shell am broadcast "${demo[@]}" notifications -e visible false >/dev/null
56
+ }
57
+
58
+ cleanup() { if [ "$STARTED_EMU" = 1 ]; then adb emu kill >/dev/null 2>&1 || true; fi; }
59
+ trap cleanup EXIT
60
+
61
+ boot
62
+ prepare
63
+ echo "installing the sample app"
64
+ (cd "$ROOT" && ./gradlew :sample:androidApp:installDebug -q)
65
+
66
+ capture() { (cd "$HERE" && "${PY[@]}" drive.py "$1" "${@:2}"); }
67
+
68
+ case "$MODE" in
69
+ record)
70
+ rm -rf "$OUT/baseline"
71
+ capture "$OUT/baseline" --record "$HERE/plan.json"
72
+ echo "plan.json updated; $OUT/baseline is a fresh baseline"
73
+ ;;
74
+ baseline)
75
+ rm -rf "$OUT/baseline" "$OUT/baseline2"
76
+ capture "$OUT/baseline" --plan "$HERE/plan.json"
77
+ if [ "${2:-}" = "--twice" ]; then
78
+ capture "$OUT/baseline2" --plan "$HERE/plan.json"
79
+ echo "noise between the two baseline runs:"
80
+ (cd "$HERE" && "${PY[@]}" diff.py "$OUT/baseline" "$OUT/baseline2" "$OUT/noise") || true
81
+ fi
82
+ ;;
83
+ check)
84
+ [ -d "$OUT/baseline" ] || { echo "no baseline: run '$0 baseline' before changing code"; exit 1; }
85
+ rm -rf "$OUT/check" "$OUT/diff"
86
+ capture "$OUT/check" --plan "$HERE/plan.json"
87
+ noise=(); [ -d "$OUT/baseline2" ] && noise=(--noise "$OUT/baseline2")
88
+ (cd "$HERE" && "${PY[@]}" diff.py "$OUT/baseline" "$OUT/check" "$OUT/diff" ${noise[@]+"${noise[@]}"}) \
89
+ || { echo "DIFFERENCES FOUND - red-marked images: $OUT/diff"; exit 1; }
90
+ echo "all captures match the baseline"
91
+ ;;
92
+ esac