Skip to content

Commit

Permalink
Add OverzoomEffect.Disabled
Browse files Browse the repository at this point in the history
Fixes #101
  • Loading branch information
saket committed Jan 31, 2025
1 parent 9d2e2b2 commit 965503b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ import androidx.compose.ui.test.performScrollToKey
import androidx.compose.ui.test.performTouchInput
import androidx.compose.ui.test.pinch
import androidx.compose.ui.test.swipeLeft
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.center
import androidx.compose.ui.unit.dp
import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.containsOnly
import assertk.assertions.isEmpty
import assertk.assertions.isEqualTo
Expand Down Expand Up @@ -275,6 +277,45 @@ class ZoomableTest {
}
}

@Test fun disable_over_and_under_zoom() {
val observedScales = ArrayDeque<ScaleFactor>()
rule.setContent {
val zoomableState = rememberZoomableState(
ZoomSpec(
maxZoomFactor = 2f,
overzoomEffect = OverzoomEffect.Disabled,
)
)
Box(
Modifier
.fillMaxSize()
.zoomable(zoomableState)
.testTag("content")
)

LaunchedEffect(Unit) {
snapshotFlow { zoomableState.contentTransformation.scale }.collect {
observedScales.addLast(it)
}
}
}

val content = rule.onNodeWithTag("content")
content.performTouchInput {
doubleClick()
}
rule.runOnIdle {
assertThat(observedScales.removeAll()).contains(ScaleFactor(2f, 2f))
}

content.performTouchInput {
pinchToZoomInBy(IntOffset(10, 10))
}
rule.runOnIdle {
assertThat(observedScales.removeAll()).isEmpty()
}
}

@Test fun pan_and_zoom_from_code(
@TestParameter animate: Boolean,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ private fun OverzoomEffect.adjust(zoomDelta: Float): Float {
else -> 1f - zoomDelta / 250
}
}
OverzoomEffect.Disabled -> 1f
OverzoomEffect.NoLimits -> zoomDelta
else -> error("unknown overzoom effect = $this")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class ZoomSpec(
val maxZoomFactor: Float
get() = maximum.factor

@Suppress("unused")
@Deprecated(
message = "Use maximum.overzoomEffect instead.",
replaceWith = ReplaceWith("maximum.overzoomEffect != OverZoomEffect.None"),
Expand Down Expand Up @@ -102,5 +103,11 @@ class OverzoomEffect internal constructor(
* manner even when it goes beyond its limit (until the gesture is released).
*/
val NoLimits: OverzoomEffect = OverzoomEffect(2)

/**
* Disables overzoom effects entirely. Content will stop zooming as soon as it
* reaches its limits, without any additional visual feedback or elasticity.
*/
val Disabled: OverzoomEffect = OverzoomEffect(3)
}
}

0 comments on commit 965503b

Please sign in to comment.