feat: make drawer impact modal count. simplify demo view model.

This commit is contained in:
rabbitism
2024-03-10 15:57:09 +08:00
committed by rabbitism
parent 2c2fc63633
commit 6e897b63fe
4 changed files with 27 additions and 79 deletions

View File

@@ -40,21 +40,21 @@
OffContent="No" OffContent="No"
OnContent="Yes" /> OnContent="Yes" />
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBlock Text="Buttons" /> <TextBlock Text="Buttons" VerticalAlignment="Center" />
<ComboBox ItemsSource="{Binding Buttons}" SelectedItem="{Binding SelectedButton}" /> <u:EnumSelector EnumType="{x:Type u:DialogButton}" Value="{Binding SelectedButton}" />
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBlock Text="Mode" /> <TextBlock Text="Mode" VerticalAlignment="Center" />
<ComboBox ItemsSource="{Binding Modes}" SelectedItem="{Binding SelectedMode}" /> <u:EnumSelector EnumType="{x:Type u:DialogMode}" Value="{Binding SelectedMode}" />
</StackPanel> </StackPanel>
<Button Command="{Binding ShowDialogCommand}" Content="Show Dialog" /> <Button Command="{Binding ShowDialogCommand}" Content="Show Dialog" />
<TextBlock> <TextBlock>
<Run Text="Default Result: " /> <Run Text="Default Result: " />
<Run Text="{Binding DefaultResult}" /> <Run Text="{Binding DefaultResult, FallbackValue=''}" />
</TextBlock> </TextBlock>
<TextBlock> <TextBlock>
<Run Text="Dialog Date: " /> <Run Text="Dialog Date: " />
<Run Text="{Binding Date}" /> <Run Text="{Binding Date, FallbackValue=''}" />
</TextBlock> </TextBlock>
</StackPanel> </StackPanel>
</TabItem> </TabItem>
@@ -73,8 +73,8 @@
OffContent="Local" OffContent="Local"
OnContent="Global" /> OnContent="Global" />
<ToggleSwitch <ToggleSwitch
Content="Modal/Regular"
Name="modal" Name="modal"
Content="Modal/Regular"
IsChecked="{Binding IsModal}" IsChecked="{Binding IsModal}"
OffContent="Regular" OffContent="Regular"
OnContent="Modal" /> OnContent="Modal" />

View File

@@ -11,85 +11,27 @@ using Ursa.Demo.Pages;
namespace Ursa.Demo.ViewModels; namespace Ursa.Demo.ViewModels;
public class DialogDemoViewModel: ObservableObject public partial class DialogDemoViewModel: ObservableObject
{ {
public ICommand ShowDialogCommand { get; set; } public ICommand ShowDialogCommand { get; set; }
public ICommand ShowCustomDialogCommand { get; set; } public ICommand ShowCustomDialogCommand { get; set; }
private DialogMode _selectedMode; [ObservableProperty] private DialogMode _selectedMode;
public DialogMode SelectedMode [ObservableProperty] private DialogButton _selectedButton;
{ [ObservableProperty] private bool _isWindow;
get => _selectedMode; [ObservableProperty] private bool _isGlobal;
set => SetProperty(ref _selectedMode, value); [ObservableProperty] private bool _isModal;
} [ObservableProperty] private bool _canLightDismiss;
[ObservableProperty] private DialogResult? _defaultResult;
public ObservableCollection<DialogMode> Modes { get; set; } [ObservableProperty] private bool _result;
[ObservableProperty] private DateTime? _date;
private DialogButton _selectedButton;
public DialogButton SelectedButton
{
get => _selectedButton;
set => SetProperty(ref _selectedButton, value);
}
public ObservableCollection<DialogButton> Buttons { get; set; }
private bool _isWindow;
public bool IsWindow
{
get => _isWindow;
set => SetProperty(ref _isWindow, value);
}
private bool _isGlobal;
public bool IsGlobal
{
get => _isGlobal;
set => SetProperty(ref _isGlobal, value);
}
private bool _isModal;
public bool IsModal
{
get => _isModal;
set => SetProperty(ref _isModal, value);
}
private bool _canLightDismiss;
public bool CanLightDismiss
{
get => _canLightDismiss;
set => SetProperty(ref _canLightDismiss, value);
}
private DialogResult? _defaultResult;
public DialogResult? DefaultResult
{
get => _defaultResult;
set => SetProperty(ref _defaultResult, value);
}
private bool _result;
public bool Result
{
get => _result;
set => SetProperty(ref _result, value);
}
private DateTime? _date;
public DateTime? Date
{
get => _date;
set => SetProperty(ref _date, value);
}
public DialogDemoViewModel() public DialogDemoViewModel()
{ {
ShowDialogCommand = new AsyncRelayCommand(ShowDialog); ShowDialogCommand = new AsyncRelayCommand(ShowDialog);
ShowCustomDialogCommand = new AsyncRelayCommand(ShowCustomDialog); ShowCustomDialogCommand = new AsyncRelayCommand(ShowCustomDialog);
Modes = new ObservableCollection<DialogMode>(Enum.GetValues<DialogMode>()); IsModal = true;
Buttons = new ObservableCollection<DialogButton>(Enum.GetValues<DialogButton>()); IsGlobal = true;
} }
private async Task ShowDialog() private async Task ShowDialog()
@@ -149,7 +91,6 @@ public class DialogDemoViewModel: ObservableObject
var vm = new DialogWithActionViewModel(); var vm = new DialogWithActionViewModel();
if (IsWindow) if (IsWindow)
{ {
if (IsModal) if (IsModal)
{ {
Result = await Dialog.ShowCustomModal<DialogWithAction, DialogWithActionViewModel, bool>( Result = await Dialog.ShowCustomModal<DialogWithAction, DialogWithActionViewModel, bool>(
@@ -161,7 +102,6 @@ public class DialogDemoViewModel: ObservableObject
Dialog.ShowCustom<DialogWithAction, DialogWithActionViewModel>( Dialog.ShowCustom<DialogWithAction, DialogWithActionViewModel>(
vm); vm);
} }
} }
else else
{ {

View File

@@ -31,6 +31,9 @@ public partial class DrawerDemoViewModel: ObservableObject
{ {
ShowDialogCommand = new AsyncRelayCommand(ShowDefaultDialog); ShowDialogCommand = new AsyncRelayCommand(ShowDefaultDialog);
ShowCustomDialogCommand = new AsyncRelayCommand(ShowCustomDrawer); ShowCustomDialogCommand = new AsyncRelayCommand(ShowCustomDrawer);
SelectedPosition = Position.Right;
IsGlobal = true;
IsModal = true;
} }
private async Task ShowDefaultDialog() private async Task ShowDefaultDialog()

View File

@@ -48,6 +48,8 @@ public partial class OverlayDialogHost
control.Measure(this.Bounds.Size); control.Measure(this.Bounds.Size);
control.Arrange(new Rect(control.DesiredSize)); control.Arrange(new Rect(control.DesiredSize));
SetDrawerPosition(control); SetDrawerPosition(control);
_modalCount++;
HasModal = _modalCount > 0;
control.AddHandler(OverlayFeedbackElement.ClosedEvent, OnDrawerControlClosing); control.AddHandler(OverlayFeedbackElement.ClosedEvent, OnDrawerControlClosing);
var animation = CreateAnimation(control.Bounds.Size, control.Position); var animation = CreateAnimation(control.Bounds.Size, control.Position);
await Task.WhenAll(animation.RunAsync(control), _maskAppearAnimation.RunAsync(mask)); await Task.WhenAll(animation.RunAsync(control), _maskAppearAnimation.RunAsync(mask));
@@ -145,10 +147,13 @@ public partial class OverlayDialogHost
control.RemoveHandler(DialogControlBase.LayerChangedEvent, OnDialogLayerChanged); control.RemoveHandler(DialogControlBase.LayerChangedEvent, OnDialogLayerChanged);
if (layer.Mask is not null) if (layer.Mask is not null)
{ {
_modalCount--;
HasModal = _modalCount > 0;
layer.Mask.RemoveHandler(PointerPressedEvent, ClickMaskToCloseDialog); layer.Mask.RemoveHandler(PointerPressedEvent, ClickMaskToCloseDialog);
var disappearAnimation = CreateAnimation(control.Bounds.Size, control.Position, false); var disappearAnimation = CreateAnimation(control.Bounds.Size, control.Position, false);
await Task.WhenAll(disappearAnimation.RunAsync(control), _maskDisappearAnimation.RunAsync(layer.Mask)); await Task.WhenAll(disappearAnimation.RunAsync(control), _maskDisappearAnimation.RunAsync(layer.Mask));
Children.Remove(layer.Mask); Children.Remove(layer.Mask);
} }
else else
{ {