forked from PrismLibrary/Prism
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request PrismLibrary#3119 from PrismLibrary/dev/ds/cleanup
Adding MAUI Navigation tests
- Loading branch information
Showing
111 changed files
with
1,081 additions
and
661 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
using System; | ||
using System.Reactive.Subjects; | ||
using Prism.Events; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 37 additions & 34 deletions
71
src/Maui/Prism.Maui/Behaviors/NavigationPageTabbedParentBehavior.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,59 @@ | ||
namespace Prism.Behaviors; | ||
using System.ComponentModel; | ||
using Prism.Xaml; | ||
|
||
namespace Prism.Behaviors; | ||
|
||
/// <summary> | ||
/// Adds a behavior to use the RootPage Title and IconImageSource if they are not set on the NavigaitonPage | ||
/// when the NavigationPage has a TabbedPage parent. | ||
/// </summary> | ||
public sealed class NavigationPageTabbedParentBehavior : BehaviorBase<NavigationPage> | ||
{ | ||
private static readonly BindableProperty NavigationPageRootPageMonitorTitleProperty = | ||
BindableProperty.CreateAttached("NavigationPageRootPageMonitorTitle", typeof(bool), typeof(NavigationPageTabbedParentBehavior), false); | ||
|
||
private static readonly BindableProperty NavigationPageRootPageMonitorIconImageSourceProperty = | ||
BindableProperty.CreateAttached("NavigationPageRootPageMonitorIconImageSource", typeof(bool), typeof(NavigationPageTabbedParentBehavior), false); | ||
|
||
private static bool GetNavigationPageRootPageMonitorTitle(BindableObject bindable) => | ||
(bool)bindable.GetValue(NavigationPageRootPageMonitorTitleProperty); | ||
|
||
private static void SetNavigationPageRootPageMonitorTitle(BindableObject bindable, bool monitorTitle) => | ||
bindable.SetValue(NavigationPageRootPageMonitorTitleProperty, monitorTitle); | ||
|
||
private static bool GetNavigationPageRootPageMonitorIconImageSource(BindableObject bindable) => | ||
(bool)bindable.GetValue(NavigationPageRootPageMonitorIconImageSourceProperty); | ||
|
||
private static void SetNavigationPageRootPageMonitorIconImageSource(BindableObject bindable, bool monitorTitle) => | ||
bindable.SetValue(NavigationPageRootPageMonitorIconImageSourceProperty, monitorTitle); | ||
|
||
/// <inheritdoc /> | ||
protected override void OnAttachedTo(NavigationPage bindable) | ||
{ | ||
base.OnAttachedTo(bindable); | ||
SetNavigationPageRootPageMonitorTitle(bindable, !bindable.IsSet(NavigationPage.TitleProperty)); | ||
SetNavigationPageRootPageMonitorIconImageSource(bindable, !bindable.IsSet(NavigationPage.IconImageSourceProperty)); | ||
bindable.ParentChanged += OnParentChanged; | ||
if (bindable.Parent is TabbedPage) | ||
OnParentChanged(bindable, EventArgs.Empty); | ||
bindable.PropertyChanged += OnRootPageSet; | ||
} | ||
|
||
private void OnRootPagePropertyChanged(object sender, PropertyChangedEventArgs e) | ||
{ | ||
if (sender is not Page page || page.Parent is not NavigationPage navigationPage) | ||
{ | ||
return; | ||
} | ||
|
||
if (e.PropertyName == DynamicTab.TitleProperty.PropertyName) | ||
{ | ||
navigationPage.Title = DynamicTab.GetTitle(page); | ||
} | ||
|
||
if (e.PropertyName == DynamicTab.IconImageSourceProperty.PropertyName) | ||
{ | ||
navigationPage.IconImageSource = DynamicTab.GetIconImageSource(page); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void OnDetachingFrom(NavigationPage bindable) | ||
{ | ||
base.OnDetachingFrom(bindable); | ||
bindable.ParentChanged -= OnParentChanged; | ||
// Sanity Check | ||
bindable.PropertyChanged -= OnRootPageSet; | ||
if (bindable.RootPage is not null) | ||
{ | ||
bindable.RootPage.PropertyChanged -= OnRootPagePropertyChanged; | ||
} | ||
} | ||
|
||
private void OnParentChanged(object sender, EventArgs e) | ||
private void OnRootPageSet(object sender, PropertyChangedEventArgs e) | ||
{ | ||
if (sender is not NavigationPage navigationPage || navigationPage.Parent is not TabbedPage) | ||
return; | ||
|
||
if (GetNavigationPageRootPageMonitorTitle(navigationPage)) | ||
navigationPage.SetBinding(NavigationPage.TitleProperty, new Binding("RootPage.Title", BindingMode.OneWay, source: navigationPage)); | ||
|
||
if (GetNavigationPageRootPageMonitorIconImageSource(navigationPage)) | ||
navigationPage.SetBinding(NavigationPage.IconImageSourceProperty, new Binding("RootPage.IconImageSource", BindingMode.OneWay, source: navigationPage)); | ||
if (sender is NavigationPage navigationPage && navigationPage.RootPage is not null) | ||
{ | ||
navigationPage.PropertyChanged -= OnRootPageSet; | ||
navigationPage.RootPage.PropertyChanged += OnRootPagePropertyChanged; | ||
navigationPage.Title = DynamicTab.GetTitle(navigationPage.RootPage); | ||
navigationPage.IconImageSource = DynamicTab.GetIconImageSource(navigationPage.RootPage); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.