Skip to content

Commit

Permalink
Merge pull request #1164 from PrismLibrary/TabbedPage-NavigationPage-…
Browse files Browse the repository at this point in the history
…IActiveAware

added support for ActiveAware NavPages in a TabbedPage
  • Loading branch information
brianlagunas committed Sep 20, 2017
2 parents b6d6b56 + 1563b30 commit bec2c08
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 38 deletions.
29 changes: 16 additions & 13 deletions Sandbox/Xamarin/HelloWorld/HelloWorld.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.12
VisualStudioVersion = 15.0.26730.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld", "HelloWorld\HelloWorld\HelloWorld.csproj", "{94318F08-2F60-4E7F-8C43-86B024BFF115}"
EndProject
Expand Down Expand Up @@ -262,8 +262,8 @@ Global
{E6C50355-D01E-4CAA-884D-D7929861315C}.Ad-Hoc|iPhone.Build.0 = Release|Any CPU
{E6C50355-D01E-4CAA-884D-D7929861315C}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Release|Any CPU
{E6C50355-D01E-4CAA-884D-D7929861315C}.Ad-Hoc|iPhoneSimulator.Build.0 = Release|Any CPU
{E6C50355-D01E-4CAA-884D-D7929861315C}.Ad-Hoc|x64.ActiveCfg = Test|Any CPU
{E6C50355-D01E-4CAA-884D-D7929861315C}.Ad-Hoc|x64.Build.0 = Test|Any CPU
{E6C50355-D01E-4CAA-884D-D7929861315C}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU
{E6C50355-D01E-4CAA-884D-D7929861315C}.Ad-Hoc|x64.Build.0 = Debug|Any CPU
{E6C50355-D01E-4CAA-884D-D7929861315C}.Ad-Hoc|x86.ActiveCfg = Release|Any CPU
{E6C50355-D01E-4CAA-884D-D7929861315C}.Ad-Hoc|x86.Build.0 = Release|Any CPU
{E6C50355-D01E-4CAA-884D-D7929861315C}.AppStore|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -274,8 +274,8 @@ Global
{E6C50355-D01E-4CAA-884D-D7929861315C}.AppStore|iPhone.Build.0 = Release|Any CPU
{E6C50355-D01E-4CAA-884D-D7929861315C}.AppStore|iPhoneSimulator.ActiveCfg = Release|Any CPU
{E6C50355-D01E-4CAA-884D-D7929861315C}.AppStore|iPhoneSimulator.Build.0 = Release|Any CPU
{E6C50355-D01E-4CAA-884D-D7929861315C}.AppStore|x64.ActiveCfg = Test|Any CPU
{E6C50355-D01E-4CAA-884D-D7929861315C}.AppStore|x64.Build.0 = Test|Any CPU
{E6C50355-D01E-4CAA-884D-D7929861315C}.AppStore|x64.ActiveCfg = Debug|Any CPU
{E6C50355-D01E-4CAA-884D-D7929861315C}.AppStore|x64.Build.0 = Debug|Any CPU
{E6C50355-D01E-4CAA-884D-D7929861315C}.AppStore|x86.ActiveCfg = Release|Any CPU
{E6C50355-D01E-4CAA-884D-D7929861315C}.AppStore|x86.Build.0 = Release|Any CPU
{E6C50355-D01E-4CAA-884D-D7929861315C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -322,8 +322,8 @@ Global
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.Ad-Hoc|iPhone.Build.0 = Release|Any CPU
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Release|Any CPU
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.Ad-Hoc|iPhoneSimulator.Build.0 = Release|Any CPU
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.Ad-Hoc|x64.ActiveCfg = Test|Any CPU
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.Ad-Hoc|x64.Build.0 = Test|Any CPU
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.Ad-Hoc|x64.Build.0 = Debug|Any CPU
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.Ad-Hoc|x86.ActiveCfg = Release|Any CPU
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.Ad-Hoc|x86.Build.0 = Release|Any CPU
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.AppStore|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -334,8 +334,8 @@ Global
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.AppStore|iPhone.Build.0 = Release|Any CPU
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.AppStore|iPhoneSimulator.ActiveCfg = Release|Any CPU
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.AppStore|iPhoneSimulator.Build.0 = Release|Any CPU
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.AppStore|x64.ActiveCfg = Test|Any CPU
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.AppStore|x64.Build.0 = Test|Any CPU
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.AppStore|x64.ActiveCfg = Debug|Any CPU
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.AppStore|x64.Build.0 = Debug|Any CPU
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.AppStore|x86.ActiveCfg = Release|Any CPU
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.AppStore|x86.Build.0 = Release|Any CPU
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -382,8 +382,8 @@ Global
{79EBB8F1-5D80-4EA1-9100-EBDC1EC51CB7}.Ad-Hoc|iPhone.Build.0 = Release|Any CPU
{79EBB8F1-5D80-4EA1-9100-EBDC1EC51CB7}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Release|Any CPU
{79EBB8F1-5D80-4EA1-9100-EBDC1EC51CB7}.Ad-Hoc|iPhoneSimulator.Build.0 = Release|Any CPU
{79EBB8F1-5D80-4EA1-9100-EBDC1EC51CB7}.Ad-Hoc|x64.ActiveCfg = Test|Any CPU
{79EBB8F1-5D80-4EA1-9100-EBDC1EC51CB7}.Ad-Hoc|x64.Build.0 = Test|Any CPU
{79EBB8F1-5D80-4EA1-9100-EBDC1EC51CB7}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU
{79EBB8F1-5D80-4EA1-9100-EBDC1EC51CB7}.Ad-Hoc|x64.Build.0 = Debug|Any CPU
{79EBB8F1-5D80-4EA1-9100-EBDC1EC51CB7}.Ad-Hoc|x86.ActiveCfg = Release|Any CPU
{79EBB8F1-5D80-4EA1-9100-EBDC1EC51CB7}.Ad-Hoc|x86.Build.0 = Release|Any CPU
{79EBB8F1-5D80-4EA1-9100-EBDC1EC51CB7}.AppStore|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -394,8 +394,8 @@ Global
{79EBB8F1-5D80-4EA1-9100-EBDC1EC51CB7}.AppStore|iPhone.Build.0 = Release|Any CPU
{79EBB8F1-5D80-4EA1-9100-EBDC1EC51CB7}.AppStore|iPhoneSimulator.ActiveCfg = Release|Any CPU
{79EBB8F1-5D80-4EA1-9100-EBDC1EC51CB7}.AppStore|iPhoneSimulator.Build.0 = Release|Any CPU
{79EBB8F1-5D80-4EA1-9100-EBDC1EC51CB7}.AppStore|x64.ActiveCfg = Test|Any CPU
{79EBB8F1-5D80-4EA1-9100-EBDC1EC51CB7}.AppStore|x64.Build.0 = Test|Any CPU
{79EBB8F1-5D80-4EA1-9100-EBDC1EC51CB7}.AppStore|x64.ActiveCfg = Debug|Any CPU
{79EBB8F1-5D80-4EA1-9100-EBDC1EC51CB7}.AppStore|x64.Build.0 = Debug|Any CPU
{79EBB8F1-5D80-4EA1-9100-EBDC1EC51CB7}.AppStore|x86.ActiveCfg = Release|Any CPU
{79EBB8F1-5D80-4EA1-9100-EBDC1EC51CB7}.AppStore|x86.Build.0 = Release|Any CPU
{79EBB8F1-5D80-4EA1-9100-EBDC1EC51CB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -589,4 +589,7 @@ Global
{3455E365-0698-46FF-AD63-E0BF6035B8BF} = {1F38DE96-6945-4467-92C4-20D9DF20121E}
{38659E75-D683-46E4-9F39-FC4F6AB9E3C5} = {1F38DE96-6945-4467-92C4-20D9DF20121E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {88C511C2-BF14-4325-AAC5-AB796303D0DD}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion Sandbox/Xamarin/HelloWorld/HelloWorld/HelloWorld/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class App : PrismApplication

protected override void OnInitialized()
{
NavigationService.NavigateAsync("MyMasterDetail/MyNavigationPage/MainPage", animated: false);
NavigationService.NavigateAsync("MyTabbedPage", animated: false);
//44115
//NavigationService.NavigateAsync("MyNavigationPage/MainPage/ViewA/ViewB", animated: false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private void Save()
async void Navigate()
{
CanNavigate = false;
await _navigationService.NavigateAsync("ViewC/ViewB", useModalNavigation: false);
await _navigationService.NavigateAsync("ViewB", useModalNavigation: false);
CanNavigate = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private void Reset()
async void Navigate()
{
CanNavigate = false;
await _navigationService.GoBackAsync();
await _navigationService.NavigateAsync("ViewA");
CanNavigate = true;
}

Expand Down
39 changes: 27 additions & 12 deletions Sandbox/Xamarin/HelloWorld/ModuleA/Views/MyTabbedPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,36 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
prism:ViewModelLocator.AutowireViewModel="True"
xmlns:b="clr-namespace:Prism.Behaviors;assembly=Prism.Forms"
xmlns:local="clr-namespace:ModuleA.Views;assembly=ModuleA"
x:Class="ModuleA.Views.MyTabbedPage">

<TabbedPage.ToolbarItems>
<ToolbarItem Text="Save" Command="{Binding ApplicationCommands.SaveCommand}"/>
<ToolbarItem Text="Reset" Command="{Binding ApplicationCommands.ResetCommand}"/>
</TabbedPage.ToolbarItems>
<TabbedPage.ToolbarItems>
<ToolbarItem Text="Save" Command="{Binding ApplicationCommands.SaveCommand}"/>
<ToolbarItem Text="Reset" Command="{Binding ApplicationCommands.ResetCommand}"/>
</TabbedPage.ToolbarItems>

<!--<NavigationPage>
<x:Arguments>
<local:ViewA Title="View A" />
</x:Arguments>
</NavigationPage>-->
<NavigationPage Title="View A">
<NavigationPage.Behaviors>
<b:NavigationPageActiveAwareBehavior />
</NavigationPage.Behaviors>
<x:Arguments>
<local:ViewA Title="View A" />
</x:Arguments>
</NavigationPage>

<NavigationPage Title="View B">
<NavigationPage.Behaviors>
<b:NavigationPageActiveAwareBehavior />
</NavigationPage.Behaviors>
<x:Arguments>
<local:ViewB Title="View B" />
</x:Arguments>
</NavigationPage>

<local:ViewC Title="View C" />

<!--<local:ViewA Title="View A" />
<local:ViewB Title="View B"/>-->

<local:ViewA Title="View A" />
<local:ViewB Title="View B"/>

</TabbedPage>
11 changes: 6 additions & 5 deletions Sandbox/Xamarin/HelloWorld/ModuleA/Views/ViewA.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="ModuleA.Views.ViewA"
Title="View A">

<StackLayout>
<Label Text="{Binding Title}" VerticalOptions="Center" HorizontalOptions="Center" />
<Button Command="{Binding NavigateCommand}" Text="Navigate" />
</StackLayout>

<StackLayout>
<Label Text="{Binding Title}" VerticalOptions="Center" HorizontalOptions="Center" />
<Label Text="{Binding IsActive}" />
<Button Command="{Binding NavigateCommand}" Text="Navigate" />
</StackLayout>

</ContentPage>
9 changes: 5 additions & 4 deletions Sandbox/Xamarin/HelloWorld/ModuleA/Views/ViewB.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
x:Class="ModuleA.Views.ViewB"
Title="View B">

<StackLayout>
<Label Text="{Binding Title}" VerticalOptions="Center" HorizontalOptions="Center" />
<Button Command="{Binding NavigateCommand}" Text="Navigate" />
</StackLayout>
<StackLayout>
<Label Text="{Binding Title}" VerticalOptions="Center" HorizontalOptions="Center" />
<Label Text="{Binding IsActive}" />
<Button Command="{Binding NavigateCommand}" Text="Navigate" />
</StackLayout>

</ContentPage>
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ protected void RootPageDisappearingHandler(object sender, EventArgs e)

void SetIsActive(object view, bool isActive)
{
PageUtilities.InvokeViewAndViewModelAction<IActiveAware>(_lastSelectedPage, activeAware => activeAware.IsActive = isActive);
var pageToSetIsActive = view is NavigationPage ? ((NavigationPage)view).CurrentPage : view;

PageUtilities.InvokeViewAndViewModelAction<IActiveAware>(pageToSetIsActive, activeAware => activeAware.IsActive = isActive);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Prism.Common;
using Xamarin.Forms;

namespace Prism.Behaviors
{
public class NavigationPageActiveAwareBehavior : BehaviorBase<NavigationPage>
{
protected override void OnAttachedTo(NavigationPage bindable)
{
bindable.PropertyChanging += NavigationPage_PropertyChanging;
bindable.PropertyChanged += NavigationPage_PropertyChanged;
base.OnAttachedTo(bindable);
}

protected override void OnDetachingFrom(NavigationPage bindable)
{
bindable.PropertyChanging -= NavigationPage_PropertyChanging;
bindable.PropertyChanged -= NavigationPage_PropertyChanged;
base.OnDetachingFrom(bindable);
}

private void NavigationPage_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "CurrentPage")
{
PageUtilities.InvokeViewAndViewModelAction<IActiveAware>(AssociatedObject.CurrentPage, (obj) => obj.IsActive = true);
}
}

private void NavigationPage_PropertyChanging(object sender, PropertyChangingEventArgs e)
{
if (e.PropertyName == "CurrentPage")
{
PageUtilities.InvokeViewAndViewModelAction<IActiveAware>(AssociatedObject.CurrentPage, (obj) => obj.IsActive = false);
}
}
}
}

0 comments on commit bec2c08

Please sign in to comment.