Skip to content

Instantly share code, notes, and snippets.

@seamusv
Last active January 17, 2020 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save seamusv/9b12e7e0bbf8b16a4e90e1c6fa245cca to your computer and use it in GitHub Desktop.
Save seamusv/9b12e7e0bbf8b16a4e90e1c6fa245cca to your computer and use it in GitHub Desktop.
ScalaJS facade for @n8tb1t/use-scroll-position
package ca.venasse.hooks
import org.scalajs.dom.html
import slinky.core.facade.ReactRef
import scala.scalajs.js
import scala.scalajs.js.JSConverters._
import scala.scalajs.js.annotation.JSImport
import scala.scalajs.js.|
@JSImport("@n8tb1t/use-scroll-position", JSImport.Namespace)
@js.native
private[this] object UseScrollPositionRaw extends js.Object {
def useScrollPosition(effect: js.Function1[UseScrollPosition.ScrollProps, _], deps: js.Array[js.Any], element: ReactRef[html.Element | Null], useWindow: Boolean, wait: Int): Unit = js.native
}
object UseScrollPosition {
@js.native
sealed trait Position extends js.Object {
val x: Float
val y: Float
}
@js.native
sealed trait ScrollProps extends js.Object {
val prevPos: Position
val currPos: Position
}
@inline def useScrollPosition(effect: ScrollProps => Unit, deps: Iterable[Any] = Iterable.empty, element: ReactRef[html.Element | Null] = null, useWindow: Boolean = false, wait: Int = 0): Unit =
UseScrollPositionRaw.useScrollPosition(effect, deps.toJSArray.asInstanceOf[js.Array[js.Any]], element, useWindow, wait)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment