marshallformula / elm-swiper / Swiper

This library handles detection of specific touch events (for mobile) that indicates a user swiping across the specified DOM element.

State


type SwipingState

Since there is no actual "swipe" event - the detection of a swipe is determined by evaluating the coordinates of "touchstart" and "touchend" events. This means some "state" must be stored by the application between events. That state is encapsulated in SwipingState. Store this so it can be passed to a hasSwipedXXX function.

initialSwipingState : SwipingState

Returns an initial SwipingState with which to initialize the application.

Events


type SwipeEvent

This event is either a "touchstart" or "touchend" event. You don't need to worry about which - just need to hang on to it so you can pass it back to a "hasSwipedXXX" function.

onSwipeEvents : (SwipeEvent -> msg) -> List (Html.Attribute msg)

Function that detects the touch events. A message wrapper is passed in to be handled in the application update handler. It returns a list of Attributes (it must be a list because it can fire both "touchstart" and "touchend" states)

Swipe Detection

hasSwipedLeft : SwipeEvent -> SwipingState -> ( SwipingState, Basics.Bool )

Checks whether the the event & state indicates a swipe to the left. Returns a tuple with the new SwipingState and the Bool answer.

hasSwipedRight : SwipeEvent -> SwipingState -> ( SwipingState, Basics.Bool )

Checks whether the event & state indicates a swipe to the right. Returns a tuple with the new SwipingState and the Bool answer.

hasSwipedUp : SwipeEvent -> SwipingState -> ( SwipingState, Basics.Bool )

Checks whether the event & state indicates a swipe upward. Returns a tuple with the new SwipingState and the Bool answer.

hasSwipedDown : SwipeEvent -> SwipingState -> ( SwipingState, Basics.Bool )

Checks whther the event & state indicates a swipe downward. Returns a tuple with the new SwipingState and the Bool answer.

touchFinished : SwipeEvent -> Basics.Bool

Convenience function that will indicate if this is a "touchend" event.