(el, props)
| 254 | * |
| 255 | */ |
| 256 | const attachTouch: AttachTouch = (el, props) => { |
| 257 | let cleanup = () => {}; |
| 258 | if (el && el.addEventListener) { |
| 259 | const baseOptions = { |
| 260 | ...defaultProps.touchEventOptions, |
| 261 | ...props.touchEventOptions, |
| 262 | }; |
| 263 | // attach touch event listeners and handlers |
| 264 | const tls: [ |
| 265 | typeof touchStart | typeof touchMove | typeof touchEnd, |
| 266 | (e: HandledEvents) => void, |
| 267 | { passive: boolean } |
| 268 | ][] = [ |
| 269 | [touchStart, onStart, baseOptions], |
| 270 | // preventScrollOnSwipe option supersedes touchEventOptions.passive |
| 271 | [ |
| 272 | touchMove, |
| 273 | onMove, |
| 274 | { |
| 275 | ...baseOptions, |
| 276 | ...(props.preventScrollOnSwipe ? { passive: false } : {}), |
| 277 | }, |
| 278 | ], |
| 279 | [touchEnd, onEnd, baseOptions], |
| 280 | ]; |
| 281 | tls.forEach(([e, h, o]) => el.addEventListener(e, h, o)); |
| 282 | // return properly scoped cleanup method for removing listeners, options not required |
| 283 | cleanup = () => tls.forEach(([e, h]) => el.removeEventListener(e, h)); |
| 284 | } |
| 285 | return cleanup; |
| 286 | }; |
| 287 | |
| 288 | const onRef = (el: HTMLElement | null) => { |
| 289 | // "inline" ref functions are called twice on render, once with null then again with DOM element |
no outgoing calls
no test coverage detected
searching dependent graphs…