PausedComposition
public sealed interface PausedComposition
PausedComposition
is the result of calling PausableComposition.setContent
or
PausableComposition.setContentWithReuse
. It is used to drive the paused composition to
completion. A PausedComposition
should not be used until isComplete
is true
and apply
has
been called.
A PausedComposition
is created paused and will only compose the content
parameter when
resume
is called the first time.
Functions
public fun resume(shouldPause: ShouldPauseCallback): Boolean
Resume the composition that has been paused. This method should be called until resume
returns true
or isComplete
is true
which has the same result as the last result of
calling resume
. The shouldPause
parameter is a lambda that returns whether the
composition should be paused. For example, in lazy lists this returns false
until just
prior to the next frame starting in which it returns true
Calling resume
after it returns true
or when isComplete
is true
will throw an
exception.
Parameters
shouldPause | A lambda that is used to determine if the composition should be paused. This lambda is called often so should be a very simple calculation. Returning true does not guarantee the composition will pause, it should only be considered a request to pause the composition. Not all composable functions are pausable and only pausable composition functions will pause. |
Returns
true if the composition is complete and false if one or more calls to resume are required to complete composition. |
public fun apply()
Apply the composition. This is the last step of a paused composition and is required to be called prior to the composition is usable.
Calling apply
should always be proceeded with a check of isComplete
before it is called
and potentially calling resume
in a loop until isComplete
returns true
. This can happen
if resume
returned true
but apply
was not synchronously called immediately afterwords.
Any state that was read that changed between when resume
being called and apply
being
called may require the paused composition to be resumed before applied.
public fun cancel()
Cancels the paused composition. This should only be used if the composition is going to be disposed and the entire composition is not going to be used.