panpf / zoomimage

ZoomImage is an gesture zoom viewing of images library specially designed for Compose Multiplatform and Android View. Supported scale, pan, locate, rotation, and super-large image subsampling.
Apache License 2.0
344 stars 19 forks source link

Crash when set containerWhitespace #63

Closed maciek-s closed 3 hours ago

maciek-s commented 4 days ago

Describe the bug

App crash when swipe without scroll after set containerWhitespace

Affected platforms

Affected components

Select of the components below:

Versions

Running Devices

Please accurately describe the device Model, OS version, and CPU Architecture

Sample code

Scaffold(
    topBar = {
        TopAppBar(
            title = {},
            colors = TopAppBarDefaults.topAppBarColors(
                containerColor = MaterialTheme.colorScheme.surface.copy(alpha = 0.8f)
            )
        )
    }
) { innerPadding ->
    val zoomState: ZoomState = rememberZoomState()

    LaunchedEffect(zoomState.zoomable) {
        zoomState.zoomable.apply {
            disabledGestureTypes = disabledGestureTypes or GestureType.ONE_FINGER_SCALE
            containerWhitespace = ContainerWhitespace(vertical = 100f, horizontal = 0f)
        }
    }

    val painter = rememberAsyncImagePainter(
        model = "https://picsum.photos/2000/2000"
    )

    ZoomImage(
        modifier = Modifier.fillMaxSize(),
        alignment = Alignment.TopCenter,
        painter = painter,
        contentDescription = null,
        contentScale = ContentScale.Fit,
        zoomState = zoomState,
        scrollBar = null,
    )
}

Reproduction steps

When swipe on image without zooming app crashed

java.lang.IllegalArgumentException: Cannot coerce value to an empty range: maximum -423.0 is less than minimum 424.0.
                                                                                                        at kotlin.ranges.RangesKt___RangesKt.coerceIn(_Ranges.kt:1442)
                                                                                                        at com.github.panpf.zoomimage.compose.util.Compose_platform_utilsKt.limitTo-3MmeM6k(compose_platform_utils.kt:362)

Screenshots

https://github.com/user-attachments/assets/d2e37340-75af-4c3b-951a-0b026e386eda

Question

In my sample, I have a transparent toolbar. Is it possible to display an image beneath the toolbar and allow zooming without clipping to the padding? Unfortunately, containerWhitespace, as shown in the video, is added after zooming. Additionally, when I add padding to the ZoomImage, it does not appear beneath the toolbar after zooming.

panpf commented 2 days ago

The problem has been found and is being solved

panpf commented 1 day ago

This issue has been fixed on the dev branch and a snapshot version is being released. You can download version 1.1.0-rc03-SNAPSHOT from the snapshot repository in two hours to test if there is still any problem.

maciek-s commented 17 hours ago

Thanks, I tested snapshot release, and issue no longer occurs. How about my question at bottom of bug description? It is possible to add top padding to ZoomImage and when zoom in do not clip image to padding?

panpf commented 9 hours ago

Open a new issue. This is similar to setting padding in View but clipPadding = false

panpf commented 3 hours ago

Fixed in version 1.0-rc03