JengaImageViewer

fun JengaImageViewer(onDismissRequest: () -> Unit, title: String, closeContentDescription: String, modifier: Modifier = Modifier, actions: @Composable RowScope.() -> Unit = {}, titleStyle: TextStyle = JengaImageViewerDefaults.titleStyle, maxScale: Float = JengaImageViewerDefaults.MaxScale, colors: JengaImageViewerColors = JengaImageViewerDefaults.colors(), content: @Composable () -> Unit)(source)

A full-screen image viewer on a dark backdrop: a top row with a close button, a title and trailing actions (e.g. download, share), above the image in content. The image can be pinch-zoomed and panned, and a double tap toggles zoom. Pressing back or the close button calls onDismissRequest.

Control visibility by conditional composition.

Parameters

onDismissRequest

called when the viewer should close.

title

the title shown in the top row (e.g. the file name).

closeContentDescription

accessibility label for the close button.

modifier

the Modifier for the viewer.

actions

trailing actions in the top row; inherit the content color.

titleStyle

the title text style.

maxScale

the largest zoom factor; at least 1.

colors

the color set; defaults to JengaImageViewerDefaults.colors.

content

the image (e.g. a JengaImage that fills the space).

Samples

var open by remember {
    mutableStateOf(
        value = true,
    )
}
if (open) {
    JengaImageViewer(
        onDismissRequest = { open = false },
        title = "photo.jpg",
        closeContentDescription = "Close",
        content = {
            JengaImage(
                url = "https://example.com/photo.jpg",
                contentDescription = null,
                fit = JengaImageFit.Contain,
            )
        },
    )
}

fun JengaImageViewer(pageCount: Int, onDismissRequest: () -> Unit, title: (page: Int) -> String, closeContentDescription: String, modifier: Modifier = Modifier, initialPage: Int = 0, actions: @Composable RowScope.(page: Int) -> Unit = {}, bottomBar: @Composable (page: Int, goToPage: (Int) -> Unit) -> Unit = { _, _ -> }, titleStyle: TextStyle = JengaImageViewerDefaults.titleStyle, maxScale: Float = JengaImageViewerDefaults.MaxScale, colors: JengaImageViewerColors = JengaImageViewerDefaults.colors(), pageContent: @Composable (page: Int) -> Unit)(source)

A full-screen viewer for several images: swipe sideways between pageCount pages, each pinch-zoomed on its own. Pages swipe only while the current page is not zoomed in, and a page's zoom resets when it leaves the screen. Pressing back or the close button calls onDismissRequest.

Control visibility by conditional composition.

Parameters

pageCount

the number of pages.

onDismissRequest

called when the viewer should close.

title

the title for a page (e.g. "Photo 2 of 3").

closeContentDescription

accessibility label for the close button.

modifier

the Modifier for the viewer.

initialPage

the page shown first.

actions

trailing actions in the top row for the shown page.

bottomBar

content under the pages (e.g. a strip of thumbnails), given the shown page and a function that moves to another page.

titleStyle

the title text style.

maxScale

the largest zoom factor; at least 1.

colors

the color set; defaults to JengaImageViewerDefaults.colors.

pageContent

the image for a page.

Samples

val urls = listOf(
    "https://example.com/1.jpg",
    "https://example.com/2.jpg",
)
var open by remember {
    mutableStateOf(
        value = true,
    )
}
if (open) {
    JengaImageViewer(
        pageCount = urls.size,
        onDismissRequest = { open = false },
        title = { page -> "Photo ${page + 1} of ${urls.size}" },
        closeContentDescription = "Close",
        pageContent = { page ->
            JengaImage(
                url = urls[page],
                contentDescription = null,
                fit = JengaImageFit.Contain,
            )
        },
    )
}