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

MvxCachingFragmentCompatActivity with a Non cached fragment #286

Open
jeremy-alley opened this issue Aug 25, 2016 · 0 comments
Open

MvxCachingFragmentCompatActivity with a Non cached fragment #286

jeremy-alley opened this issue Aug 25, 2016 · 0 comments

Comments

@jeremy-alley
Copy link

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

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

No branches or pull requests

1 participant