Skip to content

Commit

Permalink
DisplayActionSheet later
Browse files Browse the repository at this point in the history
  • Loading branch information
cshung committed Mar 4, 2022
1 parent 20657cc commit 45a39bd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
23 changes: 11 additions & 12 deletions src/Controls/src/Core/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,6 @@ public Task<bool> DisplayAlert(string title, string message, string accept, stri
return args.Result.Task;
}

internal override void OnIsPlatformEnabledChanged()
{
base.OnIsPlatformEnabledChanged();
if (IsPlatformEnabled && _pendingActions.Count > 0)
{
var actionsToProcess = _pendingActions.ToList();
_pendingActions.Clear();
foreach (var pendingAction in actionsToProcess)
pendingAction();
}
}

/// <include file="../../docs/Microsoft.Maui.Controls/Page.xml" path="//Member[@MemberName='ForceLayout']/Docs" />
public void ForceLayout()
{
Expand Down Expand Up @@ -366,6 +354,17 @@ protected override void OnParentSet()

protected override void OnSizeAllocated(double width, double height)
{
//
// NOTE!
// This is probably not the best time flush these pending actions
//
if (_pendingActions.Count > 0 && IsPlatformEnabled)
{
var actionsToProcess = _pendingActions.ToList();
_pendingActions.Clear();
foreach (var pendingAction in actionsToProcess)
pendingAction();
}
_allocatedFlag = true;
base.OnSizeAllocated(width, height);
UpdateChildrenLayout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,15 @@ void OnActionSheetRequested(Page sender, ActionSheetArguments arguments)

if (pageParent != null)
actionSheet.ShowAt(pageParent);
else
arguments.SetResult(null);
}
catch (ArgumentException) // If the page is not in the visual tree
{
if (UI.Xaml.Window.Current.Content is FrameworkElement mainPage)
if (UI.Xaml.Window.Current != null && UI.Xaml.Window.Current.Content is FrameworkElement mainPage)
actionSheet.ShowAt(mainPage);
else
arguments.SetResult(null);
}
}

Expand Down

0 comments on commit 45a39bd

Please sign in to comment.