Skip to content

Latest commit

 

History

History
88 lines (67 loc) · 2.79 KB

rotate.md

File metadata and controls

88 lines (67 loc) · 2.79 KB

Rotate

Translations: 简体中文

rotate()

ZoomImage provides a modified rotate() method to rotate the image to a specified angle, which has one parameter:

  • targetRotation: Int: Target rotation angle, which can only be a multiple of 90, such as 0, 90, 180, 270, 360, etc

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 = {
        coroutineScope.launch {
            val targetRotation = state.zoomable.transform.rotation.roundToInt() + 90
            state.zoomable.rotate(targetRotation = targetRotation)
        }
    }
) {
    Text(text = "right rotate 90")
}

Button(
    onClick = {
        coroutineScope.launch {
            val targetRotation = state.zoomable.transform.rotation.roundToInt() - 90
            state.zoomable.rotate(targetRotation = targetRotation)
        }
    }
) {
    Text(text = "left rotate 90")
}

Public Properties

// compose
val state: ZoomState by rememberZoomState()
SketchZoomAsyncImage(state = state)
val zoomable: ZoomableState = state.zoomable

// view
val sketchZoomImageView = SketchZoomImageView(context)
val zoomable: ZoomableEngine = sketchZoomImageView.zoomable

Note: The relevant properties of the view version are wrapped in StateFlow, so its name is suffixed with State compared to the compose version

  • zoomable.transform.rotation: Float: Current rotation angle (base rotation angle + user rotation angle)
  • zoomable.baseTransform.rotation: Float: The current base rotation angle, affected by the rotate() method
  • zoomable.userTransform.rotation: Float: The current user rotation angle, which is always 0

Listen property changed

  • The relevant properties of the compose version are wrapped in State and can be read directly in the Composable function to implement listening
  • The relevant properties of the view are wrapped in StateFlow, and its collect function can be called to implement the listening