Skip to content

Commit

Permalink
[fixed] swipe event on some Android browsers, resolves #25
Browse files Browse the repository at this point in the history
tested on:

- Mozilla/5.0 (Linux; U; Android 5.0.1; zh-CN; GT-I9500 Build/LRX22C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 UCBrowser/10.8.5.689 U3/0.8.0 Mobile Safari/534.30
  • Loading branch information
minwe committed May 20, 2016
1 parent 22eef39 commit 6977df2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/js/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ const Slider = React.createClass({
onSwipeLeft={this.handleSwipeLeft}
onSwipeRight={this.handleSwipeRight}
preventDefault={false}
stopPropagation={true}
>
<ul className={this.prefixClass('slides')}>
{React.Children.map(children, this.renderItem)}
Expand Down
1 change: 1 addition & 0 deletions src/js/Touchable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import React from 'react';
import TouchableMixin from './mixins/TouchableMixin';
import createChainedFunction from './utils/createChainedFunction';
import supportTouch from './utils/isTouchSupported';
import './utils/UCUIController';

const Touchable = React.createClass({
mixins: [TouchableMixin],
Expand Down
47 changes: 26 additions & 21 deletions src/js/mixins/TouchableMixin.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import React from 'react';
import React, {
PropTypes,
} from 'react';

let TouchableMixin = {
propTypes: {
moveThreshold: React.PropTypes.number,
tapDelay: React.PropTypes.number,
pressDelay: React.PropTypes.number,
preventDefault: React.PropTypes.bool,
stopPropagation: React.PropTypes.bool,

onSwipe: React.PropTypes.func,
onSwipeLeft: React.PropTypes.func,
onSwipeUp: React.PropTypes.func,
onSwipeRight: React.PropTypes.func,
onSwipeDown: React.PropTypes.func,
onTap: React.PropTypes.func,
onSingleTap: React.PropTypes.func,
onDoubleTap: React.PropTypes.func,
onPress: React.PropTypes.func,
moveThreshold: PropTypes.number,
tapDelay: PropTypes.number,
pressDelay: PropTypes.number,
preventDefault: PropTypes.bool,
stopPropagation: PropTypes.bool,

onSwipe: PropTypes.func,
onSwipeLeft: PropTypes.func,
onSwipeUp: PropTypes.func,
onSwipeRight: PropTypes.func,
onSwipeDown: PropTypes.func,
onTap: PropTypes.func,
onSingleTap: PropTypes.func,
onDoubleTap: PropTypes.func,
onPress: PropTypes.func,
},

getDefaultProps() {
Expand Down Expand Up @@ -86,14 +88,15 @@ let TouchableMixin = {
},

handleTouchMove(e) {
// console.log('touch move');
this.processEvent(e);

let endTouch = e.touches[0];
let {
touch,
deltaX,
deltaY,
} = this.state;
} = this.state;

this._cancelPress();

Expand All @@ -113,21 +116,22 @@ let TouchableMixin = {
},

handleTouchEnd(e) {
// console.log('touch end..');
this.processEvent(e);

this._cancelPress();

let {
tapDelay,
moveThreshold,
} = this.props;
} = this.props;
let {
touch,
startTouch,
endTouch,
deltaX,
deltaY,
} = this.state;
} = this.state;
let event = {
touch,
startTouch,
Expand All @@ -136,6 +140,7 @@ let TouchableMixin = {
},
};

// handle as swipe event
if ((touch.x2 && Math.abs(touch.x1 - touch.x2) > moveThreshold) ||
(touch.y2 && Math.abs(touch.y1 - touch.y2) > moveThreshold)) {

Expand All @@ -147,7 +152,7 @@ let TouchableMixin = {
event.type += this._getSwipeDirection();
this._handleEvent(event);
this._resetTouch();
});
}, 0);
}
// normal tap
else if ('last' in touch) {
Expand Down Expand Up @@ -238,7 +243,7 @@ let TouchableMixin = {
x2,
y1,
y2,
} = this.state.touch;
} = this.state.touch;

// 水平方向:水平距离大于等于垂直距离
// 垂直方向:
Expand Down
18 changes: 18 additions & 0 deletions src/js/utils/ucUIControl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// UC browser UI controller

const controller = navigator && navigator.control || {};

/**
* ucUIControl
* @param {string} feature - 'gesture' or 'longpressMenu'
* @param {boolean} state
* @returns {boolean}
*/
function ucUIControl(feature, state) {
return controller[feature] && controller[feature](state);
}

// disable gesture
ucUIControl('gesture', false);

export default ucUIControl

0 comments on commit 6977df2

Please sign in to comment.