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

housekeeping: Move UI functionality to Splat.Drawing #403

Merged
merged 5 commits into from
Sep 20, 2019
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
2 changes: 1 addition & 1 deletion build.cake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#load nuget:https://www.myget.org/F/reactiveui?package=ReactiveUI.Cake.Recipe&prerelease
#load nuget:https://pkgs.dev.azure.com/dotnet/ReactiveUI/_packaging/ReactiveUI/nuget/v3/index.json?package=ReactiveUI.Cake.Recipe&prerelease

Environment.SetVariableNames();

Expand Down
16 changes: 7 additions & 9 deletions src/Directory.build.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,19 @@
</PropertyGroup>

<ItemGroup Condition="$(IsTestProject)">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.console" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="Xunit.StaFact" Version="0.3.18" />
<PackageReference Include="Shouldly" Version="4.0.0-beta0002" />
<PackageReference Include="Microsoft.Reactive.Testing" Version="4.1.6" />
<PackageReference Include="PublicApiGenerator" Version="9.3.0" />
</ItemGroup>

<ItemGroup Condition="$(IsTestProject)">
<Compile Include="$(MSBuildThisFileDirectory)ApiGeneratorGlobalSuppressions.cs" />
</ItemGroup>

<ItemGroup Condition="$(IsTestProject) and !$(TargetFramework.StartsWith('netstandard'))">
<PackageReference Include="xunit.runner.console" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
</ItemGroup>

<ItemGroup Condition="'$(IsTestProject)' != 'true' and '$(SourceLinkEnabled)' != 'false'">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19367-01" PrivateAssets="All" />
</ItemGroup>
Expand All @@ -69,8 +68,7 @@
<ItemGroup>
<PackageReference Include="stylecop.analyzers" Version="1.1.118" PrivateAssets="all" />
<PackageReference Include="Roslynator.Analyzers" Version="2.1.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.3" PrivateAssets="all" />
<PackageReference Condition="'$(OS)' == 'Windows_NT'" Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.4" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Link="stylecop.json" />
Expand Down
10 changes: 10 additions & 0 deletions src/Directory.build.targets
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
<Project>
<PropertyGroup>
<Product>$(AssemblyName) ($(TargetFramework))</Product>
<AndroidUseIntermediateDesignerFile>true</AndroidUseIntermediateDesignerFile>
</PropertyGroup>

<PropertyGroup Condition="$(TargetFramework.StartsWith('netcoreapp'))">
<DefineConstants>$(DefineConstants);NETCOREAPP</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith('netcoreapp2'))">
<DefineConstants>$(DefineConstants);NETCOREAPP2</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith('netcoreapp3'))">
<DefineConstants>$(DefineConstants);NETCOREAPP3</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith('net4'))">
<DefineConstants>$(DefineConstants);NET_45;XAML</DefineConstants>
</PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Splat.Android.Tests/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class MainActivity : RunnerActivity
/// <inheritdoc/>
protected override void OnCreate(Bundle bundle)
{
Locator.CurrentMutable.RegisterPlatformBitmapLoader();
AddExecutionAssembly(typeof(ExtensibilityPointFactory).Assembly);

AddTestAssembly(typeof(Splat.Tests.LocatorTests).Assembly);
Expand Down
4 changes: 2 additions & 2 deletions src/Splat.Android.Tests/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="Splat.Android.Tests" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="27" />
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="Splat.Android.Tests" android:versionCode="1" android:versionName="1.0" android:installLocation="preferExternal">
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="28" />
<application android:label="Splat.Android.Tests" android:icon="@drawable/Icon"></application>
</manifest>
10 changes: 7 additions & 3 deletions src/Splat.Android.Tests/Splat.Android.Runner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v8.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v9.0</TargetFrameworkVersion>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<CopyNuGetImplementations>true</CopyNuGetImplementations>
<NoStdLib>false</NoStdLib>
Expand Down Expand Up @@ -71,13 +71,17 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms">
<Version>4.2.0.778463</Version>
<Version>4.*</Version>
</PackageReference>
<PackageReference Include="xunit.runner.devices">
<Version>2.5.25</Version>
<Version>2.*</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Splat.Drawing\Splat.Drawing.csproj">
<Project>{694d2813-14ff-456a-b1e7-c5bb82aee400}</Project>
<Name>Splat.Drawing</Name>
</ProjectReference>
<ProjectReference Include="..\Splat.Tests\Splat.Tests.csproj">
<Project>{6cad2584-aa69-4a36-8ad4-a90d040003ca}</Project>
<Name>Splat.Tests</Name>
Expand Down
3 changes: 0 additions & 3 deletions src/Splat.Autofac.Tests/DependencyResolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
// See the LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Autofac;
using Shouldly;
using Splat.Common.Test;
Expand Down
2 changes: 1 addition & 1 deletion src/Splat.Autofac.Tests/Splat.Autofac.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TargetFrameworks);net472</TargetFrameworks>

<IsPackable>false</IsPackable>
<NoWarn>$(NoWarn);1591;CA1707;SA1633</NoWarn>
<NoWarn>$(NoWarn);1591;CA1707;SA1633;CA2000</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
11 changes: 10 additions & 1 deletion src/Splat.Autofac/SplatAutofacExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,23 @@ public static class SplatAutofacExtensions
/// Initializes an instance of <see cref="AutofacDependencyResolver"/> that overrides the default <see cref="Locator"/>.
/// </summary>
/// <param name="componentContext">Autofac component context.</param>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "Dispose handled by locator.")]
public static void UseAutofacDependencyResolver(this IComponentContext componentContext) =>
Locator.SetLocator(new AutofacDependencyResolver(componentContext));

/// <summary>
/// Initializes an instance of <see cref="AutofacDependencyResolver"/> that overrides the default <see cref="Locator"/>.
/// </summary>
/// <param name="containerBuilder">Autofac container builder.</param>
public static void UseAutofacDependencyResolver(this ContainerBuilder containerBuilder) =>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "Dispose handled by locator.")]
public static void UseAutofacDependencyResolver(this ContainerBuilder containerBuilder)
{
if (containerBuilder is null)
{
throw new ArgumentNullException(nameof(containerBuilder));
}

Locator.SetLocator(new AutofacDependencyResolver(containerBuilder.Build()));
}
}
}
1 change: 1 addition & 0 deletions src/Splat.Common.Test/IScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Splat.Common.Test
/// <summary>
/// Represents a screen.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1040:Avoid empty interfaces", Justification = "For mocks only.")]
public interface IScreen
{
}
Expand Down
4 changes: 2 additions & 2 deletions src/Splat.Common.Test/IViewFor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Splat.Common.Test
/// Represents a view bound to a view model.
/// </summary>
/// <typeparam name="T">The view model type.</typeparam>
/// <seealso cref="Splat.Common.Testing.IViewFor" />
/// <seealso cref="Splat.Common.Test.IViewFor" />
public interface IViewFor<T> : IViewFor
{
/// <summary>
Expand All @@ -22,7 +22,7 @@ public interface IViewFor<T> : IViewFor
/// <summary>
/// Represents a view bound to a view model.
/// </summary>
/// <seealso cref="Splat.Common.Testing.IViewFor" />
/// <seealso cref="Splat.Common.Test.IViewFor" />
public interface IViewFor
{
/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/Splat.Common.Test/Splat.Common.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TargetFrameworks);net472</TargetFrameworks>
<NoWarn>$(NoWarn);CA2000</NoWarn>
</PropertyGroup>

</Project>
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

namespace Splat
{
Expand Down Expand Up @@ -397,7 +396,7 @@ public partial struct SplatColor
public static SplatColor LightYellow => KnownColors.FromKnownColor(KnownColor.LightYellow);

/// <summary>
/// Gets a color which is lime
/// Gets a color which is lime.
/// </summary>
public static SplatColor Lime => KnownColors.FromKnownColor(KnownColor.Lime);

Expand Down Expand Up @@ -432,7 +431,7 @@ public partial struct SplatColor
public static SplatColor MediumBlue => KnownColors.FromKnownColor(KnownColor.MediumBlue);

/// <summary>
/// Gets a color which is medium orchird.
/// Gets a color which is medium orchid.
/// </summary>
public static SplatColor MediumOrchid => KnownColors.FromKnownColor(KnownColor.MediumOrchid);

Expand Down Expand Up @@ -537,7 +536,7 @@ public partial struct SplatColor
public static SplatColor PaleGreen => KnownColors.FromKnownColor(KnownColor.PaleGreen);

/// <summary>
/// Gets a color which is pale turqoise.
/// Gets a color which is pale turquoise.
/// </summary>
public static SplatColor PaleTurquoise => KnownColors.FromKnownColor(KnownColor.PaleTurquoise);

Expand Down Expand Up @@ -567,7 +566,7 @@ public partial struct SplatColor
public static SplatColor Pink => KnownColors.FromKnownColor(KnownColor.Pink);

/// <summary>
/// Gets a color which is plum
/// Gets a color which is plum.
/// </summary>
public static SplatColor Plum => KnownColors.FromKnownColor(KnownColor.Plum);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,20 @@ public static SplatColor FromKnownColor(KnownColor color)
/// </summary>
/// <param name="name">The name of the color to generate.</param>
/// <returns>The generated SplatValue.</returns>
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Logs message but a non-failing operation.")]
public static SplatColor FromName(string name)
{
try
{
KnownColor kc = (KnownColor)Enum.Parse(typeof(KnownColor), name, true);
return FromKnownColor(kc);
}
catch
catch (Exception ex)
{
LogHost.Default.Debug(ex, "Unable to parse the known colour name.");

// This is what it returns!
SplatColor d = FromArgb(0, 0, 0, 0);
var d = FromArgb(0, 0, 0, 0);
d._name = name;
d._state |= (short)ColorType.Named;
return d;
Expand Down
98 changes: 98 additions & 0 deletions src/Splat.Drawing/DefaultPlatformModeDetector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.IO;
using System.Linq;
using System.Reflection;

#if NETFX_CORE
using System.Threading;
using System.Threading.Tasks;
using Windows.ApplicationModel;
#endif

namespace Splat
{
/// <summary>
/// Detects if we are in design mode or unit test mode based on the current platform.
/// </summary>
public class DefaultPlatformModeDetector : IPlatformModeDetector
{
#if !NETFX_CORE
private const string XamlDesignPropertiesType = "System.ComponentModel.DesignerProperties, System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e";
private const string XamlControlBorderType = "System.Windows.Controls.Border, System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e";
private const string XamlDesignPropertiesDesignModeMethodName = "GetIsInDesignMode";
private const string WpfDesignerPropertiesType = "System.ComponentModel.DesignerProperties, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
private const string WpfDesignerPropertiesDesignModeMethod = "GetIsInDesignMode";
private const string WpfDependencyPropertyType = "System.Windows.DependencyObject, WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
private const string WinFormsDesignerPropertiesType = "Windows.ApplicationModel.DesignMode, Windows, ContentType=WindowsRuntime";
private const string WinFormsDesignerPropertiesDesignModeMethod = "DesignModeEnabled";

private static bool? _cachedInDesignModeResult;
#endif

/// <inheritdoc />
public bool? InDesignMode()
{
#if NETFX_CORE
return DesignMode.DesignModeEnabled;
#else
if (_cachedInDesignModeResult.HasValue)
{
return _cachedInDesignModeResult.Value;
}

// Check Silverlight / WP8 Design Mode
var type = Type.GetType(XamlDesignPropertiesType, false);
if (type != null)
{
var mInfo = type.GetMethod(XamlDesignPropertiesDesignModeMethodName);
var dependencyObject = Type.GetType(XamlControlBorderType, false);

if (dependencyObject != null)
{
_cachedInDesignModeResult = (bool)mInfo.Invoke(null, new object[] { Activator.CreateInstance(dependencyObject) });
}
}
else if ((type = Type.GetType(WpfDesignerPropertiesType, false)) != null)
{
// loaded the assembly, could be .net
var mInfo = type.GetMethod(WpfDesignerPropertiesDesignModeMethod);
var dependencyObject = Type.GetType(WpfDependencyPropertyType, false);
if (dependencyObject != null)
{
_cachedInDesignModeResult = (bool)mInfo.Invoke(null, new object[] { Activator.CreateInstance(dependencyObject) });
}
}
else if ((type = Type.GetType(WinFormsDesignerPropertiesType, false)) != null)
{
// check WinRT next
_cachedInDesignModeResult = (bool)type.GetProperty(WinFormsDesignerPropertiesDesignModeMethod).GetMethod.Invoke(null, null);
}
else
{
var designEnvironments = new[] { "BLEND.EXE", "XDESPROC.EXE" };

var entry = Assembly.GetEntryAssembly();
if (entry != null)
{
var exeName = new FileInfo(entry.Location).Name;

if (designEnvironments.Any(x =>
x.IndexOf(exeName, StringComparison.InvariantCultureIgnoreCase) != -1))
{
_cachedInDesignModeResult = true;
}
}
}

_cachedInDesignModeResult = false;

return _cachedInDesignModeResult;
#endif
}
}
}
19 changes: 19 additions & 0 deletions src/Splat.Drawing/IPlatformModeDetector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

namespace Splat
{
/// <summary>
/// Detects properties about the current platform.
/// </summary>
public interface IPlatformModeDetector
{
/// <summary>
/// Gets a value indicating whether the current library or application is running in a GUI design mode tool.
/// </summary>
/// <returns>If we are currently running in design mode.</returns>
bool? InDesignMode();
}
}
Loading