Commit 34ca8b5
android: size custom top-bar component buttons to content (Fabric collapse fix) (#8328)
* android: re-measure custom top bar button when async React content reports its size
On the New Architecture (Fabric), a custom React-component top bar button
without explicit width/height could collapse to ~1px. The hosted React
surface lays out asynchronously, off the native measure pass, so the first
onMeasure often observes a 0-sized child and freezes the button at the ~1px
floor with no subsequent re-measure.
Attach an OnLayoutChangeListener to the hosted child that re-requests layout
when the content's size changes (so onMeasure re-runs and sizes the button to
the content). The size-changed guard makes it converge once the button
matches the content. The explicit-dimensions check is done inside the listener
because onViewAdded fires from the superclass constructor (before `component`
is assigned) for the React surface view we need to observe.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* chore: re-trigger CI
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* remove `require-label.yml` workflow (as Yogi suggested 😀)
* test: make collapsed-width assertion density-independent
The new test hardcoded the collapsed button width as 1px, which only holds at
mdpi (density 1.0). CI runs at a higher density, where resolveFinalWidth(0) =
ceil(dpToPx(1dp)) > 1. Derive the expected value from the same dpToPx formula
the production code uses instead of hardcoding it.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* test: invalidate child measure cache before re-measure assertion
The re-measure assertion failed (expected 25 but was 1) because View.measure()
caches results: re-measuring the button with the same outer spec reused the
child's stale cached 0-width measurement, so resolveFinalWidth still saw 0.
In production RN re-measures the surface when it lays out new content; model
that with child.forceLayout() (after child.layout(), which clears FORCE_LAYOUT)
so the parent's super.onMeasure observes the real content width.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* android: size custom top-bar component buttons to content via a single bounded measure
Custom React-component top bar buttons without explicit width/height collapsed to
~1px (invisible) under the New Architecture (Fabric). The two-pass measurement from
#8320/#8326 re-measured the hosted ReactSurfaceView with an EXACTLY box derived from
the first (often still-empty) discovery pass; that forced box is pushed to Fabric via
updateLayoutSpecs, so Fabric keeps laying the content out into the collapsed box and
the button never recovers. The same forcing also stretched flex-content buttons to
the full bar height.
Replace the two-pass with a single bounded (AT_MOST) measure and let ReactSurfaceView
size itself to its content (its documented AT_MOST max-of-children behavior). When
Fabric mounts/sizes the content it re-requests layout and this measure runs again
against the real content size. Explicit width/height still measure EXACTLY; vertical
centering is preserved by the existing CENTER_VERTICAL gravity.
Verified on-device (Pixel 7, newArch+Hermes) on RN 0.78.3 and 0.85.2: content-hugging
and flex component buttons render correctly; flex buttons are pixel-identical to
before. Unit tests updated for the single-pass contract.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* android: measure custom top-bar button height EXACTLY to keep content vertically centered
The previous commit fixed the collapse by measuring the React surface with a single bounded
(AT_MOST) pass, but using AT_MOST for the *height* let content-hugging surfaces shrink, which
shifted self-centering content (e.g. a flex container with justifyContent:'center') downward —
the playground buttons_navbar snapshot caught this as an off-center round button on Fabric.
Measure the height EXACTLY to the available bar height instead. A filled height box lets the
React content center itself in the bar (matching the legacy two-pass layout), while the width
stays AT_MOST so the surface still sizes to its content and the collapse fix is preserved
(forcing the width is what caused the collapse; forcing the height does not).
Verified on a Pixel 3a / API emulator (the CI device profile) in release: the buttons_navbar
snapshot test passes (centering matches), and the full Buttons (14/14) and Stack (20/20) Detox
suites pass. Unit tests updated for the filled-height contract.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 49def36 commit 34ca8b5
3 files changed
Lines changed: 32 additions & 79 deletions
This file was deleted.
Lines changed: 14 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
| |||
45 | 44 | | |
46 | 45 | | |
47 | 46 | | |
48 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
49 | 58 | | |
50 | 59 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
| 60 | + | |
| 61 | + | |
69 | 62 | | |
70 | 63 | | |
71 | 64 | | |
72 | 65 | | |
73 | 66 | | |
74 | 67 | | |
75 | 68 | | |
76 | | - | |
| 69 | + | |
77 | 70 | | |
78 | 71 | | |
79 | 72 | | |
80 | 73 | | |
81 | 74 | | |
82 | 75 | | |
83 | 76 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | 77 | | |
89 | 78 | | |
90 | 79 | | |
| |||
Lines changed: 18 additions & 41 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
35 | 41 | | |
36 | | - | |
| 42 | + | |
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
40 | 46 | | |
41 | 47 | | |
42 | 48 | | |
43 | 49 | | |
44 | | - | |
45 | | - | |
46 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
47 | 53 | | |
48 | 54 | | |
49 | | - | |
| 55 | + | |
50 | 56 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
| |||
76 | 78 | | |
77 | 79 | | |
78 | 80 | | |
79 | | - | |
| 81 | + | |
80 | 82 | | |
81 | 83 | | |
82 | 84 | | |
83 | 85 | | |
84 | 86 | | |
85 | 87 | | |
86 | 88 | | |
87 | | - | |
| 89 | + | |
88 | 90 | | |
89 | 91 | | |
90 | 92 | | |
91 | | - | |
92 | | - | |
93 | | - | |
| 93 | + | |
94 | 94 | | |
95 | | - | |
96 | | - | |
97 | 95 | | |
98 | 96 | | |
99 | 97 | | |
100 | | - | |
| 98 | + | |
101 | 99 | | |
102 | 100 | | |
103 | 101 | | |
| |||
106 | 104 | | |
107 | 105 | | |
108 | 106 | | |
109 | | - | |
| 107 | + | |
110 | 108 | | |
111 | 109 | | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
| 110 | + | |
| 111 | + | |
131 | 112 | | |
132 | 113 | | |
133 | 114 | | |
| |||
170 | 151 | | |
171 | 152 | | |
172 | 153 | | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | 154 | | |
178 | 155 | | |
179 | 156 | | |
| |||
0 commit comments