android: restore vertical centering for content-hugging custom top-bar buttons#8332
Merged
yedidyak merged 2 commits intoJun 23, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Custom React top-bar buttons (
topBar.leftButtons/rightButtonswith{ component }) that have no explicitheightrender pinned to the top of the bar instead of vertically centered on Android. It affects any content-hugging button — both text (e.g. an Owner-app "Publish" button) and fixed-size images (the profile-picture / avatar left button) — not just text.This is the vertical-alignment regression that came back with #8328 (RNN 8.8.9). #8328 correctly fixed the New-Architecture width collapse, but as part of it changed the no-explicit-dimension height spec from
AT_MOST(what #8326 used) toEXACTLYthe full bar height.Root cause
With
EXACTLYfull-bar height, the hostedReactSurfaceViewis forced to fill the whole bar. Centering then relies entirely on the content centering itself (a flex container withjustifyContent: 'center'). #8328 was validated only against such a self-centering flex button, so it missed the common case: a content-hugging button (<View><Text>…</Text></View>, or a fixed-size avatar image) is laid out at the top of the filled box → top-aligned.The
CENTER_VERTICALgravity applied inonViewAdded()(added in #8326) is still present but is moot under a filled height — the child fills the parent, so there is nothing left to center.Fix
Make the no-explicit-dimension height bounded (
AT_MOST) again, keeping #8328's content-hugging width (AT_MOST) untouched. The surface then sizes to its content height and is centered by the toolbar's action-view layout + the existingonViewAddedCENTER_VERTICALgravity — for all content-hugging buttons (text and image), without requiring each component to self-center.This recombines:
AT_MOST→ no Fabric width collapse (~1px), andAT_MOST+ gravity → correct vertical centering.Per #8328's own analysis, only a forced
EXACTLYwidth triggers the Fabric collapse; the height mode is independent, so this does not reintroduce the collapse. Buttons that pass an explicitwidth/heightare unchanged (still measuredEXACTLY).// TitleBarReactButtonView.createHeightSpec(...) int availableSize = MeasureSpec.getSize(measureSpec); - return makeMeasureSpec(availableSize > 0 ? availableSize : Math.max(resolveActionBarSize(), 1), EXACTLY); + return makeMeasureSpec(availableSize > 0 ? availableSize : Math.max(resolveActionBarSize(), 1), AT_MOST);Changes
TitleBarReactButtonView.createHeightSpec(...): no-dimension branchEXACTLY→AT_MOST(+ updated theonMeasurecomment that documented the filled-height rationale).TitleBarReactButtonViewTest: reverted the height assertions android: size custom top-bar component buttons to content (Fabric collapse fix) #8328 flipped — child height-spec mode back toAT_MOSTand measured height back to content height (CHILD_HEIGHT) in the missing-dimension / zero-parent / RTL cases. Explicit-dimension button unchanged.contentCenteringReplacesExistingVerticalGravityOnlyis now meaningful again (the child is shorter than the bar, so gravity actually centers it).Validation
TitleBarReactButtonViewTestupdated/green.Buttonssuite — esp. thebuttons_navbarsnapshot (should render top/navigation-bar buttons in the right order): the round flex component button must stay vertically centered (no snapshot regen expected, sinceAT_MOSTheight ≈ legacy content-sizing);Stacksuite green.Context & links