Skip to content

android: restore vertical centering for content-hugging custom top-bar buttons#8332

Merged
yedidyak merged 2 commits into
wix:masterfrom
Yoavpagir:fix/android-topbar-button-vertical-centering
Jun 23, 2026
Merged

android: restore vertical centering for content-hugging custom top-bar buttons#8332
yedidyak merged 2 commits into
wix:masterfrom
Yoavpagir:fix/android-topbar-button-vertical-centering

Conversation

@Yoavpagir

Copy link
Copy Markdown
Contributor

Summary

Custom React top-bar buttons (topBar.leftButtons / rightButtons with { component }) that have no explicit height render 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) to EXACTLY the full bar height.

Root cause

With EXACTLY full-bar height, the hosted ReactSurfaceView is forced to fill the whole bar. Centering then relies entirely on the content centering itself (a flex container with justifyContent: '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_VERTICAL gravity applied in onViewAdded() (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 existing onViewAdded CENTER_VERTICAL gravity — for all content-hugging buttons (text and image), without requiring each component to self-center.

This recombines:

Per #8328's own analysis, only a forced EXACTLY width triggers the Fabric collapse; the height mode is independent, so this does not reintroduce the collapse. Buttons that pass an explicit width/height are unchanged (still measured EXACTLY).

// 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 branch EXACTLYAT_MOST (+ updated the onMeasure comment 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 to AT_MOST and measured height back to content height (CHILD_HEIGHT) in the missing-dimension / zero-parent / RTL cases. Explicit-dimension button unchanged. contentCenteringReplacesExistingVerticalGravityOnly is now meaningful again (the child is shorter than the bar, so gravity actually centers it).

Validation

  • Unit: TitleBarReactButtonViewTest updated/green.
  • On-device (Detox, release): Buttons suite — esp. the buttons_navbar snapshot (should render top/navigation-bar buttons in the right order): the round flex component button must stay vertically centered (no snapshot regen expected, since AT_MOST height ≈ legacy content-sizing); Stack suite green.
  • Manual (engine RC): Owner-app "Publish" text button vertically centered & not clipped; profile/avatar left button vertically centered; Spaces RTL notification + bell still present (no collapse).

Context & links

@yedidyak yedidyak marked this pull request as ready for review June 23, 2026 12:27
@yedidyak yedidyak merged commit 3d2a176 into wix:master Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants