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 callback to be called when reportFullyDrawn is called by this class.

Unit

Adds a lock to prevent calling reportFullyDrawn.

Unit

Removes a previously registered callback so that it won't be called when reportFullyDrawn is called by this class.

Unit

Removes a lock added in addReporter.

Public properties

Boolean

Returns true after reportFullyDrawn has been called or if backed by a ComponentActivity and ComponentActivity.reportFullyDrawn has been called.

Extension functions

suspend inline Unit
FullyDrawnReporter.reportWhenComplete(reporter: suspend () -> Unit)

Tells the FullyDrawnReporter to wait until reporter has completed before calling Activity.reportFullyDrawn.

Public constructors

FullyDrawnReporter

Added in 1.7.0
FullyDrawnReporter(executor: Executor, reportFullyDrawn: () -> Unit)
Parameters
executor: Executor

The Executor on which to call reportFullyDrawn.

reportFullyDrawn: () -> Unit

Will be called when all reporters have been removed.

Public functions

addOnReportDrawnListener

Added in 1.7.0
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.

addReporter

Added in 1.7.0
fun addReporter(): Unit

Adds a lock to prevent calling reportFullyDrawn.

removeOnReportDrawnListener

Added in 1.7.0
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

Added in 1.7.0
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

Added in 1.7.0
val isFullyDrawnReportedBoolean

Returns true after reportFullyDrawn has been called or if backed by a ComponentActivity and ComponentActivity.reportFullyDrawn has been called.

Extension functions

reportWhenComplete

suspend inline fun FullyDrawnReporter.reportWhenComplete(reporter: suspend () -> Unit): Unit

Tells the FullyDrawnReporter to wait until reporter has completed before calling Activity.reportFullyDrawn.