Code Monkey home page Code Monkey logo

Comments (15)

MatthewDailey avatar MatthewDailey commented on May 23, 2024

To follow up, that work around I proposed above gave me jerky animations while the list item is removed. I went with a workaround of making every list element equal height.

from swipeactionadapter.

wdullaer avatar wdullaer commented on May 23, 2024

This issue is similar to #26

Recycling views is very important to retain good performance. It is no accident that google made this pattern mandatory in their new recyclerview.

The proper solution is probably to inspect the new item in getView and adjust the backgrounds if necessary, either by reinflating or redrawing them with new parameters.
I'll need to experiment with this to see how all of it works together.

from swipeactionadapter.

wdullaer avatar wdullaer commented on May 23, 2024

I've been trying to reproduce this behaviour for quite some time now in the demo app, but I can't.

When I explicitly set the height in getView everything works out just fine.
For safety I would give your backgrounds a height of match_parent and do a requestLayout() on your output view if you changed its height.

from swipeactionadapter.

MatthewDailey avatar MatthewDailey commented on May 23, 2024

I have set height to match_parent and adding requestLayout() didn't fix it.

I have worked around by keeping my variable text field at 1 line and adding dialog but it would be great if I could get this working so I'm happy to help debug.

Gist with with relevant code: https://gist.github.com/MatthewDailey/8ac2b26fee9a23ac46f9

Video of the error: https://www.youtube.com/watch?v=FBj4lFtOtWA

from swipeactionadapter.

wdullaer avatar wdullaer commented on May 23, 2024

The behaviour in the video is indeed due to the recycling of the row Views.

I went through your gist but couldn't quite see how you got the first item to be higher than the others.

In any case, if you want different items to have different heights, I think you'll have to set the height in getView using convertView.getLayoutParameters().height.
The idea is that your ListView rows are all very similar, any difference between them (such as the content of the fields or, in this case, the height of the row) you should account for in getView.

from swipeactionadapter.

MatthewDailey avatar MatthewDailey commented on May 23, 2024

Ok thanks! I'll give it a shot in a bit.

from swipeactionadapter.

wdullaer avatar wdullaer commented on May 23, 2024

Did you resolve your issue?

from swipeactionadapter.

MatthewDailey avatar MatthewDailey commented on May 23, 2024

Nope the work around I had is sufficient for now.

from swipeactionadapter.

graphee-gabriel avatar graphee-gabriel commented on May 23, 2024

Hello, i'm trying to use your library to delete some items from my listview.
It works perfect appart from the height resizing of the items.
I'm using the same layout in each getView(), but with height set as wrap_content. I need my rows to adapt to the textview content so i can't solve it with by fixing the height.

Could you help me on that ?

from swipeactionadapter.

wdullaer avatar wdullaer commented on May 23, 2024

I never got this to work reliably in the past.

Basically you'll have to remeasure and invalidate the row view each time you bind new data in it.

It should be doable but I haven't figured out the right incantation for it.

I don't think changed to the actual library will be required, but let me know if you need any help there.

from swipeactionadapter.

graphee-gabriel avatar graphee-gabriel commented on May 23, 2024

Well, i'm new to android so it took me 5mn to integrate the lib and making it work, and the whole day trying to find a way to remeasure the views after the animation is done.
No success so far. If you could give me a code snippet of what you have in mind you would save my day!

from swipeactionadapter.

graphee-gabriel avatar graphee-gabriel commented on May 23, 2024

Basically what i do is this :

        @Override
        public void onSwipe(int[] positionList, int[] directionList) {
            for (int i = 0; i < positionList.length; i++) {
                int direction = directionList[i];
                int position = positionList[i];
                if (direction == SwipeDirections.DIRECTION_FAR_LEFT 
                ||  direction == SwipeDirections.DIRECTION_NORMAL_LEFT) {
                        Card card = wrappedAdapter.getItem(position);
                        wrappedAdapter.remove(card);
                        swipeAdapter.notifyDataSetChanged();
                }
            }
        }

even if i try to add getListView().invalidateViews(); there, it doesn't make any difference. Could it be because this is called before the animation start and not when it's actually done?
I guess the problems come from this part of the lib :

                ViewGroup.LayoutParams lp;
                for (PendingDismissData pendingDismiss : mPendingDismisses) {
                    // Reset view presentation
                    pendingDismiss.view.setAlpha(1f);
                    pendingDismiss.view.setTranslationX(0);
                    lp = pendingDismiss.view.getLayoutParams();
                    lp.height = originalHeight;
                    pendingDismiss.view.setLayoutParams(lp);
                }

Do you think there's any way to set the lp.height to the new layout's height taking it's place?

(Offtopic : By the way is it possible to disable the right swipe?)

from swipeactionadapter.

graphee-gabriel avatar graphee-gabriel commented on May 23, 2024

Oh.. Turns out it was pretty simple :
When the animation is done just set it back to WRAP_CONTENT instead of "originalHeight"
Only fix I could find, though i had to modify the lib.

pendingDismiss.view.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT));

from swipeactionadapter.

wdullaer avatar wdullaer commented on May 23, 2024

Nice work!

I'll try this out when I have some time and add the change to the library.

Disabling swipes by direction is an often requested feature. I have an idea on how to do it, but need to find the time really.

from swipeactionadapter.

graphee-gabriel avatar graphee-gabriel commented on May 23, 2024

I did a pull request with those two change (row heights bug + swipe direction enabling settings)
None of the swipe directions are enabled by default - enables on addBackground or addDirection (for use with no background).

from swipeactionadapter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.