Skip to content

Commit

Permalink
feat(ApplicationView): IsViewModeSupported, TryEnterViewModeAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed May 10, 2021
1 parent e8cb04c commit 23493ac
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/Uno.UI.DualScreen/DuoApplicationViewSpanningRect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,19 @@ private SurfaceOrientation GetOrientation()
return null;
}
}

public bool IsDualScreen
{
get
{
if (!(ContextHelper.Current is Activity currentActivity))
{
throw new InvalidOperationException("The API was called too early in the application lifecycle");
}

InitializeHelper(currentActivity);
return _isDualScreenDevice ?? false;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Uno.Devices.Sensors
{
public interface INativeDualScreenProvider
{
bool IsDualScreen { get; }

bool? IsSpanned { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,21 @@ public void SetPreferredMinSize( global::Windows.Foundation.Size minSize)
}
#endif
// Forced skipping of method Windows.UI.ViewManagement.ApplicationView.ViewMode.get
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public bool IsViewModeSupported( global::Windows.UI.ViewManagement.ApplicationViewMode viewMode)
{
throw new global::System.NotImplementedException("The member bool ApplicationView.IsViewModeSupported(ApplicationViewMode viewMode) is not implemented in Uno.");
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Windows.Foundation.IAsyncOperation<bool> TryEnterViewModeAsync( global::Windows.UI.ViewManagement.ApplicationViewMode viewMode)
{
throw new global::System.NotImplementedException("The member IAsyncOperation<bool> ApplicationView.TryEnterViewModeAsync(ApplicationViewMode viewMode) is not implemented in Uno.");
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Windows.Foundation.IAsyncOperation<bool> TryEnterViewModeAsync( global::Windows.UI.ViewManagement.ApplicationViewMode viewMode, global::Windows.UI.ViewManagement.ViewModePreferences viewModePreferences)
{
Expand Down
39 changes: 39 additions & 0 deletions src/Uno.UWP/UI/ViewManagement/ApplicationView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using Uno.Foundation.Extensibility;
using Uno.Extensions;
using Uno.Logging;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;

namespace Windows.UI.ViewManagement
{
Expand Down Expand Up @@ -88,6 +90,43 @@ public ApplicationViewMode ViewMode
: ApplicationViewMode.Default;
}
}

public bool IsViewModeSupported(ApplicationViewMode viewMode)
{
if (viewMode == ApplicationViewMode.Default)
{
return true;
}
else if (viewMode == ApplicationViewMode.Spanning)
{
return (_applicationViewSpanningRects as INativeDualScreenProvider)?.IsDualScreen == true;
}

return false;
}

public IAsyncOperation<bool> TryEnterViewModeAsync(ApplicationViewMode viewMode) =>
AsyncOperation.FromTask(cancellation =>
{
if (ViewMode == viewMode)
{
// If we are already in the requested mode, we can return true.
return Task.FromResult(true);
}
if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning))
{
this.Log().LogWarning(
$"Cannot not enter view mode {viewMode}, " +
$"as this transition is not yet supported.");
}
return Task.FromResult(false);
});

public IAsyncOperation<bool> TryEnterViewModeAsync(ApplicationViewMode viewMode, ViewModePreferences viewModePreferences) =>
TryEnterViewModeAsync(viewMode);

public IReadOnlyList<Rect> GetSpanningRects()
{
TryInitializeSpanningRectsExtension();
Expand Down

0 comments on commit 23493ac

Please sign in to comment.