daimajia / AndroidSwipeLayout

The Most Powerful Swipe Layout!
MIT License
12.38k stars 2.67k forks source link

Enabled Swiping with multiple DragEdges #40

Closed ofermoshsaioff closed 9 years ago

ofermoshsaioff commented 10 years ago

You should really consider adding the ability to swipe to multiple directions. I.E. - left and right, or left and top for example.

daimajia commented 10 years ago

Ok, I think I'll add this feature.

22

@tasti

alexmetcalfe commented 10 years ago

I would also really like to see this feature! :)

mario commented 10 years ago

Hey,

when is this planned? We'd need it quite soon.

daimajia commented 10 years ago

@mario Sorry for my late, recently a little busy, I'll add this feature ASAP.

feliu commented 10 years ago

I'm very interested in this feature! you are awesome!

zjc commented 9 years ago

I'm very interested in this feature! you are awesome! thanks

giorgiofellipe commented 9 years ago

+1! so excited to see it in action

pavlospt commented 9 years ago

Any updates on this issue?

HarshEvilGeek commented 9 years ago

Hey, great library! Seriously, best one out there by a long way. I really need this feature as well. In particular I need a left and right swipe. Just wanted to see if you were planning on doing it soon? I need it urgently, so I was thinking of doing it myself.

The logic I had in mind was as follows:

1) Modify the attribute file to allow selections like this : left|right or left|top 2) Get this list in an mDragEdges variable 3) To ensure that minimum changes are required, I was thinking that instead of inserting logic for multiple directions in all your switch case statements, I'd still keep the single mDragEdge variable. When the user starts swiping in any direction, I'd check if that direction exists in the mDragEdges list, and I'd set the mDragEdge variable. So the rest of the logic can be as it currently is, as long as the user declares the views they need (bottom, left, etc.).

Does this approach make sense? Do you think it'll work?

daimajia commented 9 years ago

@HarshEvilGeek A really brilliant idea on this problem, it should work, but maybe still a lot of coding works.

daimajia commented 9 years ago

@HarshEvilGeek You are really awesome! Welcome to send a pull request, I'll test your great work later.

daimajia commented 9 years ago

@HarshEvilGeek Welcome to chat here, if you have any new idea or questions. https://gitter.im/daimajia/AndroidSwipeLayout

HarshEvilGeek commented 9 years ago

Hi, sorry, guess my initial comment got deleted:

Hi, for those who are interested, I created a fork and have made the required the changes.

https://github.com/HarshEvilGeek/AndroidSwipeLayout

If you're planning on using it, there are a few logical changes. In the current state, you need to set 2 view groups in your swipe layout, one of them for the background, one for the surface (the library will otherwise throw an IllegalArgumentException)

Now you need to set 1 + number of drag edges you're enabling in your xml file. I'll use those view groups in the order in which you add the drag edges. So if you say:

swipeLaout.setDragEdges(DragEdge.Left, DragEdge.Right)

The first view group will be on the left side, and the second view group will be on the right side. The last view will be the surface view (as is the case now).

Just download the repository and you'll now be able to swipe sample 1 left and right. There might be a few bugs, will work on it.

Thanks @daimajia again for the excellent library. Glad I could contribute. Will test it a bit and make a pull request

daimajia commented 9 years ago

@HarshEvilGeek Issue found: the surface view does not follow your finger when moving.

HarshEvilGeek commented 9 years ago

Oh, woops, I guess I didn't commit that change. Already fixed, thanks. Check now.

daimajia commented 9 years ago

@HarshEvilGeek Cool, I tested, it works well.

daimajia commented 9 years ago

@HarshEvilGeek issue found: It works incorrect in ListView, you can not drag the surface view back.

daimajia commented 9 years ago

@HarshEvilGeek I have to say that you are really excellent~ :+1:

HarshEvilGeek commented 9 years ago

Yeah, the directions on gridview and listview seem to be reversed as well (drag edge is left). I'm guessing the default value is set to one, so that's an easy fix. Will look into the listview issue as well. Haha, @daimajia, thanks, that means a lot coming from you.

daimajia commented 9 years ago

@HarshEvilGeek One idea. Just using the order to determine the layout is left or right may be not a good idea right now. I think we can retrieve the layout type by id. using findViewById to get the corresponding layout.

HarshEvilGeek commented 9 years ago

Setting the default drag edge to right seems to have fixed the other issue as well o.O. I have no idea how! Will look into this, but the listview is working well now.

EDIT: figured out why, the yes button listener was picking up the click. This isn't related to my changes. If you click above the yes button it works. By changing the edge to right, I just made it unlikely that you'll click on the yes button.

And yes, I agree with you, findViewById will be a cleaner way to do this. Will add support for that when I get a chance.

daimajia commented 9 years ago

Awesome!
Another problem on code style, could you please using this kind of code format when using function:

function fn() {
....
}

@jpshelley has made a pull request, adding support on RecyclerView. Thanks you guys. We are really making the most powerful swipe library. :-D

iAviatorJose commented 9 years ago

But is there any documentation related to this, on how to go with this. A sample XML code will also suffice.

daimajia commented 9 years ago

@iAviatorJose It's not finished yet...

HarshEvilGeek commented 9 years ago

Yes, I'll try to add a little bit of documentation. Unfortunately, I've been shifted to something more urgent at my company, so I won't be able to finish this till the 20th (Jan). Once I get back to it, it shouldn't take more than a few days.

iAviatorJose commented 9 years ago

Great !!! I'll be waiting for the update @HarshEvilGeek and @daimajia :)

intrications commented 9 years ago

@HarshEvilGeek I've tried out your code and it works well for me.

What is the difference between ShowMode.LayDown and ShowMode.PullOut?

HarshEvilGeek commented 9 years ago

Great to hear.

I didn't add the modes. It's a simple styling difference though added by @daimajia.

Laydown, makes it look like the background was there the whole time when you swipe (just lying below). Pullout makes it look like it's coming from the side of the screen. Switch them and play around with the app, and you'll see the difference.

intrications commented 9 years ago

@HarshEvilGeek Ah, I understand now.

I tried to work out who had added the modes through the git commits. Obviously didn't look well enough. Thanks anyway.

intrications commented 9 years ago

@HarshEvilGeek Is it possible to selectively disable swiping on individual edges?

Like setSwipeEnabled() but for each edge?

skywalkerlw commented 9 years ago

I'm confused so I have to ask
Have you done on the function of Swipe Views on Both Left and Right?

iAviatorJose commented 9 years ago

@HarshEvilGeek @daimajia have you guys completed with the swipe on both sides of a ListView Cell.

HarshEvilGeek commented 9 years ago

Hey, sorry, I've been a little busy. I do have a working fork with multiple edge swipe. I haven't generated a pull request, because there are a few more features (mainly around performance that I wanted to add first).

@wangbourne and @iAviatorJose , you can use my fork here https://github.com/HarshEvilGeek/AndroidSwipeLayout for now. I should be able to get to this next weekend, if I manage to clear up my backlog on my other projects. I know for a fact, I'll be free by the second weekend in Feb, so that's the absolute latest.

iAviatorJose commented 9 years ago

Thanks @HarshEvilGeek in between what programmatic changes i have to do .. i mean to say earlier we used to have two layout inside the swipelayout now what new i have to do to for have swipe on both the sides with respect to the new changes.

daimajia commented 9 years ago

Hey @HarshEvilGeek , good news, AndroidSwipeLayout start support RecyclerView. Something has been changed, please pull the latest code before generate a new PR. Thanks your hard work on it. :-D

HarshEvilGeek commented 9 years ago

Hey, I've added all the features requested here. Namely, 1) findViewById() for each layout (will default to using the order if the user doesn't specify), 2) touchSlop changes, 3) Support for enabling/disabling swipe for each edge individually). @daimajia , and anyone who's requested for it, I'd recommend testing it (didn't do much testing after I merged your recycler view changes). Once you're done, let me know, I'll raise a pull request.

One issue I know about is occasionally, when you do a fast swipe from a right edge to a left edge (without any pause), the offset used is the wrong one (doesn't have enough time to update). This is pretty rare and a rather minor issue. There are a few hacks to fix it, but I'll take a look later.

daimajia commented 9 years ago

@HarshEvilGeek Great work! I'll test your master branch, and will give feedback ASAP.

daimajia commented 9 years ago

@HarshEvilGeek I quickly checked the every commits you made. And made some samples to test the functions. It works really well in ListView, RecyclerView and GridView. But there are still some tiny problems.

  1. TypeArray a should call recycle() to release memory. (this is my fault ^^).
  2. SwipeLayout should own a new open method, which can specify which DragEdge to open. Check Here
HarshEvilGeek commented 9 years ago

I've added the changes. Let me know if there's anything else.

daimajia commented 9 years ago

@HarshEvilGeek Well done!
There is an imperfect part on the usage of the multi edges, when using multi edge, you have to call setDragEdges method. In a short time, it will not support top and bottom edges or other combination, just left and right.

so, we can make it easier to use. SwipeLayout can only own 2 or 3 children, if 2 then the common scenario , if 3, then multi edges scenario, we can call setDragEdges inside the SwipeLayout. how about that?

HarshEvilGeek commented 9 years ago

Hey, I'm not sure what you're talking about. I added a temp demo with 3 swipes (left, right, top). It doesn't look great because of some layout formatting, but it works perfectly. I needed to switch the coordinates for top and bottom, but aside from that. Check it out.

daimajia commented 9 years ago

@HarshEvilGeek Oh, my fault! I still thought that it could only work in two edges... please ignore my previous suggestion, it's my bullshit... :laughing:

daimajia commented 9 years ago

@HarshEvilGeek I'm testing your master branch, wait a minute.

daimajia commented 9 years ago

@HarshEvilGeek it's not easy to understand what -1 means. better set a constant (public static final) variable. like SwipeLayout.EmptyLayout. or something.

HarshEvilGeek commented 9 years ago

Sure. Done. For the topview swipe, if you want it to look like the third one, you need to add those listeners. I haven't bothered. I just did that for the demo (to show you that swipe in every direction works). Feel free to remove it.

daimajia commented 9 years ago

@HarshEvilGeek Awesome! It's time to send a pull request. I'll complete the wiki after merged. Really thanks for your hard work on this project. If you are available, and have interests, would you want be a collaborator of this repository ? (will have push access to this repo.) . :-D just like @jpshelley , he is working on swipe dismiss recently, we both want to make AndroidSwipeLayout to be the most powerful Android component.

HarshEvilGeek commented 9 years ago

Great, if the changes are done, I need to get clearance for the pull request (only because I worked on this for my job). Will ask for it now, and I'll commit in a few days I hope. They just need to confirm I'm not sharing any proprietary code or anything.

daimajia commented 9 years ago

@HarshEvilGeek Wow, it sounds pretty strict. We'll waiting for your PR, how about join this project as a collaborator?

HarshEvilGeek commented 9 years ago

Yes, that sounds great!

daimajia commented 9 years ago

@HarshEvilGeek Cool, I'll send you a confirmation via GitHub project settings. You'll get push access after be a member of this project! :smiley: