PausedComposition
-
Cmn
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.
Summary
Public functions |
||
|---|---|---|
Unit |
apply()Apply the composition. |
Cmn
|
Unit |
cancel()Cancels the paused composition. |
Cmn
|
Boolean |
resume(shouldPause: ShouldPauseCallback)Resume the composition that has been paused. |
Cmn
|
Public properties |
||
|---|---|---|
Boolean |
Returns |
Cmn
|
Boolean |
Returns |
Cmn
|
Boolean |
Returns |
Cmn
|
Public functions
apply
fun apply(): Unit
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.
cancel
fun cancel(): Unit
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.
resume
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: ShouldPauseCallback |
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 |
| Returns | |
|---|---|
Boolean |
|
Public properties
isApplied
val isApplied: Boolean
Returns true when the PausedComposition is applied. isApplied becomes true after calling apply. Calling any method on the PausedComposition when isApplied is true will throw an exception.
isCancelled
val isCancelled: Boolean
Returns true when the PausedComposition is cancelled. isCancelled becomes true after calling cancel. Calling any method on the PausedComposition when isCancelled is true will throw an exception. If isCancelled is true then the Composition that was used to create PausedComposition is in an uncertain state and must be discarded.
isComplete
val isComplete: Boolean
Returns true when the PausedComposition is complete. isComplete matches the last value returned from resume. Once a PausedComposition is isComplete the apply method should be called. If the apply method is not called synchronously and immediately after resume returns true then this isComplete can return false as any state changes read by the paused composition while it is paused will cause the composition to require the paused composition to need to be resumed before it is used.