Skip to content

Commit 3fd50ba

Browse files
committed
Initial commit
1 parent 7765282 commit 3fd50ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+221
-282
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: jfversluis

.github/workflows/ci-sample.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v4
1818
- name: Build
19-
run: dotnet build samples\Plugin.Maui.Feature.Sample.sln -c Release
19+
run: dotnet build samples\Plugin.Maui.MessagingCenter.Sample.sln -c Release

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v4
1818
- name: Build
19-
run: dotnet build src\Plugin.Maui.Feature.sln -c Release
19+
run: dotnet build src\Plugin.Maui.MessagingCenter.sln -c Release

.github/workflows/release-nuget.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ jobs:
2222
$version="${{github.ref_name}}".TrimStart("v")
2323
"version-without-v=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
2424
- name: Pack
25-
run: dotnet pack src\Plugin.Maui.Feature.sln -c Release -p:PackageVersion=${{ steps.get_version.outputs.version-without-v }}
25+
run: dotnet pack src\Plugin.Maui.MessagingCenter.sln -c Release -p:PackageVersion=${{ steps.get_version.outputs.version-without-v }}
2626
- name: Push
27-
run: dotnet nuget push src\Plugin.Maui.Feature\bin\Release\Plugin.Maui.Feature.${{ steps.get_version.outputs.version-without-v }}.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }}
27+
run: dotnet nuget push src\Plugin.Maui.MessagingCenter\bin\Release\Plugin.Maui.MessagingCenter.${{ steps.get_version.outputs.version-without-v }}.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }}
2828
env:
2929
GITHUB_TOKEN: ${{ secrets.NUGET_API_KEY }}

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Author Name
3+
Copyright (c) 2024 Gerald Versluis
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,27 @@
1-
# Plugin.Maui.Feature Template
1+
![](nuget.png)
2+
# Plugin.Maui.MessagingCenter
23

3-
The `Plugin.Maui.Feature` repository is a template repository that can be used to bootstrap your own .NET MAUI plugin project. You can use this project structure as a blueprint for your own work.
4+
`Plugin.Maui.MessagingCenter` provides a drop-in compatible replacement for the .NET MAUI MessagingCenter which has been deprecated and removed.
45

5-
Learn how to get started with your plugin in this [YouTube video](https://www.youtube.com/watch?v=ZCQrlGT7MhI&list=PLfbOp004UaYVgzmTBNVI0ql2qF0LhSEU1&index=27).
6+
Please note that you probably want to adopt the [MVVM Toolkit Messenger](https://learn.microsoft.com/dotnet/communitytoolkit/mvvm/messenger) APIs as they provide more functionality.
67

7-
This template contains:
8+
> [!IMPORTANT]
9+
> This library is meant to make the migration from Xamarin.Forms to .NET MAUI easier, not to provide a long-term solution.
810
9-
- A [sample .NET MAUI app](samples) where you can demonstrate how your plugin works and test your plugin with while developing
10-
- The [source](src) of the plugin
11-
- A boilerplate [README file](README_Feature.md) you can use (don't forget to rename to `README.md` and remove this one!)
12-
- [GitHub Actions for CI](.github/workflows) of the library and the sample app
13-
- [GitHub Action for releasing](.github/workflows) your package to NuGet
14-
- A [generic icon](nuget.png) for your project, feel free to adapt and be creative!
15-
- A [.editorconfig](.editorconfig) file to standardize the code syntax. Feel free to adapt or remove.
16-
- The [LICENSE](LICENSE) file with the MIT license. If you want this to be different, please change it. At the very least add your name in there!
11+
## Install Plugin
1712

18-
## Getting Started
13+
[![NuGet](https://img.shields.io/nuget/v/Plugin.Maui.MessagingCenter.svg?label=NuGet)](https://www.nuget.org/packages/Plugin.Maui.MessagingCenter/)
1914

20-
1. Create your own GitHub repository from this one by clicking the "Use this template" button and then "Create a new repository". More information in the [documentation](https://docs.github.com/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template). After that, clone the repo to your local machine.
15+
Available on [NuGet](http://www.nuget.org/packages/Plugin.Maui.MessagingCenter).
2116

22-
2. Replace all occurrences of `Plugin.Maui.Feature` with whatever your feature or functionality will be. For instance: `Plugin.Maui.ScreenBrightness` or `Plugin.Maui.Audio`. Of course the name can be anything, but to make it more discoverable it could be a great choice to stick to this naming scheme. You can easily do this with your favorite text-editor and do a replace all on all files.
17+
Install with the dotnet CLI: `dotnet add package Plugin.Maui.MessagingCenter`, or through the NuGet Package Manager in Visual Studio.
2318

24-
2.1 Don't forget to also rename the files and folders on your filesystem.
19+
## API Usage
2520

26-
3. In the csproj file of the plugin project (under `src`), make sure that you replace all relevant values to your project. This means the author of this project, the description of the project, the target framework (.NET 7, 8 or something else). If you don't want to or can't support a certain platform, remove that target platform altogether.
21+
After you have installed this library, you can either add the using statement at the top of each file where you are using MessagingCenter (`using Plugin.Maui.MessagingCenter;`), or opt for a [global using](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/using-directive#global-modifier) statement so you only need to do it once.
2722

28-
4. Delete this `README.md` file and rename `README_Feature.md` to `README.md`. Fill that README file with all the relevant details of your project.
23+
The API can be used the same as the .NET MAUI MessagingCenter APIs. You probably came here because you are already using the MessagingCenter in your .NET MAUI app, so you probably don't need more explanation. If you do need a reference, please find the documentation on the .NET MAUI MessagingCenter [here](https://learn.microsoft.com/dotnet/maui/fundamentals/messagingcenter) and the MVVM Toolkit Messenger [here](https://learn.microsoft.com/dotnet/communitytoolkit/mvvm/messenger).
2924

30-
5. Check the LICENSE file if this reflects the license that you want to distribute your project under. At the very least add your name there and the current year we live in.
25+
## Acknowledgements
3126

32-
6. Create a nice icon in the `nuget.png` file that will show up on nuget.org and in the NuGet manager in Visual Studio.
33-
34-
7. Write your plugin code (under `src`) and add samples to the .NET MAUI sample app (under `samples` folder)
35-
36-
8. Make super sure that your package won't show up as `Plugin.Maui.Feature` on NuGet! If one does, you owe me a drink!
37-
38-
9. Publish your package to NuGet, a nice guide to do that can be found [here](https://learn.microsoft.com/nuget/nuget-org/publish-a-package). Also see [Publish to NuGet](#publish-to-nuget) below.
39-
40-
10. Enjoy life as a .NET MAUI plugin author! ✨
41-
42-
As an example of all of this you can have a look at:
43-
44-
- [Plugin.Maui.Audio](https://github.com/jfversluis/Plugin.Maui.Audio)
45-
- [Plugin.Maui.Pedometer](https://github.com/jfversluis/Plugin.Maui.Pedometer)
46-
- [Plugin.Maui.ScreenBrightness](https://github.com/jfversluis/Plugin.Maui.ScreenBrightness)
47-
48-
## Publish to NuGet
49-
50-
If you want to publish your package to NuGet, you totally can! Included in this template are a couple of GitHub Actions. One of them goes of when you create a new tag with this pattern: `v1.0.0` or `v1.0.0-preview1`. Obviously the `1.0.0` part can be determined by you as you see fit, as long as you follow the pattern of 3 integers separated by dots.
51-
52-
You will also want to set a secret for this repository which contains your NuGet API key. Follow the documentation on that [here](https://docs.github.com/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository), and add a secret with the key `NUGET_API_KEY` and value of your NuGet API key. The API key should be authorized to push a NuGet package with the given identifier.
53-
54-
From there, after [creating a GitHub release](https://docs.github.com/repositories/releasing-projects-on-github/managing-releases-in-a-repository) your plugin will be automatically released on NuGet!
27+
The bubble icon has kindly been provided by [Smashicons](https://www.freepik.com/icon/chat_134719#fromView=keyword&page=1&position=1&uuid=c6e6ca66-ab2d-44de-85e9-6138fbc90df6)

README_Feature.md

Lines changed: 0 additions & 128 deletions
This file was deleted.

nuget.png

1.48 KB
Loading

samples/Plugin.Maui.Feature.Sample/MainPage.xaml

Lines changed: 0 additions & 8 deletions
This file was deleted.

samples/Plugin.Maui.Feature.Sample/MainPage.xaml.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.

samples/Plugin.Maui.Feature.Sample.sln renamed to samples/Plugin.Maui.MessagingCenter.Sample.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
22
# Visual Studio Version 17
33
VisualStudioVersion = 17.0.31611.283
44
MinimumVisualStudioVersion = 10.0.40219.1
5-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plugin.Maui.Feature.Sample", "Plugin.Maui.Feature.Sample\Plugin.Maui.Feature.Sample.csproj", "{490BB138-9606-4FFF-8AAD-841C5B1ED059}"
5+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plugin.Maui.MessagingCenter.Sample", "Plugin.Maui.MessagingCenter.Sample\Plugin.Maui.MessagingCenter.Sample.csproj", "{490BB138-9606-4FFF-8AAD-841C5B1ED059}"
66
EndProject
7-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plugin.Maui.Feature", "..\src\Plugin.Maui.Feature\Plugin.Maui.Feature.csproj", "{B60F3174-E978-4F2B-B117-F6F0327594C8}"
7+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plugin.Maui.MessagingCenter", "..\src\Plugin.Maui.MessagingCenter\Plugin.Maui.MessagingCenter.csproj", "{B60F3174-E978-4F2B-B117-F6F0327594C8}"
88

99
EndProject
1010
Global

samples/Plugin.Maui.Feature.Sample/App.xaml renamed to samples/Plugin.Maui.MessagingCenter.Sample/App.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version = "1.0" encoding = "UTF-8" ?>
22
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
33
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4-
x:Class="Plugin.Maui.Feature.Sample.App">
4+
x:Class="Plugin.Maui.MessagingCenter.Sample.App">
55
<Application.Resources>
66
<ResourceDictionary>
77
<ResourceDictionary.MergedDictionaries>

samples/Plugin.Maui.Feature.Sample/App.xaml.cs renamed to samples/Plugin.Maui.MessagingCenter.Sample/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Plugin.Maui.Feature.Sample;
1+
namespace Plugin.Maui.MessagingCenter.Sample;
22

33
public partial class App : Application
44
{

samples/Plugin.Maui.Feature.Sample/AppShell.xaml renamed to samples/Plugin.Maui.MessagingCenter.Sample/AppShell.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<Shell
3-
x:Class="Plugin.Maui.Feature.Sample.AppShell"
3+
x:Class="Plugin.Maui.MessagingCenter.Sample.AppShell"
44
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
55
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6-
xmlns:pages="clr-namespace:Plugin.Maui.Feature.Sample"
6+
xmlns:pages="clr-namespace:Plugin.Maui.MessagingCenter.Sample"
77
Shell.FlyoutBehavior="Disabled">
88

99
<ShellContent

samples/Plugin.Maui.Feature.Sample/AppShell.xaml.cs renamed to samples/Plugin.Maui.MessagingCenter.Sample/AppShell.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Plugin.Maui.Feature.Sample;
1+
namespace Plugin.Maui.MessagingCenter.Sample;
22

33
public partial class AppShell : Shell
44
{
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Plugin.Maui.MessagingCenter.Sample.MainPage"
5+
Title="MessagingCenter Plugin">
6+
7+
<VerticalStackLayout
8+
HorizontalOptions="Center" VerticalOptions="Center"
9+
Spacing="10">
10+
11+
<Button
12+
Text="Subscribe" Clicked="Subscribe_Clicked" />
13+
14+
<Button
15+
Text="Unsubscribe" Clicked="Unsubscribe_Clicked" />
16+
17+
<Button
18+
Text="Send Hi Message" Clicked="Button_Clicked" />
19+
</VerticalStackLayout>
20+
</ContentPage>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
namespace Plugin.Maui.MessagingCenter.Sample;
2+
3+
public partial class MainPage : ContentPage
4+
{
5+
public MainPage()
6+
{
7+
InitializeComponent();
8+
}
9+
10+
private void Button_Clicked(object sender, EventArgs e)
11+
{
12+
MessagingCenter.Send<MainPage>(this, "Hi");
13+
}
14+
15+
private void Subscribe_Clicked(object sender, EventArgs e)
16+
{
17+
MessagingCenter.Subscribe<MainPage>(this, "Hi", (sender) =>
18+
{
19+
// Do something whenever the "Hi" message is received
20+
DisplayAlert("Message Received", "Hi", "OK");
21+
});
22+
}
23+
24+
private void Unsubscribe_Clicked(object sender, EventArgs e)
25+
{
26+
MessagingCenter.Unsubscribe<MainPage>(this, "Hi");
27+
}
28+
}

samples/Plugin.Maui.Feature.Sample/MauiProgram.cs renamed to samples/Plugin.Maui.MessagingCenter.Sample/MauiProgram.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Microsoft.Extensions.DependencyInjection;
2-
using Plugin.Maui.Feature;
32

4-
namespace Plugin.Maui.Feature.Sample;
3+
namespace Plugin.Maui.MessagingCenter.Sample;
54

65
public static class MauiProgram
76
{
@@ -16,9 +15,6 @@ public static MauiApp CreateMauiApp()
1615
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
1716
});
1817

19-
builder.Services.AddTransient<MainPage>();
20-
builder.Services.AddSingleton<IFeature>(Feature.Default);
21-
2218
return builder.Build();
2319
}
2420
}

samples/Plugin.Maui.Feature.Sample/Platforms/Android/MainActivity.cs renamed to samples/Plugin.Maui.MessagingCenter.Sample/Platforms/Android/MainActivity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using Android.Content.PM;
33
using Android.OS;
44

5-
namespace Plugin.Maui.Feature.Sample;
5+
namespace Plugin.Maui.MessagingCenter.Sample;
66

77
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
88
public class MainActivity : MauiAppCompatActivity

samples/Plugin.Maui.Feature.Sample/Platforms/Android/MainApplication.cs renamed to samples/Plugin.Maui.MessagingCenter.Sample/Platforms/Android/MainApplication.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Android.App;
22
using Android.Runtime;
33

4-
namespace Plugin.Maui.Feature.Sample;
4+
namespace Plugin.Maui.MessagingCenter.Sample;
55

66
[Application]
77
public class MainApplication : MauiApplication

samples/Plugin.Maui.Feature.Sample/Platforms/iOS/AppDelegate.cs renamed to samples/Plugin.Maui.MessagingCenter.Sample/Platforms/MacCatalyst/AppDelegate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Foundation;
22

3-
namespace Plugin.Maui.Feature.Sample;
3+
namespace Plugin.Maui.MessagingCenter.Sample;
44

55
[Register("AppDelegate")]
66
public class AppDelegate : MauiUIApplicationDelegate

0 commit comments

Comments
 (0)