Skip to content

Commit

Permalink
Updated TargetFrameworks, updated to XF 4.6.0.726 and added support f…
Browse files Browse the repository at this point in the history
…or additional methods and properties from the Device class.
  • Loading branch information
rssllgrrtt committed May 2, 2020
1 parent 581c3f5 commit a27288e
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/Forms/Prism.Forms/Prism.Forms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<RootNamespace>Prism</RootNamespace>
<TargetFrameworks>netstandard2.0;MonoAndroid81</TargetFrameworks>
<TargetFrameworks>netstandard2.0;MonoAndroid90;MonoAndroid10.0</TargetFrameworks>
<Title>Prism for Xamarin.Forms</Title>
<!-- Summary is not actually supported at this time. Including the summary for future support. -->
<!--<Summary>Prism for Xamarin.Forms helps you more easily design and build rich, flexible, and easy to maintain Xamarin.Forms applications.</Summary>-->
Expand All @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="4.5.0.657" />
<PackageReference Include="Xamarin.Forms" Version="4.6.0.726" />
</ItemGroup>

<ItemGroup>
Expand Down
79 changes: 70 additions & 9 deletions src/Forms/Prism.Forms/Services/DeviceService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Prism.AppModel;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Xamarin.Forms;

Expand All @@ -19,6 +21,16 @@ public class DeviceService : IDeviceService
public const string WPF = "WPF";


/// <summary>
/// Gets a list of custom flags that were set on the device before Xamarin.Forms was initialized.
/// </summary>
public IReadOnlyList<string> Flags => Device.Flags;

/// <summary>
/// Gets the flow direction on the device.
/// </summary>
public FlowDirection FlowDirection => Device.FlowDirection;

/// <summary>
/// Gets the kind of device that Xamarin.Forms is currently working on.
/// </summary>
Expand Down Expand Up @@ -68,7 +80,38 @@ public void BeginInvokeOnMainThread(Action action)
}

/// <summary>
/// Invokes an awaitable action on the device main UI thread.
/// Returns the current SynchronizationContext from the main thread.
/// </summary>
/// <returns>The current SynchronizationContext from the main thread.</returns>
public Task<SynchronizationContext> GetMainThreadSynchronizationContextAsync()
{
return Device.GetMainThreadSynchronizationContextAsync();
}

/// <summary>
/// Returns a double that represents a font size that corresponds to size on targetElement.
/// </summary>
/// <param name="size">The named size for which to get the numeric size.</param>
/// <param name="targetElement">The element for which to calculate the numeric size.</param>
/// <returns>A double that represents a font size that corresponds to size on targetElement.</returns>
public double GetNamedSize(NamedSize size, Element targetElement)
{
return Device.GetNamedSize(size, targetElement);
}

/// <summary>
/// Returns a double that represents the named size for the font that is used on the element on the native platform.
/// </summary>
/// <param name="size">The named size for which to get the numeric size.</param>
/// <param name="targetElementType">The element type for which to calculate the numeric size.</param>
/// <returns>The named size for the font that is used on the element on the native platform.</returns>
public double GetNamedSize(NamedSize size, Type targetElementType)
{
return Device.GetNamedSize(size, targetElementType);
}

/// <summary>
/// Invokes an Action on the device main (UI) thread.
/// </summary>
/// <param name="action">The Action to invoke</param>
/// <returns>A task representing the work to be performed</returns>
Expand All @@ -78,36 +121,54 @@ public Task InvokeOnMainThreadAsync(Action action)
}

/// <summary>
/// Invokes an awaitable func of type TResult on the device main UI thread.
/// Invokes a Func on the device main (UI) thread.
/// </summary>
/// <param name="func">The func to invoke</param>
/// <typeparam name="T">The return type of the task</typeparam>
/// <param name="func">The Func to invoke.</param>
/// <typeparam name="T">The return type of the Func.</typeparam>
/// <returns>A task of type T representing the work to be performed</returns>
public Task<T> InvokeOnMainThreadAsync<T>(Func<T> func)
{
return Device.InvokeOnMainThreadAsync(func);
}

/// <summary>
/// Invokes an awaitable func of type Task TResult on the device main UI thread.
/// Invokes a Func on the device main (UI) thread.
/// </summary>
/// <param name="funcTask">The func to invoke</param>
/// <typeparam name="T">The return type of the task</typeparam>
/// <param name="funcTask">The return type of the Func.</param>
/// <typeparam name="T">The return type of the Func.</typeparam>
/// <returns>A task of type T representing the work to be performed</returns>
public Task<T> InvokeOnMainThreadAsync<T>(Func<Task<T>> funcTask)
{
return Device.InvokeOnMainThreadAsync(funcTask);
}

/// <summary>
/// Invokes an awaitable func of type Task on the device main UI thread.
/// Invokes a Func on the device main (UI) thread.
/// </summary>
/// <param name="funcTask">The func to invoke</param>
/// <param name="funcTask">The Func to invoke.</param>
/// <returns>A task representing the work to be performed</returns>
public Task InvokeOnMainThreadAsync(Func<Task> funcTask)
{
return Device.InvokeOnMainThreadAsync(funcTask);
}

/// <summary>
/// Sets a list of custom flags on the device.
/// </summary>
/// <param name="flags">The list of custom flag values.</param>
public void SetFlags(IReadOnlyList<string> flags)
{
Device.SetFlags(flags);
}

/// <summary>
/// Sets the flow direction on the device.
/// </summary>
/// <param name="flowDirection">The new flow direction value to set.</param>
public void SetFlowDirection(FlowDirection flowDirection)
{
Device.SetFlowDirection(flowDirection);
}

/// <summary>
/// Starts a recurring timer using the Device clock capabilities.
Expand Down
66 changes: 56 additions & 10 deletions src/Forms/Prism.Forms/Services/IDeviceService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Prism.AppModel;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Xamarin.Forms;

Expand All @@ -10,11 +12,21 @@ namespace Prism.Services
/// </summary>
public interface IDeviceService
{
/// <summary>
/// Gets a list of custom flags that were set on the device before Xamarin.Forms was initialized.
/// </summary>
IReadOnlyList<string> Flags { get; }

/// <summary>
/// Gets the flow direction on the device.
/// </summary>
FlowDirection FlowDirection { get; }

/// <summary>
/// Gets the kind of device that Xamarin.Forms is currently working on.
/// </summary>
TargetIdiom Idiom { get; }

/// <summary>
/// Gets the Platform (OS) that the application is running on. This is the native Device.RunTimePlatform property.
/// </summary>
Expand All @@ -30,37 +42,71 @@ public interface IDeviceService
/// </summary>
/// <param name="action">The Action to invoke</param>
void BeginInvokeOnMainThread(Action action);

/// <summary>
/// Returns the current SynchronizationContext from the main thread.
/// </summary>
/// <returns>The current SynchronizationContext from the main thread.</returns>
Task<SynchronizationContext> GetMainThreadSynchronizationContextAsync();

/// <summary>
/// Returns a double that represents a font size that corresponds to size on targetElement.
/// </summary>
/// <param name="size">The named size for which to get the numeric size.</param>
/// <param name="targetElement">The element for which to calculate the numeric size.</param>
/// <returns>A double that represents a font size that corresponds to size on targetElement.</returns>
double GetNamedSize(NamedSize size, Element targetElement);

/// <summary>
/// Returns a double that represents the named size for the font that is used on the element on the native platform.
/// </summary>
/// <param name="size">The named size for which to get the numeric size.</param>
/// <param name="targetElementType">The element type for which to calculate the numeric size.</param>
/// <returns>The named size for the font that is used on the element on the native platform.</returns>
double GetNamedSize(NamedSize size, Type targetElementType);

/// <summary>
/// Invokes an awaitable action on the device main UI thread.
/// Invokes an Action on the device main (UI) thread.
/// </summary>
/// <param name="action">The Action to invoke</param>
/// <returns>A task representing the work to be performed</returns>
Task InvokeOnMainThreadAsync(Action action);

/// <summary>
/// Invokes an awaitable func of type TResult on the device main UI thread.
/// Invokes a Func on the device main (UI) thread.
/// </summary>
/// <param name="func">The func to invoke</param>
/// <typeparam name="T">The return type of the task</typeparam>
/// <param name="func">The Func to invoke.</param>
/// <typeparam name="T">The return type of the Func.</typeparam>
/// <returns>A task of type T representing the work to be performed</returns>
Task<T> InvokeOnMainThreadAsync<T>(Func<T> func);

/// <summary>
/// Invokes an awaitable func of type Task TResult on the device main UI thread.
/// Invokes a Func on the device main (UI) thread.
/// </summary>
/// <param name="funcTask">The func to invoke</param>
/// <typeparam name="T">The return type of the task</typeparam>
/// <param name="funcTask">The return type of the Func.</param>
/// <typeparam name="T">The return type of the Func.</typeparam>
/// <returns>A task of type T representing the work to be performed</returns>
Task<T> InvokeOnMainThreadAsync<T>(Func<Task<T>> funcTask);

/// <summary>
/// Invokes an awaitable func of type Task on the device main UI thread.
/// Invokes a Func on the device main (UI) thread.
/// </summary>
/// <param name="funcTask">The func to invoke</param>
/// <param name="funcTask">The Func to invoke.</param>
/// <returns>A task representing the work to be performed</returns>
Task InvokeOnMainThreadAsync(Func<Task> funcTask);

/// <summary>
/// Sets a list of custom flags on the device.
/// </summary>
/// <param name="flags">The list of custom flag values.</param>
void SetFlags(IReadOnlyList<string> flags);

/// <summary>
/// Sets the flow direction on the device.
/// </summary>
/// <param name="flowDirection">The new flow direction value to set.</param>
void SetFlowDirection(FlowDirection flowDirection);

/// <summary>
/// Starts a recurring timer using the Device clock capabilities.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="Xamarin.Forms" Version="4.5.0.657" />
<PackageReference Include="Xamarin.Forms" Version="4.6.0.726" />
<PackageReference Include="Xamarin.Forms.Mocks" Version="3.5.0.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
Expand Down
2 changes: 1 addition & 1 deletion tests/Forms/Prism.Forms.Tests/Prism.Forms.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageReference Include="Humanizer.Core" Version="2.8.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="Xamarin.Forms" Version="4.5.0.657" />
<PackageReference Include="Xamarin.Forms" Version="4.6.0.726" />
<PackageReference Include="Xamarin.Forms.Mocks" Version="3.5.0.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="Xamarin.Forms" Version="4.5.0.657" />
<PackageReference Include="Xamarin.Forms" Version="4.6.0.726" />
<PackageReference Include="Xamarin.Forms.Mocks" Version="3.5.0.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
Expand Down

0 comments on commit a27288e

Please sign in to comment.