diff --git a/samples/Directory.Packages.props b/samples/Directory.Packages.props
index 51305bf58..77e1b927d 100644
--- a/samples/Directory.Packages.props
+++ b/samples/Directory.Packages.props
@@ -29,19 +29,19 @@
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
+
+
+
+
diff --git a/src/Uno.Toolkit.UI/Controls/NavigationBar/NativeNavigationBarPresenter.iOS.cs b/src/Uno.Toolkit.UI/Controls/NavigationBar/NativeNavigationBarPresenter.iOS.cs
index 9743537c4..8d651d0d7 100644
--- a/src/Uno.Toolkit.UI/Controls/NavigationBar/NativeNavigationBarPresenter.iOS.cs
+++ b/src/Uno.Toolkit.UI/Controls/NavigationBar/NativeNavigationBarPresenter.iOS.cs
@@ -60,13 +60,12 @@ private void OnUnloaded(object sender, RoutedEventArgs e)
partial void OnOwnerChanged()
{
// TODO: Find a proper way to decide whether a NavigationBar exists on canvas (within Page), or is mapped to the UINavigationController's NavigationBar.
-
_mainCommandClickHandler.Disposable = null;
if (GetNavBar() is { } navBar)
{
navBar.MainCommand.Click += OnMainCommandClick;
-
+
_mainCommandClickHandler.Disposable = Disposable.Create(() => navBar.MainCommand.Click -= OnMainCommandClick);
LayoutNativeNavBar(navBar);
@@ -75,6 +74,21 @@ partial void OnOwnerChanged()
private void LayoutNativeNavBar(NavigationBar navBar)
{
+ var page = navBar.FindFirstParent();
+ var parent = page?.Parent as Page;
+ if (page is not null
+ && parent?.GetType() == page.GetType())
+ {
+ // Support for Hot Reload
+ // On iOS, the current Page instance is retained and its Content is replaced with a new instance of the Page
+ // If we detect that we have fallen into this scenario, hook up the new NavigationBar from within the new Page instance
+ // to the native UINavigationBar and UINavigationItem instances.
+ var vc = parent.FindViewController();
+
+ NavigationBarHelper.SetNavigationItem(navBar, vc.NavigationItem);
+ NavigationBarHelper.SetNavigationBar(navBar, vc.NavigationController?.NavigationBar);
+ }
+
if (navBar.TryGetNative(out var nativeBar)
&& nativeBar is { })
{
diff --git a/src/Uno.Toolkit.UI/Controls/NavigationBar/Renderer.cs b/src/Uno.Toolkit.UI/Controls/NavigationBar/Renderer.cs
index fdbddf312..948496525 100644
--- a/src/Uno.Toolkit.UI/Controls/NavigationBar/Renderer.cs
+++ b/src/Uno.Toolkit.UI/Controls/NavigationBar/Renderer.cs
@@ -48,6 +48,13 @@ public Renderer(TElement element)
throw new ArgumentNullException(nameof(element));
}
+#if __IOS__
+ if (element is FrameworkElement fe)
+ {
+ fe.Unloaded += (s, e) => Dispose();
+ }
+#endif
+
_element = new WeakReference(element);
}