( state: SwipeableState, props: SwipeablePropsWithDefaultOptions, previousProps: SwipeablePropsWithDefaultOptions, attachTouch: AttachTouch )
| 323 | } |
| 324 | |
| 325 | function updateTransientState( |
| 326 | state: SwipeableState, |
| 327 | props: SwipeablePropsWithDefaultOptions, |
| 328 | previousProps: SwipeablePropsWithDefaultOptions, |
| 329 | attachTouch: AttachTouch |
| 330 | ) { |
| 331 | // if trackTouch is off or there is no el, then remove handlers if necessary and exit |
| 332 | if (!props.trackTouch || !state.el) { |
| 333 | if (state.cleanUpTouch) { |
| 334 | state.cleanUpTouch(); |
| 335 | } |
| 336 | |
| 337 | return { |
| 338 | ...state, |
| 339 | cleanUpTouch: undefined, |
| 340 | }; |
| 341 | } |
| 342 | |
| 343 | // trackTouch is on, so if there are no handlers attached, attach them and exit |
| 344 | if (!state.cleanUpTouch) { |
| 345 | return { |
| 346 | ...state, |
| 347 | cleanUpTouch: attachTouch(state.el, props), |
| 348 | }; |
| 349 | } |
| 350 | |
| 351 | // trackTouch is on and handlers are already attached, so if preventScrollOnSwipe changes value, |
| 352 | // remove and reattach handlers (this is required to update the passive option when attaching |
| 353 | // the handlers) |
| 354 | if ( |
| 355 | props.preventScrollOnSwipe !== previousProps.preventScrollOnSwipe || |
| 356 | props.touchEventOptions.passive !== previousProps.touchEventOptions.passive |
| 357 | ) { |
| 358 | state.cleanUpTouch(); |
| 359 | |
| 360 | return { |
| 361 | ...state, |
| 362 | cleanUpTouch: attachTouch(state.el, props), |
| 363 | }; |
| 364 | } |
| 365 | |
| 366 | return state; |
| 367 | } |
| 368 | |
| 369 | export function useSwipeable(options: SwipeableProps): SwipeableHandlers { |
| 370 | const { trackMouse } = options; |
no test coverage detected
searching dependent graphs…