Skip to content

Commit

Permalink
#585 Move conductor logic to Screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Nigel Sampson committed Mar 31, 2019
1 parent c18470a commit d0fd1d8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 36 deletions.
11 changes: 7 additions & 4 deletions src/Caliburn.Micro.Core/Screen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,16 @@ public virtual Task<bool> CanCloseAsync(CancellationToken cancellationToken)
/// Also provides an opportunity to pass a dialog result to it's corresponding view.
/// </summary>
/// <param name="dialogResult">The dialog result.</param>
public virtual Task TryCloseAsync(bool? dialogResult = null)
public virtual async Task TryCloseAsync(bool? dialogResult = null)
{
var closeAction = PlatformProvider.Current.GetViewCloseAction(this, Views.Values, dialogResult);
if (Parent is IConductor conductor)
{
await conductor.CloseItemAsync(this, CancellationToken.None);
}

Execute.OnUIThreadAsync(async () => await closeAction(CancellationToken.None));
var closeAction = PlatformProvider.Current.GetViewCloseAction(this, Views.Values, dialogResult);

return Task.FromResult(true);
await Execute.OnUIThreadAsync(async () => await closeAction(CancellationToken.None));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,6 @@ public virtual void ExecuteOnLayoutUpdated(object view, Action<object> handler)
/// <returns>An <see cref="Action"/> to close the view model.</returns>
public virtual Func<CancellationToken, Task> GetViewCloseAction(object viewModel, ICollection<object> views, bool? dialogResult)
{
var child = viewModel as IChild;

if (child != null)
{
var conductor = child.Parent as IConductor;

if (conductor != null)
{
return ct => conductor.CloseItemAsync(viewModel, ct);
}
}

return ct =>
{
LogManager.GetLog(typeof(Screen)).Info("TryClose requires a parent IConductor or a view with a Close method or IsOpen property.");
Expand Down
12 changes: 0 additions & 12 deletions src/Caliburn.Micro.Platform/Platforms/iOS/iOSPlatformProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,6 @@ public virtual void ExecuteOnLayoutUpdated(object view, Action<object> handler)
/// <returns>An <see cref="Action"/> to close the view model.</returns>
public virtual Func<CancellationToken, Task> GetViewCloseAction(object viewModel, ICollection<object> views, bool? dialogResult)
{
var child = viewModel as IChild;

if (child != null)
{
var conductor = child.Parent as IConductor;

if (conductor != null)
{
return ct => conductor.CloseItemAsync(viewModel, ct);
}
}

return ct =>
{
LogManager.GetLog(typeof(Screen)).Info("TryClose requires a parent IConductor or a view with a Close method or IsOpen property.");
Expand Down
8 changes: 0 additions & 8 deletions src/Caliburn.Micro.Platform/XamlPlatformProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,6 @@ public virtual void ExecuteOnLayoutUpdated(object view, Action<object> handler)
/// <exception cref="System.NotImplementedException"></exception>
public virtual Func<CancellationToken, Task> GetViewCloseAction(object viewModel, ICollection<object> views, bool? dialogResult)
{
var child = viewModel as IChild;
if (child != null) {
var conductor = child.Parent as IConductor;
if (conductor != null) {
return ct => conductor.CloseItemAsync(viewModel, ct);
}
}

foreach (var contextualView in views) {
var viewType = contextualView.GetType();
#if WINDOWS_UWP
Expand Down

0 comments on commit d0fd1d8

Please sign in to comment.