react-swipeable
Advanced tools
Comparing version 4.2.1 to 4.2.2
@@ -0,1 +1,4 @@ | ||
# 4.2.2 | ||
* fixed bug that happened when if either `onSwiping` or `onSwiped` were set we were not calling `e.preventDefault()` appropriately | ||
# 4.2.0 | ||
@@ -2,0 +5,0 @@ * Add support for calling `preventDefault` on Chrome 56+ via passive event support checking and manual event listener setup. [#88](https://github.com/dogfessional/react-swipeable/pull/88) |
@@ -56,2 +56,4 @@ 'use strict'; | ||
_this.swipeable = getInitialState(); | ||
_this.eventStart = _this.eventStart.bind(_this); | ||
@@ -68,2 +70,3 @@ _this.eventMove = _this.eventMove.bind(_this); | ||
_this.cleanupTouchmoveEvent = _this.cleanupTouchmoveEvent.bind(_this); | ||
_this.hasPassiveSupport = DetectPassiveEvents.hasSupport; | ||
@@ -73,6 +76,2 @@ return _this; | ||
Swipeable.prototype.componentWillMount = function componentWillMount() { | ||
this.swipeable = getInitialState(); | ||
}; | ||
Swipeable.prototype.componentDidMount = function componentDidMount() { | ||
@@ -162,2 +161,3 @@ if (this.props.preventDefaultTouchmoveEvent) { | ||
onSwiping = _props.onSwiping, | ||
onSwiped = _props.onSwiped, | ||
onSwipingLeft = _props.onSwipingLeft, | ||
@@ -189,2 +189,6 @@ onSwipedLeft = _props.onSwipedLeft, | ||
var cancelablePageSwipe = false; | ||
if (onSwiping || onSwiped) { | ||
cancelablePageSwipe = true; | ||
} | ||
if (pos.absX > pos.absY) { | ||
@@ -191,0 +195,0 @@ if (pos.deltaX > 0) { |
{ | ||
"name": "react-swipeable", | ||
"version": "4.2.1", | ||
"version": "4.2.2", | ||
"description": "Swipe bindings for react", | ||
@@ -14,3 +14,4 @@ "main": "lib/Swipeable.js", | ||
"start:examples": "cd ./examples && npm install && npm run start", | ||
"prepublish": "npm run build:lib" | ||
"clean": "rimraf lib", | ||
"prepare": "npm run clean && npm run build:lib" | ||
}, | ||
@@ -17,0 +18,0 @@ "jest": { |
@@ -123,3 +123,3 @@ React Swipeable | ||
Initial set up, with `node 6+`, run `npm install`. | ||
Initial set up, with `node 8+`, run `npm install`. | ||
@@ -143,7 +143,7 @@ Make changes/updates to the `src/Swipeable.js` file. | ||
`swipeable` version `>=4.2.0` should fix this issue. [PR here](https://github.com/dogfessional/react-swipeable/pull/88). | ||
The issue still exists in versions `<4.2.0`: | ||
- When this library tries to call `e.preventDefault()` in Chrome 56+ a warning is logged: | ||
- `Unable to preventDefault inside passive event listener due to target being treated as passive.` | ||
This warning is because this [change](https://developers.google.com/web/updates/2017/01/scrolling-intervention) to Chrome 56+ and the way the synthetic events are setup in reactjs. | ||
@@ -150,0 +150,0 @@ |
@@ -232,2 +232,48 @@ /* global document */ | ||
it('calls preventDefault when onSwiping is present', () => { | ||
const onSwiping = jest.fn(); | ||
const preventDefault = jest.fn(); | ||
const wrapper = mount(( | ||
<Swipeable | ||
onSwiping={onSwiping} | ||
preventDefaultTouchmoveEvent={true} | ||
> | ||
<span>Touch Here</span> | ||
</Swipeable> | ||
)); | ||
const touchHere = wrapper.find('span'); | ||
touchHere.simulate('touchStart', createStartTouchEventObject({ x: 100, y: 100, preventDefault })); | ||
touchHere.simulate('touchMove', createMoveTouchEventObject({ x: 100, y: 50, preventDefault })); | ||
touchHere.simulate('touchEnd', createMoveTouchEventObject({ x: 100, y: 5, preventDefault })); | ||
expect(onSwiping).toHaveBeenCalled(); | ||
expect(preventDefault).toHaveBeenCalled(); | ||
wrapper.unmount(); | ||
}); | ||
it('calls preventDefault when onSwiped is present', () => { | ||
const onSwiped = jest.fn(); | ||
const preventDefault = jest.fn(); | ||
const wrapper = mount(( | ||
<Swipeable | ||
onSwiped={onSwiped} | ||
preventDefaultTouchmoveEvent={true} | ||
> | ||
<span>Touch Here</span> | ||
</Swipeable> | ||
)); | ||
const touchHere = wrapper.find('span'); | ||
touchHere.simulate('touchStart', createStartTouchEventObject({ x: 100, y: 100, preventDefault })); | ||
touchHere.simulate('touchMove', createMoveTouchEventObject({ x: 100, y: 50, preventDefault })); | ||
touchHere.simulate('touchEnd', createMoveTouchEventObject({ x: 100, y: 5, preventDefault })); | ||
expect(onSwiped).toHaveBeenCalled(); | ||
expect(preventDefault).toHaveBeenCalled(); | ||
wrapper.unmount(); | ||
}); | ||
it('disables swipeable with disabled prop using touch swipe', () => { | ||
@@ -234,0 +280,0 @@ const onSwiping = jest.fn(); |
@@ -46,2 +46,7 @@ /* global document */ | ||
super(props, context); | ||
// setup internal swipeable state | ||
this.swipeable = getInitialState(); | ||
// bind this context for internal methods | ||
this.eventStart = this.eventStart.bind(this); | ||
@@ -58,10 +63,7 @@ this.eventMove = this.eventMove.bind(this); | ||
this.cleanupTouchmoveEvent = this.cleanupTouchmoveEvent.bind(this); | ||
// check for passive event support | ||
this.hasPassiveSupport = DetectPassiveEvents.hasSupport; | ||
} | ||
componentWillMount() { | ||
// setup internal swipeable state | ||
this.swipeable = getInitialState(); | ||
} | ||
componentDidMount() { | ||
@@ -160,3 +162,3 @@ // if we care about calling preventDefault and we have support for passive events | ||
delta, | ||
onSwiping, | ||
onSwiping, onSwiped, | ||
onSwipingLeft, onSwipedLeft, | ||
@@ -184,3 +186,9 @@ onSwipingRight, onSwipedRight, | ||
// track if a swipe is cancelable | ||
// so we can call prevenDefault if needed | ||
let cancelablePageSwipe = false; | ||
if (onSwiping || onSwiped) { | ||
cancelablePageSwipe = true; | ||
} | ||
if (pos.absX > pos.absY) { | ||
@@ -187,0 +195,0 @@ if (pos.deltaX > 0) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52101
943