Skip to content

Commit

Permalink
fix stopPropagation, close #11
Browse files Browse the repository at this point in the history
  • Loading branch information
warmhug committed Dec 5, 2017
1 parent bf44fc6 commit 96474e3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions examples/base.js
Expand Up @@ -6,7 +6,7 @@ import ReactDOM from 'react-dom';
class App extends React.Component {
state = {
refreshing: false,
switchContainer: true,
switchContainer: false,
};
componentDidMount() {
// setTimeout(() => { this.setState({ refreshing: true }); }, 10);
Expand Down Expand Up @@ -39,7 +39,7 @@ class App extends React.Component {
indicator={{ deactivate: '下拉' }}
>
{[1, 2, 3, 4, 5, 6, 7].map(i =>
<div key={i} style={{ textAlign: 'center', padding: 20 }}>item {i}</div>)}
<div key={i} style={{ textAlign: 'center', padding: 20 }} onClick={() => alert(1)}>item {i}</div>)}
</PullToRefresh>

<div dangerouslySetInnerHTML={{
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "rmc-pull-to-refresh",
"version": "1.0.5",
"version": "1.0.6",
"description": "React Mobile Pull To Refresh Component",
"keywords": [
"react",
Expand Down
17 changes: 16 additions & 1 deletion src/PullToRefresh.tsx
Expand Up @@ -23,6 +23,20 @@ const DOWN = 'down';
const UP = 'up';
const INDICATOR = { activate: 'release', deactivate: 'pull', release: 'loading', finish: 'finish' };

let supportsPassive = false;
try {
const opts = Object.defineProperty({}, 'passive', {
get() {
supportsPassive = true;
},
});
window.addEventListener('test', null as any, opts);
} catch (e) {
// empty
}
const willPreventDefault = supportsPassive ? { passive: false } : false;

This comment has been minimized.

Copy link
@paranoidjk

paranoidjk Dec 5, 2017

Member

为什么要加 passive: false ? 这个只与 preventDefault 有关,而且只有很高版本的 chrome 支持

This comment has been minimized.

Copy link
@warmhug

warmhug Dec 5, 2017

Author Collaborator

This comment has been minimized.

// const willNotPreventDefault = supportsPassive ? { passive: true } : false;

export default class PullToRefresh extends React.Component<PropsType, any> {
static defaultProps = {
prefixCls: 'rmc-pull-to-refresh',
Expand Down Expand Up @@ -106,7 +120,7 @@ export default class PullToRefresh extends React.Component<PropsType, any> {
touchcancel: this.onTouchEnd.bind(this, ele),
};
Object.keys(this._to).forEach(key => {
ele.addEventListener(key, this._to[key]);
ele.addEventListener(key, this._to[key], willPreventDefault);
});
}

Expand All @@ -124,6 +138,7 @@ export default class PullToRefresh extends React.Component<PropsType, any> {
this._ScreenY = this._startScreenY = e.touches[0].screenY;
// 一开始 refreshing 为 true 时 this._lastScreenY 有值
this._lastScreenY = this._lastScreenY || 0;
e.stopPropagation();
}

isEdge = (ele: any, direction: string) => {
Expand Down

0 comments on commit 96474e3

Please sign in to comment.