Skip to content

Instantly share code, notes, and snippets.

@ioleo
Forked from seamusv/UseScrollPosition.scala
Created January 17, 2020 14:09
Show Gist options
  • Save ioleo/c71343d73fa93775e8674b4ee00926bd to your computer and use it in GitHub Desktop.
Save ioleo/c71343d73fa93775e8674b4ee00926bd 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, _]): Unit = js.native
def useScrollPosition(effect: js.Function1[UseScrollPosition.ScrollProps, _], deps: js.Array[js.Any]): Unit = js.native
def useScrollPosition(effect: js.Function1[UseScrollPosition.ScrollProps, _], deps: js.Array[js.Any], element: ReactRef[html.Element | Null]): Unit = js.native
def useScrollPosition(effect: js.Function1[UseScrollPosition.ScrollProps, _], deps: js.Array[js.Any], element: ReactRef[html.Element | Null], useWindow: Boolean): Unit = js.native
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): Unit =
UseScrollPositionRaw.useScrollPosition(effect)
@inline def useScrollPosition(effect: ScrollProps => Unit, deps: Iterable[Any]): Unit =
UseScrollPositionRaw.useScrollPosition(effect, deps.toJSArray.asInstanceOf[js.Array[js.Any]])
@inline def useScrollPosition(effect: ScrollProps => Unit, deps: Iterable[Any], element: ReactRef[html.Element | Null]): Unit =
UseScrollPositionRaw.useScrollPosition(effect, deps.toJSArray.asInstanceOf[js.Array[js.Any]], element)
@inline def useScrollPosition(effect: ScrollProps => Unit, deps: Iterable[Any], element: ReactRef[html.Element | Null], useWindow: Boolean): Unit =
UseScrollPositionRaw.useScrollPosition(effect, deps.toJSArray.asInstanceOf[js.Array[js.Any]], element, useWindow)
@inline def useScrollPosition(effect: ScrollProps => Unit, deps: Iterable[Any], element: ReactRef[html.Element | Null], useWindow: Boolean, wait: Int): 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