Skip to content

Commit

Permalink
chore(calendar): Apply MS reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Jun 1, 2021
1 parent c473ae1 commit 8a3caac
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 43 deletions.
35 changes: 35 additions & 0 deletions src/Uno.UI/DirectUI/BuildTreeService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Linq;
using Windows.UI.Core;

namespace DirectUI
{
internal class BuildTreeService
{
public void RegisterWork(ITreeBuilder treeBuilder)
{
treeBuilder.IsRegisteredForCallbacks = true;
CoreDispatcher.Main.RunAsync(CoreDispatcherPriority.High, () =>
{
if (treeBuilder.IsBuildTreeSuspended)
{
RegisterWork(treeBuilder);
return;
}

treeBuilder.IsRegisteredForCallbacks = false;

var workerHasWorkLeft = treeBuilder.BuildTree();

if (workerHasWorkLeft)
{
var workerReRegistered = treeBuilder.IsRegisteredForCallbacks;
if (!workerReRegistered)
{
RegisterWork(treeBuilder);
}
}
});
}
}
}
43 changes: 4 additions & 39 deletions src/Uno.UI/DirectUI/DXamlCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Text;
using Windows.ApplicationModel.Resources;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

Expand All @@ -18,6 +17,10 @@ internal class DXamlCore
public static DXamlCore GetCurrent()
=> _current ??= new DXamlCore();

// UNO: This should **NOT** create the singleton!
// _but_ if we do return a 'null' the 'OnApplyTemplate' of the `CalendarView` will fail.
// As for now our implementation of the 'DXamlCore' is pretty light and stored as a basic singleton,
// we accept to create it even with the "NoCreate" overload.
public static DXamlCore GetCurrentNoCreate()
=> _current ??= new DXamlCore();

Expand All @@ -36,42 +39,4 @@ public BuildTreeService GetBuildTreeService()
public BudgetManager GetBudgetManager()
=> _budgetManager ??= new BudgetManager();
}

internal class BuildTreeService
{
public void RegisterWork(ITreeBuilder treeBuilder)
{
treeBuilder.IsRegisteredForCallbacks = true;
CoreDispatcher.Main.RunAsync(CoreDispatcherPriority.High, () =>
{
if (treeBuilder.IsBuildTreeSuspended)
{
RegisterWork(treeBuilder);
return;
}

treeBuilder.IsRegisteredForCallbacks = false;

var workerHasWorkLeft = treeBuilder.BuildTree();

if (workerHasWorkLeft)
{
var workerReRegistered = treeBuilder.IsRegisteredForCallbacks;
if (!workerReRegistered)
{
RegisterWork(treeBuilder);
}
}
});
}
}

internal interface ITreeBuilder
{
public bool IsBuildTreeSuspended { get; }

public bool IsRegisteredForCallbacks { get; set; }

public bool BuildTree();
}
}
6 changes: 5 additions & 1 deletion src/Uno.UI/DirectUI/FocusRect/focusrectoptions.h.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ internal struct FocusRectangleOptions
// Used to indicate whether this is a continuous focus rectangle (not dashed)
// When true, the second rect is drawn inside the first
// When false, the rects are drawn as alternating dotted lines
public bool isContinuous;
//
// IMPORTANT UNO: MS recommends to not support dashed focus visual! Only "high visibility focus rects"
// (solid lines that are thicker and have two colors to show up on any background/theme).
//
// public bool isContinuous;

// Used to indicate if we are drawing a borderless reveal glow
public bool isRevealBorderless;
Expand Down
14 changes: 14 additions & 0 deletions src/Uno.UI/DirectUI/ITreeBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Linq;

namespace DirectUI
{
internal interface ITreeBuilder
{
public bool IsBuildTreeSuspended { get; }

public bool IsRegisteredForCallbacks { get; set; }

public bool BuildTree();
}
}
3 changes: 2 additions & 1 deletion src/Uno.UI/DirectUI/JoltCollections.h.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections;
using System.Collections.Generic;
using Windows.Foundation.Collections;
using Windows.System;
using Windows.UI.Core;

namespace DirectUI
Expand All @@ -21,7 +22,7 @@ internal abstract class IteratorBase<T> : IEnumerator<T>
//END_INTERFACE_MAP(IteratorBase, ctl.WeakReferenceSource)

// UNO only
protected void CheckThread() => CoreDispatcher.CheckThreadAccess();
protected void CheckThread() => DispatcherQueue.CheckThreadAccess();

public void SetView(IVectorView<T> pView)
{
Expand Down
5 changes: 3 additions & 2 deletions src/Uno.UI/UI/Xaml/Input/FocusManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,10 @@ void OnGotFocus()
public static event EventHandler<FocusManagerGotFocusEventArgs> GotFocus;
public static event EventHandler<FocusManagerLostFocusEventArgs> LostFocus;

internal static void SetEngagedControl(Control spScrollViewer)
internal static void SetEngagedControl(Control control)
{
// UNO-TODO
// Focus engagement applies only to gamepads
// We don't support them yet with Uno.
}
}
}
15 changes: 15 additions & 0 deletions src/Uno.UWP/System/DispatcherQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ public static DispatcherQueue GetForCurrentThread()

return _current;
}

/// <summary>
/// Enforce access on the UI thread.
/// </summary>
internal static void CheckThreadAccess()
{
#if !__WASM__
// This check is disabled on WASM until threading support is enabled, since HasThreadAccess is currently user-configured (and defaults to false).
if (!CoreDispatcher.Main.HasThreadAccess)
{
throw new InvalidOperationException("The application called an interface that was marshalled for a different thread.");
}
#endif
}

#if !HAS_UNO_WINUI
public bool TryEnqueue(DispatcherQueueHandler callback)
{
Expand Down

0 comments on commit 8a3caac

Please sign in to comment.