From 3ba9de105d7a2d92dfba49ab77ace223d20adbbe Mon Sep 17 00:00:00 2001 From: paranoidjk Date: Mon, 18 Sep 2017 12:25:47 +0800 Subject: [PATCH] fix: svg className wrong usgae. close #45 --- examples/simple.tsx | 3 ++- package.json | 5 ++--- src/Swipeout.tsx | 51 ++++++++++++++++++++++++++------------------- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/examples/simple.tsx b/examples/simple.tsx index 634491c..f084f4a 100644 --- a/examples/simple.tsx +++ b/examples/simple.tsx @@ -46,7 +46,8 @@ const SwipeDemo = () => ( borderTop: '1px solid #dedede', borderBottom: '1px solid #dedede', }} - >swipe out simple demo + >swipe out simple demo + ); diff --git a/package.json b/package.json index 684dc7a..c843e34 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-swipeout", - "version": "2.0.0", + "version": "2.0.1", "description": "swipe out ui component for react(web and react-native)", "keywords": [ "react", @@ -53,8 +53,7 @@ }, "dependencies": { "babel-runtime": "6.x", - "classnames": "^2.2.5", - "omit.js": "^1.0.0", + "classnames": "2.x", "rc-gesture": "^0.0.15", "react-native-swipeout": "~2.1.1" }, diff --git a/src/Swipeout.tsx b/src/Swipeout.tsx index 9dcc576..9d4b5ff 100644 --- a/src/Swipeout.tsx +++ b/src/Swipeout.tsx @@ -1,10 +1,24 @@ import React from 'react'; import ReactDOM from 'react-dom'; import Gesture from 'rc-gesture'; -import omit from 'omit.js'; import classnames from 'classnames'; import SwipeoutPropType from './PropTypes'; +// https://developer.mozilla.org/en-US/docs/Web/API/Element/matches +// http://caniuse.com/#search=match +function closest(el, selector) { + const matchesSelector = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector; + + while (el) { + if (matchesSelector.call(el, selector)) { + return el; + } else { + el = el.parentElement; + } + } + return null; +} + export default class Swipeout extends React.Component { static defaultProps = { prefixCls: 'rc-swipeout', @@ -48,19 +62,13 @@ export default class Swipeout extends React.Component { } onCloseSwipe = (ev) => { - if (this.openedLeft || this.openedRight) { - const pNode = (node => { - while (node.parentNode && node.parentNode !== document.body) { - if (node.className.indexOf(`${this.props.prefixCls}-actions`) > -1) { - return node; - } - node = node.parentNode; - } - })(ev.target); - if (!pNode) { - ev.preventDefault(); - this.close(); - } + if (!(this.openedLeft || this.openedRight)) { + return; + } + const pNode = closest(ev.target, `.${this.props.prefixCls}-actions`); + if (!pNode) { + ev.preventDefault(); + this.close(); } } @@ -213,18 +221,17 @@ export default class Swipeout extends React.Component { render() { const { prefixCls, left, right, disabled, children, ...restProps } = this.props; - const divProps = omit(restProps, [ - 'autoClose', - 'onOpen', - 'onClose', - ]); - const refProps = { - ref: el => this.content = ReactDOM.findDOMNode(el), - }; + const { autoClose, onOpen, onClose, ...divProps } = restProps; + const cls = classnames(prefixCls, { [`${prefixCls}-swiping`]: this.state.swiping, }); + + const refProps = { + ref: el => this.content = ReactDOM.findDOMNode(el), + }; + return (left!.length || right!.length) && !disabled ? (
{/* 保证 body touchStart 后不触发 pan */}