diff options
author | Max Alfonso-Ying <maxying@google.com> | 2024-05-20 22:40:08 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2024-05-20 22:40:08 +0000 |
commit | f39fd2a4aa30b9fb6142a94ca79a6671c4b94049 (patch) | |
tree | 9cfcc9bd398081f9c3fd3f5576137e8ccd8ac842 | |
parent | d59cd1dd1323d0bbc730ad433299d10694785af2 (diff) | |
parent | f39477ee7490f75a462c00f1e4ab2a4f6e74be85 (diff) | |
download | support-androidx-main.tar.gz |
Merge "Fix NavigationDrawerItem with large font" into androidx-mainandroidx-main
3 files changed, 29 insertions, 8 deletions
diff --git a/compose/material3/material3/samples/src/main/java/androidx/compose/material3/samples/DrawerSamples.kt b/compose/material3/material3/samples/src/main/java/androidx/compose/material3/samples/DrawerSamples.kt index 6d07a5132ff..8d8df430d9d 100644 --- a/compose/material3/material3/samples/src/main/java/androidx/compose/material3/samples/DrawerSamples.kt +++ b/compose/material3/material3/samples/src/main/java/androidx/compose/material3/samples/DrawerSamples.kt @@ -104,7 +104,7 @@ fun ModalNavigationDrawerSample() { items.forEach { item -> NavigationDrawerItem( icon = { Icon(item, contentDescription = null) }, - label = { Text(item.name) }, + label = { Text(item.name.substringAfterLast(".")) }, selected = item == selectedItem.value, onClick = { scope.launch { drawerState.close() } @@ -167,7 +167,7 @@ fun PermanentNavigationDrawerSample() { items.forEach { item -> NavigationDrawerItem( icon = { Icon(item, contentDescription = null) }, - label = { Text(item.name) }, + label = { Text(item.name.substringAfterLast(".")) }, selected = item == selectedItem.value, onClick = { selectedItem.value = item @@ -229,7 +229,7 @@ fun DismissibleNavigationDrawerSample() { items.forEach { item -> NavigationDrawerItem( icon = { Icon(item, contentDescription = null) }, - label = { Text(item.name) }, + label = { Text(item.name.substringAfterLast(".")) }, selected = item == selectedItem.value, onClick = { scope.launch { drawerState.close() } diff --git a/compose/material3/material3/src/androidInstrumentedTest/kotlin/androidx/compose/material3/NavigationDrawerItemTest.kt b/compose/material3/material3/src/androidInstrumentedTest/kotlin/androidx/compose/material3/NavigationDrawerItemTest.kt index 3ecd26fb050..af1eb3a868f 100644 --- a/compose/material3/material3/src/androidInstrumentedTest/kotlin/androidx/compose/material3/NavigationDrawerItemTest.kt +++ b/compose/material3/material3/src/androidInstrumentedTest/kotlin/androidx/compose/material3/NavigationDrawerItemTest.kt @@ -29,18 +29,20 @@ import androidx.compose.ui.semantics.SemanticsProperties import androidx.compose.ui.test.SemanticsMatcher import androidx.compose.ui.test.assert import androidx.compose.ui.test.assertHasClickAction -import androidx.compose.ui.test.assertHeightIsAtLeast +import androidx.compose.ui.test.assertHeightIsEqualTo import androidx.compose.ui.test.assertIsEqualTo import androidx.compose.ui.test.assertIsNotSelected import androidx.compose.ui.test.assertIsSelected import androidx.compose.ui.test.assertLeftPositionInRootIsEqualTo import androidx.compose.ui.test.assertWidthIsEqualTo import androidx.compose.ui.test.getBoundsInRoot +import androidx.compose.ui.test.getUnclippedBoundsInRoot import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.onRoot import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.height import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.MediumTest import com.google.common.truth.Truth.assertThat @@ -50,7 +52,6 @@ import org.junit.runner.RunWith @MediumTest @RunWith(AndroidJUnit4::class) -@OptIn(ExperimentalMaterial3Api::class) class NavigationDrawerItemTest { @get:Rule @@ -74,7 +75,27 @@ class NavigationDrawerItemTest { rule.onNodeWithTag(DrawerItemTag) .assertWidthIsEqualTo(264.dp) - .assertHeightIsAtLeast(NavigationDrawerTokens.ActiveIndicatorHeight) + .assertHeightIsEqualTo(NavigationDrawerTokens.ActiveIndicatorHeight) + } + + @Test + fun navigationDrawerItem_size_withLargeContent() { + rule.setMaterialContent(lightColorScheme()) { + Column(Modifier.width(264.dp)) { + NavigationDrawerItem( + icon = {}, + label = { Text("Multi \nline \nlabel \nis \ntall") }, + selected = true, + onClick = {}, + modifier = Modifier.testTag(DrawerItemTag) + ) + } + } + + rule.onNodeWithTag(DrawerItemTag).assertWidthIsEqualTo(264.dp) + rule.onNodeWithTag(DrawerItemTag).getUnclippedBoundsInRoot().let { + assertThat(it.height).isGreaterThan(NavigationDrawerTokens.ActiveIndicatorHeight) + } } @Test diff --git a/compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/NavigationDrawer.kt b/compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/NavigationDrawer.kt index 88d5dd49f07..46dba835536 100644 --- a/compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/NavigationDrawer.kt +++ b/compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/NavigationDrawer.kt @@ -35,7 +35,7 @@ import androidx.compose.foundation.layout.WindowInsetsSides import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.only import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.sizeIn @@ -951,7 +951,7 @@ fun NavigationDrawerItem( onClick = onClick, modifier = modifier .semantics { role = Role.Tab } - .height(NavigationDrawerTokens.ActiveIndicatorHeight) + .heightIn(min = NavigationDrawerTokens.ActiveIndicatorHeight) .fillMaxWidth(), shape = shape, color = colors.containerColor(selected).value, |