Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public PopupRenderer()
{
}

[Preserve(Conditional = true)]
public PopupRenderer(UIViewController viewController)
{
ViewController = viewController;
}

public void SetElementSize(Size size) =>
Control?.SetElementSize(size);

Expand Down Expand Up @@ -134,18 +140,27 @@ void CreateControl()
void SetViewController()
{
IVisualElementRenderer currentPageRenderer;
var modalStackCount = Application.Current.MainPage?.Navigation?.ModalStack?.Count ?? 0;
var mainPage = Application.Current.MainPage;
if (modalStackCount > 0)
var page = Application.Current.MainPage;
var modalStackCount = page?.Navigation.ModalStack.Count ?? 0;
if (modalStackCount > 0 && page is not null)
{
var index = modalStackCount - 1;
currentPageRenderer = Platform.GetRenderer(mainPage!.Navigation!.ModalStack![index]);
page = page.Navigation.ModalStack[index];
currentPageRenderer = Platform.GetRenderer(page);
}
else
{
currentPageRenderer = Platform.GetRenderer(page);
}

if (currentPageRenderer == null)
{
ViewController ??= page?.CreateViewController();
}
else
{
currentPageRenderer = Platform.GetRenderer(mainPage);
ViewController ??= currentPageRenderer.ViewController;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that we just want to set the ViewController if it's null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously, we always set it. it was done by CreateControl. it was the only 1 place where we set it.
now we also set ViewController in ctor. we do not want to set it here again.
hope I correctly understand your question.

}
ViewController = currentPageRenderer.ViewController;
}

void SetEvents()
Expand Down