Skip to content

Fix BpkTopNavBar Arabic title truncation and BpkSegmentedControl long labels - #2915

Merged
Henrik Sym (henrik-sky) merged 10 commits into
mainfrom
fix-nav-bar-title-rtl-truncation
Dec 3, 2026
Merged

Henrik Sym (henrik-sky) merged 10 commits into
mainfrom
fix-nav-bar-title-rtl-truncation

Conversation

@peterInTown

@peterInTown peterliu (peterInTown) commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two text-truncation fixes found in the Skyscanner app's Search Control GC when it is shown in other languages.

  1. BpkTopNavBar: the title is truncated for some Arabic strings.
  2. BpkSegmentedControl: a long label is truncated even when the other labels leave space unused (for example German Hin- und Rückflug).

1. BpkTopNavBar title truncated for Arabic

Cause

The titles are wrap-content BpkText with maxLines = 1 and TextOverflow.Ellipsis. For some Arabic strings the intrinsic width Compose reports is smaller than the width the text needs. Measured on an emulator with heading2 in RTL for ابحث عن رحلة: maxIntrinsicWidth = 454.5px, but the text wraps onto a second line when maxLines is unlimited, and is ellipsized when maxLines = 1. The title is therefore laid out too narrow and shows ابحث عن رح.... English titles are not affected.

Fix

Modifier.fillMaxWidth() on the expanded and collapsed title texts, so they are laid out against the available width instead of the intrinsic width. A title that genuinely does not fit is still ellipsized.

Screenshots

Before After
Screenshot_20261202_180430 Screenshot_20261202_180816

Changes

  • BpkTopNavBarImpl: fillMaxWidth() on both titles
  • BpkTopNavBarTitleTest (androidTest): an expanded Arabic title in RTL and an English title in LTR are not ellipsized

2. BpkSegmentedControl truncating long labels

Cause

Every segment was a Row child with weight(1f), so each got an equal share of the width. A label that needs more than its share is ellipsized even when the other labels use much less.

Fix

BpkSegmentedControlImpl now uses a custom Layout instead of the Row:

  • If every label fits its equal share, the layout is exactly as before.
  • If a label does not fit but all labels fit together, each segment gets what it needs plus an equal share of the leftover, so the long label gets more room.
  • If the labels cannot all fit, a label that fits an equal share keeps its full text and only the longer labels share the remaining width. Those can still be ellipsized.

The rounding follows Row's weighted children, so the equal-width case is pixel-identical and the existing snapshots do not change. The public API is unchanged.

Behaviour change to be aware of: segments are no longer always equal width when a label does not fit.

Screenshots

Before After
Screenshot 2026-11-26 at 17 32 21 Screenshot_20261202_180524

Changes

  • BpkSegmentedControlImpl: custom measure policy and distributeSegmentWidths
  • BpkSegmentedControlWidthsTest (unit, 9 tests): the width distribution
  • BpkSegmentedControlLabelsTest (androidTest, 5 tests): German labels at 343dp are not ellipsized, English labels keep equal widths, the longest label gets the most width, labels that cannot all fit still fill the control, and with one very long label only that one is ellipsized

Testing

  • Both new instrumented test classes fail without the fixes (Arabic title and Hin- und Rückflug ellipsized) and pass with them on an API 37 emulator
  • detekt passes
  • The existing BpkTopNavBarTest (20), BpkNavBarTest, BpkModalTest and BpkSegmentedControlTest (14) snapshot tests pass with no changes
  • Both fixes were checked in the Skyscanner app against a local snapshot: the Search Control GC title in Arabic, and the tabs in German
  • Other bold wrap-content Arabic BpkText may have the same intrinsic width mismatch. Only the nav bar title is changed here.

Remember to include the following changes:

  • Component README.md (no API or documented behaviour change for the documented cases)
  • Tests

The expanded and collapsed titles were wrap-content with maxLines = 1 and an ellipsis. For some Arabic strings the reported intrinsic width is smaller than the width the text needs, so the title was laid out too narrow and ellipsized even though there was plenty of room. Give the titles the full available width.

Co-authored-by: OpenCode <noreply@opencode.ai>
Copilot AI lite review requested due to automatic review settings December 2, 2026 06:05
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor
Warnings
⚠️ One or more component files were updated, but the tests weren't updated. If your change is not covered by existing tests please add snapshot tests.
⚠️

One or more component files were updated, but the docs screenshots weren't updated. If the changes are visual or it is a new component please regenerate the screenshots via ./gradlew recordScreenshots.

⚠️

One or more component files were updated, but README.md wasn't updated. If your change contains API changes/additions or a new component please update the relevant component README.

Generated by 🚫 Danger Kotlin against 7f9120a

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open issues
What changed in this PR

Fixes an issue where BpkTopNavBar titles in Arabic (RTL) were being incorrectly ellipsized due to Compose intrinsic width measurement, by ensuring the title is measured against available width.

Changes:

  • Apply Modifier.fillMaxWidth() to expanded and collapsed title BpkText in BpkTopNavBarImpl.
  • Add Android instrumented tests verifying Arabic (RTL) and English (LTR) titles are not ellipsized.
File Description
backpack-compose/​src/​main/​kotlin/​net/​skyscanner/​backpack/​compose/​navigationbar/​internal/​BpkTopNavBarImpl.kt Forces title text to measure within available width to prevent erroneous ellipsizing in RTL.
backpack-compose/​src/​androidTest/​kotlin/​net/​skyscanner/​backpack/​compose/​navigationbar/​BpkTopNavBarTitleTest.kt Adds coverage to ensure titles are not ellipsized for Arabic RTL and English LTR.

Review effort: Lite

Copilot AI lite review requested due to automatic review settings December 2, 2026 06:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

4 open issues

Review effort: Lite

… room #trivial

Every button got an equal share of the width, so a long label was ellipsized even when the other labels left space unused. When every label fits its equal share the layout is unchanged. Otherwise the width is shared by what each label needs, and labels that fit an equal share keep their full text.

Co-authored-by: OpenCode <noreply@opencode.ai>
Copilot AI lite review requested due to automatic review settings December 2, 2026 09:23
@peterInTown peterliu (peterInTown) changed the title Fix BpkTopNavBar title being truncated for Arabic Fix BpkTopNavBar Arabic title truncation and BpkSegmentedControl long labels Dec 2, 2026
…nav bar title #trivial

Co-authored-by: OpenCode <noreply@opencode.ai>
@peterInTown peterliu (peterInTown) added the minor A new & backwards compatible feature/component label Dec 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot AI lite review requested due to automatic review settings December 2, 2026 09:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…ify children by layoutId #trivial

- Return zero widths instead of throwing when no width is available
- Tag buttons and dividers with layoutId instead of relying on child order
- Constrain the unbounded-width result to the incoming constraints
- Match the selectable node in the width assertions

Co-authored-by: OpenCode <noreply@opencode.ai>
Copilot AI lite review requested due to automatic review settings December 2, 2026 12:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

3 open issues
9 resolved since last review

Review effort: Lite

…red width #trivial

Co-authored-by: OpenCode <noreply@opencode.ai>
Copilot AI lite review requested due to automatic review settings December 2, 2026 13:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…n the checks #trivial

- Only take a pixel back from elements that still have width when rounding
- Compare against remaining / unsettled to avoid an integer overflow
- Assert the buttons span the control using measured bounds instead of an assumed divider width

Co-authored-by: OpenCode <noreply@opencode.ai>
Copilot AI lite review requested due to automatic review settings December 2, 2026 14:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace the Row-style remainder correction with cumulative edge rounding. Widths always add up to the total and can never be negative, so no special cases are needed. Add sweep tests for the invariants. The 4-button snapshots may shift by 1px.

Co-authored-by: OpenCode <noreply@opencode.ai>
Copilot AI lite review requested due to automatic review settings December 3, 2026 07:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot AI lite review requested due to automatic review settings December 3, 2026 07:26
…am the test cases #trivial

Co-authored-by: OpenCode <noreply@opencode.ai>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot AI lite review requested due to automatic review settings December 3, 2026 07:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@henrik-sky
Henrik Sym (henrik-sky) merged commit a7a0278 into main Dec 3, 2026
19 of 20 checks passed
@henrik-sky
Henrik Sym (henrik-sky) deleted the fix-nav-bar-title-rtl-truncation branch December 3, 2026 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor A new & backwards compatible feature/component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants