Skip to content

Commit 3467c36

Browse files
authored
Fix For Maui WinUI Registrations (#3577)
1 parent 2ef3d99 commit 3467c36

13 files changed

+47
-45
lines changed

src/ReactiveUI.Maui/ActivationForViewFetcher.cs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
using System;
77
using System.Reactive.Linq;
88
using System.Reflection;
9-
#if HAS_WINUI
9+
#if WINUI_TARGET
1010
using Microsoft.UI.Xaml;
1111
using Windows.Foundation;
12+
#endif
1213

14+
#if IS_WINUI
1315
namespace ReactiveUI.WinUI;
1416
#endif
15-
#if HAS_MAUI
17+
#if IS_MAUI
1618
using System.ComponentModel;
1719
using Microsoft.Maui.Controls;
1820

@@ -27,13 +29,15 @@ public class ActivationForViewFetcher : IActivationForViewFetcher
2729
{
2830
/// <inheritdoc/>
2931
public int GetAffinityForView(Type view) =>
30-
#if HAS_WINUI
31-
typeof(FrameworkElement).GetTypeInfo().IsAssignableFrom(view.GetTypeInfo())
32+
#if WINUI_TARGET
33+
#if IS_MAUI
34+
typeof(Page).GetTypeInfo().IsAssignableFrom(view.GetTypeInfo()) ||
3235
#endif
33-
#if HAS_MAUI
34-
typeof(Page).GetTypeInfo().IsAssignableFrom(view.GetTypeInfo()) ||
36+
typeof(FrameworkElement).GetTypeInfo().IsAssignableFrom(view.GetTypeInfo())
37+
#else
38+
typeof(Page).GetTypeInfo().IsAssignableFrom(view.GetTypeInfo()) ||
3539
typeof(View).GetTypeInfo().IsAssignableFrom(view.GetTypeInfo()) ||
36-
typeof(Cell).GetTypeInfo().IsAssignableFrom(view.GetTypeInfo())
40+
typeof(Cell).GetTypeInfo().IsAssignableFrom(view.GetTypeInfo())
3741
#endif
3842
? 10 : 0;
3943

@@ -42,10 +46,12 @@ public IObservable<bool> GetActivationForView(IActivatableView view)
4246
{
4347
var activation =
4448
GetActivationFor(view as ICanActivate) ??
45-
#if HAS_WINUI
49+
#if WINUI_TARGET
4650
GetActivationFor(view as FrameworkElement) ??
51+
#if IS_MAUI
52+
GetActivationFor(view as Page) ??
4753
#endif
48-
#if HAS_MAUI
54+
#else
4955
GetActivationFor(view as Page) ??
5056
GetActivationFor(view as View) ??
5157
GetActivationFor(view as Cell) ??
@@ -55,9 +61,10 @@ public IObservable<bool> GetActivationForView(IActivatableView view)
5561
return activation.DistinctUntilChanged();
5662
}
5763

58-
private static IObservable<bool>? GetActivationFor(ICanActivate? canActivate) => canActivate?.Activated.Select(_ => true).Merge(canActivate.Deactivated.Select(_ => false));
64+
private static IObservable<bool>? GetActivationFor(ICanActivate? canActivate) =>
65+
canActivate?.Activated.Select(_ => true).Merge(canActivate.Deactivated.Select(_ => false));
5966

60-
#if HAS_MAUI
67+
#if !WINUI_TARGET || (WINUI_TARGET && IS_MAUI)
6168
private static IObservable<bool>? GetActivationFor(Page? page)
6269
{
6370
if (page is null)
@@ -85,7 +92,9 @@ public IObservable<bool> GetActivationForView(IActivatableView view)
8592

8693
return appearing.Merge(disappearing);
8794
}
95+
#endif
8896

97+
#if !WINUI_TARGET
8998
private static IObservable<bool>? GetActivationFor(View? view)
9099
{
91100
if (view is null)
@@ -135,14 +144,12 @@ public IObservable<bool> GetActivationForView(IActivatableView view)
135144

136145
return appearing.Merge(disappearing);
137146
}
138-
#endif
139-
140-
#if HAS_WINUI
141-
private static IObservable<bool> GetActivationFor(FrameworkElement? view)
147+
#else
148+
private static IObservable<bool>? GetActivationFor(FrameworkElement? view)
142149
{
143150
if (view is null)
144151
{
145-
return Observable<bool>.Empty;
152+
return null;
146153
}
147154

148155
var viewLoaded = Observable.FromEvent<TypedEventHandler<FrameworkElement, object>, bool>(

src/ReactiveUI.Maui/Common/AutoDataTemplateBindingHook.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// The .NET Foundation licenses this file to you under the MIT license.
44
// See the LICENSE file in the project root for full license information.
55

6-
#if HAS_WINUI
6+
#if WINUI_TARGET
77
using System;
88
using System.Diagnostics.CodeAnalysis;
99
using System.Linq;

src/ReactiveUI.Maui/Common/BooleanToVisibilityTypeConverter.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
// See the LICENSE file in the project root for full license information.
55

66
using System;
7-
#if HAS_MAUI
8-
using Microsoft.Maui;
9-
#endif
10-
#if HAS_WINUI
7+
#if WINUI_TARGET
118
using Microsoft.UI.Xaml;
9+
#else
10+
using Microsoft.Maui;
1211
#endif
1312

1413
namespace ReactiveUI
@@ -46,7 +45,7 @@ public bool TryConvert(object? from, Type toType, object? conversionHint, out ob
4645
{
4746
var fromAsBool = (hint & BooleanToVisibilityHint.Inverse) != 0 ? !fromBool : fromBool;
4847

49-
#if !NETFX_CORE && !HAS_UNO && !HAS_WINUI
48+
#if !WINUI_TARGET
5049
var notVisible = (hint & BooleanToVisibilityHint.UseHidden) != 0 ? Visibility.Hidden : Visibility.Collapsed;
5150
#else
5251
var notVisible = Visibility.Collapsed;

src/ReactiveUI.Maui/Common/ReactivePage.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
// The .NET Foundation licenses this file to you under the MIT license.
44
// See the LICENSE file in the project root for full license information.
55

6-
#if HAS_MAUI
7-
using Microsoft.Maui.Controls;
8-
#endif
9-
#if HAS_WINUI
6+
#if WINUI_TARGET
107
using Microsoft.UI.Xaml;
118
using Microsoft.UI.Xaml.Controls;
9+
#else
10+
using Microsoft.Maui.Controls;
1211
#endif
1312

1413
namespace ReactiveUI
@@ -81,7 +80,7 @@ class ReactivePage<TViewModel> :
8180
Page, IViewFor<TViewModel>
8281
where TViewModel : class
8382
{
84-
#if HAS_WINUI
83+
#if WINUI_TARGET
8584
/// <summary>
8685
/// The view model dependency property.
8786
/// </summary>
@@ -123,7 +122,7 @@ public TViewModel? ViewModel
123122
set => ViewModel = (TViewModel?)value;
124123
}
125124

126-
#if HAS_MAUI
125+
#if !WINUI_TARGET
127126
/// <inheritdoc/>
128127
protected override void OnBindingContextChanged()
129128
{

src/ReactiveUI.Maui/Common/ReactiveUserControl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// The .NET Foundation licenses this file to you under the MIT license.
44
// See the LICENSE file in the project root for full license information.
55

6-
#if HAS_WINUI
6+
#if WINUI_TARGET
77
using System;
88
using System.Diagnostics.CodeAnalysis;
99
using Microsoft.UI.Xaml;

src/ReactiveUI.Maui/Common/RoutedViewHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// The .NET Foundation licenses this file to you under the MIT license.
44
// See the LICENSE file in the project root for full license information.
55

6-
#if HAS_WINUI
6+
#if WINUI_TARGET
77
using System;
88
using System.Collections.Generic;
99
using System.Diagnostics.CodeAnalysis;

src/ReactiveUI.Maui/Common/ViewModelViewHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// The .NET Foundation licenses this file to you under the MIT license.
44
// See the LICENSE file in the project root for full license information.
55

6-
#if HAS_WINUI
6+
#if WINUI_TARGET
77
using System;
88
using System.Diagnostics.CodeAnalysis;
99
using System.Reactive;

src/ReactiveUI.Maui/ReactiveUI.Maui.csproj

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
<PackageDescription>Contains the ReactiveUI platform specific extensions for Microsoft Maui</PackageDescription>
77
<PackageTags>mvvm;reactiveui;rx;reactive extensions;observable;LINQ;events;frp;maui;android;ios;mac;forms;net</PackageTags>
88
<UseMaui>true</UseMaui>
9+
<DefineConstants>IS_MAUI</DefineConstants>
910
</PropertyGroup>
1011

1112
<PropertyGroup Condition="$(TargetFramework.EndsWith('-windows10.0.19041.0'))">
12-
<DefineConstants>HAS_WINUI</DefineConstants>
13-
</PropertyGroup>
14-
<PropertyGroup Condition="!$(TargetFramework.EndsWith('-windows10.0.19041.0'))">
15-
<DefineConstants>HAS_MAUI</DefineConstants>
13+
<DefineConstants>$(DefineConstants);WINUI_TARGET;</DefineConstants>
1614
</PropertyGroup>
1715

1816
<ItemGroup Condition="$(TargetFramework.EndsWith('-windows10.0.19041.0'))">
@@ -26,8 +24,5 @@
2624
<ItemGroup>
2725
<Compile Remove="Common\RoutedViewHost.cs" />
2826
</ItemGroup>
29-
<ItemGroup>
30-
<ProjectReference Include="..\ReactiveUI\ReactiveUI.csproj" />
31-
</ItemGroup>
3227

3328
</Project>

src/ReactiveUI.Maui/Registrations.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55

66
using System;
77

8-
#if HAS_WINUI
8+
#if WINUI_TARGET
99
using System.Reactive.Concurrency;
1010
using Splat;
11+
#endif
1112

13+
#if IS_WINUI
1214
namespace ReactiveUI.WinUI;
1315
#endif
14-
#if HAS_MAUI
16+
#if IS_MAUI
1517
namespace ReactiveUI.Maui;
1618
#endif
1719

@@ -37,7 +39,7 @@ public void Register(Action<Func<object>, Type> registerFunction)
3739
registerFunction(() => new ActivationForViewFetcher(), typeof(IActivationForViewFetcher));
3840
registerFunction(() => new BooleanToVisibilityTypeConverter(), typeof(IBindingTypeConverter));
3941

40-
#if HAS_WINUI
42+
#if WINUI_TARGET
4143
registerFunction(() => new PlatformOperations(), typeof(IPlatformOperations));
4244
registerFunction(() => new DependencyObjectObservableForProperty(), typeof(ICreatesObservableForProperty));
4345
registerFunction(() => new AutoDataTemplateBindingHook(), typeof(IPropertyBindingHook));

src/ReactiveUI.Maui/WinUI/DependencyObjectObservableForProperty.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// The .NET Foundation licenses this file to you under the MIT license.
44
// See the LICENSE file in the project root for full license information.
55

6-
#if HAS_WINUI
6+
#if WINUI_TARGET
77
using System;
88
using System.Globalization;
99
using System.Linq.Expressions;

0 commit comments

Comments
 (0)