Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ ios
android
yarn.lock
assets/index.css
package-lock.json
package-lock.json
81 changes: 42 additions & 39 deletions assets/index.less
Original file line number Diff line number Diff line change
@@ -1,47 +1,50 @@
@swipeout-prefix-cls: rc-swipeout;

.@{swipeout-prefix-cls} {
overflow: hidden;
position: relative;
&-content {
position: relative;
background-color: #fff;
}
&-cover {
position: absolute;
z-index: 2;
background: transparent;
height: 100%;
width: 100%;
top: 0;
display: none;
}
& .@{swipeout-prefix-cls}-content,
& .@{swipeout-prefix-cls}-actions {
transition: all 250ms;
}
&-actions {
position: absolute;
top: 0;
bottom: 0;
display: flex;
overflow: hidden;
white-space: nowrap;
&-left {
left: 0;
position: relative;
&-content {
position: relative;
background-color: #fff;
}
&-right {
right: 0;
&-cover {
position: absolute;
z-index: 2;
background: transparent;
height: 100%;
width: 100%;
top: 0;
display: none;
}
}
&-btn {
display: flex;
align-items: center;
justify-content: center;
position: relative;
overflow: hidden;
&-text{
padding: 0 12px;
& .@{swipeout-prefix-cls}-content,
& .@{swipeout-prefix-cls}-actions {
transition: all 250ms;
}
&-swiping .@{swipeout-prefix-cls}-content {
transition: none;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @silentcloud antd-mobile 层面可能也要做这个处理 #44

虽然 swiping 这个 classname 实测动态的加和删也有点跟不太上。

}
&-actions {
position: absolute;
top: 0;
bottom: 0;
display: flex;
overflow: hidden;
white-space: nowrap;
&-left {
left: 0;
}
&-right {
right: 0;
}
}
&-btn {
display: flex;
align-items: center;
justify-content: center;
position: relative;
overflow: hidden;
&-text {
padding: 0 12px;
}
}
}
}
9 changes: 2 additions & 7 deletions examples/simple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,10 @@ const SwipeDemo = () => (
ReactDOM.render(
<div style={{ marginBottom: 12 }}>
<SwipeDemo />
<div style={{height: 100}}></div>
<SwipeDemo />
<SwipeDemo />
<SwipeDemo />
<SwipeDemo />
<SwipeDemo />
<SwipeDemo />
<SwipeDemo />
<SwipeDemo />
<SwipeDemo />
<div style={{height: 100}}></div>
<SwipeDemo />
</div>,
document.getElementById('__react-content'),
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"babel-runtime": "6.x",
"classnames": "^2.2.5",
"omit.js": "^1.0.0",
"rc-hammerjs": "^0.6.6",
"rc-gesture": "^0.0.15",
"react-native-swipeout": "~2.1.1"
},
"devDependencies": {
Expand All @@ -64,7 +64,6 @@
"@types/react-dom": "15.5.1",
"@types/react-native": "^0.47.2",
"expect.js": "0.3.x",
"hammer-simulator": "0.0.1",
"pre-commit": "1.x",
"rc-test": "~6.0.3",
"rc-tools": "6.x",
Expand Down
47 changes: 28 additions & 19 deletions src/Swipeout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
import Hammer from 'rc-hammerjs';
import Gesture from 'rc-gesture';
import omit from 'omit.js';
import classnames from 'classnames';
import SwipeoutPropType from './PropTypes';
Expand Down Expand Up @@ -65,7 +65,8 @@ export default class Swipeout extends React.Component <SwipeoutPropType, any> {
}

onPanStart = (e) => {
const { direction, deltaX } = e;
const { direction, moveStatus } = e;
const { x: deltaX } = moveStatus;
// http://hammerjs.github.io/api/#directions
const isLeft = direction === 2;
const isRight = direction === 4;
Expand All @@ -90,8 +91,9 @@ export default class Swipeout extends React.Component <SwipeoutPropType, any> {
this._setStyle(deltaX);
}
}
onPan = (e) => {
const { deltaX } = e;
onPanMove = (e) => {
const { moveStatus } = e;
const { x: deltaX } = moveStatus;
if (!this.swiping) {
return;
}
Expand All @@ -103,18 +105,16 @@ export default class Swipeout extends React.Component <SwipeoutPropType, any> {
return;
}

const btnsLeftWidth = this.btnsLeftWidth;
const btnsRightWidth = this.btnsRightWidth;
const { moveStatus } = e;
const { x: deltaX } = moveStatus;

const { deltaX } = e;

const needOpenRight = this.needShowRight && Math.abs(deltaX) > btnsRightWidth / 2;
const needOpenLeft = this.needShowLeft && Math.abs(deltaX) > btnsRightWidth / 2;
const needOpenRight = this.needShowRight && Math.abs(deltaX) > this.btnsRightWidth / 2;
const needOpenLeft = this.needShowLeft && Math.abs(deltaX) > this.btnsLeftWidth / 2;

if (needOpenRight) {
this.open(-btnsRightWidth, false, true);
this.doOpenRight();
} else if (needOpenLeft) {
this.open(btnsLeftWidth, true, false);
this.doOpenLeft();
} else {
this.close();
}
Expand All @@ -126,6 +126,13 @@ export default class Swipeout extends React.Component <SwipeoutPropType, any> {
this.needShowRight = false;
}

doOpenLeft = () => {
this.open(this.btnsLeftWidth, true, false);
}

doOpenRight = () => {
this.open(-this.btnsRightWidth, true, false);
}
// left & right button click
onBtnClick(ev, btn) {
const onPress = btn.onPress;
Expand All @@ -151,13 +158,13 @@ export default class Swipeout extends React.Component <SwipeoutPropType, any> {

// set content & actions style
_setStyle = (value) => {

const limit = value > 0 ? this.btnsLeftWidth : -this.btnsRightWidth;
const contentLeft = this._getContentEasing(value, limit);
this.content.style.left = `${contentLeft}px`;
const transform = `translate3d(${contentLeft}px, 0px, 0px)`;
this.content.style.transform = transform;
if (this.cover) {
this.cover.style.display = Math.abs(value) > 0 ? 'block' : 'none';
this.cover.style.left = `${contentLeft}px`;
this.cover.style.transform = transform;
}
}

Expand Down Expand Up @@ -224,15 +231,17 @@ export default class Swipeout extends React.Component <SwipeoutPropType, any> {
<div className={`${prefixCls}-cover`} ref={(el) => this.cover = el} />
{ this.renderButtons(left, 'left') }
{ this.renderButtons(right, 'right') }
<Hammer
direction="DIRECTION_HORIZONTAL"
<Gesture
onPanStart={this.onPanStart}
onPan={this.onPan}
onPanMove={this.onPanMove}
onPanEnd={this.onPanEnd}
onSwipeLeft={this.doOpenRight}
onSwipeRight={this.doOpenLeft}
direction="horizontal"
{...refProps}
>
<div className={`${prefixCls}-content`}>{children}</div>
</Hammer>
</Gesture>
</div>
) : (
<div {...refProps} {...divProps}>{children}</div>
Expand Down
Loading