mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 12:07:28 +00:00
Refactor SearchBarResultState.Initial and NoResultsFound to data objects
This commit is contained in:
+7
-7
@@ -59,7 +59,7 @@ fun <T> SearchBar(
|
||||
modifier: Modifier = Modifier,
|
||||
enabled: Boolean = true,
|
||||
showBackButton: Boolean = true,
|
||||
resultState: SearchBarResultState<T> = SearchBarResultState.Initial(),
|
||||
resultState: SearchBarResultState<T> = SearchBarResultState.Initial,
|
||||
shape: Shape = SearchBarDefaults.inputFieldShape,
|
||||
tonalElevation: Dp = SearchBarDefaults.TonalElevation,
|
||||
windowInsets: WindowInsets = SearchBarDefaults.windowInsets,
|
||||
@@ -134,7 +134,7 @@ fun <T> SearchBar(
|
||||
resultHandler(resultState.results)
|
||||
}
|
||||
|
||||
is SearchBarResultState.NoResultsFound<T> -> {
|
||||
is SearchBarResultState.NoResultsFound -> {
|
||||
// No results found, show a message
|
||||
Spacer(Modifier.size(80.dp))
|
||||
|
||||
@@ -200,12 +200,12 @@ object ElementSearchBarDefaults {
|
||||
}
|
||||
|
||||
@Immutable
|
||||
sealed interface SearchBarResultState<in T> {
|
||||
sealed interface SearchBarResultState<out T> {
|
||||
/** No search results are available yet (e.g. because the user hasn't entered a search term). */
|
||||
class Initial<T> : SearchBarResultState<T>
|
||||
data object Initial : SearchBarResultState<Nothing>
|
||||
|
||||
/** The search has completed, but no results were found. */
|
||||
class NoResultsFound<T> : SearchBarResultState<T>
|
||||
data object NoResultsFound : SearchBarResultState<Nothing>
|
||||
|
||||
/** The search has completed, and some matching users were found. */
|
||||
data class Results<T>(val results: T) : SearchBarResultState<T>
|
||||
@@ -249,7 +249,7 @@ internal fun SearchBarActiveWithNoResultsPreview() = ElementThemedPreview {
|
||||
ContentToPreview(
|
||||
initialQuery = "search term",
|
||||
active = true,
|
||||
resultState = SearchBarResultState.NoResultsFound<String>(),
|
||||
resultState = SearchBarResultState.NoResultsFound,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ private fun ContentToPreview(
|
||||
initialQuery: String = "",
|
||||
active: Boolean = false,
|
||||
showBackButton: Boolean = true,
|
||||
resultState: SearchBarResultState<String> = SearchBarResultState.Initial(),
|
||||
resultState: SearchBarResultState<String> = SearchBarResultState.Initial,
|
||||
contentPrefix: @Composable ColumnScope.() -> Unit = {},
|
||||
contentSuffix: @Composable ColumnScope.() -> Unit = {},
|
||||
resultHandler: @Composable ColumnScope.(String) -> Unit = {},
|
||||
|
||||
Reference in New Issue
Block a user