Skip to content

Commit c56abae

Browse files
author
Jean-Marie Alfonsi
committed
feat: TemplatedTaskLoader Events
1 parent 600ecc9 commit c56abae

4 files changed

Lines changed: 53 additions & 8 deletions

File tree

Retronado.Maui/Views/CommandsPage.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
IsRefreshing="{Binding Loader.ShowRefresher}"
3232
RefreshColor="{StaticResource AccentColor}">
3333
<ScrollView Grid.Row="1">
34-
<tlv:TemplatedTaskLoader TaskLoaderNotifier="{Binding Loader}">
34+
<tlv:TemplatedTaskLoader x:Name="TaskLoader"
35+
TaskLoaderNotifier="{Binding Loader}">
3536
<tlv:TemplatedTaskLoader.ResultControlTemplate>
3637
<ControlTemplate>
3738
<Grid x:DataType="viewModels:CommandsPageViewModel"

Retronado.Maui/Views/CommandsPage.xaml.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
using Microsoft.Maui.Controls.PlatformConfiguration;
1+
using Microsoft.Maui.Controls.PlatformConfiguration;
22
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;
3+
using Sharpnado.TaskLoaderView;
34

45
namespace Sample.Views;
56

@@ -10,6 +11,12 @@ public CommandsPage()
1011
InitializeComponent();
1112

1213
ResourcesHelper.SetSublimeGameMode();
14+
15+
// Subscribe to TemplatedTaskLoader events
16+
TaskLoader.LoadingControlTemplateLoaded += OnLoadingControlTemplateLoaded;
17+
TaskLoader.ResultControlTemplateLoaded += OnResultControlTemplateLoaded;
18+
TaskLoader.ErrorControlTemplateLoaded += OnErrorControlTemplateLoaded;
19+
TaskLoader.EmptyControlTemplateLoaded += OnEmptyControlTemplateLoaded;
1320
}
1421

1522
protected override void OnAppearing()
@@ -20,4 +27,24 @@ protected override void OnAppearing()
2027
safeInsets.Bottom = 0;
2128
Padding = safeInsets;
2229
}
23-
}
30+
31+
private void OnLoadingControlTemplateLoaded(object? sender, EventArgs e)
32+
{
33+
System.Diagnostics.Debug.WriteLine("[CommandsPage] Loading template loaded");
34+
}
35+
36+
private void OnResultControlTemplateLoaded(object? sender, EventArgs e)
37+
{
38+
System.Diagnostics.Debug.WriteLine("[CommandsPage] Result template loaded");
39+
}
40+
41+
private void OnErrorControlTemplateLoaded(object? sender, EventArgs e)
42+
{
43+
System.Diagnostics.Debug.WriteLine("[CommandsPage] Error template loaded");
44+
}
45+
46+
private void OnEmptyControlTemplateLoaded(object? sender, EventArgs e)
47+
{
48+
System.Diagnostics.Debug.WriteLine("[CommandsPage] Empty template loaded");
49+
}
50+
}

Sharpnado.Maui.TaskLoaderView/Sharpnado.Maui.TaskLoaderView.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
<RootNamespace>Sharpnado.TaskLoaderView</RootNamespace>
1111

1212
<Product>$(AssemblyName) ($(TargetFramework))</Product>
13-
<AssemblyVersion>2.6.1.0</AssemblyVersion>
14-
<AssemblyFileVersion>2.6.1.0</AssemblyFileVersion>
15-
<Version>2.6.1.0</Version>
13+
<AssemblyVersion>2.6.2.0</AssemblyVersion>
14+
<AssemblyFileVersion>2.6.2.0</AssemblyFileVersion>
15+
<Version>2.6.2.0</Version>
1616
<PackOnBuild>true</PackOnBuild>
1717
<NeutralLanguage>en</NeutralLanguage>
1818
<UseFullSemVerForNuGet>false</UseFullSemVerForNuGet>
@@ -22,7 +22,7 @@
2222
<RepositoryUrl>https://github.com/roubachof/Sharpnado.TaskLoaderView</RepositoryUrl>
2323
<PackageIcon>maui_logo.png</PackageIcon>
2424
<PackageTags>maui, netmaui, xamarin, xamarin.forms, skeleton, loading, states, async, task, loader, isbusy, control, taskloader, taskloadernotifier</PackageTags>
25-
<PackageReleaseNotes>Fix the insertion of the loading states view that could cause an index out of range exception.</PackageReleaseNotes>
25+
<PackageReleaseNotes>Added events to TemplatedTaskLoader for each control template state (LoadingControlTemplateLoaded, ResultControlTemplateLoaded, ErrorControlTemplateLoaded, EmptyControlTemplateLoaded). These events are raised when the corresponding control template is loaded, allowing you to react to state changes.</PackageReleaseNotes>
2626
<Title>Maui TaskLoaderView: free yourself from IsBusy=true!</Title>
2727
<Summary>Free yourself from IsBusy=true! The `TaskLoaderView` is a UI component that handles all your UI loading state (Loading, Error, Result, Notification), and removes all the pain of async loading from your view models (try catch / async void / IsBusy / HasErrors / base view models / ...) thanks to its brother the `TaskLoaderNotifier`.</Summary>
2828
<Description>Free yourself from IsBusy=true!

Sharpnado.Maui.TaskLoaderView/TemplatedTaskLoader.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace Sharpnado.TaskLoaderView;
44

55
public class TemplatedTaskLoader : ContentView
66
{
7+
78
public static readonly BindableProperty TaskLoaderNotifierProperty = BindableProperty.Create(
89
nameof(TaskLoaderNotifier),
910
typeof(ITaskLoaderNotifier),
@@ -30,6 +31,14 @@ public class TemplatedTaskLoader : ContentView
3031
typeof(ControlTemplate),
3132
typeof(TemplatedTaskLoader));
3233

34+
public event EventHandler? ResultControlTemplateLoaded;
35+
36+
public event EventHandler? LoadingControlTemplateLoaded;
37+
38+
public event EventHandler? ErrorControlTemplateLoaded;
39+
40+
public event EventHandler? EmptyControlTemplateLoaded;
41+
3342
public ITaskLoaderNotifier? TaskLoaderNotifier
3443
{
3544
get => (ITaskLoaderNotifier?)GetValue(TaskLoaderNotifierProperty);
@@ -90,24 +99,28 @@ private void Initialize()
9099
if (TaskLoaderNotifier.ShowResult)
91100
{
92101
ControlTemplate = ResultControlTemplate;
102+
ResultControlTemplateLoaded?.Invoke(this, EventArgs.Empty);
93103
return;
94104
}
95105

96106
if (TaskLoaderNotifier.ShowError)
97107
{
98108
ControlTemplate = ErrorControlTemplate ?? ResultControlTemplate;
109+
ErrorControlTemplateLoaded?.Invoke(this, EventArgs.Empty);
99110
return;
100111
}
101112

102113
if (TaskLoaderNotifier.ShowEmptyState)
103114
{
104115
ControlTemplate = EmptyControlTemplate ?? ResultControlTemplate;
116+
EmptyControlTemplateLoaded?.Invoke(this, EventArgs.Empty);
105117
return;
106118
}
107119

108120
if (TaskLoaderNotifier.ShowLoader)
109121
{
110122
ControlTemplate = LoadingControlTemplate ?? ResultControlTemplate;
123+
LoadingControlTemplateLoaded?.Invoke(this, EventArgs.Empty);
111124
}
112125
}
113126

@@ -117,19 +130,23 @@ private void NotifierPropertyChanged(object sender, PropertyChangedEventArgs e)
117130
{
118131
case nameof(ITaskLoaderNotifier.ShowResult) when TaskLoaderNotifier!.ShowResult:
119132
ControlTemplate = ResultControlTemplate;
133+
ResultControlTemplateLoaded?.Invoke(this, EventArgs.Empty);
120134
break;
121135

122136
case nameof(ITaskLoaderNotifier.ShowError) when TaskLoaderNotifier!.ShowError:
123137
ControlTemplate = ErrorControlTemplate;
138+
ErrorControlTemplateLoaded?.Invoke(this, EventArgs.Empty);
124139
break;
125140

126141
case nameof(ITaskLoaderNotifier.ShowLoader) when TaskLoaderNotifier!.ShowLoader:
127142
ControlTemplate = LoadingControlTemplate;
143+
LoadingControlTemplateLoaded?.Invoke(this, EventArgs.Empty);
128144
break;
129145

130146
case nameof(ITaskLoaderNotifier.ShowEmptyState) when TaskLoaderNotifier!.ShowEmptyState:
131147
ControlTemplate = EmptyControlTemplate;
148+
EmptyControlTemplateLoaded?.Invoke(this, EventArgs.Empty);
132149
break;
133150
}
134151
}
135-
}
152+
}

0 commit comments

Comments
 (0)