@@ -17,6 +17,8 @@ limitations under the License.
17
17
import {
18
18
Builder ,
19
19
CoreTypes ,
20
+ EventData ,
21
+ GestureStateTypes ,
20
22
GridLayout ,
21
23
ItemSpec ,
22
24
PanGestureEventData ,
@@ -57,7 +59,6 @@ export class SwipeView extends GridLayout implements definition.SwipeView {
57
59
private _previousDelta = 0 ;
58
60
private _isParentPanIn = false ;
59
61
private _animationDuration = 250 ;
60
- private _prevPanState : number ;
61
62
62
63
public refresh ( ) {
63
64
if ( ! this . _swipeView ) {
@@ -87,28 +88,23 @@ export class SwipeView extends GridLayout implements definition.SwipeView {
87
88
88
89
this . style . padding = 0 ;
89
90
90
- this . parent ?. on ( "pan" , ( e : PanGestureEventData ) => {
91
- this . _isParentPanIn = e . state === 2 && Math . abs ( e . deltaY ) > 5 ;
92
- if ( this . _isParentPanIn
93
- && this . getChildAt ( 1 ) ?. translateX !== 0 ) {
94
- this . _resetTransition ( ) ;
95
- }
96
- } ) ;
97
- this . parent ?. on ( SwipeView . swipeViewSwipeStartedEvent , ( e ) => {
98
- if ( e . object !== this ) {
99
- this . _resetTransition ( ) ;
100
- }
101
- } ) ;
102
- this . parent ?. on ( "itemTap" , this . _resetTransition . bind ( this ) ) ;
91
+ this . parent ?. on ( "pan" , this . _onParentPan , this ) ;
92
+ this . parent ?. on ( SwipeView . swipeViewSwipeStartedEvent , this . _onSwipeViewSwipeStarted , this ) ;
93
+ this . parent ?. on ( "itemTap" , this . _resetTransition , this ) ;
103
94
104
- this . on ( "pan" , this . _onPan . bind ( this ) ) ;
105
- this . _swipeView . on ( "tap" , this . _resetTransition . bind ( this ) ) ;
95
+ this . on ( "pan" , this . _onPan , this ) ;
96
+ this . _swipeView . on ( "tap" , this . _resetTransition , this ) ;
106
97
}
107
98
108
99
public onUnloaded ( ) : void {
109
- this . off ( "pan" ) ;
110
- this . off ( "tap" ) ;
100
+ this . parent ?. off ( "pan" , this . _onParentPan , this ) ;
101
+ this . parent ?. off ( SwipeView . swipeViewSwipeStartedEvent , this . _onSwipeViewSwipeStarted , this ) ;
102
+ this . parent ?. off ( "itemTap" , this . _resetTransition , this ) ;
103
+
104
+ this . off ( "pan" , this . _onPan , this ) ;
105
+ this . _swipeView . off ( "tap" , this . _resetTransition , this ) ;
111
106
107
+ this . removeChild ( this . _swipeView ) ;
112
108
this . _swipeView . removeChildren ( ) ;
113
109
this . _swipeView = undefined ;
114
110
this . _leftActionsTemplateView = undefined ;
@@ -130,9 +126,8 @@ export class SwipeView extends GridLayout implements definition.SwipeView {
130
126
return ;
131
127
}
132
128
133
- // Swipe start
134
- if ( e . state === 2
135
- && this . _prevPanState !== e . state ) {
129
+ // Pan start
130
+ if ( e . state === GestureStateTypes . began ) {
136
131
this . parent ?. notify ( {
137
132
eventName : SwipeView . swipeViewSwipeStartedEvent ,
138
133
object : this ,
@@ -150,14 +145,12 @@ export class SwipeView extends GridLayout implements definition.SwipeView {
150
145
this . _swipeView . height = Utils . layout . toDeviceIndependentPixels ( finalHeight ) ;
151
146
}
152
147
153
- this . _prevPanState = e . state ;
154
-
155
148
const itemView = this . getChildAt ( 1 ) ;
156
149
const leftActionsViewMeasuredWidth = Utils . layout . toDeviceIndependentPixels ( this . _leftActionsTemplateView ?. getMeasuredWidth ( ) ) ;
157
150
const rightActionsViewMeasuredWidth = Utils . layout . toDeviceIndependentPixels ( this . _rightActionsTemplateView ?. getMeasuredWidth ( ) ) ;
158
151
159
152
// Pan Stop
160
- if ( e . state === 3 ) {
153
+ if ( e . state === GestureStateTypes . ended ) {
161
154
let translateX = 0 ;
162
155
if ( e . deltaX < 0 && itemView . translateX < 0 ) {
163
156
translateX = - rightActionsViewMeasuredWidth ;
@@ -202,6 +195,20 @@ export class SwipeView extends GridLayout implements definition.SwipeView {
202
195
}
203
196
}
204
197
}
198
+
199
+ private _onParentPan ( e : PanGestureEventData ) {
200
+ this . _isParentPanIn = e . state === GestureStateTypes . changed && Math . abs ( e . deltaY ) > 5 ;
201
+ if ( this . _isParentPanIn
202
+ && this . getChildAt ( 1 ) ?. translateX !== 0 ) {
203
+ this . _resetTransition ( ) ;
204
+ }
205
+ }
206
+
207
+ private _onSwipeViewSwipeStarted ( e : EventData ) {
208
+ if ( e . object !== this ) {
209
+ this . _resetTransition ( ) ;
210
+ }
211
+ }
205
212
}
206
213
207
214
leftActionsTemplateProperty . register ( SwipeView ) ;
0 commit comments