16

I'm learning accompanist pager and I want to set effect on the pager.

I want to use the lerp method like the document

Modifier.graphicsLayer {
    // Calculate the absolute offset for the current page from the
    // scroll position. We use the absolute value which allows us 
    // to mirror any effects for both directions
    val pageOffset = 
        calculateCurrentOffsetForPage(page).absoluteValue

    // We animate the scaleX + scaleY, between 85% and 100%
    lerp(
      start = 0.85f,
      stop = 1f,
      fraction = 1f - pageOffset.coerceIn(0f, 1f)).also { scale ->
        scaleX = scale
        scaleY = scale
      }

    // We animate the alpha, between 50% and 100%
    alpha = lerp(
      start = 0.5f,
      stop = 1f,
      fraction = 1f - pageOffset.coerceIn(0f, 1f)
                                )

but I can't find the right import for the lerp method for animating the scale like documentation. any suggestions are welcome

MohammadBaqer
  • 766
  • 6
  • 32
  • 3
    have you tried `import androidx.compose.ui.util.lerp`? – MR3YY Mar 03 '22 at 16:54
  • @MR3YY yes, but I couldnt find that – MohammadBaqer Mar 03 '22 at 17:21
  • how you couldn't find it? do you mean AS isn't able to resolve it? – MR3YY Mar 03 '22 at 17:22
  • @MR3YY there is no `androidx.compose.ui.util` – MohammadBaqer Mar 03 '22 at 17:26
  • 1
    maybe google isn't publishing `:ui-util` artifact. but anyway as a workaround it is super easy to make a `lerp` function without depending on extra dependency, Copy the function body from: main:compose/ui/ui-util/src/commonMain/kotlin/androidx/compose/ui/util/MathHelpers.kt;l=24?q=lerp&ss=androidx%2Fplatform%2Fframeworks%2Fsupport:compose – MR3YY Mar 03 '22 at 17:34
  • @MR3YY from where ? – MohammadBaqer Mar 03 '22 at 17:40
  • 3
    the given link: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-util/src/commonMain/kotlin/androidx/compose/ui/util/MathHelpers.kt;l=24?q=lerp&sq=&ss=androidx%2Fplatform%2Fframeworks%2Fsupport:compose%2F – MR3YY Mar 03 '22 at 17:42

1 Answers1

43

I faced this issue. The issue solved after add this dependency:

implementation "androidx.compose.ui:ui-util:$compose_version"

Enes Zor
  • 973
  • 8
  • 14