Как сделать DrawerMenu в версиях MvvmCross? v. 5.4.2

Я использую StarWarsEaxmple из репозитория MvvmCross и не могу заставить его работать. Вывод MvvmCross , проблема на мой взгляд либо в разных версиях MvvmCross либо в Presenter. В образцах версия 5.1.1, а в моем проекте 5.4.2. И демонстрирует странное поведение.

Я вижу пустой ящик, когда не использую MvvmCross NavigationService. Однако, когда я последовательно перемещаюсь по обоим ViewModels (как в примере), я вижу только страницу меню без ящика, а другой фрейм страницы даже не вызывается.

Ссылка на пример MvvmCross

Основное действие

[Activity(Icon = "@drawable/icon", 
    Theme = "@style/AppTheme", LaunchMode = LaunchMode.SingleTop, 
    ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : MvxCachingFragmentCompatActivity<MainViewModel>
{
    public DrawerLayout DrawerLayout;
    //This method is invoked
    protected override void OnCreate(Bundle bundle)
    {            base.OnCreate(bundle);
        SetContentView(Resource.Layout.activity_main);

        DrawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawerLayout);

        ViewModel.ShowDefaultMenuItem();
    }
....

Фрагмент меню

[MvxFragment(typeof(MainViewModel), Resource.Id.navigationFrame)]
[Register("VacationManager.Droid.Activities.MenuFragment")]
public class MenuFragment : MvxFragment<MenuViewModel>, NavigationView.IOnNavigationItemSelectedListener
{
    private NavigationView _navigationView;
    private IMenuItem _previousMenuItem;

   //This method is invoked too
    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {

        base.OnCreateView(inflater, container, savedInstanceState);
        var view = this.BindingInflate(Resource.Layout.menu_view, null);

        _navigationView = view.FindViewById<NavigationView>(Resource.Id.navigation_view);
        _navigationView.SetNavigationItemSelectedListener(this);

        return view;
    }
}

Основная часть страницы

[MvxFragment(typeof(MainViewModel), Resource.Id.bodyFrame, false)]
[Register("VacationManager.Droid.Activities.VacationRequestListFragment")]
public class VacationRequestListFragment : BaseFragment<VacationRequestListViewModel> // You can find BaseFragment in sample
{
    protected override int FragmentId => Resource.Layout.fragment_list;
    //It is never invoked
    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        base.OnCreateView(inflater, container, savedInstanceState);
        return this.BindingInflate(Resource.Layout.fragment_list, container, false);
    }
} 

Макет главной страницы

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:local="http://schemas.android.com/apk/res-auto"
      android:id="@+id/drawerLayout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@color/warning">

      <!-- Center Side -->


      <android.support.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/mainFrame">

            <include layout="@layout/toolbar" />
            <FrameLayout
              android:id="@+id/bodyFrame"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_centerInParent="true"/>

            <android.support.design.widget.FloatingActionButton
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="bottom|right"
              android:layout_margin="16dp"
              android:src="@drawable/bullseye"
              local:layout_anchor="@id/bodyFrame"
              local:layout_anchorGravity="bottom|right|end" />

      </android.support.design.widget.CoordinatorLayout>

      <!-- Left Side -->
      <FrameLayout
        android:id="@+id/navigationFrame"
        android:layout_height="match_parent"
        android:layout_width="240dp"
        android:layout_gravity="left|start"
        android:clickable="true" />

</android.support.v4.widget.DrawerLayout>

Макет главной страницы

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.NavigationView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:id="@+id/navigation_view"
    android:layout_height="match_parent"
    android:layout_width="wrap_content"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeToolbarNavigationView"
    android:background="@color/colorPrimary"
    local:itemTextColor="@color/light_gray"
    local:itemIconTint="@color/light_gray"
    local:headerLayout="@layout/navigation_header"
    local:menu="@menu/navigation_drawer" />

Основная модель просмотра

public void ShowDefaultMenuItem()
{
    NavigationService.Navigate<VacationRequestListViewModel>();
    NavigationService.Navigate<MenuViewModel>();
}

Кажется, я теряю мелкие детали... Будем признательны за любую помощь.


person Oleg Kosuakiv    schedule 08.11.2017    source источник


Ответы (1)


Проблема была в первую очередь в пространствах имен атрибутов над действиями. Они должны быть MvvmCross.Droid.Views.Fragments . А также вместо MvxFragmentAttribute нам нужно использовать MvxFragmentPresentationAttribute. Тогда это работает.

person Oleg Kosuakiv    schedule 09.11.2017
comment
Здорово, что вам удалось ее решить! Я обновил StarWarsSample до версии 5.4.2. - person nmilcoff; 14.11.2017