Skip to content

Commit

Permalink
feat: Adding reactive flag
Browse files Browse the repository at this point in the history
  • Loading branch information
nickrandolph committed Nov 1, 2022
1 parent 1bedf9a commit 58298c9
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 35 deletions.
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 @@ -59,7 +64,7 @@ private static void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
views.Register(
new ViewMap(ViewModel: typeof(ShellViewModel)),
new ViewMap<MainPage, MainViewModel>(),
new ViewMap<SecondPage, SecondViewModel>()
new DataViewMap<SecondPage, SecondViewModel, Entity>()
);

routes
Expand Down
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
@@ -1,24 +1,69 @@
//-:cnd:noEmit
//+:cnd:noEmit
#if(reactive)
using Uno.Extensions.Reactive;
#else
using System.Windows.Input;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
#endif

namespace MyExtensionsApp.Presentation;

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

public IState<string> Name { get; }

public MainViewModel(
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<SecondViewModel>(this, data: new Entity(name!));
}

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

[ObservableProperty]
private string? name;

public ICommand GoToSecond { get; }

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

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

GoToSecond = new AsyncRelayCommand(GoToSecondView);
}

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

private INavigator _navigator;
}
#endif

//-:cnd:noEmit

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

namespace MyExtensionsApp.Presentation;

public partial class SecondViewModel
public partial record SecondViewModel (Entity Entity)
{

public SecondViewModel()
{
}
}

0 comments on commit 58298c9

Please sign in to comment.