Skip to content

Commit e6b035f

Browse files
committed
bump 0.5.0, remove onTouchEnd
1 parent 454322f commit e6b035f

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ ReactDom.render(
6464
| level | string or array | `all` | With the drawer level element. `all`/ null / className / id / tagName / array |
6565
| levelTransition | string | `transform .3s cubic-bezier(0.78, 0.14, 0.15, 0.86)` | level css transition |
6666
| parent | string | `body` | parent element. if is `null` use React.creactElement |
67-
| onChange | function | null | change callback(open) |
68-
| onSwitch | function | null | icon or bg click function |
67+
| onChange | func | null | change callback(open) |
68+
| onMaskClick | func | null | mask close click function |
69+
| onIconClick | func | nul | icon click function |
6970

71+
> 0.5 onSwitch split into `onMaskClick` `onIconClick`;
7072
7173
## Development
7274

examples/change.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class Demo extends React.Component {
2727
console.log(bool);
2828
}
2929
onTouchEnd = () => {
30+
this.setState({
31+
open: false,
32+
});
33+
}
34+
onSwitch = () => {
3035
this.setState({
3136
open: !this.state.open,
3237
});
@@ -38,7 +43,7 @@ class Demo extends React.Component {
3843
width="240px"
3944
onChange={this.onChange}
4045
open={this.state.open}
41-
onSwitch={this.onTouchEnd}
46+
onMaskClick={this.onTouchEnd}
4247
iconChild={false}
4348
level={null}
4449
>
@@ -91,7 +96,7 @@ class Demo extends React.Component {
9196
>
9297
内容区块
9398
<button
94-
onClick={this.onTouchEnd}
99+
onClick={this.onSwitch}
95100
style={{ height: 24, width: 100, marginLeft: 20, color: '#000', lineHeight: '24px' }}
96101
>
97102
{!this.state.open ? '打开' : '关闭'}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-drawer-menu",
3-
"version": "0.4.0",
3+
"version": "0.5.0",
44
"description": "drawer menu animation component for react",
55
"keywords": [
66
"react",

src/Drawer.jsx

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class Drawer extends React.PureComponent {
2020
openClassName: PropTypes.string,
2121
iconChild: PropTypes.any,
2222
onChange: PropTypes.func,
23-
onSwitch: PropTypes.func,
23+
onMaskClick: PropTypes.func,
24+
onIconClick: PropTypes.func,
2425
}
2526
static defaultProps = {
2627
className: 'drawer',
@@ -31,7 +32,8 @@ class Drawer extends React.PureComponent {
3132
level: 'all',
3233
levelTransition: 'transform .3s cubic-bezier(0.78, 0.14, 0.15, 0.86)',
3334
onChange: () => { },
34-
onSwitch: () => { },
35+
onMaskClick: () => { },
36+
onIconClick: () => { },
3537
iconChild: (<i className="drawer-button-icon" />),
3638
}
3739

@@ -109,7 +111,6 @@ class Drawer extends React.PureComponent {
109111
}
110112

111113
onTouchEnd = (e, close) => {
112-
this.props.onSwitch(e);
113114
if (this.props.open !== undefined) {
114115
return;
115116
}
@@ -123,7 +124,17 @@ class Drawer extends React.PureComponent {
123124
});
124125
}
125126

126-
touchStart = (e) => {
127+
onMaskTouchEnd = (e) => {
128+
this.props.onMaskClick(e);
129+
this.onTouchEnd(e, true);
130+
}
131+
132+
onIconTouchEnd = (e) => {
133+
this.props.onSwitch(e);
134+
this.onTouchEnd(e);
135+
}
136+
137+
onScrollTouchStart = (e) => {
127138
if (e.touches.length > 1) {
128139
return;
129140
}
@@ -133,7 +144,8 @@ class Drawer extends React.PureComponent {
133144
y: touchs.pageY,
134145
};
135146
}
136-
touchEnd = () => {
147+
148+
onScrollTouchEnd = () => {
137149
this.mousePos = null;
138150
}
139151

@@ -234,7 +246,7 @@ class Drawer extends React.PureComponent {
234246

235247
getChildToRender = () => {
236248
const open = this.props.open !== undefined ? this.props.open : this.state.open;
237-
const { className, openClassName, placement, children, width, iconChild } = this.props;
249+
const { className, style, openClassName, placement, children, width, iconChild } = this.props;
238250
const wrapperClassname = classnames(this.props.className, {
239251
[`${className}-${placement}`]: true,
240252
[openClassName]: open,
@@ -262,11 +274,10 @@ class Drawer extends React.PureComponent {
262274
}
263275
}
264276
return (
265-
<div className={wrapperClassname}>
277+
<div className={wrapperClassname} style={style}>
266278
<div
267279
className={`${className}-bg`}
268-
onTouchEnd={(e) => { this.onTouchEnd(e, true); }}
269-
onClick={(e) => { this.onTouchEnd(e, true); }}
280+
onClick={this.onMaskTouchEnd}
270281
/>
271282
<div
272283
className={`${className}-content-wrapper`}
@@ -277,8 +288,8 @@ class Drawer extends React.PureComponent {
277288
>
278289
<div
279290
className={`${className}-content`}
280-
onTouchStart={this.touchStart}
281-
onTouchEnd={this.touchEnd}
291+
onTouchStart={this.onScrollTouchStart}
292+
onTouchEnd={this.onScrollTouchEnd}
282293
ref={(c) => {
283294
this.contextDom = c;
284295
}}
@@ -288,7 +299,7 @@ class Drawer extends React.PureComponent {
288299
{iconChildToRender && (
289300
<div
290301
className={`${className}-button`}
291-
onClick={(e) => { this.onTouchEnd(e); }}
302+
onClick={this.onIconTouchEnd}
292303
>
293304
{iconChildToRender}
294305
</div>

0 commit comments

Comments
 (0)