Repository navigation
Fix BpkTopNavBar Arabic title truncation and BpkSegmentedControl long labels #2915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Henrik Sym (henrik-sky)
merged 10 commits into
main
from
fix-nav-bar-title-rtl-truncation
Dec 3, 2026
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0fc1cb8
Fix BpkTopNavBar title being truncated for Arabic #trivial
peterInTown b0727c5
Updated snapshots
skyscanner-backpack-bot[bot] b174274
Fix BpkSegmentedControl truncating long labels when others have spare…
peterInTown da545ac
Address review: guard the text layout lookup and cover the collapsed …
peterInTown f171be1
Address review: fix zero-width crash in BpkSegmentedControl and ident…
peterInTown a7892e6
Address review: keep short segment labels whole when rounding the sha…
peterInTown 49542f5
Address review: keep the width total exact with zero widths and harde…
peterInTown ae2dc98
Simplify BpkSegmentedControl pixel rounding to cumulative edges #trivial
peterInTown 0ce1325
Updated snapshots
skyscanner-backpack-bot[bot] 7f9120a
Address review: compare each label with its equal-width slot and stre…
peterInTown File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
...androidTest/kotlin/net/skyscanner/backpack/compose/navigationbar/BpkTopNavBarTitleTest.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /** | ||
| * Backpack for Android - Skyscanner's Design System | ||
| * | ||
| * Copyright 2018 - 2026 Skyscanner Ltd | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package net.skyscanner.backpack.compose.navigationbar | ||
|
|
||
| import androidx.compose.runtime.CompositionLocalProvider | ||
| import androidx.compose.ui.platform.LocalLayoutDirection | ||
| import androidx.compose.ui.semantics.SemanticsActions | ||
| import androidx.compose.ui.semantics.getOrNull | ||
| import androidx.compose.ui.test.hasText | ||
| import androidx.compose.ui.test.junit4.createComposeRule | ||
| import androidx.compose.ui.text.TextLayoutResult | ||
| import androidx.compose.ui.unit.LayoutDirection | ||
| import net.skyscanner.backpack.compose.theme.BpkTheme | ||
| import org.junit.Assert.assertFalse | ||
| import org.junit.Assert.assertTrue | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
|
|
||
| class BpkTopNavBarTitleTest { | ||
|
|
||
| @get:Rule | ||
| val composeTestRule = createComposeRule() | ||
|
|
||
| @Test | ||
| fun givenShortArabicTitle_whenExpandedInRtl_thenTitleIsNotEllipsized() { | ||
| setContent(title = ARABIC_TITLE, layoutDirection = LayoutDirection.Rtl) | ||
|
|
||
| assertTitlesAreNotEllipsized(ARABIC_TITLE) | ||
| } | ||
|
|
||
| @Test | ||
| fun givenShortEnglishTitle_whenExpanded_thenTitleIsNotEllipsized() { | ||
| setContent(title = ENGLISH_TITLE, layoutDirection = LayoutDirection.Ltr) | ||
|
|
||
| assertTitlesAreNotEllipsized(ENGLISH_TITLE) | ||
| } | ||
|
|
||
| private fun assertTitlesAreNotEllipsized(title: String) { | ||
| val nodes = composeTestRule.onAllNodes(hasText(title), useUnmergedTree = true).fetchSemanticsNodes() | ||
| assertTrue("Expected the title to be displayed", nodes.isNotEmpty()) | ||
| nodes.forEach { node -> | ||
| val results = mutableListOf<TextLayoutResult>() | ||
| node.config.getOrNull(SemanticsActions.GetTextLayoutResult)?.action?.invoke(results) | ||
| val layout = results.single() | ||
|
peterInTown marked this conversation as resolved.
Resolved
peterInTown marked this conversation as resolved.
Resolved
|
||
| assertFalse("Title '$title' is ellipsized", layout.isLineEllipsized(0)) | ||
| assertFalse("Title '$title' overflows its width", layout.didOverflowWidth) | ||
| } | ||
| } | ||
|
|
||
| private fun setContent(title: String, layoutDirection: LayoutDirection) { | ||
| composeTestRule.setContent { | ||
| BpkTheme { | ||
| CompositionLocalProvider(LocalLayoutDirection provides layoutDirection) { | ||
| BpkTopNavBar( | ||
| state = rememberFixedTopAppBarState(TopNavBarStatus.Expanded), | ||
| navIcon = NavIcon.Close(contentDescription = "Close", onClick = {}), | ||
| title = title, | ||
| style = NavBarStyle.SurfaceContrast, | ||
| ) | ||
|
peterInTown marked this conversation as resolved.
Resolved
peterInTown marked this conversation as resolved.
Resolved
|
||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private companion object { | ||
| const val ARABIC_TITLE = "ابحث عن رحلة" | ||
| const val ENGLISH_TITLE = "Search flights" | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.