Skip to content

Commit 17ab166

Browse files
authored
Add Feature to MAUI (#3475)
1 parent 544e204 commit 17ab166

File tree

7 files changed

+176
-13
lines changed

7 files changed

+176
-13
lines changed

src/Directory.build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@
4848
<PackageReference Include="xunit.runner.console" Version="2.4.2" />
4949
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
5050
<PackageReference Include="Xunit.StaFact" Version="1.1.11" />
51-
<PackageReference Include="FluentAssertions" Version="6.9.0" />
51+
<PackageReference Include="FluentAssertions" Version="6.10.0" />
5252
<PackageReference Include="Microsoft.Reactive.Testing" Version="5.0.0" />
5353
<PackageReference Include="PublicApiGenerator" Version="10.3.0" />
5454
<PackageReference Include="coverlet.msbuild" Version="3.2.0" PrivateAssets="All" />
55-
<PackageReference Include="Verify.Xunit" Version="19.8.1" />
55+
<PackageReference Include="Verify.Xunit" Version="19.9.3" />
5656
</ItemGroup>
5757

5858
<ItemGroup Condition="'$(IsTestProject)' != 'true'">

src/ReactiveUI.AndroidX/ReactiveUI.AndroidX.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
</ItemGroup>
1717

1818
<ItemGroup>
19-
<PackageReference Include="Xamarin.AndroidX.Core" Version="1.9.0.1" />
20-
<PackageReference Include="Xamarin.AndroidX.Preference" Version="1.2.0.3" />
21-
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.Core.UI" Version="1.0.0.16" />
22-
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.7.0.1" />
23-
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.5.1.1" />
19+
<PackageReference Include="Xamarin.AndroidX.Core" Version="1.9.0.2" />
20+
<PackageReference Include="Xamarin.AndroidX.Preference" Version="1.2.0.4" />
21+
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.Core.UI" Version="1.0.0.17" />
22+
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.7.0.2" />
23+
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.5.1.2" />
2424
<PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.3.0" />
2525
<Reference Include="System.Runtime.Serialization" />
2626
</ItemGroup>

src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@
1010
</ItemGroup>
1111

1212
<ItemGroup Condition=" $(TargetFramework.StartsWith('netstandard')) ">
13-
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.17" />
13+
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.32" />
1414
</ItemGroup>
1515

16-
<ItemGroup Condition=" $(TargetFramework.StartsWith('net6')) or $(TargetFramework.StartsWith('net7')) ">
17-
<PackageReference Include="Microsoft.AspNetCore.Components" Version="6.0.10" />
16+
<ItemGroup Condition=" $(TargetFramework.StartsWith('net6')) ">
17+
<PackageReference Include="Microsoft.AspNetCore.Components" Version="6.0.14" />
18+
</ItemGroup>
19+
20+
<ItemGroup Condition=" $(TargetFramework.StartsWith('net7')) ">
21+
<PackageReference Include="Microsoft.AspNetCore.Components" Version="7.0.3" />
1822
</ItemGroup>
1923

2024
<ItemGroup>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) 2022 .NET Foundation and Contributors. All rights reserved.
2+
// Licensed to the .NET Foundation under one or more agreements.
3+
// The .NET Foundation licenses this file to you under the MIT license.
4+
// See the LICENSE file in the project root for full license information.
5+
6+
using Microsoft.Maui.Controls;
7+
8+
namespace ReactiveUI.Maui;
9+
10+
/// <summary>
11+
/// ReactiveShell.
12+
/// </summary>
13+
/// <typeparam name="TViewModel">The type of the view model.</typeparam>
14+
/// <seealso cref="Microsoft.Maui.Controls.Shell" />
15+
/// <seealso cref="ReactiveUI.IViewFor&lt;TViewModel&gt;" />
16+
public class ReactiveShell<TViewModel> : Shell, IViewFor<TViewModel>
17+
where TViewModel : class
18+
{
19+
/// <summary>
20+
/// The view model bindable property.
21+
/// </summary>
22+
public static readonly BindableProperty ViewModelProperty = BindableProperty.Create(
23+
nameof(ViewModel),
24+
typeof(TViewModel),
25+
typeof(ReactiveShell<TViewModel>),
26+
default(TViewModel),
27+
BindingMode.OneWay,
28+
propertyChanged: OnViewModelChanged);
29+
30+
/// <summary>
31+
/// Gets or sets the ViewModel to display.
32+
/// </summary>
33+
public TViewModel? ViewModel
34+
{
35+
get => (TViewModel)GetValue(ViewModelProperty);
36+
set => SetValue(ViewModelProperty, value);
37+
}
38+
39+
/// <inheritdoc/>
40+
object? IViewFor.ViewModel
41+
{
42+
get => ViewModel;
43+
set => ViewModel = (TViewModel?)value;
44+
}
45+
46+
/// <inheritdoc/>
47+
protected override void OnBindingContextChanged()
48+
{
49+
base.OnBindingContextChanged();
50+
ViewModel = BindingContext as TViewModel;
51+
}
52+
53+
private static void OnViewModelChanged(BindableObject bindableObject, object oldValue, object newValue) => bindableObject.BindingContext = newValue;
54+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright (c) 2022 .NET Foundation and Contributors. All rights reserved.
2+
// Licensed to the .NET Foundation under one or more agreements.
3+
// The .NET Foundation licenses this file to you under the MIT license.
4+
// See the LICENSE file in the project root for full license information.
5+
6+
using System;
7+
using Microsoft.Maui.Controls;
8+
using Splat;
9+
10+
namespace ReactiveUI.Maui;
11+
12+
/// <summary>
13+
/// ReactiveShellContent.
14+
/// </summary>
15+
/// <typeparam name="TViewModel">The type of the view model.</typeparam>
16+
/// <seealso cref="Microsoft.Maui.Controls.ShellContent" />
17+
/// <seealso cref="ReactiveUI.IActivatableView" />
18+
public class ReactiveShellContent<TViewModel> : ShellContent, IActivatableView
19+
where TViewModel : class
20+
{
21+
/// <summary>
22+
/// The contract property.
23+
/// </summary>
24+
public static readonly BindableProperty ContractProperty = BindableProperty.Create(
25+
nameof(Contract),
26+
typeof(string),
27+
typeof(ReactiveShellContent<TViewModel>),
28+
null,
29+
BindingMode.Default,
30+
propertyChanged: ViewModelChanged);
31+
32+
/// <summary>
33+
/// The view model property.
34+
/// </summary>
35+
public static readonly BindableProperty ViewModelProperty = BindableProperty.Create(
36+
nameof(ViewModel),
37+
typeof(TViewModel),
38+
typeof(ReactiveShellContent<TViewModel>),
39+
default(TViewModel),
40+
BindingMode.Default,
41+
propertyChanged: ViewModelChanged);
42+
43+
/// <summary>
44+
/// Initializes a new instance of the <see cref="ReactiveShellContent{TViewModel}" /> class.
45+
/// </summary>
46+
public ReactiveShellContent()
47+
{
48+
var view = Locator.Current.GetService<IViewFor<TViewModel>>(Contract);
49+
if (view is not null)
50+
{
51+
ContentTemplate = new DataTemplate(() => view);
52+
}
53+
}
54+
55+
/// <summary>
56+
/// Gets or sets the view model.
57+
/// </summary>
58+
/// <value>
59+
/// The view model.
60+
/// </value>
61+
public TViewModel? ViewModel
62+
{
63+
get => (TViewModel)GetValue(ViewModelProperty);
64+
set => SetValue(ViewModelProperty, value);
65+
}
66+
67+
/// <summary>
68+
/// Gets or sets the contract for the view.
69+
/// </summary>
70+
/// <value>
71+
/// The contract.
72+
/// </value>
73+
public string? Contract
74+
{
75+
get => (string?)GetValue(ContractProperty);
76+
set => SetValue(ContractProperty, value);
77+
}
78+
79+
private static void ViewModelChanged(BindableObject bindable, object oldValue, object newValue)
80+
{
81+
if (Locator.Current is null)
82+
{
83+
throw new NullReferenceException(nameof(Locator.Current));
84+
}
85+
86+
if (bindable is ReactiveShellContent<TViewModel> svm)
87+
{
88+
var view = Locator.Current.GetService<IViewFor<TViewModel>>(svm.Contract);
89+
if (view is not null)
90+
{
91+
svm.ContentTemplate = new DataTemplate(() => view);
92+
}
93+
}
94+
}
95+
}

src/ReactiveUI.Tests/Platforms/winforms/API/WinformsApiApprovalTests.Winforms.DotNet6_0.verified.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
[assembly: System.Runtime.Versioning.TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName=".NET Framework 4.6.2")]
1+
[assembly: System.Runtime.Versioning.SupportedOSPlatform("Windows10.0.17763.0")]
2+
[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName=".NET 6.0")]
3+
[assembly: System.Runtime.Versioning.TargetPlatform("Windows10.0.17763.0")]
24
namespace ReactiveUI.Winforms
35
{
46
public class ActivationForViewFetcher : ReactiveUI.IActivationForViewFetcher, Splat.IEnableLogger
@@ -106,4 +108,12 @@ namespace ReactiveUI.Winforms
106108
public int GetAffinityForObject(System.Type type, string propertyName, bool beforeChanged = false) { }
107109
public System.IObservable<ReactiveUI.IObservedChange<object, object?>> GetNotificationForProperty(object sender, System.Linq.Expressions.Expression expression, string propertyName, bool beforeChanged = false, bool suppressWarnings = false) { }
108110
}
111+
}
112+
namespace System.Reactive.Concurrency
113+
{
114+
public class ControlScheduler : System.Reactive.Concurrency.LocalScheduler, System.Reactive.Concurrency.ISchedulerPeriodic { }
115+
}
116+
namespace System.Reactive.Linq
117+
{
118+
public static class ControlObservable { }
109119
}

src/ReactiveUI.Tests/ReactiveUI.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<Project Sdk="MSBuild.Sdk.Extras">
1+
<Project Sdk="MSBuild.Sdk.Extras">
22

33
<PropertyGroup>
44
<TargetFrameworks>net462;net6.0</TargetFrameworks>
5-
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net472;net6.0-windows</TargetFrameworks>
5+
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net472;net6.0-windows10.0.17763.0</TargetFrameworks>
66
<NoWarn>$(NoWarn);CS1591</NoWarn>
77
</PropertyGroup>
88

0 commit comments

Comments
 (0)