Skip to content

Commit

Permalink
New: Support for touch events (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
felher committed May 9, 2024
1 parent 8f009b8 commit 05d54e6
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,54 @@ trait GlobalEventProps {
lazy val lostPointerCapture: EventProp[dom.PointerEvent] = eventProp("lostpointercapture")


// -- Touch Events --


/**
* The touchstart event is fired when one or more touch points are
* placed on the touch surface.
*
* - [[https://developer.mozilla.org/en-US/docs/Web/API/Element/touchstart_event touchstart_event @ MDN]]
* - [[https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent TouchEvent @ MDN]]
* - [[https://developer.mozilla.org/en-US/docs/Web/API/Touch_events#browser_compatibility Touch_events#browser_compatibility @ MDN]]
*/
lazy val onTouchStart: EventProp[dom.TouchEvent] = eventProp("touchstart")


/**
* The touchmove event is fired when one or more touch points are moved
* along the touch surface.
*
* - [[https://developer.mozilla.org/en-US/docs/Web/API/Element/touchmove_event touchmove_event @ MDN]]
* - [[https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent TouchEvent @ MDN]]
* - [[https://developer.mozilla.org/en-US/docs/Web/API/Touch_events#browser_compatibility Touch_events#browser_compatibility @ MDN]]
*/
lazy val onTouchMove: EventProp[dom.TouchEvent] = eventProp("touchmove")


/**
* The touchcancel event is fired when one or more touch points have
* been disrupted in an implementation-specific manner.
*
* - [[https://developer.mozilla.org/en-US/docs/Web/API/Element/touchcancel_event touchcancel_event @ MDN]]
* - [[https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent TouchEvent @ MDN]]
* - [[https://developer.mozilla.org/en-US/docs/Web/API/Touch_events#browser_compatibility Touch_events#browser_compatibility @ MDN]]
*/
lazy val onTouchCancel: EventProp[dom.TouchEvent] = eventProp("touchcancel")


/**
* The touchend event fires when one or more touch points are removed
* from the touch surface. Remember that it is possible to get a
* touchcancel event instead.
*
* - [[https://developer.mozilla.org/en-US/docs/Web/API/Element/touchend_event touchend_event @ MDN]]
* - [[https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent TouchEvent @ MDN]]
* - [[https://developer.mozilla.org/en-US/docs/Web/API/Touch_events#browser_compatibility Touch_events#browser_compatibility @ MDN]]
*/
lazy val onTouchEnd: EventProp[dom.TouchEvent] = eventProp("touchend")


// -- Form Events --


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class CanonicalDefGroups {
val globalEventPropDefGroups: List[(String, List[EventPropDef])] = List(
"Mouse Events" -> MouseEventPropDefs.defs,
"Pointer Events" -> PointerEventPropDefs.defs,
"Touch Events" -> TouchEventPropDefs.defs,
"Form Events" -> FormEventPropDefs.defs,
"Keyboard Events" -> KeyboardEventPropDefs.defs,
"Clipboard Events" -> ClipboardEventPropDefs.defs,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.raquo.domtypes.defs.eventProps

import com.raquo.domtypes.common.EventPropDef

/** Touch events: triggered by a finger or stylus on a touch surface */
object TouchEventPropDefs {
val defs: List[EventPropDef] = List(

EventPropDef(
scalaName = "onTouchStart",
domName = "touchstart",
scalaJsEventType = "dom.TouchEvent",
javascriptEventType = "TouchEvent",
commentLines = List(
"The touchstart event is fired when one or more touch points are",
"placed on the touch surface."
),
docUrls = List(
"https://developer.mozilla.org/en-US/docs/Web/API/Element/touchstart_event",
"https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent",
"https://developer.mozilla.org/en-US/docs/Web/API/Touch_events#browser_compatibility",
),
),

EventPropDef(
scalaName = "onTouchMove",
domName = "touchmove",
scalaJsEventType = "dom.TouchEvent",
javascriptEventType = "TouchEvent",
commentLines = List(
"The touchmove event is fired when one or more touch points are moved",
"along the touch surface.",
),
docUrls = List(
"https://developer.mozilla.org/en-US/docs/Web/API/Element/touchmove_event",
"https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent",
"https://developer.mozilla.org/en-US/docs/Web/API/Touch_events#browser_compatibility",
),
),

EventPropDef(
scalaName = "onTouchCancel",
domName = "touchcancel",
scalaJsEventType = "dom.TouchEvent",
javascriptEventType = "TouchEvent",
commentLines = List(
"The touchcancel event is fired when one or more touch points have",
"been disrupted in an implementation-specific manner.",
),
docUrls = List(
"https://developer.mozilla.org/en-US/docs/Web/API/Element/touchcancel_event",
"https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent",
"https://developer.mozilla.org/en-US/docs/Web/API/Touch_events#browser_compatibility",
),
),

EventPropDef(
scalaName = "onTouchEnd",
domName = "touchend",
scalaJsEventType = "dom.TouchEvent",
javascriptEventType = "TouchEvent",
commentLines = List(
"The touchend event fires when one or more touch points are removed",
"from the touch surface. Remember that it is possible to get a",
"touchcancel event instead.",
),
docUrls = List(
"https://developer.mozilla.org/en-US/docs/Web/API/Element/touchend_event",
"https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent",
"https://developer.mozilla.org/en-US/docs/Web/API/Touch_events#browser_compatibility",
),
),
)
}

0 comments on commit 05d54e6

Please sign in to comment.