FullyDrawnReporter
class FullyDrawnReporter
Manages when to call Activity.reportFullyDrawn. Different parts of the UI may individually indicate when they are ready for interaction. Activity.reportFullyDrawn will only be called by this class when all parts are ready. At least one addReporter or reportWhenComplete must be used before Activity.reportFullyDrawn will be called by this class.
For example, to use coroutines:
val fullyDrawnReporter = componentActivity.fullyDrawnReporter
launch {
fullyDrawnReporter.reportWhenComplete {
dataLoadedMutex.lock()
dataLoadedMutex.unlock()
}
}
Or it can be manually controlled:
// On the UI thread:
fullyDrawnReporter.addReporter()
// Do the loading on worker thread:
fullyDrawnReporter.removeReporter()Summary
Public constructors |
|---|
FullyDrawnReporter(executor: Executor, reportFullyDrawn: () -> Unit) |
Public functions |
|
|---|---|
Unit |
addOnReportDrawnListener(callback: () -> Unit)Registers |
Unit |
Adds a lock to prevent calling |
Unit |
removeOnReportDrawnListener(callback: () -> Unit)Removes a previously registered |
Unit |
Removes a lock added in |
Public properties |
|
|---|---|
Boolean |
Returns |
Extension functions |
|
|---|---|
suspend inline Unit |
FullyDrawnReporter.reportWhenComplete(reporter: suspend () -> Unit)Tells the |
Public constructors
FullyDrawnReporter
FullyDrawnReporter(executor: Executor, reportFullyDrawn: () -> Unit)
| Parameters | |
|---|---|
executor: Executor |
The |
reportFullyDrawn: () -> Unit |
Will be called when all reporters have been removed. |
Public functions
addOnReportDrawnListener
fun addOnReportDrawnListener(callback: () -> Unit): Unit
Registers callback to be called when reportFullyDrawn is called by this class. If it has already been called, then callback will be called immediately.
Once callback has been called, it will be removed and removeOnReportDrawnListener does not need to be called to remove it.
removeOnReportDrawnListener
fun removeOnReportDrawnListener(callback: () -> Unit): Unit
Removes a previously registered callback so that it won't be called when reportFullyDrawn is called by this class.
removeReporter
fun removeReporter(): Unit
Removes a lock added in addReporter. When all locks have been removed, reportFullyDrawn will be called on the next animation frame.
Public properties
isFullyDrawnReported
val isFullyDrawnReported: Boolean
Returns true after reportFullyDrawn has been called or if backed by a ComponentActivity and ComponentActivity.reportFullyDrawn has been called.
Extension functions
FullyDrawnReporter.reportWhenComplete
suspend inline fun FullyDrawnReporter.reportWhenComplete(reporter: suspend () -> Unit): Unit
Tells the FullyDrawnReporter to wait until reporter has completed before calling Activity.reportFullyDrawn.