Skip to content

Latest commit

 

History

History
54 lines (42 loc) · 1.84 KB

locate.md

File metadata and controls

54 lines (42 loc) · 1.84 KB

Locate

Translations: 简体中文

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 state: ZoomState by rememberZoomState()

SketchZoomAsyncImage(
    imageUri = "http://sample.com/sample.jpg",
    contentDescription = "view image",
    modifier = Modifier.fillMaxSize(),
    state = state,
)

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 {
            state.zoomable.locate(
                contentPoint = state.zoomable.contentSize.center,
                targetScale = state.zoomable.transform.scaleX.coerceAtLeast(state.zoomable.mediumScale),
                animated = true,
            )
        }
    }
) {
    Text(text = "locate to center")
}