EmbeddedPhotoPickerState

@RequiresApi(value = 34)
@ExperimentalPhotoPickerComposeApi
interface EmbeddedPhotoPickerState


State model of a EmbeddedPhotoPickerSession. This interface models the state and session management lifecycle of the Embedded Photopicker between the client application and the remote service.

A default implementation is provided via the rememberEmbeddedPhotoPickerState composable which can be used to obtain an implementation that should work for most use cases. This object can be passed to the EmbeddedPhotoPicker composable which provides the display layer for the Embedded PhotoPicker.

Callbacks to the underlying session are exposed here to push Compose state into the remote view.

Summary

Public functions

open suspend Unit

Request the EmbeddedPhotoPickerSession deselect the media item with the provided Uri.

suspend Unit

Request the EmbeddedPhotoPickerSession deselect media items with the provided list of Uris from its interface.

Unit

Notify the underlying EmbeddedPhotoPickerSession that the current Configuration has changed.

Unit

Notify the underlying EmbeddedPhotoPickerSession that its parent view has been resized.

Unit

Receiver for when the user is done with their selection and the picker should be collapsed.

Unit

Receiver for when the Photopicker Session encounters a terminal error.

Unit

Receiver for when URI permission has been granted to item(s) selected by the user.

Unit

Receiver for when URI permission has been revoked of an item deselected by the user.

suspend Unit
@RequiresExtension(extension = 34, version = 15)
runSession(
    provider: EmbeddedPhotoPickerProvider,
    featureInfo: EmbeddedPhotoPickerFeatureInfo,
    onReceiveSession: (EmbeddedPhotoPickerSession) -> Unit
)

Run a EmbeddedPhotoPickerSession using the state provided by this state object.

Public properties

Boolean

The current expanded state of this state object.

Boolean

The current ready state of this state object.

Set<Uri>

A read-only set of URIs representing the currently selected media items.

IBinder?

The host token for the SurfaceControlViewHost where the picker UI will be rendered.

Public functions

deselectUri

Added in 1.0.0-alpha02
open suspend fun deselectUri(uri: Uri): Unit

Request the EmbeddedPhotoPickerSession deselect the media item with the provided Uri.

NOTE: The Uri should have been received from the PhotoPicker. Regular android.provider.MediaStore uris, or other Uris passed here will be ignored by the Photopicker.

Parameters
uri: Uri

the Uri that should be deselected in the PhotoPicker's interface.

deselectUris

suspend fun deselectUris(uris: List<Uri>): Unit

Request the EmbeddedPhotoPickerSession deselect media items with the provided list of Uris from its interface.

NOTE: The Uri should have been received from the PhotoPicker. Regular android.provider.MediaStore uris, or other Uris passed here will be ignored by the PhotoPicker.

Parameters
uris: List<Uri>

the List of Uri that should be deselected in the PhotoPicker's interface.

notifyConfigurationChanged

Added in 1.0.0-alpha02
fun notifyConfigurationChanged(config: Configuration): Unit

Notify the underlying EmbeddedPhotoPickerSession that the current Configuration has changed.

notifyResized

Added in 1.0.0-alpha02
fun notifyResized(size: IntSize): Unit

Notify the underlying EmbeddedPhotoPickerSession that its parent view has been resized.

Parameters
size: IntSize

The new size of the parent view.

onSelectionComplete

Added in 1.0.0-alpha02
fun onSelectionComplete(): Unit

Receiver for when the user is done with their selection and the picker should be collapsed.

See also
EmbeddedPhotoPickerClient

#onSelectionComplete

onSessionError

Added in 1.0.0-alpha02
fun onSessionError(throwable: Throwable): Unit

Receiver for when the Photopicker Session encounters a terminal error.

See also
EmbeddedPhotoPickerClient

#onSessionError

onUriPermissionGranted

fun onUriPermissionGranted(uris: List<Uri>): Unit

Receiver for when URI permission has been granted to item(s) selected by the user.

See also
EmbeddedPhotoPickerClient

#onUriPermissionGranted

onUriPermissionRevoked

fun onUriPermissionRevoked(uris: List<Uri>): Unit

Receiver for when URI permission has been revoked of an item deselected by the user.

See also
EmbeddedPhotoPickerClient

#onUriPermissionRevoked

runSession

Added in 1.0.0-alpha02
@RequiresExtension(extension = 34, version = 15)
suspend fun runSession(
    provider: EmbeddedPhotoPickerProvider,
    featureInfo: EmbeddedPhotoPickerFeatureInfo,
    onReceiveSession: (EmbeddedPhotoPickerSession) -> Unit
): Unit

Run a EmbeddedPhotoPickerSession using the state provided by this state object.

This suspended function should be started from a androidx.compose.runtime.LaunchedEffect in the composable hosting the SurfaceView the EmbeddedPhotoPicker is drawing to. The function should perform the necessary startup logic with the EmbeddedPhotoPickerProvider, and then run the provided client in a child scope of the current CoroutineScope. Throughout the entire session, and then close / cleanup any resources being used when the suspended function is cancelled.

Parameters
provider: EmbeddedPhotoPickerProvider

The provider that should be used for this session.

featureInfo: EmbeddedPhotoPickerFeatureInfo

The client provided EmbeddedPhotoPickerFeatureInfo to configure the Embedded PhotoPicker.

onReceiveSession: (EmbeddedPhotoPickerSession) -> Unit

A callback from the display layer, which can be used to pass the opened Session back to the display layer so it can be attached to the SurfaceView.

Public properties

isExpanded

Added in 1.0.0-alpha02
var isExpandedBoolean

The current expanded state of this state object. Signifies whether the underlying EmbeddedPhotopicker session is expanded or collapsed.

isReadyToRunSession

Added in 1.0.0-alpha02
val isReadyToRunSessionBoolean

The current ready state of this state object. Signifies that the Compose host is ready, which allows the display layer Composable to call runSession.

selectedMedia

Added in 1.0.0-alpha02
val selectedMediaSet<Uri>

A read-only set of URIs representing the currently selected media items. Updated internally based on granted/revoked permissions.

surfaceHostToken

Added in 1.0.0-alpha02
var surfaceHostTokenIBinder?

The host token for the SurfaceControlViewHost where the picker UI will be rendered. Set externally before runSession is called.