-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 #3039 from PrismLibrary/dev/ds/navigation-tabs
Use RootPage Title/IconImageSource when parent is TabbedPage
- Loading branch information
Showing
11 changed files
with
155 additions
and
9 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions
56
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
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); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void OnDetachingFrom(NavigationPage bindable) | ||
{ | ||
base.OnDetachingFrom(bindable); | ||
bindable.ParentChanged -= OnParentChanged; | ||
} | ||
|
||
private void OnParentChanged(object sender, EventArgs 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)); | ||
} | ||
} |
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
11 changes: 10 additions & 1 deletion
11
tests/Maui/Prism.DryIoc.Maui.Tests/Mocks/Views/MockViewA.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,3 +1,12 @@ | ||
namespace Prism.DryIoc.Maui.Tests.Mocks.Views; | ||
|
||
public class MockViewA : ContentPage { } | ||
public class MockViewA : ContentPage | ||
{ | ||
public const string ExpectedTitle = "Mock View A"; | ||
public static readonly ImageSource ExpectedIconImageSource = "home.png"; | ||
public MockViewA() | ||
{ | ||
Title = ExpectedTitle; | ||
IconImageSource = ExpectedIconImageSource; | ||
} | ||
} |