KivyMD
KivyMD copied to clipboard
MDCardSwipe does not work when using with MDefreshLayout
trafficstars
Description of the Bug
MDCardSwipe does not work when using with MDefreshLayout. But it works when replacing the MDRefreshLayout with a BoxLayout
Test:
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
type_swipe: "hand"
MDCardSwipeLayerBox:
MDCardSwipeFrontBox:
OneLineListItem:
id: content
text: root.text
_no_ripple_effect: True
Screen:
MDScrollViewRefreshLayout: # Does not work
refresh_callback: lambda *args: print("refresh")
root_layout: root
# BoxLayout: # works
# orientation: "vertical"
BoxLayout:
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 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: Windows 10
- Python: 3.7.4
- Kivy: 2.0.0
- KivyMD: master
This could be a temporary solution until the bug gets fixed. Unfortunately the swipe action only works from top of the list not from Toolbar.
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.factory import Factory
from kivy.properties import StringProperty
from kivymd.uix.card import MDCardSwipe
from kivymd.utils import asynckivy
Builder.load_string('''
<SwipeToDeleteItem>:
size_hint_y: None
height: content.height
type_swipe: "hand"
MDCardSwipeLayerBox:
MDCardSwipeFrontBox:
OneLineListItem:
id: content
text: root.text
_no_ripple_effect: True
<Example@FloatLayout>
BoxLayout:
orientation: 'vertical'
MDToolbar:
elevation: 10
title: app.title
MDScrollViewRefreshLayout:
id: refresh_layout
refresh_callback: app.refresh_callback
root_layout: root
MDList:
id: box
size_hint_y: None
height: self.minimum_height
cols: 1
''')
class SwipeToDeleteItem(MDCardSwipe):
text = StringProperty()
class Example(MDApp):
title = 'Refresh Layout'
screen = None
x = 0
y = 15
def build(self):
self.screen = Factory.Example()
self.set_list()
return self.screen
def set_list(self):
async def set_list():
await asynckivy.sleep(0)
for i in range(20):
self.screen.ids.box.add_widget(
SwipeToDeleteItem(text=f"One-line item {i}")
)
asynckivy.start(set_list())
def refresh_callback(self, *args):
lambda *args: print("refresh")
Example().run()
The issue is deprecated due to the new API of the KivyMD library 2.0.0 version