-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
108 additions
and
46 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
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 |
---|---|---|
|
@@ -41,66 +41,84 @@ private async void OnInitialized(object sender, EventArgs e) | |
await PopAllAsync(false); | ||
} | ||
|
||
public async Task PushAsync(PopupPage page, bool animate = true) | ||
public Task PushAsync(PopupPage page, bool animate = true) | ||
{ | ||
animate = CanBeAnimated(animate); | ||
|
||
if (animate) | ||
{ | ||
page.PreparingAnimation(); | ||
await AddAsync(page); | ||
await Task.Delay(10); | ||
await page.AppearingAnimation(); | ||
} | ||
else | ||
return InvokeThreadSafty(async () => | ||
{ | ||
await AddAsync(page); | ||
} | ||
if (page.IsBeingAppeared) | ||
return; | ||
page.IsBeingAppeared = true; | ||
animate = CanBeAnimated(animate); | ||
if (animate) | ||
{ | ||
page.PreparingAnimation(); | ||
await AddAsync(page); | ||
await page.AppearingAnimation(); | ||
} | ||
else | ||
{ | ||
await AddAsync(page); | ||
} | ||
page.IsBeingAppeared = false; | ||
}); | ||
} | ||
|
||
public Task PopAsync(bool animate = true) | ||
{ | ||
animate = CanBeAnimated(animate); | ||
return InvokeThreadSafty(async () => | ||
{ | ||
animate = CanBeAnimated(animate); | ||
if (PopupStack.Count == 0) | ||
throw new IndexOutOfRangeException("There is not page in PopupStack"); | ||
if (!PopupStack.Any()) | ||
throw new IndexOutOfRangeException("There is not page in PopupStack"); | ||
return RemovePageAsync(PopupStack.Last(), animate); | ||
await RemovePageAsync(PopupStack.Last(), animate); | ||
}); | ||
} | ||
|
||
public async Task PopAllAsync(bool animate = true) | ||
public Task PopAllAsync(bool animate = true) | ||
{ | ||
animate = CanBeAnimated(animate); | ||
return InvokeThreadSafty(async () => | ||
{ | ||
animate = CanBeAnimated(animate); | ||
var popupTasks = _popupStack.ToList().Select(page => RemovePageAsync(page, animate)); | ||
if (!PopupStack.Any()) | ||
throw new IndexOutOfRangeException("There is not page in PopupStack"); | ||
await Task.WhenAll(popupTasks); | ||
var popupTasks = PopupStack.ToList().Select(page => RemovePageAsync(page, animate)); | ||
await Task.WhenAll(popupTasks); | ||
}); | ||
} | ||
|
||
public async Task RemovePageAsync(PopupPage page, bool animate = true) | ||
public Task RemovePageAsync(PopupPage page, bool animate = true) | ||
{ | ||
if (page == null) | ||
throw new NullReferenceException("Page can not be null"); | ||
|
||
if(page.IsBeingDismissed) | ||
return; | ||
return InvokeThreadSafty(async () => | ||
{ | ||
if (page == null) | ||
throw new NullReferenceException("Page can not be null"); | ||
animate = CanBeAnimated(animate); | ||
if (page.IsBeingDismissed) | ||
return; | ||
page.IsBeingDismissed = true; | ||
animate = CanBeAnimated(animate); | ||
if (animate) | ||
await page.DisappearingAnimation(); | ||
page.IsBeingDismissed = true; | ||
await RemoveAsync(page); | ||
await Task.Delay(50); | ||
if (animate) | ||
await page.DisappearingAnimation(); | ||
if (animate) | ||
page.DisposingAnimation(); | ||
await RemoveAsync(page); | ||
page.IsBeingDismissed = false; | ||
if (animate) | ||
page.DisposingAnimation(); | ||
await Task.Delay(5); | ||
page.IsBeingDismissed = false; | ||
}); | ||
} | ||
|
||
// Private | ||
|
@@ -113,8 +131,8 @@ private async Task AddAsync(PopupPage page) | |
|
||
private async Task RemoveAsync(PopupPage page) | ||
{ | ||
_popupStack.Remove(page); | ||
await PopupPlatform.RemoveAsync(page); | ||
_popupStack.Remove(page); | ||
} | ||
|
||
// Internal | ||
|
@@ -133,5 +151,23 @@ private bool CanBeAnimated(bool animate) | |
} | ||
|
||
#endregion | ||
|
||
#region Helpers | ||
|
||
Task InvokeThreadSafty(Func<Task> action) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rotorgames
Author
Owner
|
||
{ | ||
var tcs = new TaskCompletionSource<bool>(); | ||
|
||
Device.BeginInvokeOnMainThread(async () => | ||
{ | ||
await action.Invoke(); | ||
tcs.SetResult(true); | ||
}); | ||
|
||
return tcs.Task; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
InvokeThreadSafEty