KivyMD icon indicating copy to clipboard operation
KivyMD copied to clipboard

For some reason that I did not identify the SwipeToDeleteItem only works on the computer.

Open CoutinhoElias opened this issue 4 years ago • 2 comments

Description of the Bug

For some reason that I did not identify the SwipeToDeleteItem only works on the computer.

I click and hold the item, drag it to the left and it does not work on android, only on the computer.

Code and Logs

Code extracted from End full code

Before sending this model of the documentation I took care to package it for testing and the same problem occurs.

from kivy.lang import Builder
from kivy.properties import StringProperty

from kivymd.app import MDApp
from kivymd.uix.card import MDCardSwipe

KV = '''
<SwipeToDeleteItem>:
    size_hint_y: None
    height: content.height

    MDCardSwipeLayerBox:
        padding: "8dp"

        MDIconButton:
            icon: "trash-can"
            pos_hint: {"center_y": .5}
            on_release: app.remove_item(root)

    MDCardSwipeFrontBox:

        OneLineListItem:
            id: content
            text: root.text
            _no_ripple_effect: True


MDScreen:

    MDBoxLayout:
        orientation: "vertical"
        spacing: "10dp"

        MDToolbar:
            elevation: 10
            title: "MDCardSwipe"

        ScrollView:

            MDList:
                id: md_list
                padding: 0
'''


class SwipeToDeleteItem(MDCardSwipe):
    text = StringProperty()


class TestCard(MDApp):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.screen = Builder.load_string(KV)

    def build(self):
        return self.screen

    def remove_item(self, instance):
        self.screen.ids.md_list.remove_widget(instance)

    def on_start(self):
        for i in range(20):
            self.screen.ids.md_list.add_widget(
                SwipeToDeleteItem(text=f"One-line item {i}")
            )


TestCard().run()

Versions

OS: Ubuntu 20.04.2 LTS Python: 3.8.5 Kivy: 2.0.0 KivyMD: 0.104.2.dev0, git-8f83652, 2021-05-16

CoutinhoElias avatar May 25 '21 13:05 CoutinhoElias

The main issue is with MDList padding is 0 which means on the phone screen it is the very edge of the phone nearly impossible to touch. The other issue I found is the default swipe_distance is too small to comfortably touch and move the slide.

This is the solution

from kivy.lang import Builder
from kivy.properties import StringProperty
from kivymd.app import MDApp
from kivymd.uix.card import MDCardSwipe

KV = '''
<SwipeToDeleteItem>:
    size_hint_y: None
    height: content.height
    swipe_distance: "200dp"

    MDCardSwipeLayerBox:
        padding: "8dp"

        MDIconButton:
            icon: "trash-can"
            pos_hint: {"center_y": .5}
            on_release: app.remove_item(root)

    MDCardSwipeFrontBox:

        OneLineListItem:
            id: content
            text: root.text
            _no_ripple_effect: True


MDScreen:

    MDBoxLayout:
        orientation: "vertical"
        spacing: "10dp"

        MDToolbar:
            elevation: 10
            title: "MDCardSwipe"

        ScrollView:

            MDList:
                id: md_list
                padding: 2
'''


class SwipeToDeleteItem(MDCardSwipe):
    text = StringProperty()


class TestCard(MDApp):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.screen = Builder.load_string(KV)

    def build(self):
        return self.screen

    def remove_item(self, instance):
        self.screen.ids.md_list.remove_widget(instance)

    def on_start(self):
        for i in range(20):
            self.screen.ids.md_list.add_widget(
                SwipeToDeleteItem(text=f"One-line item {i}")
            )


TestCard().run()

This should be mentioned in the document please.

sollarp avatar Sep 17 '21 20:09 sollarp

I fully agree! After your tips worked here too!

CoutinhoElias avatar Oct 10 '21 01:10 CoutinhoElias