r-swipeable
r-swipeable provides Swipeable
which makes its subcomponents horizontally swipeable.
- Repositions to nearest child center after a flick gesture.
- Uses
requestAnimationFrame
to manage translations changes.
Usage
Swipe and drag
;; { return 1 2 3 4 5;} const SwipeableComponent = <Swipeable> </Swipeable>; ;
Example
Add button navigation
To manage the swiper state from a parent component us the following structure:
{ superprops; thisonChange = thisonChange; thisforward = thisstep; thisbackward = thisstep; } { let currentIndex = thisstatecurrentIndex; if forward this; else this; } { // Update container state if swipeable is updated internally by a drag. this; } { return <div> <Swipeable onChange= thisonChange currentIndex= thisstatecurrentIndex > </Swipeable> <div onClick= thisforward > `Go to forwards` </div> <div onClick= thisbackward > `Go to backwards` </div> </div> ; } ;
API
<Swipeable>
Wrapper component which makes its child elements swipeable.
Props
children
(required) - Elements that will be wrapper (in row).
children
(required) - Elements that will be wrapper and made swipeable. (horizontally)
flickSensitivity
- Specifies a limit which decides when an actual flick gesture should be triggered.
slopeLimit
- Indicates if a swipe should be considered x-drag or y-drag. It's only possible to swipe in on direction at the time.
Methods
onChange(callback)
Called with the new index
as a parameter, every time a new index is set.
{ ...} <Swipeable onChange= cb > ...</Swipeable>