The Developer Preview for Android 11 is now available; test it out and share your feedback.

CommitScope

interface CommitScope
androidx.compose.CommitScope

A CommitScope represents an object that executes some code and has a cleanup in the context of the Composition lifecycle. It has an "onDispose" operation to cleanup anything that it created whenever it leaves the composition.

Summary

Public methods

abstract Unit
onDispose(callback: () -> Unit)

Provide a lambda which will be executed as this CommitScope leaves the composition.

Inherited extension functions

From androidx.compose
operator T

IMPORTANT: This global operator is TEMPORARY, and should be removed whenever an answer for contextual composers is reached.

Public methods

onDispose

abstract fun onDispose(callback: () -> Unit): Unit

Provide a lambda which will be executed as this CommitScope leaves the composition. It will be executed only once. Use this to schedule cleanup for anything that you construct during the CommitScope's creation.

Parameters
callback: () -> Unit A callback to be executed when this CommitScope leaves the composition.