Skip to content

Add parameter for custom BringToView delay #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import kotlinx.coroutines.delay
@Composable
fun CropperPreview(
state: CropState,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
bringToViewDelay: Long = 500,
) {
val style = LocalCropperStyle.current
val imgTransform by animateImgTransform(target = state.transform)
Expand All @@ -42,6 +43,7 @@ fun CropperPreview(
hasOverride = pendingDrag != null,
outer = view.toSize().toRect().deflate(viewPadding),
mat = viewMat, local = state.region,
delay = bringToViewDelay,
)
Canvas(
modifier = modifier
Expand Down Expand Up @@ -79,7 +81,8 @@ private fun BringToView(
hasOverride: Boolean,
outer: Rect,
mat: ViewMat,
local: Rect
local: Rect,
delay: Long = 500,
) {
if (outer.isEmpty) return
DisposableEffect(Unit) {
Expand All @@ -92,7 +95,7 @@ private fun BringToView(
if (hasOverride) overrideBlock = true
else {
if (overrideBlock) {
delay(500)
delay(delay)
overrideBlock = false
}
mat.fit(mat.matrix.map(local), outer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ fun ImageCropperDialog(
dialogPadding: PaddingValues = PaddingValues(16.dp),
dialogShape: Shape = RoundedCornerShape(8.dp),
topBar: @Composable (CropState) -> Unit = { DefaultTopBar(it) },
cropControls: @Composable BoxScope.(CropState) -> Unit = { DefaultControls(it) }
cropControls: @Composable BoxScope.(CropState) -> Unit = { DefaultControls(it) },
bringToViewDelay: Long = 500,
) {
CompositionLocalProvider(LocalCropperStyle provides style) {
Dialog(
Expand All @@ -57,7 +58,11 @@ fun ImageCropperDialog(
.weight(1f)
.clipToBounds()
) {
CropperPreview(state = state, modifier = Modifier.fillMaxSize())
CropperPreview(
state = state,
modifier = Modifier.fillMaxSize(),
bringToViewDelay = bringToViewDelay,
)
cropControls(state)
}
}
Expand Down