-
Notifications
You must be signed in to change notification settings - Fork 160
Keep DropdownMenu open after selection #604
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
Open
riko111
wants to merge
19
commits into
DroidKaigi:main
Choose a base branch
from
riko111:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+62
−74
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a88c063
Keep DropdownMenu open after item selection to allow multiple selections
riko111 7b3cb0a
Merge branch 'DroidKaigi:main' into main
riko111 bcde281
Merge branch 'DroidKaigi:main' into main
riko111 6870bea
Merge branch 'DroidKaigi:main' into main
riko111 c87891a
Merge branch 'DroidKaigi:main' into main
riko111 691ffca
Add long-press multi-selection mode for category items in DropdownMenu
riko111 dad2ba7
Apply spotless formatting
riko111 54245dc
Remove unused onFilterLongPress and simplify multi-selection behavior
riko111 086ce5d
Merge branch 'DroidKaigi:main' into main
riko111 efc037e
Remove unused onFilterLongPress and simplify multi-selection behavior
riko111 fe96229
Keep layout stable by fading out unselected icons and locking chip wi…
riko111 0cd6f88
Keep layout stable by fading out unselected icons and locking chip wi…
riko111 ac9f434
Remove sessionType dropdown list from tests after component removal
riko111 e4a21b2
Anchor DropdownMenu to a stable empty Box (menuAnchor) and remove wid…
riko111 3c3894b
Remove default empty lambda; make onMultiSelectFinished nullable and …
riko111 0b4274a
Revert "Remove default empty lambda; make onMultiSelectFinished nulla…
riko111 fcfa0af
Merge branch 'DroidKaigi:main' into main
riko111 aad08e5
spotless-check
riko111 c475cbd
Merge remote-tracking branch 'origin/main'
riko111 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
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 |
|---|---|---|
| @@ -1,16 +1,18 @@ | ||
| package io.github.droidkaigi.confsched.sessions.components | ||
|
|
||
| import androidx.compose.foundation.combinedClickable | ||
| import androidx.compose.foundation.horizontalScroll | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.heightIn | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.rememberScrollState | ||
| import androidx.compose.material.icons.Icons | ||
| import androidx.compose.material.icons.filled.ArrowDropDown | ||
| import androidx.compose.material.icons.filled.Check | ||
| import androidx.compose.material3.DropdownMenu | ||
| import androidx.compose.material3.DropdownMenuItem | ||
| import androidx.compose.material3.FilterChip | ||
| import androidx.compose.material3.FilterChipDefaults | ||
| import androidx.compose.material3.Icon | ||
|
|
@@ -25,6 +27,9 @@ import androidx.compose.runtime.setValue | |
| import androidx.compose.runtime.withFrameNanos | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.draw.alpha | ||
| import androidx.compose.ui.hapticfeedback.HapticFeedbackType | ||
| import androidx.compose.ui.platform.LocalHapticFeedback | ||
| import androidx.compose.ui.platform.LocalSoftwareKeyboardController | ||
| import androidx.compose.ui.platform.testTag | ||
| import androidx.compose.ui.unit.dp | ||
|
|
@@ -33,7 +38,6 @@ import io.github.droidkaigi.confsched.sessions.SearchScreenUiState | |
| import io.github.droidkaigi.confsched.sessions.SessionsRes | ||
| import io.github.droidkaigi.confsched.sessions.filter_chip_category | ||
| import io.github.droidkaigi.confsched.sessions.filter_chip_day | ||
| import io.github.droidkaigi.confsched.sessions.filter_chip_session_type | ||
| import io.github.droidkaigi.confsched.sessions.filter_chip_supported_language | ||
| import kotlinx.coroutines.launch | ||
| import org.jetbrains.compose.resources.stringResource | ||
|
|
@@ -88,21 +92,6 @@ fun SearchFilterRow( | |
| modifier = Modifier.testTag(SearchFilterRowFilterCategoryChipTestTag), | ||
| ) | ||
| } | ||
|
|
||
| // Session type filter dropdown | ||
| if (filters.availableSessionTypes.isNotEmpty()) { | ||
| FilterDropdown( | ||
| label = stringResource(SessionsRes.string.filter_chip_session_type), | ||
| selectedItems = filters.selectedSessionTypes, | ||
| items = filters.availableSessionTypes, | ||
| itemLabel = { it.label.currentLangTitle }, | ||
| onItemSelected = { sessionType -> | ||
| onFilterToggle(SearchScreenEvent.Filter.SessionType(sessionType)) | ||
| }, | ||
| modifier = Modifier.testTag(SearchFilterRowFilterSessionTypeChipTestTag), | ||
| ) | ||
| } | ||
|
|
||
| // Language filter dropdown | ||
| if (filters.availableLanguages.isNotEmpty()) { | ||
| FilterDropdown( | ||
|
|
@@ -126,10 +115,13 @@ private fun <T> FilterDropdown( | |
| items: List<T>, | ||
| itemLabel: (T) -> String, | ||
| onItemSelected: (T) -> Unit, | ||
| onMultiSelectFinished: (List<T>) -> Unit = {}, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| val keyboardController = LocalSoftwareKeyboardController.current | ||
| val haptics = LocalHapticFeedback.current | ||
| var expanded by remember { mutableStateOf(false) } | ||
| var isMultiSelectMode by remember { mutableStateOf(false) } | ||
| val scope = rememberCoroutineScope() | ||
|
|
||
| Box(modifier = modifier) { | ||
|
|
@@ -142,17 +134,17 @@ private fun <T> FilterDropdown( | |
| } | ||
| }.invokeOnCompletion { expanded = true } | ||
| }, | ||
| modifier = Modifier, | ||
| label = { | ||
| Row( | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| horizontalArrangement = Arrangement.spacedBy(4.dp), | ||
| ) { | ||
| if (selectedItems.isNotEmpty()) { | ||
| Icon( | ||
| imageVector = Icons.Default.Check, | ||
| contentDescription = null, | ||
| ) | ||
| } | ||
|
Comment on lines
-150
to
-155
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| Icon( | ||
| imageVector = Icons.Default.Check, | ||
| contentDescription = null, | ||
| modifier = Modifier.alpha(if (selectedItems.isNotEmpty()) 1f else 0f), | ||
| ) | ||
| Text( | ||
| text = if (selectedItems.isNotEmpty()) { | ||
| selectedItems.joinToString { itemLabel(it) } | ||
|
|
@@ -162,39 +154,60 @@ private fun <T> FilterDropdown( | |
| style = MaterialTheme.typography.labelLarge, | ||
| maxLines = 1, | ||
| ) | ||
| Icon( | ||
| imageVector = Icons.Default.ArrowDropDown, | ||
| contentDescription = null, | ||
| ) | ||
| if (selectedItems.isNotEmpty()) { | ||
| Icon( | ||
| imageVector = Icons.Default.ArrowDropDown, | ||
| contentDescription = null, | ||
| ) | ||
| } | ||
| } | ||
| }, | ||
| colors = FilterChipDefaults.filterChipColors( | ||
| selectedContainerColor = MaterialTheme.colorScheme.secondaryContainer, | ||
| selectedLabelColor = MaterialTheme.colorScheme.onSecondaryContainer, | ||
| ), | ||
| ) | ||
|
|
||
| DropdownMenu( | ||
| expanded = expanded, | ||
| onDismissRequest = { expanded = false }, | ||
| ) { | ||
| items.forEach { item -> | ||
| DropdownMenuItem( | ||
| modifier = Modifier.testTag(DropdownFilterChipTestTagPrefix.plus(item)), | ||
| leadingIcon = { | ||
| if (selectedItems.contains(item)) { | ||
| Icon( | ||
| imageVector = Icons.Default.Check, | ||
| contentDescription = null, | ||
| Box { | ||
| DropdownMenu( | ||
| expanded = expanded, | ||
| onDismissRequest = { | ||
| if (isMultiSelectMode) onMultiSelectFinished(selectedItems.toList()) | ||
| expanded = false | ||
| isMultiSelectMode = false | ||
| }, | ||
| ) { | ||
| items.forEach { item -> | ||
| Row( | ||
| modifier = Modifier | ||
| .testTag(DropdownFilterChipTestTagPrefix.plus(item)) | ||
| .fillMaxWidth() | ||
| .heightIn(min = 48.dp) | ||
| .combinedClickable( | ||
| onClick = { | ||
| onItemSelected(item) | ||
| if (!isMultiSelectMode) { | ||
| expanded = false | ||
| } | ||
| }, | ||
| onLongClick = { | ||
| isMultiSelectMode = true | ||
| haptics.performHapticFeedback(HapticFeedbackType.LongPress) | ||
| onItemSelected(item) | ||
| }, | ||
| ) | ||
| } | ||
| }, | ||
| text = { Text(itemLabel(item)) }, | ||
| onClick = { | ||
| onItemSelected(item) | ||
| expanded = false | ||
| }, | ||
| ) | ||
| .padding(horizontal = 12.dp, vertical = 8.dp), | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| ) { | ||
| Icon( | ||
| Icons.Default.Check, | ||
| contentDescription = null, | ||
| modifier = Modifier | ||
| .padding(end = 12.dp) | ||
| .alpha(if (selectedItems.contains(item)) 1f else 0f), | ||
| ) | ||
| Text(itemLabel(item), style = MaterialTheme.typography.bodyLarge) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
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.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifying default values for lambda parameters has some downsides: it can make it easy to forget to provide a value, and at a glance it’s not always clear whether a value is actually being passed. Therefore, unless there’s a specific reason, I’d prefer to remove default empty lambdas.