Skip to content

Commit c00d91e

Browse files
committed
Added virtual Initialize method for TinyApplication.
1 parent 7b27ad2 commit c00d91e

File tree

7 files changed

+38
-7
lines changed

7 files changed

+38
-7
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ public partial class App : TinyApplication
2828
}
2929
```
3030

31+
If you want to run code asynchronous when the app starts you can override the **Initialize** method of **TinyApplication**.
32+
33+
```csharp
34+
public App()
35+
{
36+
InitializeComponent();
37+
38+
MainPage = new AppShell();
39+
}
40+
41+
protected override async Task Initialize()
42+
{
43+
44+
}
45+
```
46+
3147
### TinyView
3248
TinyMvvm has a base view called **TinyView** that you need to use if you want to use the overides from **TinyViewModel**. TinyView has ContentPage as it's base class so you can use it exactly as a normal ContentPage.
3349

src/TinyMvvm.Maui/TinyApplication.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ event EventHandler ITinyApplication.ApplicationSleep
3030
public TinyApplication()
3131
{
3232
ApplicationResolver.Current = this;
33+
34+
TinyDispatcher.BeginInvokeOnMainThread(async () => await Initialize());
35+
}
36+
37+
protected virtual Task Initialize()
38+
{
39+
return Task.CompletedTask;
3340
}
3441

3542
protected override void OnResume()

src/TinyMvvm.Maui/TinyDispatcher.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
namespace TinyMvvm.Maui;
1+
namespace TinyMvvm;
32

43
internal static class TinyDispatcher
54
{

src/TinyMvvm.Maui/TinyView.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using TinyMvvm.Maui;
2-
3-
namespace TinyMvvm;
1+
namespace TinyMvvm;
42

53
public abstract class TinyView : ContentPage
64
{

src/TinyMvvm.Maui/TinyViewModel.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using CommunityToolkit.Mvvm.ComponentModel;
2-
using TinyMvvm.Maui;
32

43
namespace TinyMvvm;
54

src/TinyMvvm.Sample/App.xaml.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,17 @@ public App()
88

99
MainPage = new AppShell();
1010
}
11+
12+
protected override async Task Initialize()
13+
{
14+
await base.Initialize();
15+
16+
17+
//To test that it not hangs the application.
18+
for(int i = 0; i < 100; i++)
19+
{
20+
await Task.Delay(1000);
21+
}
22+
}
1123
}
1224

src/TinyMvvm.Sample/ViewModels/MainViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public MainViewModel(ICityService cityService)
3737
private ICommand show;
3838
public ICommand Show => show ??= new RelayCommand<City>(async (city) =>
3939
{
40-
await Navigation.NavigateTo($"{nameof(DetailsViewModel)}", city.Country);
40+
await Navigation.NavigateTo($"{nameof(DetailsViewModel)}", city.Name);
4141
});
4242

4343
[ObservableProperty]

0 commit comments

Comments
 (0)