Skip to content

Commit

Permalink
Fix For Maui WinUI Registrations
Browse files Browse the repository at this point in the history
Fix for #3576
  • Loading branch information
ChrisPulman committed Jul 8, 2023
1 parent 2ef3d99 commit f481c56
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
30 changes: 22 additions & 8 deletions src/ReactiveUI.Maui/ActivationForViewFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
#if HAS_WINUI
using Microsoft.UI.Xaml;
using Windows.Foundation;

namespace ReactiveUI.WinUI;
#endif
#if HAS_MAUI
using System.ComponentModel;
using Microsoft.Maui.Controls;
#endif

#if IS_WINUI
namespace ReactiveUI.WinUI;
#endif
#if IS_MAUI
using Microsoft.Maui.Controls;

Check warning on line 22 in src/ReactiveUI.Maui/ActivationForViewFetcher.cs

View workflow job for this annotation

GitHub Actions / build / build

The using directive for 'Microsoft.Maui.Controls' appeared previously in this namespace

Check warning on line 22 in src/ReactiveUI.Maui/ActivationForViewFetcher.cs

View workflow job for this annotation

GitHub Actions / build / build

The using directive for 'Microsoft.Maui.Controls' appeared previously in this namespace

namespace ReactiveUI.Maui;
#endif
Expand All @@ -28,12 +33,15 @@ public class ActivationForViewFetcher : IActivationForViewFetcher
/// <inheritdoc/>
public int GetAffinityForView(Type view) =>
#if HAS_WINUI
#if IS_MAUI
typeof(Page).GetTypeInfo().IsAssignableFrom(view.GetTypeInfo()) ||
#endif
typeof(FrameworkElement).GetTypeInfo().IsAssignableFrom(view.GetTypeInfo())
#endif
#if HAS_MAUI
typeof(Page).GetTypeInfo().IsAssignableFrom(view.GetTypeInfo()) ||
typeof(Page).GetTypeInfo().IsAssignableFrom(view.GetTypeInfo()) ||
typeof(View).GetTypeInfo().IsAssignableFrom(view.GetTypeInfo()) ||
typeof(Cell).GetTypeInfo().IsAssignableFrom(view.GetTypeInfo())
typeof(Cell).GetTypeInfo().IsAssignableFrom(view.GetTypeInfo())
#endif
? 10 : 0;

Expand All @@ -44,6 +52,9 @@ public IObservable<bool> GetActivationForView(IActivatableView view)
GetActivationFor(view as ICanActivate) ??
#if HAS_WINUI
GetActivationFor(view as FrameworkElement) ??
#if IS_MAUI
GetActivationFor(view as Page) ??
#endif
#endif
#if HAS_MAUI
GetActivationFor(view as Page) ??
Expand All @@ -55,9 +66,10 @@ public IObservable<bool> GetActivationForView(IActivatableView view)
return activation.DistinctUntilChanged();
}

private static IObservable<bool>? GetActivationFor(ICanActivate? canActivate) => canActivate?.Activated.Select(_ => true).Merge(canActivate.Deactivated.Select(_ => false));
private static IObservable<bool>? GetActivationFor(ICanActivate? canActivate) =>
canActivate?.Activated.Select(_ => true).Merge(canActivate.Deactivated.Select(_ => false));

#if HAS_MAUI
#if HAS_MAUI || (HAS_WINUI && IS_MAUI)
private static IObservable<bool>? GetActivationFor(Page? page)
{
if (page is null)
Expand Down Expand Up @@ -85,7 +97,9 @@ public IObservable<bool> GetActivationForView(IActivatableView view)

return appearing.Merge(disappearing);
}
#endif

#if HAS_MAUI
private static IObservable<bool>? GetActivationFor(View? view)
{
if (view is null)
Expand Down Expand Up @@ -138,11 +152,11 @@ public IObservable<bool> GetActivationForView(IActivatableView view)
#endif

#if HAS_WINUI
private static IObservable<bool> GetActivationFor(FrameworkElement? view)
private static IObservable<bool>? GetActivationFor(FrameworkElement? view)
{
if (view is null)
{
return Observable<bool>.Empty;
return null;
}

var viewLoaded = Observable.FromEvent<TypedEventHandler<FrameworkElement, object>, bool>(
Expand Down
8 changes: 3 additions & 5 deletions src/ReactiveUI.Maui/ReactiveUI.Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
<PackageDescription>Contains the ReactiveUI platform specific extensions for Microsoft Maui</PackageDescription>
<PackageTags>mvvm;reactiveui;rx;reactive extensions;observable;LINQ;events;frp;maui;android;ios;mac;forms;net</PackageTags>
<UseMaui>true</UseMaui>
<DefineConstants>IS_MAUI</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="$(TargetFramework.EndsWith('-windows10.0.19041.0'))">
<DefineConstants>HAS_WINUI</DefineConstants>
<DefineConstants>$(DefineConstants);HAS_WINUI;</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="!$(TargetFramework.EndsWith('-windows10.0.19041.0'))">
<DefineConstants>HAS_MAUI</DefineConstants>
<DefineConstants>$(DefineConstants);HAS_MAUI;</DefineConstants>
</PropertyGroup>

<ItemGroup Condition="$(TargetFramework.EndsWith('-windows10.0.19041.0'))">
Expand All @@ -26,8 +27,5 @@
<ItemGroup>
<Compile Remove="Common\RoutedViewHost.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ReactiveUI\ReactiveUI.csproj" />
</ItemGroup>

</Project>
4 changes: 3 additions & 1 deletion src/ReactiveUI.Maui/Registrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
#if HAS_WINUI
using System.Reactive.Concurrency;
using Splat;
#endif

#if IS_WINUI
namespace ReactiveUI.WinUI;
#endif
#if HAS_MAUI
#if IS_MAUI
namespace ReactiveUI.Maui;
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/ReactiveUI.WinUI/ReactiveUI.WinUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<PackageDescription>Contains the ReactiveUI platform specific extensions for WinUI Desktop</PackageDescription>
<RootNamespace>ReactiveUI.WinUI.Desktop</RootNamespace>
<DefineConstants>HAS_WINUI</DefineConstants>
<PackageTags>mvvm;reactiveui;rx;reactive extensions;observable;LINQ;events;winui</PackageTags>
<UseWinUI>true</UseWinUI>
<DefineConstants>IS_WINUI;HAS_WINUI;</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit f481c56

Please sign in to comment.