Florian
11/09/2020, 6:07 PMinline fun SearchView.onQueryTextChanged(crossinline listener: (String) -> Unit) {
this.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {
return true
}
override fun onQueryTextChange(newText: String?): Boolean {
listener(newText.orEmpty())
return true
}
})
}
Do I understand that correctly, the crossinline modifier assures that we can't call return in the lambda we are passing to this function? Because if we don't call return here, we would leave the onQueryTextChange method.Animesh Sahu
11/09/2020, 6:15 PMonQueryTextChange should not happen iirc, but always do Tools -> Kotlin -> Show Kotlin Bytecode -> Decompile to Java for complete sure(ity). Create a check with a test lambda and decompile !Florian
11/09/2020, 6:22 PMFlorian
11/09/2020, 6:25 PMlouiscad
11/09/2020, 7:39 PMlistener to have suspend calls and return expressions. listener can still throw theoretically though.Florian
11/10/2020, 7:53 AM