Skip to content

Latest commit

 

History

History
55 lines (43 loc) · 1.88 KB

locate.md

File metadata and controls

55 lines (43 loc) · 1.88 KB

Locate

Translations: 简体中文

Tip

locate()

ZoomImage provides a modified locate() method to locate the specified position of the image, which is displayed in the middle of the screen (except for the edge position), which has three parameters:

  • contentPoint: IntOffset: The anchor on the content, the origin is the upper-left corner of the content
  • targetScale: Float = transform.scaleX: The target magnification, which defaults to the current magnification
  • animated: Boolean = false: Whether to use animation, the default is false

example:

val zoomState: ZoomState by rememberZoomState()

SketchZoomAsyncImage(
  imageUri = "https://sample.com/sample.jpeg",
    contentDescription = "view image",
    modifier = Modifier.fillMaxSize(),
    zoomState = zoomState,
)

val coroutineScope = rememberCoroutineScope()
Button(
    onClick = {
        // Locate to the center of the content and zoom to mediumScale if the current zoom factor is less than MediumScale
        coroutineScope.launch {
            zoomState.zoomable.locate(
                contentPoint = zoomState.zoomable.contentSize.center,
                targetScale = zoomState.zoomable.transform.scaleX.coerceAtLeast(zoomState.zoomable.mediumScale),
                animated = true,
            )
        }
    }
) {
    Text(text = "locate to center")
}