Skip to content

Commit

Permalink
Fixed issue on iOS and other minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
xperiandri committed Jun 2, 2021
1 parent 1173782 commit 8706b7c
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DisposableFixer" Version="3.3.0" />
<PackageReference Include="Elmish.Uno" Version="1.0.0-ci-*" />
<PackageReference Include="Elmish" Version="3.1.0" />
<PackageReference Include="FSharp.Core" Version="5.0.*" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
Expand Down
47 changes: 15 additions & 32 deletions src/Templates/SolutionTemplate/SolutionTemplate.Shared/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
Expand All @@ -20,50 +18,45 @@

using AppProgram = SolutionTemplate.Programs.App.Program;

//-:cnd:noEmit
namespace SolutionTemplate
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public sealed partial class App : Application
{


private readonly IServiceProvider serviceProvider;
#pragma warning disable IDE0044 // Add readonly modifier
private IServiceScope scope;
#pragma warning restore IDE0044 // Add readonly modifier
private readonly Lazy<Shell> shell = new Lazy<Shell>();

//-:cnd:noEmit
#if NET5_0 && WINDOWS
private Window window;

#else
private Windows.UI.Xaml.Window window;
#endif
//+:cnd:noEmit

internal IServiceProvider ServiceProvider => scope.ServiceProvider;

/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
InitializeLogging();
var hostBuilder =
Host.CreateDefaultBuilder()
.ConfigureServices(ConfigureServices)
;
this.InitializeComponent();

var hostBuilder = Host.CreateDefaultBuilder().ConfigureServices(ConfigureServices);
serviceProvider = hostBuilder.Build().Services;
scope = serviceProvider.CreateScope();
this.InitializeComponent();
//-:cnd:noEmit

#if HAS_UNO || NETFX_CORE
this.Suspending += OnSuspending;
#endif
//+:cnd:noEmit
}

private void ConfigureServices(HostBuilderContext ctx, IServiceCollection services) =>
Expand All @@ -82,10 +75,10 @@ private void ConfigureServices(HostBuilderContext ctx, IServiceCollection servic
/// will be used such as when the application is launched to open a specific file.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
#pragma warning disable CA1062 // Validate arguments of public methods
#pragma warning disable CA1725 // Parameter names should match base declaration
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
//-:cnd:noEmit
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
Expand All @@ -99,25 +92,17 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
#else
window = Windows.UI.Xaml.Window.Current;
#endif
//+:cnd:noEmit
var shell = this.shell.Value;
// Get a Frame to act as the navigation context and navigate to the first page
var rootFrame = shell.RootFrame;

// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame.Content == null)
{
// Create a Frame to act as the navigation context and navigate to the first page

shell = new Shell();
rootFrame = shell.RootFrame;
var viewModel = ServiceProvider.GetRequiredService<AppProgram>();
Elmish.Uno.ViewModel.StartLoop(Host.ElmConfig, shell, Elmish.ProgramModule.run, viewModel.Program);

//rootFrame.NavigationFailed += OnNavigationFailed;

Windows.UI.Xaml.Window.Current.Content = shell;

#pragma warning disable CA1062 // Validate arguments of public methods
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
#pragma warning restore CA1062 // Validate arguments of public methods
Expand All @@ -128,11 +113,10 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
// Place the frame in the current Window
window.Content = shell;
}
//-:cnd:noEmit

#if !(NET5_0 && WINDOWS)
if (e.PrelaunchActivated == false)
if (!e.PrelaunchActivated)
#endif
//+:cnd:noEmit
{
if (rootFrame.Content == null)
{
Expand All @@ -145,6 +129,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
window.Activate();
}
}
#pragma warning restore CA1062 // Validate arguments of public methods
#pragma warning restore CA1725 // Parameter names should match base declaration

/// <summary>
Expand All @@ -168,19 +153,16 @@ private static void InitializeLogging()
{
var factory = LoggerFactory.Create(builder =>
{
//-:cnd:noEmit
#if __WASM__
builder.AddProvider(new global::Uno.Extensions.Logging.WebAssembly.WebAssemblyConsoleLoggerProvider());
#elif __IOS__
#pragma warning disable DF0000 // Marks undisposed anonymous objects from object creations.
builder.AddProvider(new global::Uno.Extensions.Logging.OSLogLoggerProvider());
#pragma warning restore DF0000 // Marks undisposed anonymous objects from object creations.
#elif NETFX_CORE
builder.AddDebug();
#else
builder.AddConsole();
#endif
//+:cnd:noEmit

// Exclude logs below this level
builder.SetMinimumLevel(LogLevel.Information);

Expand Down Expand Up @@ -221,3 +203,4 @@ private static void InitializeLogging()
}
}
}
//+:cnd:noEmit
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<Page
<Page
x:Class="SolutionTemplate.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:SolutionTemplate"
xmlns:unotookit="using:Uno.UI.Toolkit"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">

<Grid>
<Grid unotookit:VisibleBoundsPadding.PaddingMask="All">
<TextBlock Text="{Binding Text}" />
</Grid>
</Page>
19 changes: 10 additions & 9 deletions src/Templates/SolutionTemplate/SolutionTemplate.Shared/Shell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
x:Class="SolutionTemplate.Shell"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Custom="using:Microsoft.Toolkit.Uwp.UI.Triggers"
xmlns:Custom1="using:Microsoft.Toolkit.Uwp.UI.Converters"
xmlns:Custom2="using:SolutionTemplate.Converter"
xmlns:conv="using:SolutionTemplate.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:SolutionTemplate"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:tconv="using:Microsoft.Toolkit.Uwp.UI.Converters"
xmlns:tctrl="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:ttrig="using:Microsoft.Toolkit.Uwp.UI.Triggers"
xmlns:textensions="using:Microsoft.Toolkit.Uwp.UI.Extensions"
x:Name="shell"
d:DesignHeight="300"
d:DesignWidth="400"
NavigationFailedCommand="{Binding Notifications.NavigationFailedCommand}"
mc:Ignorable="d">
<local:ShellBase.Resources>
<conv:StringToSeverityConverter x:Key="StringToSeverityConverter" />
<XamlUICommand
x:Key="RemoveNotificationCommand"
Command="{Binding DataContext.Notifications.RemoveNotificationCommand, ElementName=shell}"
Expand All @@ -31,7 +31,7 @@
IsIconVisible="True"
IsOpen="{Binding IsOpen}"
Message="{Binding Text}"
Severity="{Binding Type, Converter={StaticResource StringToSeverityConvector}}" />
Severity="{Binding Type, Converter={StaticResource StringToSeverityConverter}}" />
</Grid>
</DataTemplate>
</local:ShellBase.Resources>
Expand All @@ -50,11 +50,12 @@
Grid.Row="1"
ItemTemplate="{StaticResource NotificationItemTemplate}"
ItemsSource="{Binding Notifications.Notifications}" />
<!--<VisualStateManager.VisualStateGroups>

<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="NetworkStateGroup">
<VisualState x:Name="Connected">
<VisualState.StateTriggers>
<Custom:NetworkConnectionStateTrigger ConnectionState="Connected" />
<ttrig:NetworkConnectionStateTrigger ConnectionState="Connected" />
</VisualState.StateTriggers>
</VisualState>
<VisualState x:Name="Disconnected">
Expand All @@ -64,11 +65,11 @@
<Setter Target="shell.(extensions:ApplicationViewExtensions.Title)" Value="Отсутствует подключение к сети" />
</VisualState.Setters>
<VisualState.StateTriggers>
<Custom:NetworkConnectionStateTrigger ConnectionState="Disconnected" />
<ttrig:NetworkConnectionStateTrigger ConnectionState="Disconnected" />
</VisualState.StateTriggers>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>-->
</VisualStateManager.VisualStateGroups>
</Grid>

</local:ShellBase>
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
<UpToDateCheckInput Include="..\SolutionTemplate.Shared\**\*.xaml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Elmish" Version="3.1.0" />
<PackageReference Include="Elmish.Uno" Version="1.0.0-ci-*" />
<PackageReference Include="FSharp.Core" Version="5.0.*" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
<UpToDateCheckInput Include="..\SolutionTemplate.Shared\**\*.xaml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Elmish" Version="3.1.0" />
<PackageReference Include="Elmish.Uno" Version="1.0.0-ci-*" />
<PackageReference Include="FSharp.Core" Version="5.0.*" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
<NoWarn>NU1701;NU1702</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Elmish" Version="3.1.0" />
<PackageReference Include="Elmish.Uno" Version="1.0.0-ci-*" />
<PackageReference Include="FSharp.Core" Version="5.0.*" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
<NoWarn>NU1701;NU1702;DF0033</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Elmish" Version="3.1.0" />
<PackageReference Include="Elmish.Uno" Version="1.0.0-ci-*" />
<PackageReference Include="FSharp.Core" Version="5.0.*" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
-->
<Version>6.2.11</Version>
</PackageReference>
<PackageReference Include="Elmish" Version="3.1.0" />
<PackageReference Include="Elmish.Uno" Version="1.0.0-ci-*" />
<PackageReference Include="FSharp.Core" Version="5.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="5.0.0" />
<PackageReference Include="Microsoft.Toolkit" Version="7.0.*" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@
<None Include="wwwroot\web.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Elmish" Version="3.1.0" />
<PackageReference Include="Elmish.Uno" Version="1.0.0-ci-*" />
<PackageReference Include="FSharp.Core" Version="5.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.*" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="5.0.*" />
<PackageReference Include="Uno.Extensions.Logging.WebAssembly.Console" Version="1.0.*" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@
<Reference Include="Xamarin.iOS" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Elmish" Version="3.1.0" />
<PackageReference Include="Elmish.Uno" Version="1.0.0-ci-*" />
<PackageReference Include="FSharp.Core" Version="5.0.*" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Uno.Extensions.Logging.OSLog " Version="1.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@
<Reference Include="System.Memory" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DisposableFixer" Version="3.3.0" />
<PackageReference Include="Elmish" Version="3.1.0" />
<PackageReference Include="Elmish.Uno" Version="1.0.0-ci-*" />
<PackageReference Include="FSharp.Core" Version="5.0.*" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
Expand Down

0 comments on commit 8706b7c

Please sign in to comment.