Skip to content
This repository has been archived by the owner. It is now read-only.
This repository has been archived by the owner. It is now read-only.

Navigating back to the same VM and going to it again is not working #233

Open

Description

@sescandell

Steps to reproduce

  1. Create an app with only one VM and a fragment to display it (suppose the VM has one property ID)
  2. From the fragment, create a Command to navigate to the same VM but with a different "criteria" (imagine navigating to a same object but with a different ID)
  3. Follow the navigation:
    1. Launch the app
    2. Display the VM with ID 1
    3. From this fragment, click on the button to navigate to the VM with ID 2
    4. Press the back button
    5. Press the button to navigate to the VM with ID 2

Expected behavior

The fragment with ViewModel ID 2 should be displayed

Actual behavior

Nothing happens

Origin of the issue

The ShouldReplaceCurrentFragment returns FragmentReplaceMode.NoReplace.

This is because when navigating to VM with ID 2, ShowFragment set the fragInfo.CachedFragment with informations about VM with ID 2. When we click on the back button, we so display back the VM with ID 1.
Then if we click again on the button to display VM with ID 2, the fragment's tag to display is the same as the one currently displayed but with informations from VM ID 2 (pressing the back button didn't update CachedFragment object in "currentFragInfo").

Keep it simple, issue is the cached Fragment is not updated on BackButton pressed if going back to a fragment with the same tag.

Activity

  1. sescandell commented on May 8, 2016

    @sescandell
    ContributorAuthor

    A Workaround I found (I think working for most cases) is to update the BackButtonPressed method with the following:

    public override void OnBackPressed()
            {
                if (SupportFragmentManager.BackStackEntryCount >= 1)
                {
                    // MODIFICATION HERE: go back over all fragments with the same tag
                    var lastFragment = GetLastFragmentInfo();
                    SupportFragmentManager.PopBackStackImmediate(lastFragment.Tag, (int)PopBackStackFlags.Inclusive);
    
                    if (FragmentCacheConfiguration.EnableOnFragmentPoppedCallback)
                    {
                        //NOTE(vvolkgang) this is returning ALL the frags. Should we return only the visible ones?
                        var currentFragsInfo = GetCurrentCacheableFragmentsInfo();
                        OnFragmentPopped(currentFragsInfo);
                    }
    
                    return;
                }
    
                base.OnBackPressed();
            }

    This imply that if you navigate to the same fragment with different parameters, pressing the back button will redirect the user over all its navigation on that fragment (something acceptable for my context). Don't know what would be the situation if there is actually only one fragment for all the application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions