Last active
May 20, 2022 21:00
-
-
Save pauloaapereira/9ceebc2e8c0f3d741f0debf41d044cef to your computer and use it in GitHub Desktop.
Jetpack Compose - Auto Complete Search Bar_3
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
| 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) | |
| override var shouldWrapContentHeight by mutableStateOf(false) | |
| override var boxMaxHeight: Dp by mutableStateOf(TextFieldDefaults.MinHeight * 3) | |
| override var boxBorderStroke by mutableStateOf(BorderStroke(2.dp, Color.Black)) | |
| override var boxShape: Shape by mutableStateOf(RoundedCornerShape(8.dp)) | |
| override fun filter(query: String) { | |
| if (isSearching) | |
| filteredItems = startItems.filter { entity -> | |
| entity.filter(query) | |
| } | |
| } | |
| override fun onItemSelected(block: ItemSelected<T>) { | |
| onItemSelectedBlock = block | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment