ShamylZakariya / StickyHeaders

Adapter and LayoutManager for Android RecyclerView which enables sticky header positioning.
MIT License
1.4k stars 185 forks source link

Everything is disappearing #35

Open EzimetYusup opened 7 years ago

EzimetYusup commented 7 years ago

Hey @ShamylZakariya how u doing !recently I found an issue : when I collapse last section everything is disappeared, last section was sticky on top, and has 10 child items, when I collapse them everything is gone, here i changed this line : https://github.com/ShamylZakariya/StickyHeaders/blob/master/stickyheaders/src/main/java/org/zakariya/stickyheaders/SectioningAdapter.java#L938 to offset += 1; it is working fine? do u want me to make PR?

EzimetYusup commented 7 years ago

the scenario was I have 3 section all has header, no footer, 1st and 2nd section each has one child item, but 3rd has 10 child items, all section was open, section 3 was sticky on top and clicked header to collapse section 3, then everything is disappeared.

ShamylZakariya commented 7 years ago

I'm on vacation in Hawaii, Burt I'll take a look at this when I have the opportunity.

On Fri, Nov 18, 2016, 6:16 AM EzimetYusup notifications@github.com wrote:

the scenario was I have 3 section all has header, no footer, 1st and 2nd section each has one child item, but 3rd has 10 child items, all section was open, section 3 was sticky on top and clicked header to collapse section 3, then everything is disappeared.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ShamylZakariya/StickyHeaders/issues/35#issuecomment-261571919, or mute the thread https://github.com/notifications/unsubscribe-auth/ABqa9EIWoxHxsu3odR-BwdAjwIH9ZzaVks5q_c93gaJpZM4K2mt6 .

Shamyl Zakariya

https://shamylzakariya.github.io/

EzimetYusup commented 7 years ago

@ShamylZakariya Cool, Enjoy ur vacation, just ping me when u get a chance to look at.

ShamylZakariya commented 7 years ago

Hey, I've looked at the method in question, and replacing +=2 with +=1 may fix it for your use case, but it will break everything else. The +=2 is there to handle the header and its "ghost header" (the item used by the library to track natural position of headers).

So I need to figure out a more comprehensive fix. Can you make me a minimal demo app which reproduces this? You can use the library's demo code as a skeleton.

EzimetYusup commented 7 years ago

@ShamylZakariya Sure, I can make one and will let u know!

EzimetYusup commented 7 years ago

Hey @ShamylZakariya change this line to https://github.com/ShamylZakariya/StickyHeaders/blob/master/app/src/main/java/org/zakariya/stickyheadersapp/ui/CollapsingSectionsDemoActivity.java#L19

adapter = new SimpleDemoAdapter(3, 10, false, false, true, SHOW_ADAPTER_POSITIONS);

then do following : sticky

EzimetYusup commented 7 years ago

@ShamylZakariya I found that in this case, when calling notifyItemRemoved method of RecyclerView, the position is not correct. maybe @mmangliers knows better.

EzimetYusup commented 7 years ago

Hey @ShamylZakariya ! did you get any chance to take a look at it?

ShamylZakariya commented 7 years ago

I'll be working on this this week I hope to have a fix or some kind of workaround in a few days.

On Mon, Nov 28, 2016 at 7:01 AM EzimetYusup notifications@github.com wrote:

Hey @ShamylZakariya https://github.com/ShamylZakariya ! did you get any chance to take a look at it?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ShamylZakariya/StickyHeaders/issues/35#issuecomment-263293148, or mute the thread https://github.com/notifications/unsubscribe-auth/ABqa9NqrTCBdLYrsNIOqSi8TqMMKVR6Jks5rCuzggaJpZM4K2mt6 .

--

Shamyl Zakariya

https://shamylzakariya.github.io/

EzimetYusup commented 7 years ago

@ShamylZakariya Ok cool! thanks!

ShamylZakariya commented 7 years ago

@EzimetYusup Can you try updating your repo? I've pushed a few changes to update the gradle files, which includes bringing in recyclerview 25.0.1. This new version of recyclerview seems to fix a long standing bug I was experiencing, and it also seems to not fix per se but change how your bug manifests.

What I'm seeing now is that instead of going blank, the recyclerview scrolls to the top.

Let me know if you can confirm this behavior.

Obviously, I'm still going to do my best to track this down.

ShamylZakariya commented 7 years ago

@EzimetYusup BTW, how did you encode that animated GIF? It's much better looking than my screen recordings.

EzimetYusup commented 7 years ago

@ShamylZakariya hey, thanks for getting back to me, I did not get chance to update the repo today, will do tomorrow. this is what I used: screen shot 2016-11-29 at 5 55 54 pm

EzimetYusup commented 7 years ago

Hey @ShamylZakariya , I just upgraded the repo, and found that the bug is still exist, unless I do offset += 1;

EzimetYusup commented 7 years ago

@ShamylZakariya is this offset += 1; change, breaking something?

ShamylZakariya commented 7 years ago

@EzimetYusup It breaks the method: the +2 is required, because StickyHeaderLayoutManager vends two headers per section. One which is placed in its natural position, and which doesn't draw anything, and a second one which is the visible, sticky one. Because is uses two headers, the adapter position must be advanced by two steps.

I am looking into a fix for this, but the switch from += 2 to += 1 breaks functionality of that method.

mmangliers commented 7 years ago

Easy fix in onLayoutChildren:

firstViewAdapterPosition = state.getItemCount() - 1;

instead of setting to 0 (first item) on screen clear, set to last item. I can make a pull request if you want but it's a pretty tiny fix

FDFD1313 commented 5 years ago

Hey Shamyl, can i use this in sticky header?: findLastCompletelyVisibleItemPosition

hunganh-px commented 5 years ago

First of all, I'm sorry for my bad English. Not sure if there are some one could fixed this issue but I found a way to overcome it. I found a problem with the firstViewTop variable in StickyHeaderLayoutManager. Its value might decrease to minus thousands, so when the section is collapse, it will pull entire view to that position. So everything looks disappeared but in fact, it still there but has been hung in very "high" position. And you cannot pull it down. If there is any header remain on screen, click on it several times and you will see everything come back. Log the firstViewTop and you will see how it happens. My solution is quiet ugly, but it works. I created an interface and implemented it in the activity.

@Override public void onHeaderClicked(int index) { recyclerView.scrollToPosition(index); }

Whenever I click on the header, I call that function, passing the section index from getAdapterPositionForSectionHeader(holder.getSection()) and the recyclerView will scroll itself to the header, prevent it to be pulled away to the firstViewTop. Not a good idea, but it solved the problem and help me to avoid using huge lib like FlexibleAdapter.