Skip to content

Commit 0487aef

Browse files
committed
Changes based on PR feedback, simplify FlyoutPage Detail
1 parent 26495f3 commit 0487aef

File tree

2 files changed

+25
-45
lines changed

2 files changed

+25
-45
lines changed

src/Controls/src/Core/FlyoutPage/FlyoutPage.cs

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -53,72 +53,49 @@ public Page Detail
5353
throw new InvalidOperationException("Detail must not already have a parent.");
5454

5555
var previousDetail = _detail;
56-
var destinationPage = value is NavigationPage destinationNavPage ? destinationNavPage.CurrentPage : value;
56+
57+
// Get the actual pages for navigation events (unwrap NavigationPages)
58+
var destinationPage =
59+
value is NavigationPage destinationNavPage ? destinationNavPage.CurrentPage : value;
5760
var previousPage = previousDetail is NavigationPage previousNavPage
5861
? previousNavPage.CurrentPage
5962
: previousDetail;
6063

61-
// Triggering NavigatingFrom event for the previous or initial Detail
62-
if (previousDetail != null)
63-
{
64-
if (previousDetail is NavigationPage prevNavPage)
65-
prevNavPage.CurrentPage?.SendNavigatingFrom(
66-
new NavigatingFromEventArgs(destinationPage, NavigationType.Replace));
67-
else
68-
previousDetail?.SendNavigatingFrom(new NavigatingFromEventArgs(value, NavigationType.Replace));
69-
}
70-
else if (value is NavigationPage currentNavPage)
64+
// Send NavigatingFrom event to the previous detail (if any)
65+
if (previousDetail is not null)
7166
{
72-
// Triggering NavigatingFrom for initial Detail when it is a NavigationPage
73-
currentNavPage.CurrentPage?.SendNavigatingFrom(
74-
new NavigatingFromEventArgs(currentNavPage.CurrentPage, NavigationType.Replace)); // Initial Detail
67+
previousDetail.SendNavigatingFrom(new NavigatingFromEventArgs(destinationPage,
68+
NavigationType.Replace));
7569
}
7670
else
7771
{
78-
// Triggering NavigatingFrom for initial Detail when it is not a NavigationPage
79-
value?.SendNavigatingFrom(new NavigatingFromEventArgs(value,
80-
NavigationType.Replace)); // Initial Detail
72+
// For initial detail, send NavigatingFrom to itself
73+
value.SendNavigatingFrom(new NavigatingFromEventArgs(destinationPage, NavigationType.Replace));
8174
}
8275

76+
// Update the detail property
8377
OnPropertyChanging();
84-
if (_detail != null)
78+
if (_detail is not null)
8579
InternalChildren.Remove(_detail);
8680
_detail = value;
8781
InternalChildren.Add(_detail);
8882
OnPropertyChanged();
8983

90-
// Handling Appearing and Disappearing events if the FlyoutPage has appeared
84+
// Handle Appearing/Disappearing events if the FlyoutPage has appeared
9185
if (HasAppeared)
9286
{
93-
// Triggering Disappearing for the previous Detail
94-
if (previousDetail is NavigationPage prevNavPage)
95-
prevNavPage.CurrentPage?.SendDisappearing();
96-
else
97-
previousDetail?.SendDisappearing();
98-
99-
// Triggering Appearing for the new Detail
100-
if (_detail is NavigationPage detailNavPage)
101-
detailNavPage.CurrentPage?.SendAppearing();
102-
else
103-
_detail?.SendAppearing();
87+
previousDetail?.SendDisappearing();
88+
_detail?.SendAppearing();
10489
}
10590

106-
// Trigger NavigatedFrom for previousDetail, NavigatedTo for new Detail
107-
if (previousDetail != null)
91+
// Send NavigatedFrom and NavigatedTo events
92+
if (previousDetail is not null)
10893
{
109-
if (previousDetail is NavigationPage prevNavPage)
110-
prevNavPage.CurrentPage?.SendNavigatedFrom(
111-
new NavigatedFromEventArgs(destinationPage, NavigationType.Replace));
112-
else
113-
previousDetail?.SendNavigatedFrom(new NavigatedFromEventArgs(destinationPage,
114-
NavigationType.Replace));
94+
previousDetail.SendNavigatedFrom(
95+
new NavigatedFromEventArgs(destinationPage, NavigationType.Replace));
11596
}
11697

117-
if (_detail is NavigationPage newNavPage)
118-
newNavPage.CurrentPage?.SendNavigatedTo(new NavigatedToEventArgs(previousPage,
119-
NavigationType.Replace));
120-
else
121-
_detail?.SendNavigatedTo(new NavigatedToEventArgs(previousPage, NavigationType.Replace));
98+
_detail.SendNavigatedTo(new NavigatedToEventArgs(previousPage, NavigationType.Replace));
12299
}
123100
}
124101

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue21814FlyoutPage.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,11 @@ public void PopNavigationPageAfterPush()
110110
App.WaitForElement(FlyoutContent2);
111111

112112
// Popping back to Item 1
113-
App.Back();
114-
App.WaitForElement(FlyoutContent1);
113+
#if ANDROID || WINDOWS
114+
App.TapBackArrow();
115+
#elif IOS || MACCATALYST
116+
App.TapBackArrow("Item 1");
117+
#endif
115118

116119
// Verifying navigation events for pop from Item 2 to Item 1
117120
// Popping to Item 1 does not trigger OnNavigatedFrom for Item 1

0 commit comments

Comments
 (0)