protected override MvxBasePresentationAttribute GetAttributeForViewModel(Type viewModelType) { IList <MvxBasePresentationAttribute> attributes; if (ViewModelToPresentationAttributeMap.TryGetValue(viewModelType, out attributes)) { MvxBasePresentationAttribute attribute = null; if (attributes.Count > 1) { var fragmentAttributes = attributes.OfType <MvxFragmentPresentationAttribute>(); // check if fragment can be displayed as child fragment first foreach (var item in fragmentAttributes.Where(att => att.FragmentHostViewType != null)) { var fragment = GetFragmentByViewType(item.FragmentHostViewType); // if the fragment exists, and is on top, then use the current attribute if (fragment != null && fragment.IsVisible && fragment.View.FindViewById(item.FragmentContentId) != null) { attribute = item; break; } } // if attribute is still null, check if fragment can be displayed in current activity if (attribute == null) { var currentActivityHostViewModelType = GetCurrentActivityViewModelType(); foreach (var item in fragmentAttributes.Where(att => att.ActivityHostViewModelType != null)) { if (CurrentActivity.FindViewById(item.FragmentContentId) != null && item.ActivityHostViewModelType == currentActivityHostViewModelType) { attribute = item; break; } } } } if (attribute == null) { attribute = attributes.FirstOrDefault(); } return(GetOverridePresentationAttribute(attribute.ViewType) ?? attribute); } return(CreateAttributeForViewModel(viewModelType)); }
protected override MvxBasePresentationAttribute GetAttributeForViewModel(Type viewModelType) { IList <MvxBasePresentationAttribute> attributes; if (ViewModelToPresentationAttributeMap.TryGetValue(viewModelType, out attributes)) { MvxBasePresentationAttribute attribute = null; if (attributes.Count > 1) { var fragmentAttributes = attributes.OfType <MvxFragmentPresentationAttribute>(); // check if fragment can be displayed as child fragment first foreach (var item in fragmentAttributes.Where(att => att.FragmentHostViewType != null)) { var fragment = GetFragmentByViewType(item.FragmentHostViewType); // if the fragment exists, and is on top, then use the current attribute if (fragment != null && fragment.IsVisible && fragment.View.FindViewById(item.FragmentContentId) != null) { attribute = item; break; } } // if attribute is still null, check if fragment can be displayed in current activity if (attribute == null) { var currentActivityHostViewModelType = GetCurrentActivityViewModelType(); foreach (var item in fragmentAttributes.Where(att => att.ActivityHostViewModelType != null)) { if (CurrentActivity.FindViewById(item.FragmentContentId) != null && item.ActivityHostViewModelType == currentActivityHostViewModelType) { attribute = item; break; } } } } if (attribute == null) { attribute = attributes.FirstOrDefault(); } if (attribute.ViewType?.GetInterfaces().OfType <IMvxOverridePresentationAttribute>().FirstOrDefault() is IMvxOverridePresentationAttribute view) { var presentationAttribute = view.PresentationAttribute(); if (presentationAttribute != null) { return(presentationAttribute); } } return(attribute); } var viewType = ViewsContainer.GetViewType(viewModelType); if (viewType.IsSubclassOf(typeof(DialogFragment))) { MvxTrace.Trace($"PresentationAttribute not found for {viewModelType.Name}. " + $"Assuming DialogFragment presentation"); return(new MvxDialogFragmentPresentationAttribute()); } if (viewType.IsSubclassOf(typeof(Fragment))) { MvxTrace.Trace($"PresentationAttribute not found for {viewModelType.Name}. " + $"Assuming Fragment presentation"); return(new MvxFragmentPresentationAttribute(GetCurrentActivityViewModelType(), Android.Resource.Id.Content)); } MvxTrace.Trace($"PresentationAttribute not found for {viewModelType.Name}. " + $"Assuming Activity presentation"); return(new MvxActivityPresentationAttribute() { ViewModelType = viewModelType }); }