-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: master
Are you sure you want to change the base?
Conversation
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.
good job @RostyslavKloos !
app/src/main/java/com/skyyo/samples/features/autoComplete/CustomExposedDropdownMenuSample.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/com/skyyo/samples/features/autoComplete/CustomExposedDropdownMenuSample.kt
Outdated
Show resolved
Hide resolved
.../main/java/com/skyyo/samples/features/autoComplete/AndroidViewTextFieldWithDropDownSample.kt
Outdated
Show resolved
Hide resolved
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.
- pushed small cleanup commit to your branch.
NativeExposedDropDownMenuSample
->AutocompleteDropdownWithFilteringInside
CustomExposedDropdownMenuSample
->AutocompleteDropdownWithOutsideFiltering
AndroidViewTextFieldWithDropDownSample
->AndroidViewAutocompleteDropdownWithOutsideFiltering
- Not sure why we have 2x
AndroidViewTextFieldWithDropDownSample
, Unless there is something to showcase, let's please leave single one @RostyslavKloos 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 } |
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.
? can be deleted
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.
- I wanted to demonstrate how it should behave depends on layout position. But yeah, it's not necessary
- 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
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.
- The biggest issue is still lagging, which causes ANR.
- There is empty dropdown in certain scenarios.
Video describing the above. - Not sure what's the difference between two "AndroidViews".
- Not sure what's the difference between "native exposed dropdown menu" and "custom exposed dropdown menu"
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) } | ||
} | ||
} |
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.
work is not done on BG thread. you need to use the withContext
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.
viewModelScope.launch(Dispatchers.Default) { doWork }
viewModelScope.launch { withContext(Dispatchers.Default) { doWork }
isn't it the same thing?
about questions above
- Yes. and I can't do anything with it. check please 3 point with detail explanation
- done fixing
- No difference, I'll remove one of them
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 toAndroidView
andcustom 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.
val filteredList = countries.filter { country -> | ||
country | ||
.lowercase() | ||
.startsWith(input.lowercase()) && country != input | ||
} |
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.
seems we are not using filteredList
anywhere
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.
we actually use:
handle[SUGGESTIONS] = if (input.isEmpty()) countries else ... filteredList
.lowercase() | ||
.startsWith(input.lowercase()) && country != input | ||
} | ||
filteredList.also { onExpandedChange(true) } |
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.
is there any reason not to do filteredList.also { onExpandedChange(true) }
-> onExpandedChange(true)
?
val textFieldValue = remember { | ||
mutableStateOf(TextFieldValue(query, TextRange(query.length))) | ||
} |
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.
shouldn't we use query
as a key here?
modifier: Modifier = Modifier, | ||
countries: List<String>, | ||
) { | ||
val coroutineScope = rememberCoroutineScope() |
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.
redundant coroutineScope
improvements compare to "exposedDropDown" implementation:
differences compare to "androidView" implementation:
2022-05-18.12.58.48.mp4