Skip to content
This repository was archived by the owner on Jul 11, 2025. It is now read-only.

Commit 1261217

Browse files
author
Rob Orgiu
committed
Fix suggestion from alexvanyo
1 parent a6c8106 commit 1261217

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

CanonicalLayouts/list-detail-compose/app/src/main/java/com/example/listdetailcompose/ui/ListDetailSample.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import androidx.compose.material3.Text
3737
import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
3838
import androidx.compose.material3.adaptive.layout.ListDetailPaneScaffold
3939
import androidx.compose.material3.adaptive.layout.ListDetailPaneScaffoldRole
40+
import androidx.compose.material3.adaptive.layout.PaneAdaptedValue
4041
import androidx.compose.material3.adaptive.navigation.rememberListDetailPaneScaffoldNavigator
4142
import androidx.compose.runtime.Composable
4243
import androidx.compose.runtime.getValue
@@ -85,9 +86,12 @@ fun ListDetailSample() {
8586
value = navigator.scaffoldValue,
8687
listPane = {
8788
val currentSelectedWordIndex = selectedWordIndex
89+
val isDetailVisible =
90+
navigator.scaffoldValue[ListDetailPaneScaffoldRole.Detail] == PaneAdaptedValue.Expanded
91+
8892
ListContent(
8993
words = sampleWords.map(DefinedWord::word),
90-
selectionState = if (currentSelectedWordIndex != null) {
94+
selectionState = if (isDetailVisible && currentSelectedWordIndex != null) {
9195
SelectionVisibilityState.ShowSelection(currentSelectedWordIndex)
9296
} else {
9397
SelectionVisibilityState.NoSelection
@@ -157,6 +161,7 @@ private fun ListContent(
157161
onClick = { onIndexClick(index) }
158162
)
159163
}
164+
160165
is SelectionVisibilityState.ShowSelection -> {
161166
Modifier.selectable(
162167
selected = index == selectionState.selectedWordIndex,
@@ -179,6 +184,7 @@ private fun ListContent(
179184
1.dp,
180185
MaterialTheme.colorScheme.outline
181186
)
187+
182188
is SelectionVisibilityState.ShowSelection ->
183189
if (index == selectionState.selectedWordIndex) {
184190
null

CanonicalLayouts/list-detail-compose/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
plugins {
17-
id 'com.android.application' version '8.3.1' apply false
18-
id 'com.android.library' version '8.3.1' apply false
17+
id 'com.android.application' version '8.3.2' apply false
18+
id 'com.android.library' version '8.3.2' apply false
1919
id 'org.jetbrains.kotlin.android' version '1.9.22' apply false
2020
}

0 commit comments

Comments
 (0)