ParentActivity与main Fragment之间MVVMCross Navigation重叠产生滚动效果

MVVMCross Navigation between Parent Activity and main Fragment overlaps and produces scrolling effect

我有一个针对 MVVMCross 6 的旧 Xamarin Android 项目。 应用程序启动时,MVVMcross 会加载欢迎词 activity。 然后用户选择登录按钮,加载登录 activity 或注册 activity。 然后在登录后,用户被重定向到包含主页片段的 MainActivity。 上面提到的每个活动都有其视图模型。 Home 片段也有它的视图模型。 我首先使用 viewmodel 导航,在从 signin/signup 导航到主 activity 页面之前,我先关闭当前页面。

问题是,当我从 signin/signup 页面导航到包含主页片段的主 activity 时,应用程序中会出现重叠动画,并且 MVVMcross 会实例化MainActivity连续几次。

当我查看 Visualstudio 的输出 window 时,我看到了这个:

(MvvmCross.Logging.MvxLog) PresentationAttribute not found for MainActivity. Assuming Activity presentation (MvxAndroid) Activity host with ViewModelType MyApp.Mobile.ViewModels.MainViewModel is not CurrentTopActivity. Showing Activity before showing Fragment for MyApp.Mobile.ViewModels.HomeViewModel Activity host with ViewModelType MyApp.Mobile.ViewModels.MainViewModel is not CurrentTopActivity. Showing Activity before showing Fragment for MyApp.Mobile.ViewModels.HomeViewModel (MvvmCross.Logging.MvxLog) PresentationAttribute not found for MainActivity. Assuming Activity presentation (MvvmCross.Logging.MvxLog) PresentationAttribute not found for MainActivity. Assuming Activity presentation

从错误消息中,我可以了解到主要 activity 及其片段正在争夺导航堆栈的顶部。

为了导航,我使用了“IMvxNavigationService” 以下是我如何导航到包含应用程序片段的 MainActivity。

await this.navigationService.Navigate<MainViewModel>();

以下是我如何将演示者附加到要在主视图模型中显示的每个片段:

[MvxFragmentPresentation(typeof(MainViewModel), Resource.Id.content_frame, true)]
public class HomeFragment : BaseTabFragment<HomeViewModel>
{
}

并且 BaseTabFragment 具有以下声明:

public abstract class BaseTabFragment<TViewModel> : BaseFragment<TViewModel> where TViewModel : class, IMvxViewModel

并且 Base 片段继承自:“MvxFragment”

我尝试创建一个自定义 MVVMcross 片段演示器,我在其中将“ActivityFlags.NewTask | ActivityFlags.ClearTop | ActivityFlags.ClearTask”标志添加到顶级活动,但这不起作用。有人可以帮忙吗?

从我的角度来看,如果您真的从 signing-activity 切换到 main-activity,您还必须将视图创建为 activity。所以 MainViewModel 应该作为 activity 映射到 MainView 并且应该是一种“父级”。

片段是活动的一部分。

看看这个例子,希望对你有帮助。

https://github.com/MvvmCross/MvvmCross/tree/master/Projects/Playground/Playground.Droid

这些特别之处: https://github.com/MvvmCross/MvvmCross/blob/master/Projects/Playground/Playground.Droid/Activities/RootView.cs https://github.com/MvvmCross/MvvmCross/blob/master/Projects/Playground/Playground.Droid/Activities/TabsRootView.cs