Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SL-9275] Replace MessagingCenter with Messenger (from Community Toolkit) #44

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions Float.Core/Analytics/AnalyticsMessageType.cs

This file was deleted.

12 changes: 7 additions & 5 deletions Float.Core/Analytics/AnalyticsService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using CommunityToolkit.Mvvm.Messaging;
using Float.Core.Messages;
#if NETSTANDARD
using Xamarin.Forms;
#else
Expand All @@ -23,7 +25,7 @@ public abstract class AnalyticsService
/// </summary>
protected AnalyticsService()
{
MessagingCenter.Subscribe<UI.BaseContentPage, string>(this, AnalyticsMessageType.PageView, HandlePageView);
WeakReferenceMessenger.Default.Register<PageViewMessage>(this, HandlePageView);
}

/// <summary>
Expand Down Expand Up @@ -161,11 +163,11 @@ protected virtual bool ShouldTrackUsage()
/// <summary>
/// Handler for when a page view occurs.
/// </summary>
/// <param name="page">The page that appeared.</param>
/// <param name="name">The page name.</param>
void HandlePageView(UI.BaseContentPage page, string name)
/// <param name="sender">The page that appeared.</param>
/// <param name="message">The page name.</param>
void HandlePageView(object sender, PageViewMessage message)
{
TrackPageView(name, page);
TrackPageView(message.Value, message.Page);
}
}
}
1 change: 1 addition & 0 deletions Float.Core/Float.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="[12.0.1,]" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="[8.2.2,9)" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('netstandard'))">
<PackageReference Include="Xamarin.Forms" Version="[5.0.0.1874,6)" />
Expand Down
33 changes: 33 additions & 0 deletions Float.Core/Messages/PageViewMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using CommunityToolkit.Mvvm.Messaging.Messages;
#if NETSTANDARD
using Xamarin.Forms;
#else
using Microsoft.Maui.Controls;
#endif

namespace Float.Core.Messages
{
/// <summary>
/// The page view message class definition.
/// </summary>
public class PageViewMessage : ValueChangedMessage<string>
{
/// <summary>
/// Initializes a new instance of the <see cref="PageViewMessage"/> class.
/// </summary>
/// <param name="eventName">The event name.</param>
/// <param name="page">The page displayed.</param>
public PageViewMessage(string eventName, Page page) : base(eventName)
{
Page = page;
}

/// <summary>
/// Gets the page displayed.
/// </summary>
/// <value>
/// The page displayed.
/// </value>
public Page Page { get; }
}
}
4 changes: 3 additions & 1 deletion Float.Core/UI/BaseContentPage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using CommunityToolkit.Mvvm.Messaging;
using Float.Core.Extensions;
using Float.Core.Messages;
#if NETSTANDARD
using Xamarin.Forms;
#else
Expand Down Expand Up @@ -62,7 +64,7 @@ protected override void OnBindingContextChanged()
/// <param name="name">The page name.</param>
protected void TrackPageView(string name)
{
MessagingCenter.Send(this, Analytics.AnalyticsMessageType.PageView, name);
WeakReferenceMessenger.Default.Send(new PageViewMessage(name, this));
}

/// <inheritdoc />
Expand Down
Loading