knledg/touch-events/2.0.0

NOTE: this package is not compatible with Elm 0.19.1

TouchEvents

The is a library to provide touch event helpers

Types

= TouchStart
| TouchEnd
| TouchMove

Supported touch event types

= Left
| Right
| Up
| Down

Supported touch directions

type alias Touch =
{ clientX : Float
, clientY : Float
}

Type alias for the touch record on the touch event object

Helpers

emptyTouch : Touch

Returns a Touch record with 0 as default values

getDirectionX : Float -> Float -> Direction

Gets the direction of the swipe on the x axis (Left or Right)

Event Handlers

onTouchEvent : TouchEvent -> (Touch -> msg) -> Attribute msg

Higher level touch event handler

This takes a TouchEvent type and application Msg type. The Msg type should take a TouchEvent.Touch type.

type Msg
  = UserSwipeStart TouchEvents.Touch

view model =
  div
    [ TouchEvents.onTouchEvent TouchEvents.TouchStart UserSwipeStart
    ]
    []
onTouchEnd : (Touch -> msg) -> Attribute msg

Lower level "touchend" event handler

Takes the application Msg type which should take TouchEvents.Touch as a payload

type Msg
  = UserSwipeEnd TouchEvents.Touch

view model =
  div
    [ TouchEvents.onTouchEnd UserSwipeEnd
    ]
    []
onTouchStart : (Touch -> msg) -> Attribute msg

Lower level "touchstart" event handler

Takes the application Msg type which should take TouchEvents.Touch as a payload

type Msg
  = UserSwipeStart TouchEvents.Touch

view model =
  div
    [ TouchEvents.onTouchStart UserSwipeStart
    ]
    []
onTouchMove : (Touch -> msg) -> Attribute msg

Lower level "touchmove" event handler