Event in Recycleview

74 views
Skip to first unread message

Degenerate Tech

unread,
May 24, 2024, 5:09:25 AMMay 24
to Kivy users support
I want an event In kivy RecycleView . When I start scrolling 
Upward or Downward direction 
. One Event fire . 

ELLIOT GARBUS

unread,
May 24, 2024, 10:36:40 AMMay 24
to kivy-...@googlegroups.com
Look at ScrollView. RecycleView is derived from ScrollView. There are some events for start, stop, and move. 
Let me know if that does what you want.  

Sent from my iPhone

On May 24, 2024, at 2:09 AM, Degenerate Tech <sksah...@gmail.com> wrote:

I want an event In kivy RecycleView . When I start scrolling 
Upward or Downward direction 
. One Event fire . 

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/f83c7981-4a8c-4ea4-973a-8cf82c5a4e2cn%40googlegroups.com.

Degenerate Tech

unread,
May 28, 2024, 2:51:08 AMMay 28
to Kivy users support
I was trying to do . when anyone scroll up direction MDBottomNavigation pos_hint={'center_y':-0.1} (so it disappear )
and when anyone scroll down direction MDBottomNavigation pos_hint={'center_y':0.1} (so it visible )
see my approch . working but after one up scroll when i scroll  up again . MDBottomNavigation widget's pos_hint={'center_y':0.1}   (visible ) but here i want to it remains disappear.
i don't know where i am wrong .


see code

RecycleView:
id: rv
viewclass: 'Item'
key_size: 'height'
#on_data:print('hhh')
on_scroll_y:root._scroll(*args)
on_scroll_start:root._scroll_start(self.scroll_y)
effect_cls: "ScrollEffect"

        RecycleBoxLayout:

        padding: dp(1), dp(10), dp(1), dp(10)
            default_size: None,dp(80)
            default_size_hint: 1, None
            size_hint_y: None
            height: self.minimum_height
            orientation: 'vertical'
            spacing:'10dp'
            key_size:'vc_size'



############
initially 
_old_y=None
_old_diff=0



def _scroll(self,*args):

diff=self._old_y-args[-1]
#print(diff)
d=self._old_diff-diff
print(d)

if d<0:

if self._obj.ids.bnav.pos_hint['center_y']==0.1:
Animation(pos_hint={'center_y':-0.1},d=0.1).start(self._obj.ids.bnav)

else:
if self._obj.ids.bnav.pos_hint['center_y']==-0.1:
Animation(pos_hint={'center_y':+0.1},d=0.1).start(self._obj.ids.bnav)

self._old_diff=diff

def _scroll_start(self,y):
self._old_y=y

ElliotG

unread,
May 28, 2024, 4:00:17 PMMay 28
to Kivy users support
Here is an example that detects the scroll up or down using scroll_y.  I changed the Buttons to Labels to simplify scrolling.

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.recycleview import RecycleView
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty, ListProperty


kv = '''
<TwoButtons>:
# This class is used as the viewclass in the RecycleView
# The means this widget will be instanced to view one element of data from the data list.
# The RecycleView data list is a list of dictionaries.  The keys in the dictionary specify the
# attributes of the widget.
    Label:
        text: root.left_text
        # on_release: print(f'Button {self.text} pressed')
    Label:
        text: root.right_text
        # on_release: print(f'Button {self.text} pressed')
       
BoxLayout:
    orientation: 'vertical'
    Button:
        size_hint_y: None
        height: 48
        text: 'Add widget to RV list'
        on_release: rv.add()
   
    RV:                          # A Reycleview
        id: rv
        viewclass: 'TwoButtons'  # The view class is TwoButtons, defined above.
        data: self.rv_data_list  # the data is a list of dicts defined below in the RV class.
        scroll_type: ['bars', 'content']
        bar_width: 10
        RecycleBoxLayout:        
            # This layout is used to hold the Recycle widgets
            default_size: None, dp(48)   # This sets the height of the BoxLayout that holds a TwoButtons instance.

            default_size_hint: 1, None
            size_hint_y: None
            height: self.minimum_height   # To scroll you need to set the layout height.
            orientation: 'vertical'
'''


class TwoButtons(BoxLayout):        # The viewclass definitions, and property definitions.
    left_text = StringProperty()
    right_text = StringProperty()


class RV(RecycleView):
    rv_data_list = ListProperty()     # A list property is used to hold the data for the recycleview, see the kv code

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.rv_data_list = [{'left_text': f'Left {i}', 'right_text': f'Right {i}'} for i in range(40)]
        # This list comprehension is used to create the data list for this simple example.
        # The data created looks like:
        # [{'left_text': 'Left 0', 'right_text': 'Right 0'}, {'left_text': 'Left 1', 'right_text': 'Right 1'},
        # {'left_text': 'Left 2', 'right_text': 'Right 2'}, {'left_text': 'Left 3'},...
        # notice the keys in the dictionary correspond to the kivy properties in the TwoButtons class.
        # The data needs to be in this kind of list of dictionary formats.  The RecycleView instances the
        # widgets, and populates them with data from this list.
        self.prev_scroll_pos = self.scroll_y

    def add(self):
        l = len(self.rv_data_list)
        self.rv_data_list.extend([{'left_text': f'Added Left {i}', 'right_text': f'Added Right {i}'} for i in range(l,l+1)])

    def on_scroll_y(self, rv, v):
        if v < self.prev_scroll_pos:
            print('down')
        else:
            print('up')
        self.prev_scroll_pos = v

class RVTwoApp(App):

    def build(self):
        return Builder.load_string(kv)


RVTwoApp().run()

Degenerate Tech

unread,
May 29, 2024, 7:06:55 AMMay 29
to Kivy users support
see the video red box some time working but some time blinking . which looking very bad .
i want if user scroll upward direction red box disappear and remains disappear for next upcoming up scroll and
appear in down scroll for next upcomming down scroll.
Screencast from 29-05-24 04:33:06 PM IST.webm
code.py

Degenerate Tech

unread,
May 29, 2024, 9:27:11 AMMay 29
to Kivy users support
I want to do this type of things .see bottom navigation .

Record_2024-05-29-18-53-54_480x1068.mp4

ElliotG

unread,
May 29, 2024, 11:57:04 AMMay 29
to Kivy users support
Like this?  I have added some animation to the movement of the box at the bottom.
If you wanted the animation to have a more delayed start, you could use the Clock.trigger() to delay the start.
I removed the overscroll effect to remove the "error" at the top and bottom.


code.py

Degenerate Tech

unread,
May 29, 2024, 1:27:32 PMMay 29
to Kivy users support
Yes . Thank you . I was thinking .  Why this idea does not comes in my brain.
🤔 🤔 🤔 

Reply all
Reply to author
Forward
0 new messages