@@ -8,6 +8,7 @@ import { Key } from '../../util/key';
8
8
import { NavParams } from '../../navigation/nav-params' ;
9
9
import { Picker } from './picker' ;
10
10
import { PickerOptions , PickerColumn , PickerColumnOption } from './picker-options' ;
11
+ import { Haptic } from '../../util/haptic' ;
11
12
import { UIEventManager } from '../../util/ui-event-manager' ;
12
13
import { ViewController } from '../../navigation/view-controller' ;
13
14
@@ -53,12 +54,13 @@ export class PickerColumnCmp {
53
54
maxY : number ;
54
55
rotateFactor : number ;
55
56
lastIndex : number ;
57
+ lastTempIndex : number ;
56
58
receivingEvents : boolean = false ;
57
59
events : UIEventManager = new UIEventManager ( ) ;
58
60
59
61
@Output ( ) ionChange : EventEmitter < any > = new EventEmitter ( ) ;
60
62
61
- constructor ( config : Config , private elementRef : ElementRef , private _sanitizer : DomSanitizer ) {
63
+ constructor ( config : Config , private elementRef : ElementRef , private _sanitizer : DomSanitizer , private _haptic : Haptic ) {
62
64
this . rotateFactor = config . getNumber ( 'pickerRotateFactor' , 0 ) ;
63
65
}
64
66
@@ -114,6 +116,9 @@ export class PickerColumnCmp {
114
116
115
117
this . minY = ( minY * this . optHeight * - 1 ) ;
116
118
this . maxY = ( maxY * this . optHeight * - 1 ) ;
119
+
120
+ this . _haptic . gestureSelectionStart ( ) ;
121
+
117
122
return true ;
118
123
}
119
124
@@ -146,6 +151,14 @@ export class PickerColumnCmp {
146
151
}
147
152
148
153
this . update ( y , 0 , false , false ) ;
154
+
155
+ let currentIndex = Math . max ( Math . abs ( Math . round ( y / this . optHeight ) ) , 0 ) ;
156
+ if ( currentIndex !== this . lastTempIndex ) {
157
+ // Trigger a haptic event for physical feedback that the index has changed
158
+ this . _haptic . gestureSelectionChanged ( ) ;
159
+ }
160
+ this . lastTempIndex = currentIndex ;
161
+
149
162
}
150
163
151
164
pointerEnd ( ev : UIEvent ) {
@@ -209,6 +222,8 @@ export class PickerColumnCmp {
209
222
if ( isNaN ( this . y ) || ! this . optHeight ) {
210
223
// fallback in case numbers get outta wack
211
224
this . update ( y , 0 , true , true ) ;
225
+ this . _haptic . gestureSelectionEnd ( ) ;
226
+
212
227
213
228
} else if ( Math . abs ( this . velocity ) > 0 ) {
214
229
// still decelerating
@@ -230,12 +245,13 @@ export class PickerColumnCmp {
230
245
this . velocity = 0 ;
231
246
}
232
247
233
- console . log ( `decelerate y: ${ y } , velocity: ${ this . velocity } , optHeight: ${ this . optHeight } ` ) ;
248
+ // console.debug (`decelerate y: ${y}, velocity: ${this.velocity}, optHeight: ${this.optHeight}`);
234
249
235
250
var notLockedIn = ( y % this . optHeight !== 0 || Math . abs ( this . velocity ) > 1 ) ;
236
251
237
252
this . update ( y , 0 , true , ! notLockedIn ) ;
238
253
254
+
239
255
if ( notLockedIn ) {
240
256
// isn't locked in yet, keep decelerating until it is
241
257
this . rafId = raf ( this . decelerate . bind ( this ) ) ;
@@ -247,9 +263,17 @@ export class PickerColumnCmp {
247
263
248
264
// create a velocity in the direction it needs to scroll
249
265
this . velocity = ( currentPos > ( this . optHeight / 2 ) ? 1 : - 1 ) ;
266
+ this . _haptic . gestureSelectionEnd ( ) ;
250
267
251
268
this . decelerate ( ) ;
252
269
}
270
+
271
+ let currentIndex = Math . max ( Math . abs ( Math . round ( y / this . optHeight ) ) , 0 ) ;
272
+ if ( currentIndex !== this . lastTempIndex ) {
273
+ // Trigger a haptic event for physical feedback that the index has changed
274
+ this . _haptic . gestureSelectionChanged ( ) ;
275
+ }
276
+ this . lastTempIndex = currentIndex ;
253
277
}
254
278
255
279
optClick ( ev : UIEvent , index : number ) {
0 commit comments