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

feat: Adding reactive flag #881

Merged
merged 2 commits into from
Nov 2, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"longName": "tests",
"shortName": "tests"
},
"reactive": {
"longName": "reactive",
"shortName": "reactive"
},
"wasm-pwa-manifest": {
"longName": "wasm-pwa-manifest",
"shortName": "pwa"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@
},
"defaultValue": "true",
"isVisible":true
},
{
"id": "Reactive",
"name": {
"text": "Data - Reactive Extensions"
},
"description":
{
"text": "Uses Reactive extensions"
},
"defaultValue": "true",
"isVisible":true
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@
"defaultValue": "true",
"description": "Includes unit and UI test projects"
},
"reactive": {
"type": "parameter",
"dataType": "bool",
"defaultValue": "true",
"description": "Whether or not to use Reactive extensions"
},
"mobile": {
"type": "computed",
"dataType": "bool",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<NoWarn>$(NoWarn);Uno0001;CS1998;CA1416;NU1507</NoWarn>
<DefineConstants>$(DefineConstants);REACTIVE</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Project ToolsVersion="15.0">
<ItemGroup>
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.0.0" />
<PackageVersion Include="coverlet.collector" Version="3.1.0" />
<PackageVersion Include="FluentAssertions" Version="6.7.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//-:cnd:noEmit

namespace MyExtensionsApp;

public sealed partial class App : Application
Expand Down Expand Up @@ -46,7 +45,13 @@ private static IHost BuildAppHost()


// Enable navigation, including registering views and viewmodels
.UseNavigation(ReactiveViewModelMappings.ViewModelMappings, RegisterRoutes)
.UseNavigation(
//+:cnd:noEmit
#if(reactive)
ReactiveViewModelMappings.ViewModelMappings,
#endif
//-:cnd:noEmit
RegisterRoutes)

// Add navigation support for toolkit controls such as TabBar and NavigationView
.UseToolkitNavigation()
Expand All @@ -57,18 +62,18 @@ private static IHost BuildAppHost()
private static void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
{
views.Register(
new ViewMap(ViewModel: typeof(ShellViewModel)),
new ViewMap<MainPage, MainViewModel>(),
new ViewMap<SecondPage, SecondViewModel>()
new ViewMap(ViewModel: typeof(ShellModel)),
new ViewMap<MainPage, MainModel>(),
new DataViewMap<SecondPage, SecondModel, Entity>()
);

routes
.Register(
new RouteMap("", View: views.FindByViewModel<ShellViewModel>(),
new RouteMap("", View: views.FindByViewModel<ShellModel>(),
Nested: new RouteMap[]
{
new RouteMap("Main", View: views.FindByViewModel<MainViewModel>()),
new RouteMap("Second", View: views.FindByViewModel<SecondViewModel>()),
new RouteMap("Main", View: views.FindByViewModel<MainModel>()),
new RouteMap("Second", View: views.FindByViewModel<SecondModel>()),
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
xmlns:uen="using:Uno.Extensions.Navigation.UI"
xmlns:utu="using:Uno.Toolkit.UI"
xmlns:not_skia="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
NavigationCacheMode="Required"
Background="{ThemeResource BackgroundBrush}">

<Grid>
Expand All @@ -16,11 +17,16 @@
<RowDefinition />
</Grid.RowDefinitions>
<utu:NavigationBar Content="{Binding Title}" />
<Button Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="Go to Second Page"
not_skia:AutomationProperties.AutomationId="SecondPageButton"
Command="{Binding GoToSecond}"/>

<StackPanel Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<TextBox Text="{Binding Name, Mode=TwoWay}"
PlaceholderText="Enter your name:"
Margin="8" />
<Button Content="Go to Second Page"
not_skia:AutomationProperties.AutomationId="SecondPageButton"
Command="{Binding GoToSecond}" />
</StackPanel>
</Grid>
</Page>
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@
</AppBarButton>
</utu:NavigationBar.MainCommand>
</utu:NavigationBar>

<TextBlock Text="{Binding Entity.Name}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
/>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//-:cnd:noEmit

namespace MyExtensionsApp.Business.Models;

public record Entity(string Name);
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Uno.Extensions.Authentication" />
<PackageReference Include="Uno.Extensions.Configuration" />
<PackageReference Include="Uno.Extensions.Core" />
<PackageReference Include="Uno.Extensions.Hosting" />
<PackageReference Include="Uno.Extensions.Http" />
<PackageReference Include="Uno.Extensions.Http.Refit" />
<PackageReference Include="Uno.Extensions.Localization" />
<PackageReference Include="Uno.Extensions.Logging.Serilog" />
<PackageReference Include="Uno.Extensions.Navigation" />
<PackageReference Include="Uno.Extensions.Serialization" />
<PackageReference Include="Uno.Extensions.Serialization.Http" />
<PackageReference Include="Uno.Extensions.Serialization.Refit" />
<PackageReference Include="Uno.Extensions.Reactive" />
<PackageReference Include="Uno.Extensions.Reactive.WinUI" />
</ItemGroup>

<ItemGroup>
<!--#if (!reactive) -->
<PackageReference Include="CommunityToolkit.Mvvm" />
<!--#endif -->

<PackageReference Include="Uno.Extensions.Authentication" />
<PackageReference Include="Uno.Extensions.Configuration" />
<PackageReference Include="Uno.Extensions.Core" />
<PackageReference Include="Uno.Extensions.Hosting" />
<PackageReference Include="Uno.Extensions.Http" />
<PackageReference Include="Uno.Extensions.Http.Refit" />
<PackageReference Include="Uno.Extensions.Localization" />
<PackageReference Include="Uno.Extensions.Logging.Serilog" />
<PackageReference Include="Uno.Extensions.Navigation" />
<PackageReference Include="Uno.Extensions.Serialization" />
<PackageReference Include="Uno.Extensions.Serialization.Http" />
<PackageReference Include="Uno.Extensions.Serialization.Refit" />
<PackageReference Include="Uno.Extensions.Reactive" />
<PackageReference Include="Uno.Extensions.Reactive.WinUI" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//+:cnd:noEmit
nickrandolph marked this conversation as resolved.
Show resolved Hide resolved
#if(reactive)
using Uno.Extensions.Reactive;
#else
using System.Windows.Input;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
#endif

namespace MyExtensionsApp.Presentation;

#if (reactive)
public partial class MainModel
{
public string? Title { get; }

public IState<string> Name { get; }

public MainModel(
INavigator navigator,
IOptions<AppConfig> appInfo)
{

_navigator = navigator;
Title = $"Main - {appInfo?.Value?.Title}";

Name = State<string>.Value(this, ()=>"");
}

public async Task GoToSecond()
{
var name = await Name;
await _navigator.NavigateViewModelAsync<SecondModel>(this, data: new Entity(name!));
}

private INavigator _navigator;
}
#else
public partial class MainModel:ObservableObject
{
public string? Title { get; }

[ObservableProperty]
private string? name;

public ICommand GoToSecond { get; }

public MainModel(
INavigator navigator,
IOptions<AppConfig> appInfo)
{

_navigator = navigator;
Title = $"Main - {appInfo?.Value?.Title}";

GoToSecond = new AsyncRelayCommand(GoToSecondView);
}

public async Task GoToSecondView()
{
await _navigator.NavigateViewModelAsync<SecondModel>(this, data: new Entity(Name!));
}

private INavigator _navigator;
}
#endif

//-:cnd:noEmit

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//-:cnd:noEmit

namespace MyExtensionsApp.Presentation;

public partial record SecondModel (Entity Entity)
{
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace MyExtensionsApp.Presentation;

public class ShellViewModel
public class ShellModel
{
private INavigator Navigator { get; }


public ShellViewModel(
public ShellModel(
INavigator navigator)
{

Expand All @@ -18,6 +18,6 @@ public ShellViewModel(

public async Task Start()
{
await Navigator.NavigateViewModelAsync<MainViewModel>(this);
await Navigator.NavigateViewModelAsync<MainModel>(this);
}
}