You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`delta` can be either a `number` or an `object` specifying different deltas for each direction, [`left`, `right`, `up`, `down`], direction values are optional and will default to `10`;
67
-
68
-
```js
69
-
{
70
-
delta: { up:20, down:20 } // up and down ">= 20", left and right default to ">= 10"
71
-
}
72
-
```
73
-
74
-
#### swipeDuration
75
-
A swipe lasting more than `swipeDuration`, in milliseconds, will **not** be considered a swipe.
76
-
- It will also **not** trigger any callbacks and the swipe event will stop being tracked
77
-
-**Defaults** to `Infinity` for backwards compatibility, a sensible duration could be something like `250`
78
-
- Feature mimicked from `use-gesture`[swipe.duration](https://use-gesture.netlify.app/docs/options/#swipeduration)
79
-
80
-
```js
81
-
{
82
-
swipeDuration:250// only swipes under 250ms will trigger callbacks
83
-
}
84
-
```
85
-
86
-
#### touchEventOptions
87
-
88
-
Allows the user to set the options for the touch event listeners( currently only `passive` option ).
89
-
-`touchstart`, `touchmove`, and `touchend` event listeners
90
-
-**Defaults** to `{ passive: true }`
91
-
- this provides users full control of if/when they want to set [passive](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#options)
vxvy, // [ deltaX/time, deltaY/time] - velocity per axis
111
-
dir, // direction of swipe (Left|Right|Up|Down)
112
-
}
113
-
```
114
-
115
-
**None of the props/config options are required.**
116
-
117
-
### Hook details
118
-
119
-
- Hook use requires **react >= 16.8.3**
120
-
- The props contained in `handlers` are currently `ref` and `onMouseDown`
121
-
- Please spread `handlers` as the props contained in it could change as react changes event listening capabilities
122
-
123
-
### `preventScrollOnSwipe` details
124
-
125
-
This prop prevents scroll during swipe in most cases. Use this to **stop scrolling** in the browser while a user swipes.
126
-
127
-
Swipeable will call `e.preventDefault()` internally in an attempt to stop the browser's [touchmove](https://developer.mozilla.org/en-US/docs/Web/Events/touchmove) event default action (mostly scrolling).
128
-
129
-
**NOTE:**`preventScrollOnSwipe` option **supersedes**`touchEventOptions.passive` for the `touchmove` event listener
130
-
131
-
**Example scenario:**
132
-
> If a user is swiping right with props `{ onSwipedRight: userSwipedRight, preventScrollOnSwipe: true }` then `e.preventDefault()` will be called, but if the user was swiping left then `e.preventDefault()` would **not** be called.
133
-
134
-
`e.preventDefault()` is only called when:
135
-
-`preventScrollOnSwipe: true`
136
-
-`trackTouch: true`
137
-
- the users current swipe has an associated `onSwiping` or `onSwiped` handler/prop
138
-
139
-
Please experiment with the [example app](http://formidablelabs.github.io/react-swipeable/) to test `preventScrollOnSwipe`.
140
-
141
-
#### passive listener details
142
-
Swipeable adds the passive event listener option, by default, to **internal uses** of touch `addEventListener`'s. We set the `passive` option to `false` only when `preventScrollOnSwipe` is `true` and only to `touchmove`. Other listeners will retain `passive: true`.
Here is more information on react's long running passive [event issue](https://github.com/facebook/react/issues/6436).
149
-
150
-
We previously had issues with chrome lighthouse performance deducting points for not having passive option set so it is now on by default except in the case mentioned above.
151
-
152
-
If, however, you really **need**_all_ of the listeners to be passive (for performance reasons or otherwise), you can prevent all scrolling on the swipeable container by using the `touch-action` css property instead, [see below for an example](#how-to-use-touch-action-to-prevent-scrolling).
153
-
154
-
### Version 7 Updates and migration
155
-
156
-
If upgrading from v6 refer to the release notes and the [migration doc](./migration.md).
157
-
158
-
## FAQs
159
-
160
-
### How can I add a swipe listener to the `document`?
161
-
Example by [@merrywhether#180](https://github.com/FormidableLabs/react-swipeable/issues/180#issuecomment-649677983)
162
-
163
-
##### Example codesandbox with swipeable on document and nested swipe
### How to use `touch-action` to prevent scrolling?
202
-
203
-
Sometimes you don't want the `body` of your page to scroll along with the user manipulating or swiping an item. Or you might want all of the internal event listeners to be passive and performant.
204
-
205
-
You can prevent scrolling via [preventScrollOnSwipe](#preventscrollonswipe-details), which calls `event.preventDefault()` during `onTouchMove`. **But** there may be a simpler, more effective solution, which has to do with a simple CSS property.
206
-
207
-
`touch-action` is a CSS property that sets how an element's region can be manipulated by a touchscreen user. See the [documentation for `touch-action`](https://developer.mozilla.org/en-US/docs/Web/CSS/touch-action) to determine which property value to use for your particular use case.
This is a somewhat contrived example as the final outcome would be similar to the static example. However, there may be cases where you want to determine when the user can scroll based on the user's swiping action along with any number of variables from state and props.
9
+
Visit the [Docs site](https://commerce.nearform.com/open-source/react-swipeable) for information on [usage](https://commerce.nearform.com/open-source/react-swipeable/docs/usage), [api](https://commerce.nearform.com/open-source/react-swipeable/api), and [demos](https://commerce.nearform.com/open-source/react-swipeable/docs/demo).
0 commit comments