代码之家  ›  专栏  ›  技术社区  ›  trampster

如何升级mvxfragmentattribute

  •  1
  • trampster  · 技术社区  · 6 年前

    我正在将我的项目从4.3更新到mvvmcross 6.0

    mvxfragmentattribute已不存在,似乎已被mvxfragmentpresentationattribute替换

    但是,当使用新属性时,会出现以下错误:

    System.NullReferenceException: FrameLayout to show Fragment not found
    at MvvmCross.Droid.Support.V7.AppCompat.MvxAppCompatViewPresenter.ShowFragment (System.Type view, MvvmCross.Platforms.Android.Presenters.Attributes.MvxFragmentPresentationAttribute attribute, MvvmCross.ViewModels.MvxViewModelRequest request) [0x00090] in <8141cf24d04c4cc6ba0be8d85f7b3f82>:0 
    at MvvmCross.Platforms.Android.Presenters.MvxAndroidViewPresenter.<RegisterAttributeTypes>b__21_2 (System.Type view, MvvmCross.Presenters.Attributes.MvxBasePresentationAttribute attribute, MvvmCross.ViewModels.MvxViewModelRequest request) [0x00000] in <17df0d0bdae848b7a8a12b58d710f763>:0 
    at MvvmCross.Platforms.Android.Presenters.MvxAndroidViewPresenter.Show (MvvmCross.ViewModels.MvxViewModelRequest request) [0x00014] in <17df0d0bdae848b7a8a12b58d710f763>:0 
    at MvvmCross.Platforms.Android.Views.MvxAndroidViewDispatcher+<>c__DisplayClass2_0.<ShowViewModel>b__0 () [0x00000] in <17df0d0bdae848b7a8a12b58d710f763>:0 
    at MvvmCross.Base.MvxMainThreadAsyncDispatcher+<>c__DisplayClass0_0.<ExecuteOnMainThreadAsync>b__0 () [0x00000] in <17df0d0bdae848b7a8a12b58d710f763>:0 
    at MvvmCross.Base.MvxMainThreadAsyncDispatcher+<>c__DisplayClass1_0+<<ExecuteOnMainThreadAsync>b__0>d.MoveNext () [0x00011] in <17df0d0bdae848b7a8a12b58d710f763>:0 
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
    at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
    at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <263adecfa58f4c449f1ff56156d886fd>:0 
    at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <263adecfa58f4c449f1ff56156d886fd>:0 
    at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <263adecfa58f4c449f1ff56156d886fd>:0 
    at (wrapper dynamic-method) System.Object.515beccd-4ae3-42be-a59f-9c8897c1459b(intptr,intptr)
    

    不幸的是,这并不能告诉我哪个framelayout甚至哪个片段和堆栈跟踪都不包含我的代码。

    然而,在此之前,只有一个碎片被击中:

    旧属性用法:

    [MvxFragment(typeof(MainViewModel), Resource.Id.main_frame_layout)]
    

    新属性用法:

    [MvxFragmentPresentation(typeof(MainViewModel), Resource.Id.main_frame_layout)]
    

    是的,MyIrFraseFraseDebug确实存在于我的MeMyVIEW布局中,如下:

    <?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:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/main_draw_layout"
        android:fitsSystemWindows="true">
        <android.support.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/main_frame_layout"
                android:layout_centerInParent="true" />
        </android.support.design.widget.CoordinatorLayout>
        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="left|start"
            android:id="@+id/main_navigation_layout" />
    </android.support.v4.widget.DrawerLayout>
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   trampster    6 年前

    我正在调用viewmodel的start方法中的navigationservice.navigate来显示片段。然而,MVVMcross 5中的生命周期发生了变化 here 是的。start方法现在在视图显示之前触发,或者至少在视图显示完成之前触发。这意味着活动存在,但布局尚未膨胀,所以MIN框架的布局还不存在。

    修复方法是将导航调用移动到新的viewAppeared方法。