-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split out "Overlays" and "Sheets" (#21)
* Split generic "overlay" concept from "sheets" * Some renames * Use injected ISafeAreaService
- Loading branch information
Showing
29 changed files
with
476 additions
and
393 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using UniSky.Services; | ||
using Windows.Foundation; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Markup; | ||
|
||
namespace UniSky.Controls.Overlay; | ||
|
||
[ContentProperty(Name = nameof(OverlayContent))] | ||
public abstract class OverlayControl : Control | ||
{ | ||
public static readonly DependencyProperty OverlayContentProperty = | ||
DependencyProperty.Register("OverlayContent", typeof(object), typeof(OverlayControl), new PropertyMetadata(null)); | ||
|
||
public static readonly DependencyProperty OverlayContentTemplateProperty = | ||
DependencyProperty.Register("OverlayContentTemplate", typeof(DataTemplate), typeof(OverlayControl), new PropertyMetadata(null)); | ||
|
||
public static readonly DependencyProperty TitleContentProperty = | ||
DependencyProperty.Register("TitleContent", typeof(object), typeof(OverlayControl), new PropertyMetadata(null)); | ||
|
||
public static readonly DependencyProperty TitleContentTemplateProperty = | ||
DependencyProperty.Register("TitleContentTemplate", typeof(DataTemplate), typeof(OverlayControl), new PropertyMetadata(null)); | ||
|
||
public static readonly DependencyProperty PreferredWindowSizeProperty = | ||
DependencyProperty.Register("PreferredWindowSize", typeof(Size), typeof(OverlayControl), new PropertyMetadata(new Size(320, 400))); | ||
|
||
public IOverlayController Controller { get; private set; } | ||
|
||
public object OverlayContent | ||
{ | ||
get => (object)GetValue(OverlayContentProperty); | ||
set => SetValue(OverlayContentProperty, value); | ||
} | ||
|
||
public DataTemplate OverlayContentTemplate | ||
{ | ||
get => (DataTemplate)GetValue(OverlayContentTemplateProperty); | ||
set => SetValue(OverlayContentTemplateProperty, value); | ||
} | ||
|
||
public object TitleContent | ||
{ | ||
get => (object)GetValue(TitleContentProperty); | ||
set => SetValue(TitleContentProperty, value); | ||
} | ||
|
||
public DataTemplate TitleContentTemplate | ||
{ | ||
get => (DataTemplate)GetValue(TitleContentTemplateProperty); | ||
set => SetValue(TitleContentTemplateProperty, value); | ||
} | ||
|
||
public Size PreferredWindowSize | ||
{ | ||
get => (Size)GetValue(PreferredWindowSizeProperty); | ||
set => SetValue(PreferredWindowSizeProperty, value); | ||
} | ||
|
||
public event TypedEventHandler<OverlayControl, RoutedEventArgs> Hidden; | ||
public event TypedEventHandler<OverlayControl, OverlayHidingEventArgs> Hiding; | ||
public event TypedEventHandler<OverlayControl, OverlayShowingEventArgs> Showing; | ||
public event TypedEventHandler<OverlayControl, RoutedEventArgs> Shown; | ||
|
||
internal void SetOverlayController(IOverlayController controller) | ||
{ | ||
Controller = controller; | ||
} | ||
|
||
internal void InvokeHidden() | ||
{ | ||
OnHidden(new RoutedEventArgs()); | ||
} | ||
|
||
internal async Task<bool> InvokeHidingAsync() | ||
{ | ||
var ev = new OverlayHidingEventArgs(); | ||
OnHiding(ev); | ||
|
||
await ev.WaitOnDeferral(); | ||
|
||
return !ev.Cancel; | ||
} | ||
|
||
internal void InvokeShowing(object parameter) | ||
{ | ||
OnShowing(new OverlayShowingEventArgs(parameter)); | ||
} | ||
|
||
internal void InvokeShown() | ||
{ | ||
OnShown(new RoutedEventArgs()); | ||
} | ||
|
||
protected virtual void OnHiding(OverlayHidingEventArgs args) | ||
{ | ||
Hiding?.Invoke(this, args); | ||
} | ||
|
||
protected virtual void OnHidden(RoutedEventArgs args) | ||
{ | ||
Hidden?.Invoke(this, args); | ||
} | ||
|
||
protected virtual void OnShowing(OverlayShowingEventArgs args) | ||
{ | ||
Showing?.Invoke(this, args); | ||
} | ||
|
||
protected virtual void OnShown(RoutedEventArgs args) | ||
{ | ||
Shown?.Invoke(this, args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Threading.Tasks; | ||
using Windows.Foundation; | ||
using Windows.UI.Xaml; | ||
|
||
namespace UniSky.Controls.Overlay; | ||
|
||
public class OverlayHidingEventArgs : RoutedEventArgs | ||
{ | ||
private Deferral _deferral; | ||
private TaskCompletionSource<object> _deferralCompletion; | ||
|
||
public Deferral GetDeferral() | ||
{ | ||
_deferralCompletion = new TaskCompletionSource<object>(); | ||
return (_deferral ??= new Deferral(OnDeferralCompleted)); | ||
} | ||
|
||
public bool Cancel { get; set; } = false; | ||
|
||
internal Task WaitOnDeferral() | ||
{ | ||
if (_deferral == null) | ||
return Task.CompletedTask; | ||
else | ||
return _deferralCompletion.Task; | ||
} | ||
|
||
private void OnDeferralCompleted() | ||
{ | ||
_deferralCompletion?.SetResult(null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Windows.UI.Xaml; | ||
|
||
namespace UniSky.Controls.Overlay; | ||
|
||
public class OverlayShowingEventArgs : RoutedEventArgs | ||
{ | ||
public object Parameter { get; } | ||
|
||
public OverlayShowingEventArgs(object parameter) | ||
{ | ||
Parameter = parameter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.