Skip to content

Commit 906a6c5

Browse files
committed
fix touch in scrollview
1 parent fc91f75 commit 906a6c5

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

kivymd/uix/scrollview.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,9 @@ class StretchOverScrollBehavior:
504504

505505
_internal_scale = None
506506

507+
def _touch_key(self):
508+
return f"{id(self)}_stretch_active"
509+
507510
def __init__(self, *args, **kwargs):
508511
self.effect_cls = StretchOverScrollStencil
509512
super().__init__(*args, **kwargs)
@@ -516,19 +519,30 @@ def __init__(self, *args, **kwargs):
516519
self.effect_x.scale_axis = "x"
517520

518521
def on_touch_down(self, touch):
519-
self.effect_x.last_touch_pos = touch.pos
520-
self.effect_y.last_touch_pos = touch.pos
521-
return super().on_touch_down(touch)
522+
handled = super().on_touch_down(touch)
523+
if handled:
524+
touch.ud[self._touch_key()] = True
525+
self.effect_x.last_touch_pos = touch.pos
526+
self.effect_y.last_touch_pos = touch.pos
527+
return handled
522528

523529
def on_touch_move(self, touch):
524-
self.effect_x.convert_overscroll(touch)
525-
self.effect_y.convert_overscroll(touch)
526-
return super().on_touch_move(touch)
530+
handled = super().on_touch_move(touch)
531+
if (
532+
touch.ud.get(self._touch_key())
533+
and touch.grab_current in (None, self)
534+
):
535+
self.effect_x.convert_overscroll(touch)
536+
self.effect_y.convert_overscroll(touch)
537+
return handled
527538

528539
def on_touch_up(self, touch):
529-
self.effect_x.reset_scale()
530-
self.effect_y.reset_scale()
531-
return super().on_touch_up(touch)
540+
handled = super().on_touch_up(touch)
541+
if touch.ud.get(self._touch_key()):
542+
self.effect_x.reset_scale()
543+
self.effect_y.reset_scale()
544+
touch.ud.pop(self._touch_key(), None)
545+
return handled
532546

533547

534548
class MDScrollView(

0 commit comments

Comments
 (0)