Skip to content

Commit

Permalink
fix: fix OnBackButtonPressedAction to return bool
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-YousefiTelori committed Sep 25, 2024
1 parent 28cd783 commit a17ed50
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface IPage
/// <summary>
///
/// </summary>
Action OnBackButtonPressedAction { get; set; }
Func<bool> OnBackButtonPressedAction { get; set; }
/// <summary>
///
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ private void CustomContentPage_Loaded(object sender, EventArgs e)
OnLoadComplete?.Invoke();
}

public Action OnBackButtonPressedAction { get; set; }
public Func<bool> OnBackButtonPressedAction { get; set; }

public Action OnLoadComplete { get; set; }

protected override bool OnBackButtonPressed()
{
OnBackButtonPressedAction?.Invoke();
if (OnBackButtonPressedAction is not null)
return OnBackButtonPressedAction();
return base.OnBackButtonPressed();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,26 @@ public override async Task<TResponseData> PushDataAsync<TData, TResponseData>(TD
if (page.BindingContext is IResponsibleViewModel responsibleViewModel)
{
if (ipage != null)
ipage.OnBackButtonPressedAction = responsibleViewModel.Close;
{
if (ipage.OnBackButtonPressedAction is null)
{
ipage.OnBackButtonPressedAction = () =>
{
responsibleViewModel.Close();
return true;
};
}
else
{
var func = ipage.OnBackButtonPressedAction;
ipage.OnBackButtonPressedAction = () =>
{
responsibleViewModel.Close();
return func();
};
}
}

var result = await responsibleViewModel.GetResult();
if (result != null && result is TResponseData responseData)
return responseData;
Expand Down Expand Up @@ -92,7 +111,7 @@ public override Task<bool> OpenBrowser(string url)
///
/// </summary>
/// <param name="pageName"></param>
public void RegisterContentPage<TView>(string pageName)
public virtual void RegisterContentPage<TView>(string pageName)
where TView : ContentView, new()
{
Pages.TryAdd(pageName, () =>
Expand All @@ -103,4 +122,17 @@ public void RegisterContentPage<TView>(string pageName)
};
});
}

public virtual void RegisterContentPage<TView, TEasyContentPage>(string pageName)
where TView : ContentView, new()
where TEasyContentPage : EasyContentPage, new()
{
Pages.TryAdd(pageName, () =>
{
return new TEasyContentPage()
{
Content = new TView()
};
});
}
}

0 comments on commit a17ed50

Please sign in to comment.