You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the method 'ShowNestedFragment' in the 'MvxAppCompatViewPresenter', an exception is thrown when the host fragment is not visible (lines 242-243): if (!fragmentHost.IsVisible) throw new InvalidOperationException($"Fragment host is not visible when trying to show View {view.Name} as Nested Fragment");
Steps to reproduce 📜
Create an activity A, create two fragments (B & C). The activity A hosts fragment B, and fragment B hosts fragment C.
Activity has AppCompActivty as base, and uses the default MvxAppCompatViewPresenter. Fragment B is declared with [MvxFragmentPresentation] attribute and has Activity A as the ActivityHostViewModelType. Fragment C is declared with [MvxFragmentPresentation] attribute with Fragment B as the fragmentHostViewType .
In the view models, by using the navigation service:
-Navigate fragment B in ViewAppeared override in Activity A's viewmodel.
Navigate to fragment C in ViewAppeared override in Fragment B's viewmodel.
ViewAppeared are mapped to the activity's/fragment's onResume.
My reason for setting it up this way is that I can have as much control of the navigation in the view models for code reusability.
Expected behavior 🤔
I expected Fragment C to be displayed.
Actual behavior 🐛
Instead, Fragment C was not shown. There is an exception thrown in ShowNestedFragment, because the host fragment B was not visible.
My understanding is that a host fragment will not yet be visible (on the foreground), when initializing fragment B & C together. The OnResume event occurs before the window has focus.
Google also states:
onWindowFocusChanged
void onWindowFocusChanged (boolean hasFocus)
Called when the current Window of the activity gains or loses focus. This is the best indicator of whether this activity is visible to the user. The default implementation clears the key tracking state, so should always be called.
Note that this provides information about global focus state, which is managed independently of activity lifecycles. As such, while focus changes will generally have some relation to lifecycle changes (an activity that is stopped will not generally get window focus), you should not rely on any particular order between the callbacks here and those in the other lifecycle methods such as onResume().
It took me a while to figure this out. I have got it working now by creating a custom view presenter. In this presenter, I override the the ShowNestedFragment method and do not preform the IsVisisbility check.
Is there a reason that you are checking against IsVisibility?
Configuration 🔧
Version: 5.2.*
Platform:
📱 iOS
🤖 Android
🏁 WPF
🌎 UWP
🍎 MacOS
📺 tvOS
🐒 Xamarin.Forms
The text was updated successfully, but these errors were encountered:
It could be the case that you have a Fragment with two different MvxFragmentPresentationAttributes, both for nested presentation. Then we use IsVisible to decide which one is the more appropiate to use.
We can't do much here as this is more of an Android-related problem.
I guess your options are:
Set a Task.Delay and wait until the view appears
Perform the nested navigation from a different place
Override the ViewPresenter method and remove that condition if that works for your app.
In the method 'ShowNestedFragment' in the 'MvxAppCompatViewPresenter', an exception is thrown when the host fragment is not visible (lines 242-243):
if (!fragmentHost.IsVisible) throw new InvalidOperationException($"Fragment host is not visible when trying to show View {view.Name} as Nested Fragment");
Steps to reproduce 📜
Create an activity A, create two fragments (B & C). The activity A hosts fragment B, and fragment B hosts fragment C.
Activity has AppCompActivty as base, and uses the default MvxAppCompatViewPresenter. Fragment B is declared with [MvxFragmentPresentation] attribute and has Activity A as the ActivityHostViewModelType. Fragment C is declared with [MvxFragmentPresentation] attribute with Fragment B as the fragmentHostViewType .
In the view models, by using the navigation service:
-Navigate fragment B in ViewAppeared override in Activity A's viewmodel.
ViewAppeared are mapped to the activity's/fragment's onResume.
My reason for setting it up this way is that I can have as much control of the navigation in the view models for code reusability.
Expected behavior 🤔
I expected Fragment C to be displayed.
Actual behavior 🐛
Instead, Fragment C was not shown. There is an exception thrown in ShowNestedFragment, because the host fragment B was not visible.
My understanding is that a host fragment will not yet be visible (on the foreground), when initializing fragment B & C together. The OnResume event occurs before the window has focus.
Google also states:
It took me a while to figure this out. I have got it working now by creating a custom view presenter. In this presenter, I override the the ShowNestedFragment method and do not preform the IsVisisbility check.
Is there a reason that you are checking against IsVisibility?
Configuration 🔧
Version: 5.2.*
Platform:
The text was updated successfully, but these errors were encountered: