-
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.
Now lazy views activation is lifecycle aware (OnAppearing/OnDisappear…
…ing)
- Loading branch information
Showing
15 changed files
with
206 additions
and
107 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
8 changes: 5 additions & 3 deletions
8
Prism.Forms.LazyView/Behaviors/LazyLoadContentViewBehavior.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,12 +1,14 @@ | ||
using Xamarin.Forms; | ||
using Prism.AppModel; | ||
using Xamarin.Forms; | ||
|
||
namespace Prism.Forms.LazyView.Behaviors | ||
{ | ||
public class LazyLoadContentViewBehavior : LazyLoadBehaviorBase<ContentView> | ||
{ | ||
protected override void SetContent(ContentView element, View contentView) | ||
protected override void SetContent(ContentView contentView, View view) | ||
{ | ||
element.Content = contentView; | ||
((view as ContentView)?.BindingContext as IPageLifecycleAware)?.OnAppearing(); | ||
contentView.Content = view; | ||
} | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
Sample/Prism.Forms.LazyView.Sample/ViewModels/EncrustedSlowContentViewModel.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,21 @@ | ||
using Prism.Navigation; | ||
|
||
namespace Prism.Forms.LazyView.Sample.ViewModels | ||
{ | ||
public class EncrustedSlowContentViewModel : SlowContentViewModel | ||
{ | ||
public EncrustedSlowContentViewModel(INavigationService navigationService) : base(navigationService) | ||
{ | ||
} | ||
|
||
public override void OnAppearing() | ||
{ | ||
base.OnAppearing(); | ||
} | ||
|
||
public override void OnDisappearing() | ||
{ | ||
base.OnDisappearing(); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Sample/Prism.Forms.LazyView.Sample/Views/EncrustedSlowContentView.xaml
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,15 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<ContentView | ||
x:Class="Prism.Forms.LazyView.Sample.Views.EncrustedSlowContentView" | ||
xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:prism="http://prismlibrary.com" | ||
xmlns:viewModels="clr-namespace:Prism.Forms.LazyView.Sample.ViewModels;assembly=Prism.Forms.LazyView.Sample" | ||
prism:ViewModelLocator.AutowireViewModel="True" | ||
x:DataType="viewModels:EncrustedSlowContentViewModel"> | ||
<ContentView.Content> | ||
<StackLayout> | ||
<Label Text="This should call the vm OnAppearing/OnDisappearing methods, when toggling IsActive" /> | ||
</StackLayout> | ||
</ContentView.Content> | ||
</ContentView> |
24 changes: 24 additions & 0 deletions
24
Sample/Prism.Forms.LazyView.Sample/Views/EncrustedSlowContentView.xaml.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,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
using Xamarin.Forms; | ||
using Xamarin.Forms.Xaml; | ||
|
||
namespace Prism.Forms.LazyView.Sample.Views | ||
{ | ||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
public partial class EncrustedSlowContentView : ContentView | ||
{ | ||
public EncrustedSlowContentView() | ||
{ | ||
InitializeComponent(); | ||
|
||
// Simulating a complex view | ||
// NEVER do this in real code | ||
Task.Delay(TimeSpan.FromSeconds(3)).Wait(); | ||
} | ||
} | ||
} |
25 changes: 13 additions & 12 deletions
25
Sample/Prism.Forms.LazyView.Sample/Views/LoadingSlowContentView.xaml
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,16 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:d="http://xamarin.com/schemas/2014/forms/design" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
x:Class="Prism.Forms.LazyView.Sample.Views.LoadingSlowContentView"> | ||
<ContentView.Content> | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<ContentView | ||
x:Class="Prism.Forms.LazyView.Sample.Views.LoadingSlowContentView" | ||
xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:d="http://xamarin.com/schemas/2014/forms/design" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d"> | ||
<ContentView.Content> | ||
<Grid> | ||
<StackLayout VerticalOptions="Center" HorizontalOptions="Center"> | ||
<ActivityIndicator IsRunning="True" HorizontalOptions="Center"/> | ||
<Label Text="{Binding Counter, StringFormat='Loading View and ViewModel...{0}0%'}" HorizontalOptions="Center"/> | ||
<StackLayout HorizontalOptions="Center" VerticalOptions="Center"> | ||
<ActivityIndicator HorizontalOptions="Center" IsRunning="True" /> | ||
<Label HorizontalOptions="Center" Text="{Binding Counter, StringFormat='Loading View and ViewModel...{0}0%'}" /> | ||
</StackLayout> | ||
</Grid> | ||
</ContentView.Content> | ||
</ContentView.Content> | ||
</ContentView> |
60 changes: 40 additions & 20 deletions
60
Sample/Prism.Forms.LazyView.Sample/Views/SlowContentView.xaml
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,34 +1,54 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:viewModels="clr-namespace:Prism.Forms.LazyView.Sample.ViewModels;assembly=Prism.Forms.LazyView.Sample" | ||
x:Class="Prism.Forms.LazyView.Sample.Views.SlowContentView" | ||
Margin="10" | ||
x:DataType="viewModels:SlowContentViewModel"> | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<ContentView | ||
x:Class="Prism.Forms.LazyView.Sample.Views.SlowContentView" | ||
xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:lazyView="clr-namespace:Prism.Forms.LazyView;assembly=Prism.Forms.LazyView" | ||
xmlns:viewModels="clr-namespace:Prism.Forms.LazyView.Sample.ViewModels;assembly=Prism.Forms.LazyView.Sample" | ||
xmlns:views="clr-namespace:Prism.Forms.LazyView.Sample.Views;assembly=Prism.Forms.LazyView.Sample" | ||
Margin="10" | ||
x:DataType="viewModels:SlowContentViewModel"> | ||
<Grid> | ||
<StackLayout Orientation="Vertical" HorizontalOptions="Center" VerticalOptions="Center"> | ||
<Label Text="{Binding Description}" | ||
HorizontalOptions="Center" LineBreakMode="WordWrap" /> | ||
<StackLayout | ||
HorizontalOptions="Center" | ||
Orientation="Vertical" | ||
VerticalOptions="Center"> | ||
<Label | ||
HorizontalOptions="Center" | ||
LineBreakMode="WordWrap" | ||
Text="{Binding Description}" /> | ||
<StackLayout Orientation="Horizontal"> | ||
<Label Text="Long process on ViewModel:"/> | ||
<Label Text="{Binding Counter, StringFormat='{0}0%'}" | ||
HorizontalOptions="Center"> | ||
<Label Text="Long process on ViewModel:" /> | ||
<Label HorizontalOptions="Center" Text="{Binding Counter, StringFormat='{0}0%'}"> | ||
<Label.Triggers> | ||
<DataTrigger TargetType="Label" Binding="{Binding Counter}" Value="0"> | ||
<Setter Property="IsVisible" Value="False"/> | ||
<DataTrigger | ||
Binding="{Binding Counter}" | ||
TargetType="Label" | ||
Value="0"> | ||
<Setter Property="IsVisible" Value="False" /> | ||
</DataTrigger> | ||
</Label.Triggers> | ||
</Label> | ||
<Label Text="Result!" | ||
HorizontalOptions="Center" IsVisible="False"> | ||
<Label | ||
HorizontalOptions="Center" | ||
IsVisible="False" | ||
Text="Result!"> | ||
<Label.Triggers> | ||
<DataTrigger TargetType="Label" Binding="{Binding Counter}" Value="0"> | ||
<Setter Property="IsVisible" Value="True"/> | ||
<DataTrigger | ||
Binding="{Binding Counter}" | ||
TargetType="Label" | ||
Value="0"> | ||
<Setter Property="IsVisible" Value="True" /> | ||
</DataTrigger> | ||
</Label.Triggers> | ||
</Label> | ||
</StackLayout> | ||
<Button Text="Navigate to Other" Command="{Binding NavigateCommand}"/> | ||
<Button Command="{Binding NavigateCommand}" Text="Navigate to Other" /> | ||
<Button Clicked="Button_OnClicked" Text="Toggle incrusted view" /> | ||
<lazyView:LazyContentView | ||
x:Name="LazyContentView" | ||
x:DataType="viewModels:EncrustedSlowContentViewModel" | ||
x:TypeArguments="views:LoadingSlowContentView,views:EncrustedSlowContentView" /> | ||
</StackLayout> | ||
</Grid> | ||
</ContentView> |
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
57 changes: 23 additions & 34 deletions
57
Sample/Prism.Forms.LazyView.Sample/Views/TabHostPage.xaml
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,40 +1,29 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:prism="http://prismlibrary.com" | ||
prism:ViewModelLocator.AutowireViewModel="True" | ||
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core" | ||
android:TabbedPage.ToolbarPlacement="Bottom" | ||
xmlns:views="clr-namespace:Prism.Forms.LazyView.Sample.Views;assembly=Prism.Forms.LazyView.Sample" | ||
xmlns:lazyView="clr-namespace:Prism.Forms.LazyView;assembly=Prism.Forms.LazyView" | ||
xmlns:behaviors="clr-namespace:Prism.Forms.LazyView.Behaviors;assembly=Prism.Forms.LazyView" | ||
x:Class="Prism.Forms.LazyView.Sample.Views.TabHostPage" | ||
xmlns:viewModels="clr-namespace:Prism.Forms.LazyView.Sample.ViewModels;assembly=Prism.Forms.LazyView.Sample" | ||
x:Name="This" | ||
Title="{Binding Title}" | ||
BarBackgroundColor="LightGray"> | ||
<TabbedPage | ||
x:Class="Prism.Forms.LazyView.Sample.Views.TabHostPage" | ||
xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core" | ||
xmlns:behaviors="clr-namespace:Prism.Forms.LazyView.Behaviors;assembly=Prism.Forms.LazyView" | ||
xmlns:lazyView="clr-namespace:Prism.Forms.LazyView;assembly=Prism.Forms.LazyView" | ||
xmlns:prism="http://prismlibrary.com" | ||
xmlns:viewModels="clr-namespace:Prism.Forms.LazyView.Sample.ViewModels;assembly=Prism.Forms.LazyView.Sample" | ||
xmlns:views="clr-namespace:Prism.Forms.LazyView.Sample.Views;assembly=Prism.Forms.LazyView.Sample" | ||
x:Name="This" | ||
Title="{Binding Title}" | ||
android:TabbedPage.ToolbarPlacement="Bottom" | ||
prism:ViewModelLocator.AutowireViewModel="True" | ||
BarBackgroundColor="LightGray"> | ||
|
||
<!--A page defined from here--> | ||
<ContentPage Title="Builtin"> | ||
<Grid> | ||
<StackLayout Orientation="Vertical" | ||
HorizontalOptions="Center" | ||
VerticalOptions="Center"> | ||
<Label Text="A page defined from the TabHostPage" /> | ||
<Button Text="Select Lazy tab" | ||
Command="{prism:SelectTab SlowContentView}"/> | ||
</StackLayout> | ||
</Grid> | ||
</ContentPage> | ||
<!-- A normal page referenced --> | ||
<views:StandardPage /> | ||
|
||
<!--A normal page referenced--> | ||
<!--<views:StandardPage/>--> | ||
<views:TopTabHostPage /> | ||
|
||
<views:TopTabHostPage/> | ||
|
||
<!--A page referenced but constructed the lazy way--> | ||
<lazyView:LazyContentPage Title="{Binding Title}" | ||
x:DataType="viewModels:SlowContentViewModel" | ||
x:TypeArguments="views:LoadingSlowContentView,views:SlowContentView"/> | ||
<!-- A page referenced but constructed the lazy way --> | ||
<lazyView:LazyContentPage | ||
Title="{Binding Title}" | ||
x:DataType="viewModels:SlowContentViewModel" | ||
x:TypeArguments="views:LoadingSlowContentView,views:SlowContentView" /> | ||
|
||
</TabbedPage> |
Oops, something went wrong.