Skip to content

Latest commit

 

History

History
61 lines (45 loc) · 1.2 KB

Capturable.md

File metadata and controls

61 lines (45 loc) · 1.2 KB

Capturable

Capturable is a composable that allows you to (capture / take snapshot of / take screenshot of) any composable.

Step 1 : Define state

val captureState = rememberCaptureState() // Returns MutableState<CaptureState?>

Step 2 : Composable

Enclose the composable to be captured inside the Capturable composable :

@Composable
fun Capturable(
    state: MutableState<CaptureState?>,
    content: @Composable () -> Unit
)

Example :

Capturable(state = captureState) {
    CountryCard(
        country = Country("IN", "Bharat", "Asia")
    )
}

Everything inside the content composable will be captured.

Step 3 : Capture

To capture the passed composable as Bitmap, invoke the captureState.capture() function :

fun MutableState<CaptureState?>.capture(
    callback: (Bitmap) -> Unit // Use the bitmap inside this lambda
)

Example :

Button(
    onClick = {
        captureState.capture { bitmap ->
            saveAndShareImage(bitmap)
        }
    }
) {
    Text(text = "Capture & Share")
}