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.

MvxCachingFragmentCompatActivity with a Non cached fragment #286

Description

@jeremy-alley

I'm trying to create a Non-cacheable fragment by setting the IsCacheableFragment attribute on my fragment. However, when I do this, the ViewModel never gets set. Using your example project I did the following.

Steps to reproduce

Set the IsCacheableFragment equal to false

[MvxFragment(typeof(MainViewModel), Resource.Id.content_frame, true, IsCacheableFragment =false)]
[Register("example.droid.fragments.ExampleRecyclerViewFragment")]
public class ExampleRecyclerViewFragment : BaseFragment<ExampleRecyclerViewModel>
{...

I get a null exception error in OnCreate of the Fragment due to the ViewModel being null

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
        var view = base.OnCreateView(inflater, container, savedInstanceState);

        var recyclerView = view.FindViewById<MvxRecyclerView>(Resource.Id.my_recycler_view);
        if (recyclerView != null)
        {
            recyclerView.HasFixedSize = true;
            var layoutManager = new LinearLayoutManager(Activity);
            recyclerView.SetLayoutManager(layoutManager);
        }
         //ViewModel is null
        _itemSelectedToken = ViewModel.WeakSubscribe(() => ViewModel.SelectedItem,
            (sender, args) => {
                if (ViewModel.SelectedItem != null)
                    Toast.MakeText(Activity,
                        $"Selected: {ViewModel.SelectedItem.Title}",
                        ToastLength.Short).Show();
            });
         ....

Expected behavior

I thought this would allow the fragment to not be cached. I was able to achieve my desired results by doing something similar to this. http://stackoverflow.com/questions/37195393/mvxcachingfragmentcompatactivity-refresh-cached-fragment

I posted this question to stackoverflow as well.
http://stackoverflow.com/questions/39111689/mvxcachingfragmentcompatactivity-with-a-non-cached-fragment

Actual behavior

The ViewModel is null in the OnCreate method of my fragment

Configuration

Version: 4.2.3

Activity

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