-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[XF] IActiveAware not working when ContentPage (as child of a TabbedPage) is wrapped into a navigationpage #1076
Comments
Thanks for reporting this. I'll check it out. |
At current it's not designed to. I believe to make this work we'll need to support You could easily make it work for the initial child page, but it becomes a bit more complex how to manage IActiveAware as you add children to the NavigationPage. If you implement a NavigationPage like the following you should get the behavior that you're looking for in the mean time. public class MyNavigationPage : NavigationPage, IActiveAware
{
public bool IsActive { get; set; }
public event EventHandler IsActiveChanged;
private void OnIsActiveChanged()
{
PageUtilities.InvokeViewAndViewModelAction<IActiveAware>(CurrentPage, (obj) => obj.IsActive = IsActive);
}
protected override void OnPropertyChanging(string propertyName = null)
{
base.OnPropertyChanging(propertyName);
if(propertyName == nameof(CurrentPage))
{
PageUtilities.InvokeViewAndViewModelAction<IActiveAware>(CurrentPage, (obj) => obj.IsActive = false);
}
}
protected override void OnPropertyChanged(string propertyName = null)
{
base.OnPropertyChanged(propertyName);
if(propertyName == nameof(CurrentPage))
{
PageUtilities.InvokeViewAndViewModelAction<IActiveAware>(CurrentPage, (obj) => obj.IsActive = true);
}
}
} |
I'm not sure this is very hard. We just modify the current IActiveAware behavior to check to see if the page is a NavigationPage, and if it is set the IsActive on the NavigainPage.CurrentPage. At least off the top of my head it seems like a simple fix. It may not be the case when I actually start looking into it. |
Actually, now I see what you are saying. If you are on a tab, and then navigate within the tab's navigationPage, the new current page has to update the active property on both the previous and current. Or should it? Is this a scenario we want to handle? Maybe this falls into the "custom" scenario and you must manually handle the more complex scenario? Hmmmm.... |
@brianlagunas if you don't manage the children of the NavigationPage then you might set the initial child page (say ViewA) to |
So three possible options I see here:
|
Keep in mind, the primary use of this feature is going to be in a TabbedPage scenario. So this means that the tabs will most likely be defined in XAML. I'm curious if we should take the behavior approach, and automatically apply it to the NavigationPage tab. I am looking the approach with the least amount of effort on the developers part, and the highest amount of maintainability on ours. |
That is a valid point, though one of he goals for v7 was the creation of tabs through the Navigation Parameters |
Sure, but this approach will work in all scenarios since we would be adding the behavior to a NavigationPage tab regardless of how it was added. |
True... there are benefits and drawbacks in my opinion to all three methods.
|
Just to add for anyone looking for an interim solution: public MyNavigationPage(Page root) : base(root) { } |
One more note about the As a result, This causes an unexpected behavior, at least in my specific case, because I'm trying to ensure that a |
@cpboyd after implementing the custom navigation page suggested by @dansiegel, the navigation service won't navigate the child view and I'm seeing this in the ouput: "pushViewController:animated: called on <Xamarin_Forms_Platform_iOS_NavigationRenderer 0x7fcebf018400> while an existing transition or presentation is occurring; the navigation stack will not be updated." any thoughts? |
@jgtaveras What is the child view that you're referring to? A child of the How has was the Lastly, how are you performing the navigation itself? Have you registered the page for navigation (assuming it's not the root page declared through XAML)? I'm able to use Prism's NavigationService (as described here) to navigate from my XAML-declared root page to other pages that have been registered for navigation. (And |
This is what I'm referring:
The Root TabbedPage is defined in Xaml as follows
*Note, namespaces, titles and icons removed for simplicity Navigation to View B is being done through a command in the view model using the navigation service
And yes all page had been registered correctly
|
It looks like you've basically done what I've done, so I have doubts that this is a Prism issue. A quick Google returns the following in the top 4 results: Both of those seem to indicate issues with UIAlertControllers. |
thx for the support @cpboyd indeed Prism wasn't the problem, Acr.UserDialogs was the one to blame in this case |
@cpboyd Did you find a way around the page being set as Active even when its first loaded? I'm getting the same issue. |
This has been fixed in the latest CI build. Please test it out on MyGet. Follow the instructions here: #1164 |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Repro steps
The text was updated successfully, but these errors were encountered: