@@ -29,11 +29,12 @@ export default class AtSwipeAction extends React.Component<
29
29
this . maxOffsetSize = maxDistance
30
30
this . state = {
31
31
componentId : uuid ( ) ,
32
- offsetSize : 0 ,
32
+ // eslint-disable-next-line no-extra-boolean-cast
33
+ offsetSize : ! ! isOpened ? - this . maxOffsetSize : 0 ,
33
34
_isOpened : ! ! isOpened ,
34
35
needAnimation : false
35
36
}
36
- this . moveX = 0
37
+ this . moveX = this . state . offsetSize
37
38
this . eleWidth = areaWidth
38
39
this . moveRatio = moveRatio || 0.5
39
40
}
@@ -43,17 +44,16 @@ export default class AtSwipeAction extends React.Component<
43
44
const { _isOpened } = this . state
44
45
45
46
if ( isOpened !== _isOpened ) {
46
- const isOpened = ! ! this . props . isOpened
47
47
this . moveX = isOpened ? 0 : this . maxOffsetSize
48
- this . _reset ( isOpened ) // TODO: Check behavior
48
+ this . _reset ( ! ! isOpened ) // TODO: Check behavior
49
49
}
50
50
}
51
51
52
52
private _reset ( isOpened : boolean ) : void {
53
53
if ( isOpened ) {
54
54
this . setState ( {
55
55
_isOpened : true ,
56
- offsetSize : 0
56
+ offsetSize : - this . maxOffsetSize
57
57
} )
58
58
} else {
59
59
this . setState (
@@ -62,7 +62,7 @@ export default class AtSwipeAction extends React.Component<
62
62
} ,
63
63
( ) => {
64
64
this . setState ( {
65
- offsetSize : this . maxOffsetSize ,
65
+ offsetSize : 0 ,
66
66
_isOpened : false
67
67
} )
68
68
}
@@ -101,22 +101,22 @@ export default class AtSwipeAction extends React.Component<
101
101
}
102
102
103
103
onTouchEnd = e => {
104
- if ( this . moveX === 0 ) {
104
+ if ( this . moveX === - this . maxOffsetSize ) {
105
105
this . _reset ( true )
106
106
this . handleOpened ( e )
107
107
return
108
108
}
109
- if ( this . moveX === this . maxOffsetSize ) {
109
+ if ( this . moveX === 0 ) {
110
110
this . _reset ( false )
111
111
this . handleClosed ( e )
112
112
return
113
113
}
114
- if ( this . state . _isOpened && this . moveX > 0 ) {
114
+ if ( this . state . _isOpened && this . moveX < 0 ) {
115
115
this . _reset ( false )
116
116
this . handleClosed ( e )
117
117
return
118
118
}
119
- if ( this . maxOffsetSize - this . moveX < this . maxOffsetSize * this . moveRatio ) {
119
+ if ( Math . abs ( this . moveX ) < this . maxOffsetSize * this . moveRatio ) {
120
120
this . _reset ( false )
121
121
this . handleClosed ( e )
122
122
} else {
@@ -129,12 +129,6 @@ export default class AtSwipeAction extends React.Component<
129
129
this . moveX = e . detail . x
130
130
}
131
131
132
- componentDidMount ( ) : void {
133
- const isOpened = ! ! this . props . isOpened
134
- this . moveX = isOpened ? 0 : this . maxOffsetSize
135
- this . _reset ( isOpened )
136
- }
137
-
138
132
public render ( ) : JSX . Element {
139
133
const { componentId, offsetSize } = this . state
140
134
const { options } = this . props
@@ -163,7 +157,8 @@ export default class AtSwipeAction extends React.Component<
163
157
onTouchEnd = { this . onTouchEnd }
164
158
onChange = { this . onChange }
165
159
style = { {
166
- width : `${ this . eleWidth } px`
160
+ width : `${ this . eleWidth } px` ,
161
+ left : `${ this . maxOffsetSize } px`
167
162
} }
168
163
>
169
164
{ this . props . children }
0 commit comments