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

View File

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

View File

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

View File

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