Element events
The type of $event on every Lynx element event. Angular infers it in your templates, so a misspelt detail field fails the build. import type { LynxEvent, ImageLoadDetail } from '@blotch/angular-lynx';
Usage
- In a template, write nothing. Angular knows each element's events: in
(bindload)="size.set($event.detail)",$eventis alreadyLynxEvent<ImageLoadDetail>. - For a handler declared in the class, type its parameter with
LynxEventand the event's detail type, from the tables below. - Every prefix has the same type.
(catchtap),(capture-bindtap)and(global-bindtap)get what(bindtap)gets, and so on for every event. - An event the element doesn't fire stays the DOM
Event, such as(bindload)on a<view>. $eventisn't a DOMEvent. A handler that takesEventno longer compiles: change its parameter to the type below.
API
LynxEvent
LynxEventTarget
Plain data, not the element: it has no methods. id is the element's id attribute, uid Lynx's internal number for it, and dataset its data-* attributes without the data- prefix. A dataset value is unknown because a property binding, such as [data-item]="item", keeps its value's type.
Events every element fires
TouchEvent has the same fields as LynxEvent<{ x: number; y: number }>, plus touches and changedTouches. Import it, and the other @lynx-js/types events, by name: without the import, TypeScript uses the DOM's TouchEvent. The detail types are on <view>.
Pointer events
(pointerdown), (pointermove), (pointerup), (pointercancel), (pointerover), (pointerout), (pointerenter), (pointerleave), (gotpointercapture) and (lostpointercapture) work on every element, without a bind prefix, as in a browser. Lynx sends only touches, so AngularLynx makes each touch into the pointer events a browser fires for one, in the same order, and $event is a DOM PointerEvent: each finger is a pointer (pointerId), pointerType is 'touch', and offsetX/offsetY are relative to the element. Libraries written for the web listen for these, such as angular-three for taps on a 3D scene.
A touch's events go to the element it started on, wherever the finger moves, as if every pointer were captured; setPointerCapture() changes only hasPointerCapture() and the capture events. In the web preview, they're the browser's own pointer events, including a mouse's. A (click), which is Lynx's bindtap, has the offsetX and offsetY of where the pointer lifted, on an element with pointer listeners.
A finger keeps its pointerId until it lifts, at the element and at the document. With multi-touch off, the LynxView's default, there's one touch at a time, and its pointerId is 0.
(mouseover), (mouseenter), (mouseout) and (mouseleave) come from the first finger too, as a phone's browser makes them from a tap: mouseover and mouseenter when it touches the element, after pointerenter, and mouseout and mouseleave when it lifts, after pointerleave. Code written for a mouse's hover, such as Angular's @defer (on hover), runs when a finger touches the element. Only the element hears them: document:mouseover never runs on iOS or Android. In the web preview, they're the browser's own.
document:, window: and body: listeners
Host listeners on the document, the window and the body work as in a browser, and so do the libraries written for the browser that use them:
An element's ownerDocument is a document that hears the screen's events, and inject(DOCUMENT) is the same object. Its defaultView is window. So document.addEventListener(), window.addEventListener() and RxJS's fromEvent(document, 'click') hear them too.
- They run after the touched element's listeners and the body's, as in a browser. A capturing listener,
{ capture: true }, runs before them. - They hear a touch that a
(catchtap)or anothercatchhandler stopped. In a browser,stopPropagation()hides an event from the document. On Lynx they still hear it, on the next timer, after every listener of that touch. - A pointer event's
targetis the element touched, thenativeElementof itsElementRef, and itsoffsetX/offsetYare relative to that element. A touch event and aclickare Lynx's own event objects, as an element's listeners get them. window.innerWidthandwindow.innerHeightare the LynxView's size in CSS pixels. Until its first layout, they're the screen's, fromSystemInfo.- iOS and Android send no mouse events, so
document:mousemovenever runs there: listen forpointermove. - In the web preview, they're the browser's own events inside the
<lynx-view>, a mouse's included, and the size is the<lynx-view>'s. Key events are the page's.
Each element's own events
The fields of each detail type are in its element's Events table.
<image> and <svg>
<text>
See <text>.
<input> and <textarea>
See <input> and <textarea>.
<scroll-view>
See <scroll-view>.
<list>
ListScrollDetail adds <list>'s fields to ScrollDetail. ListAttachedCell and ListItemInfo are the types of its item arrays. See <list>.
Other elements
- The other elements fire only the common events, such as
<view>,<blur-view>and<list-item>.
Related
- Handling taps and events
- Elements:
LYNX_ELEMENTS - Testing event reference: firing these events in tests
