(options: SwipeableProps)
| 367 | } |
| 368 | |
| 369 | export function useSwipeable(options: SwipeableProps): SwipeableHandlers { |
| 370 | const { trackMouse } = options; |
| 371 | const transientState = React.useRef({ ...initialState }); |
| 372 | const transientProps = React.useRef<SwipeablePropsWithDefaultOptions>({ |
| 373 | ...defaultProps, |
| 374 | }); |
| 375 | |
| 376 | // track previous rendered props |
| 377 | const previousProps = React.useRef<SwipeablePropsWithDefaultOptions>({ |
| 378 | ...transientProps.current, |
| 379 | }); |
| 380 | previousProps.current = { ...transientProps.current }; |
| 381 | |
| 382 | // update current render props & defaults |
| 383 | transientProps.current = { |
| 384 | ...defaultProps, |
| 385 | ...options, |
| 386 | }; |
| 387 | // Force defaults for config properties |
| 388 | let defaultKey: keyof ConfigurationOptions; |
| 389 | for (defaultKey in defaultProps) { |
| 390 | if (transientProps.current[defaultKey] === void 0) { |
| 391 | (transientProps.current[defaultKey] as any) = defaultProps[defaultKey]; |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | const [handlers, attachTouch] = React.useMemo( |
| 396 | () => |
| 397 | getHandlers( |
| 398 | (stateSetter) => |
| 399 | (transientState.current = stateSetter( |
| 400 | transientState.current, |
| 401 | transientProps.current |
| 402 | )), |
| 403 | { trackMouse } |
| 404 | ), |
| 405 | [trackMouse] |
| 406 | ); |
| 407 | |
| 408 | transientState.current = updateTransientState( |
| 409 | transientState.current, |
| 410 | transientProps.current, |
| 411 | previousProps.current, |
| 412 | attachTouch |
| 413 | ); |
| 414 | |
| 415 | return handlers; |
| 416 | } |
searching dependent graphs…