Skip to content

Commit

Permalink
#43 remove safe area for modal (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmidID authored Sep 10, 2024
1 parent 6decdd4 commit e6d7e11
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 36 deletions.
18 changes: 10 additions & 8 deletions src/AvaloniaInside.Shell/NavigationBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,14 +519,16 @@ protected virtual void UpdateHeader(object? view, ContentControl itemPresenter)

protected virtual void UpdateSafePaddingSizes()
{
TopSafeSpace = SafePadding.Top;
TopSafePadding = new Thickness(0, SafePadding.Top, 0, 0);
LeftSafeSpace = SafePadding.Left;
LeftSafePadding = new Thickness(SafePadding.Left, 0, 0, 0);
RightSafeSpace = SafePadding.Right;
RightSafePadding = new Thickness(0, 0, SafePadding.Right, 0);

Height = PlatformHeight + (ApplyTopSafePadding ? SafePadding.Top : 0);
var safePadding = Page?.IsModal != true ? SafePadding : new Thickness(0, 0, 0, 0);

TopSafeSpace = safePadding.Top;
TopSafePadding = new Thickness(0, safePadding.Top, 0, 0);
LeftSafeSpace = safePadding.Left;
LeftSafePadding = new Thickness(safePadding.Left, 0, 0, 0);
RightSafeSpace = safePadding.Right;
RightSafePadding = new Thickness(0, 0, safePadding.Right, 0);

Height = PlatformHeight + (ApplyTopSafePadding ? safePadding.Top : 0);
}

#endregion
Expand Down
77 changes: 63 additions & 14 deletions src/AvaloniaInside.Shell/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
using System.Threading;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Interactivity;

namespace AvaloniaInside.Shell;

[PseudoClasses(":modal")]
public class Page : UserControl, INavigationLifecycle, INavigatorLifecycle, INavigationBarProvider
{
private ContentPresenter? _navigationBarPlaceHolder;
Expand All @@ -22,8 +24,6 @@ public class Page : UserControl, INavigationLifecycle, INavigatorLifecycle, INav

public INavigator? Navigator => Shell?.Navigator;

public NavigationChain Chain { get; internal set; }

protected override Type StyleKeyOverride => typeof(Page);

#region Shell
Expand All @@ -39,6 +39,28 @@ public ShellView? Shell

#endregion

#region Chain

public static readonly DirectProperty<Page, NavigationChain?> BackCommandProperty =
AvaloniaProperty.RegisterDirect<Page, NavigationChain?>(
nameof(Chain),
o => o.Chain,
(o, v) => o.Chain = v);

private NavigationChain? _chain;

public NavigationChain? Chain
{
get => _chain;
set
{
if (SetAndRaise(BackCommandProperty, ref _chain, value))
IsModal = value?.Type == NavigateType.Modal;
}
}

#endregion

#region SafePadding

public static readonly StyledProperty<Thickness> SafePaddingProperty =
Expand Down Expand Up @@ -234,6 +256,25 @@ public Thickness TabSafePadding

#endregion

#region IsModal

/// <summary>
/// Defines the <see cref="IsModal"/> property.
/// </summary>
public static readonly StyledProperty<bool> IsModalProperty =
AvaloniaProperty.Register<ToggleButton, bool>(nameof(IsModal), false);

/// <summary>
/// Gets or sets whether the <see cref="Page"/> is modal.
/// </summary>
public bool IsModal
{
get => GetValue(IsModalProperty);
internal set => SetValue(IsModalProperty, value);
}

#endregion

#endregion

#region Lifecycle
Expand Down Expand Up @@ -264,6 +305,8 @@ protected override void OnLoaded(RoutedEventArgs e)
this[!ApplyBottomSafePaddingProperty] = this[!ShellView.EnableSafeAreaForBottomProperty];
this[!ApplyLeftSafePaddingProperty] = this[!ShellView.EnableSafeAreaForLeftProperty];
this[!ApplyRightSafePaddingProperty] = this[!ShellView.ApplyRightSafePaddingProperty];

IsModal = Chain.Type == NavigateType.Modal;
}

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
Expand All @@ -280,6 +323,11 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
{
UpdateSafePaddingSizes();
}
else if (change.Property == IsModalProperty)
{
PseudoClasses.Set(":modal", IsModal);
UpdateSafePaddingSizes();
}
}

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
Expand All @@ -297,7 +345,7 @@ private void ApplyNavigationBar()
return;

if ((type == NavigationBarAttachType.ToLastPage && Chain is HostNavigationChain) ||
(type == NavigationBarAttachType.ToFirstHostThenPage && Chain?.Back is HostNavigationChain))
(type == NavigationBarAttachType.ToFirstHostThenPage && Chain.Back is HostNavigationChain))
return;

_navigationBarPlaceHolder.Content = _navigationBar = new NavigationBar(this);
Expand All @@ -309,17 +357,18 @@ private void ApplyNavigationBar()

protected virtual void UpdateSafePaddingSizes()
{
TopSafeSpace = SafePadding.Top;
TopSafePadding = new Thickness(0, SafePadding.Top, 0, 0);
BottomSafeSpace = SafePadding.Bottom;
BottomSafePadding = new Thickness(0, 0, 0, SafePadding.Bottom);
LeftSafeSpace = SafePadding.Left;
LeftSafePadding = new Thickness(SafePadding.Left, 0, 0, 0);
RightSafeSpace = SafePadding.Right;
RightSafePadding = new Thickness(0, 0, SafePadding.Right, 0);

PageSafePadding = new Thickness(SafePadding.Left, 0, SafePadding.Right, SafePadding.Bottom);

var safePadding = !IsModal ? SafePadding : new Thickness(0, 0, 0, 0);

TopSafeSpace = safePadding.Top;
TopSafePadding = new Thickness(0, safePadding.Top, 0, 0);
BottomSafeSpace = safePadding.Bottom;
BottomSafePadding = new Thickness(0, 0, 0, safePadding.Bottom);
LeftSafeSpace = safePadding.Left;
LeftSafePadding = new Thickness(safePadding.Left, 0, 0, 0);
RightSafeSpace = safePadding.Right;
RightSafePadding = new Thickness(0, 0, safePadding.Right, 0);

PageSafePadding = new Thickness(safePadding.Left, 0, safePadding.Right, safePadding.Bottom);
}

#endregion
Expand Down
30 changes: 16 additions & 14 deletions src/AvaloniaInside.Shell/TabPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,26 +254,28 @@ static void SetPrivateDateTimePropertyValue<T>(T member, string propName, object

protected override void UpdateSafePaddingSizes()
{
TopSafeSpace = SafePadding.Top;
TopSafePadding = new Thickness(0, SafePadding.Top, 0, 0);
BottomSafeSpace = SafePadding.Bottom;
BottomSafePadding = new Thickness(0, 0, 0, SafePadding.Bottom);
LeftSafeSpace = SafePadding.Left;
LeftSafePadding = new Thickness(SafePadding.Left, 0, 0, 0);
RightSafeSpace = SafePadding.Right;
RightSafePadding = new Thickness(0, 0, SafePadding.Right, 0);
var safePadding = !IsModal ? SafePadding : new Thickness(0, 0, 0, 0);

TopSafeSpace = safePadding.Top;
TopSafePadding = new Thickness(0, safePadding.Top, 0, 0);
BottomSafeSpace = safePadding.Bottom;
BottomSafePadding = new Thickness(0, 0, 0, safePadding.Bottom);
LeftSafeSpace = safePadding.Left;
LeftSafePadding = new Thickness(safePadding.Left, 0, 0, 0);
RightSafeSpace = safePadding.Right;
RightSafePadding = new Thickness(0, 0, safePadding.Right, 0);

PageSafePadding = new Thickness(
TabStripPlacement != Dock.Left ? SafePadding.Left : 0,
TabStripPlacement != Dock.Left ? safePadding.Left : 0,
0,
TabStripPlacement != Dock.Right ? SafePadding.Right : 0,
TabStripPlacement != Dock.Bottom ? SafePadding.Bottom : 0);
TabStripPlacement != Dock.Right ? safePadding.Right : 0,
TabStripPlacement != Dock.Bottom ? safePadding.Bottom : 0);

TabSafePadding = new Thickness(
TabStripPlacement != Dock.Right ? SafePadding.Left : 0,
TabStripPlacement != Dock.Right ? safePadding.Left : 0,
0,
TabStripPlacement != Dock.Left ? SafePadding.Right : 0,
TabStripPlacement != Dock.Top ? SafePadding.Bottom : 0);
TabStripPlacement != Dock.Left ? safePadding.Right : 0,
TabStripPlacement != Dock.Top ? safePadding.Bottom : 0);
}

#endregion
Expand Down

0 comments on commit e6d7e11

Please sign in to comment.