Skip to content
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

implement autocompleteDropDownMenu #37

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

RostyslavKloos
Copy link
Collaborator

@RostyslavKloos RostyslavKloos commented May 18, 2022

improvements compare to "exposedDropDown" implementation:

  1. there no lags using large lists
  2. popup menu width same as textfield

differences compare to "androidView" implementation:

  1. a bit space under popUp menu
2022-05-18.12.58.48.mp4

Copy link
Owner

@Skyyo Skyyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job @RostyslavKloos !

@RostyslavKloos RostyslavKloos requested a review from Skyyo May 23, 2022 18:18
Copy link
Owner

@Skyyo Skyyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. pushed small cleanup commit to your branch.
  2. NativeExposedDropDownMenuSample -> AutocompleteDropdownWithFilteringInside
  3. CustomExposedDropdownMenuSample -> AutocompleteDropdownWithOutsideFiltering
  4. AndroidViewTextFieldWithDropDownSample -> AndroidViewAutocompleteDropdownWithOutsideFiltering
  5. Not sure why we have 2x AndroidViewTextFieldWithDropDownSample, Unless there is something to showcase, let's please leave single one @RostyslavKloos
  6. NativeExposedDropDownMenuSample has noticeable lag when filtering. Also it doesn't suggest new items upon cleaning the field from input. Attaching video https://photos.app.goo.gl/qXYymgfE7JZZtVMd7

}
}
}
val autoCompleteTextView = remember { textInputLayout.editText as? AutoCompleteTextView }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? can be deleted

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I wanted to demonstrate how it should behave depends on layout position. But yeah, it's not necessary
  2. That's true. But this is how compose implementation of autocomplete works now and that's why I created own implementation which not lagging.
    about suggestions - I'll check

Copy link
Owner

@Skyyo Skyyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The biggest issue is still lagging, which causes ANR.
  2. There is empty dropdown in certain scenarios.
    Video describing the above.
  3. Not sure what's the difference between two "AndroidViews".
  4. Not sure what's the difference between "native exposed dropdown menu" and "custom exposed dropdown menu"

Comment on lines 29 to 40
viewModelScope.launch(Dispatchers.Default) {
handle[SUGGESTIONS] = if (input.isEmpty()) {
countries.also { onExpandedChange(false) }
} else {
val filteredList = countries.filter { country ->
country
.lowercase()
.startsWith(input.lowercase()) && country != input
}
filteredList.also { onExpandedChange(true) }
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

work is not done on BG thread. you need to use the withContext

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

viewModelScope.launch(Dispatchers.Default) { doWork }
viewModelScope.launch { withContext(Dispatchers.Default) { doWork }
isn't it the same thing?

about questions above

  1. Yes. and I can't do anything with it. check please 3 point with detail explanation
  2. done fixing
  3. No difference, I'll remove one of them
  4. native exposed dropdown menu -> current implementation by jetpack compose which works very bad with large list of data, because it uses column instead of lazyColumn under hood. that's why you can see lags, which causes ANR, because I used large list of data. And i added this sample on screen especially to show that lagging compare to AndroidView and custom implementation
    custom exposed dropdown menu -> my implementation. which based on implementation by jetpack compose. (so I just copy pasted most of code) The main work I did - replace column with lazyColumn which causes all the problems with lags.

Comment on lines 33 to 37
val filteredList = countries.filter { country ->
country
.lowercase()
.startsWith(input.lowercase()) && country != input
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems we are not using filteredList anywhere

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we actually use:

handle[SUGGESTIONS] = if (input.isEmpty()) countries else ... filteredList

.lowercase()
.startsWith(input.lowercase()) && country != input
}
filteredList.also { onExpandedChange(true) }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any reason not to do filteredList.also { onExpandedChange(true) } -> onExpandedChange(true) ?

Comment on lines +36 to +38
val textFieldValue = remember {
mutableStateOf(TextFieldValue(query, TextRange(query.length)))
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we use query as a key here?

modifier: Modifier = Modifier,
countries: List<String>,
) {
val coroutineScope = rememberCoroutineScope()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant coroutineScope

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants