This file contains 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
typealias CustomFilter<T> = (T, String) -> Boolean | |
fun <T> List<T>.asAutoCompleteEntities(filter: CustomFilter<T>): List<ValueAutoCompleteEntity<T>> { | |
return map { | |
object : ValueAutoCompleteEntity<T> { | |
override val value: T = it | |
override fun filter(query: String): Boolean { | |
return filter(value, query) |
This file contains 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
@Stable | |
interface ValueAutoCompleteEntity<T> : AutoCompleteEntity { | |
val value: T | |
} |
This file contains 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
private fun Modifier.autoComplete( | |
autoCompleteItemScope: AutoCompleteDesignScope | |
): Modifier = composed { | |
val baseModifier = if (autoCompleteItemScope.shouldWrapContentHeight) | |
wrapContentHeight() | |
else | |
heightIn(0.dp, autoCompleteItemScope.boxMaxHeight) | |
baseModifier | |
.testTag(AutoCompleteBoxTag) |
This file contains 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
@ExperimentalAnimationApi | |
@Composable | |
fun <T : AutoCompleteEntity> AutoCompleteBox( | |
items: List<T>, | |
itemContent: @Composable (T) -> Unit, | |
content: @Composable AutoCompleteScope<T>.() -> Unit | |
) { | |
val autoCompleteState = remember { AutoCompleteState(startItems = items) } |
This file contains 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
@Composable | |
fun <T : AutoCompleteEntity> AutoCompleteBox( | |
items: List<T>, | |
itemContent: @Composable (T) -> Unit, | |
content: @Composable AutoCompleteScope<T>.() -> Unit | |
) { | |
... | |
} |
This file contains 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
class AutoCompleteState<T : AutoCompleteEntity>(private val startItems: List<T>) : AutoCompleteScope<T> { | |
private var onItemSelectedBlock: ItemSelected<T>? = null | |
fun selectItem(item: T) { | |
onItemSelectedBlock?.invoke(item) | |
} | |
var filteredItems by mutableStateOf(startItems) | |
override var isSearching by mutableStateOf(false) | |
override var boxWidthPercentage by mutableStateOf(.9f) |
This file contains 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
private typealias ItemSelected<T> = (T) -> Unit | |
@Stable | |
interface AutoCompleteScope<T : AutoCompleteEntity> : AutoCompleteDesignScope { | |
var isSearching: Boolean | |
fun filter(query: String) | |
fun onItemSelected(block: ItemSelected<T> = {}) | |
} |
This file contains 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
@Stable | |
interface AutoCompleteEntity { | |
fun filter(query: String): Boolean | |
} | |
@Stable | |
interface ValueAutoCompleteEntity<T> : AutoCompleteEntity { | |
val value: T | |
} |
This file contains 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
Curtain( | |
foldingDuration = 400, | |
mainCell = { | |
Card( | |
modifier = Modifier.fillMaxWidth(), | |
backgroundColor = Color.DarkGray, | |
) { | |
Box( | |
modifier = Modifier.fillMaxWidth().padding(16.dp) | |
) { |
This file contains 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
@Composable | |
private fun FoldedCell( | |
isOpened: Boolean, | |
cellsQuantity: Int, | |
foldingDuration: Int, | |
index: Int, | |
content: @Composable () -> Unit | |
) { | |
var cellMaxHeight by remember { mutableStateOf(0.dp) } | |
val transition = updateTransition(targetState = isOpened) |