skoumalcz / fragment-back

Tiny library for handling back in fragments.
Apache License 2.0
47 stars 11 forks source link

Doesn't work for fragments inside a ViewPager #2

Closed aritraroy closed 7 years ago

aritraroy commented 8 years ago

It works for other fragments attached to an activity. But if there is a ViewPager and I want to handle back events inside the ViewPager fragments, then those fragments never get the event dispatched.

gingo commented 8 years ago

It works for me even if Fragments are inside ViewPager. Please check newly added example.

aritraroy commented 8 years ago

It doesn't work for me. I will explain you the situation.

I have an Activity which has a Fragment inside it. This Fragment contains a ViewPager containing 3 Fragments. I want to handle back pressed event in the Activity, parent Fragment and the Fragments inside the ViewPager.

But the issue is that I never get a callback in the child fragments. I think the problem is here,

List<Fragment> fragmentList = gActivity.getSupportFragmentManager().getFragments();

I have attached debugger and found this fragment list not containing any of my fragments inside the ViewPager and because of which the events are not dispatched to them.

Your idea of solving this problem is excellent. Hope to get some help on this issue.

gingo commented 8 years ago

Nested fragments are now supported. Should work right out of the box for you, just upgrade to version 0.2.0.

aritraroy commented 8 years ago

Thanks. Your enhancement works. But I had to put several null checks to prevent crashes which were happening because of this.

I would recommend you to improve the code and put the necessary null checks in place to make the library more robust.

gingo commented 8 years ago

I found only one place where NPE could happen. Is it already ok in version 0.2.1?

aritraroy commented 8 years ago

I actually had to fork the library to add the null checks myself as I was having several crashes and need to push an update to production as quick as I can.

I will put your 0.2.1 version and test it exhaustively later. Thanks a lot for the awesome support btw. 👍

gingo commented 8 years ago

Is your fork publicly available? Or can you make push-request with NPE checks?

gingo commented 7 years ago

I'm closing this ticket. Feel free to reopen, or open new one if you find any new issues.