Niklas Gürtler
02/12/2021, 11:08 AMwithContext(Dispatchers.Main) { invalidate() }
with postInvalidate()
Adam Powell
02/12/2021, 2:36 PMNiklas Gürtler
02/12/2021, 2:37 PMAdam Powell
02/12/2021, 3:16 PMNiklas Gürtler
02/12/2021, 3:16 PMZach Klippenstein (he/him) [MOD]
02/12/2021, 3:37 PMinvalidate()
call is finished (i.e. all the necessary flags have been set), the second will return immediately. launch(Dispatchers.Main) { invalidate() }
would be a better potential candidate for linting.Adam Powell
02/12/2021, 3:53 PMpostInvalidate
-alike at all instead of a plain invalidate
. Most code that calls View.invalidate
should generally be part of a view subclass itself and call it when custom view state changes. Meaningful postInvalidate
usages tend to date back before the Choreographer
was introduced in jellybean and should be so rare today that a lint warning to prefer a particular version of something you shouldn't use at all anymore isn't really necessary.Niklas Gürtler
02/12/2021, 3:54 PMclass MyView : SomeViewClass {
fun onCreate () {
GlobalScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
loadWebAPI ()
postInvalidate()
// or
withContext(Dispatchers.Main) { invalidate() }
}
}
}
Adam Powell
02/12/2021, 4:02 PMtheView.setData(data)
. The view would then call invalidate()
on itself in the implementation of setData
. Invalidating isn't the responsibility of code that binds data to views.Adam Powell
02/12/2021, 4:02 PMNiklas Gürtler
02/12/2021, 4:03 PMAdam Powell
02/12/2021, 4:05 PMAdam Powell
02/12/2021, 4:05 PMNiklas Gürtler
02/12/2021, 4:05 PMAdam Powell
02/12/2021, 4:08 PMAdam Powell
02/12/2021, 4:09 PMNiklas Gürtler
02/12/2021, 4:09 PMAdam Powell
02/12/2021, 4:10 PMAdam Powell
02/12/2021, 4:11 PMAdam Powell
02/12/2021, 4:11 PMNiklas Gürtler
02/12/2021, 4:12 PMAdam Powell
02/12/2021, 4:14 PMNiklas Gürtler
02/12/2021, 4:14 PM