@@ -27,6 +27,11 @@ export class Segment implements ComponentInterface {
27
27
28
28
// Value before the segment is dragged
29
29
private valueBeforeGesture ?: SegmentValue ;
30
+ /**
31
+ * Whether the segment "indicator" is currently being dragged.
32
+ * This is used to prevent updating the segment view content while the gesture is still active.
33
+ */
34
+ private gesturing = false ;
30
35
31
36
private segmentViewEl ?: HTMLIonSegmentViewElement | null = null ;
32
37
private lastNextIndex ?: number ;
@@ -36,7 +41,7 @@ export class Segment implements ComponentInterface {
36
41
* This behavior is enabled by default, but is set false when scrolling content views
37
42
* since we don't want to "double scroll" the segment view.
38
43
*/
39
- private triggerScrollOnValueChange ?: boolean ;
44
+ private updateContentOnValueChange ?: boolean ;
40
45
41
46
@Element ( ) el ! : HTMLIonSegmentElement ;
42
47
@@ -104,12 +109,10 @@ export class Segment implements ComponentInterface {
104
109
if ( previous && current ) {
105
110
if ( ! this . segmentViewEl ) {
106
111
this . checkButton ( previous , current ) ;
107
- } else if ( this . triggerScrollOnValueChange !== false ) {
108
- this . updateSegmentView ( ) ;
112
+ } else if ( this . updateContentOnValueChange !== false && ! this . gesturing ) {
113
+ this . updateSegmentView ( this . modeSmoothScroll ) ;
109
114
}
110
115
}
111
- } else if ( value !== undefined && oldValue === undefined && this . segmentViewEl ) {
112
- this . updateSegmentView ( ) ;
113
116
}
114
117
115
118
/**
@@ -123,7 +126,7 @@ export class Segment implements ComponentInterface {
123
126
this . scrollActiveButtonIntoView ( ) ;
124
127
}
125
128
126
- this . triggerScrollOnValueChange = undefined ;
129
+ this . updateContentOnValueChange = undefined ;
127
130
}
128
131
129
132
/**
@@ -227,6 +230,7 @@ export class Segment implements ComponentInterface {
227
230
228
231
onStart ( detail : GestureDetail ) {
229
232
this . valueBeforeGesture = this . value ;
233
+ this . gesturing = true ;
230
234
this . activate ( detail ) ;
231
235
}
232
236
@@ -245,10 +249,11 @@ export class Segment implements ComponentInterface {
245
249
if ( value !== undefined ) {
246
250
if ( this . valueBeforeGesture !== value ) {
247
251
this . emitValueChange ( ) ;
248
- this . updateSegmentView ( ) ;
252
+ this . updateSegmentView ( this . modeSmoothScroll ) ;
249
253
}
250
254
}
251
255
this . valueBeforeGesture = undefined ;
256
+ this . gesturing = false ;
252
257
}
253
258
254
259
/**
@@ -270,6 +275,13 @@ export class Segment implements ComponentInterface {
270
275
return this . getButtons ( ) . find ( ( button ) => button . value === this . value ) ;
271
276
}
272
277
278
+ /**
279
+ * The smooth scroll behavior of the segment view is tied to the mode.
280
+ */
281
+ private get modeSmoothScroll ( ) {
282
+ return getIonMode ( this ) === 'ios' ? false : true ;
283
+ }
284
+
273
285
/*
274
286
* Activate both the segment and the buttons
275
287
* due to a bug with ::slotted in Safari
@@ -400,7 +412,7 @@ export class Segment implements ComponentInterface {
400
412
401
413
if ( this . lastNextIndex === undefined || this . lastNextIndex !== nextIndex ) {
402
414
this . lastNextIndex = nextIndex ;
403
- this . triggerScrollOnValueChange = false ;
415
+ this . updateContentOnValueChange = false ;
404
416
405
417
this . checkButton ( current , buttons [ nextIndex ] ) ;
406
418
this . emitValueChange ( ) ;
@@ -613,7 +625,7 @@ export class Segment implements ComponentInterface {
613
625
}
614
626
615
627
if ( this . segmentViewEl ) {
616
- this . updateSegmentView ( ) ;
628
+ this . updateSegmentView ( this . modeSmoothScroll ) ;
617
629
618
630
if ( this . scrollable && previous ) {
619
631
this . checkButton ( previous , current ) ;
0 commit comments