Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fragments instead of replacing them #64

Closed
azurh opened this issue May 14, 2018 · 8 comments
Closed

Add fragments instead of replacing them #64

azurh opened this issue May 14, 2018 · 8 comments

Comments

@azurh
Copy link

azurh commented May 14, 2018

I'm wondering if there is a way to alter the FragmentTransaction instance, which is being used in the forward(Forward command) method, as seen in the SupportFragmentNavigator class. I need to fragmentTransaction.add() fragments instead of fragmentTransaction.replace()-ing them.

I'm using the navigateTo method to show the next Fragment, like so:

App.get().getRouter().navigateTo(Screens.CUSTOMER_DETAIL, customer);

I have a Fragment which basically hosts a RecyclerView with a lots of data (customers), returned by remote API.
Clicking an item from that list will open a new screen which will host detailed data for that customer.

A common scenario you might guess.

When I go back from the detail screen, the API is invoked again, the list reloaded, scrolling position gone, search filters invalidated etc.
That's because the library uses fragmentTransaction.replace(), but fragmentTransaction.add() is what I need, to avoid the reload.

I've copied locally these two classes: SupportFragmentNavigator and SupportAppNavigator and changed what I need, and it works.
But it's a dirty solution.

Is there an API in Cicerone which will provide customization options for this manner?

@terrakok
Copy link
Owner

Hi! Thanks for proposal)
Cicerone is pragmatic library. Replace fragment is more frequently operation than add. I don't wont that library contains much solutions for all cases.
But navigator API is easy for extends)

What do you think?

@azurh
Copy link
Author

azurh commented May 27, 2018

@terrakok

Thanks for your response.

The navigator API is indeed easy to extend (like setupFragmentTransactionAnimation()), but unfortunately not in terms of altering the FragmentTransaction parameters like choosing between replace or add, except making local copies of SupportFragmentNavigator and SupportAppNavigator, which I have done, but it's a hacky solution IMHO.

I would be happy to issue a PR which will tackle this feature, but I understand that you don't want to bloat the simplicity of Cicerone.

Do you have an advice on how to persist the fragment UI and data, in a way that the Fragment instance would't be cleared (and the data wouldn't be downloaded again) — when going back, while still using FragmentTransaction#replace()?

@terrakok
Copy link
Owner

When you replaced fragment, it didn't destroyed , only views were cleared . FragmentManager saved fragment instance

@java1developer
Copy link

fragmentTransaction.add() example: show progress as transparent fragment

@terrakok
Copy link
Owner

Progress is not screen for navigation chain! 😱

@inwady
Copy link

inwady commented Sep 17, 2019

I need to use library which requires #add instead of #replace. I added crutches to change logic for fragmentTransaction.add() because things such as checkAndStartActivity, localStackCopy are private.

@terrakok
Copy link
Owner

#101

@terrakok terrakok reopened this Sep 17, 2019
@terrakok
Copy link
Owner

https://github.com/terrakok/Cicerone/releases/tag/v5.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants