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
Copy file name to clipboardExpand all lines: CHANGELOG.md
+49Lines changed: 49 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,52 @@
1
+
# UNRELEASED
2
+
3
+
**New Features:**
4
+
- add new `swipeDuration` prop - "allowable duration of a swipe"
5
+
- A swipe lasting more than `swipeDuration`, in milliseconds, will **not** be considered a swipe.
6
+
- Feature mimicked from `use-gesture`[swipe.duration](https://use-gesture.netlify.app/docs/options/#swipeduration)
7
+
- Defaults to `Infinity` for backwards compatibility
8
+
- add new `touchEventOptions` prop that can set the options for the touch event listeners
9
+
- 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)
10
+
- Defaults to `{ passive: true }`
11
+
- add new `onTouchStartOrOnMouseDown` prop that is called for `touchstart` and `mousedown`. Before a swipe even starts.
12
+
- combined with `touchEventOptions` allows users the ability to now call `preventDefault` on `touchstart`
13
+
- add new `onTouchEndOrOnMouseUp` prop that is called for `touchend` and `mouseup`.
14
+
- add [react 18](https://reactjs.org/blog/2022/03/29/react-v18.html) to `peerDependencies`
15
+
16
+
**Breaking Changes:**
17
+
* we have dropped support for `es5` transpiled output
* same functionality but renamed to be more explicit on its intended use
22
+
***fixed bug** - where toggling this prop did not re-attach event listeners
23
+
***update** - we now **only** change the `passive` event listener option for `touchmove` depending on this prop
24
+
* see notes in README for more details [readme#passive-listener](https://github.com/FormidableLabs/react-swipeable#passive-listener)
25
+
* Thank you [@stefvhuynh](https://github.com/stefvhuynh)
26
+
27
+
**Bug fixes:**
28
+
* fix bug where directional swiped check allowed `undefined`/falsy values to set `cancelablePageSwipe`
29
+
* Thank you [@bhj](https://github.com/bhj) for the [comment](https://github.com/FormidableLabs/react-swipeable/pull/240#issuecomment-1014980025)
30
+
* fix bug when both `trackTouch` and `trackMouse` were present that triggered an erroneous swipe when the user clicked outside and above the swipeable area
31
+
* See [issue 304](https://github.com/FormidableLabs/react-swipeable/issues/304) for details
32
+
* Thank you [@Sacret](https://github.com/Sacret)
33
+
34
+
**Infrastructure:**
35
+
* post `size-limit report` to PRs with bundle diff sizes
`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`;
61
67
62
68
```js
63
69
{
64
-
delta: { top:20, bottom:20 } // top and bottom when ">= 20", left and right default to ">= 10"
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
65
83
}
66
84
```
67
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)
-`preventScrollOnSwipe` option **supersedes**`touchEventOptions.passive` for `touchmove` event listener
94
+
- See `preventScrollOnSwipe` for [more details](#preventscrollonswipe-details)
95
+
68
96
## Swipe Event Data
69
97
70
98
All Event Handlers are called with the below event data, `SwipeEventData`.
@@ -73,7 +101,7 @@ All Event Handlers are called with the below event data, `SwipeEventData`.
73
101
{
74
102
event, // source event
75
103
initial, // initial swipe [x,y]
76
-
first, // true for first event
104
+
first, // true for the first event of a tracked swipe
77
105
deltaX, // x offset (current.x - initial.x)
78
106
deltaY, // y offset (current.y - initial.y)
79
107
absX, // absolute deltaX
@@ -90,47 +118,42 @@ All Event Handlers are called with the below event data, `SwipeEventData`.
90
118
91
119
- Hook use requires **react >= 16.8.3**
92
120
- The props contained in `handlers` are currently `ref` and `onMouseDown`
93
-
- Please spread `handlers` as the props contained in it could change as react improves event listening capabilities
121
+
- Please spread `handlers` as the props contained in it could change as react changes event listening capabilities
94
122
95
-
### `preventDefaultTouchmoveEvent` details
123
+
### `preventScrollOnSwipe` details
96
124
97
-
This prop allows you to prevent the browser's [touchmove](https://developer.mozilla.org/en-US/docs/Web/Events/touchmove) event default action, mostly "scrolling".
125
+
This prop prevents scroll during swipe in most cases. Use this to **stop scrolling** in the browser while a user swipes.
98
126
99
-
Use this to **stop scrolling** in the browser while a user swipes.
100
-
- You can additionally try `touch-action` css property, [see below](#how-to-use-touch-action-to-prevent-scrolling)
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.
101
133
102
134
`e.preventDefault()` is only called when:
103
-
-`preventDefaultTouchmoveEvent: true`
135
+
-`preventScrollOnSwipe: true`
104
136
-`trackTouch: true`
105
137
- the users current swipe has an associated `onSwiping` or `onSwiped` handler/prop
106
138
107
-
Example scenario:
108
-
> If a user is swiping right with props `{ onSwipedRight: userSwipedRight, preventDefaultTouchmoveEvent: true }` then `e.preventDefault()` will be called, but if the user was swiping left then `e.preventDefault()` would **not** be called.
109
-
110
-
Please experiment with the [example app](http://formidablelabs.github.io/react-swipeable/) to test `preventDefaultTouchmoveEvent`.
139
+
Please experiment with the [example app](http://formidablelabs.github.io/react-swipeable/) to test `preventScrollOnSwipe`.
111
140
112
-
#### passive listener
113
-
With v6 we've added the passive event listener option, by default, to **internal uses** of `addEventListener`. We set the `passive` option to `false` only when `preventDefaultTouchmoveEvent` is `true`.
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`.
React's long running passive [event issue](https://github.com/facebook/react/issues/6436).
148
+
Here is more information on react's long running passive [event issue](https://github.com/facebook/react/issues/6436).
120
149
121
-
We previously had issues with chrome lighthouse performance deducting points for not having passive option set.
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.
122
151
123
-
### Browser Support
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).
124
153
125
-
The release of v6 `react-swipeable` we only support browsers that support options object for `addEventListener`, [Browser compatibility](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Browser_compatibility). Which mainly means `react-swipeable` does not support ie11 by default, you need to polyfill options. For example using [event-listener-with-options](https://github.com/Macil/event-listener-with-options).
154
+
### Version 7 Updates and migration
126
155
127
-
### Version 6 Updates and migration
128
-
129
-
If upgrading from v5 or later please refer to the release notes and the [v6 migration doc](./migration.md)
130
-
131
-
v6 now only exports a hook, `useSwipeable`.
132
-
133
-
If you would like something similar to the old `<Swipeable>` component you can recreate it from the hook. There are examples in the [migration doc](./migration.md#swipeable-component-examples).
156
+
If upgrading from v6 refer to the release notes and the [migration doc](./migration.md).
134
157
135
158
## FAQs
136
159
@@ -174,21 +197,39 @@ const MyComponent = () => {
174
197
175
198
### How to use `touch-action` to prevent scrolling?
176
199
177
-
Sometimes you don't want the `body` of your page to scroll along with the user manipulating or swiping an item.
200
+
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.
178
201
179
-
You might try to prevent the event default action via [preventDefaultTouchmoveEvent](#preventdefaulttouchmoveevent-details), which calls `event.preventDefault()`. **But** there may be a simpler, more effective solution, which has to do with a simple CSS property.
202
+
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.
180
203
181
-
`touch-action` is a CSS property that sets how an element's region can be manipulated by a touchscreen user.
204
+
`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.
0 commit comments