Skip to content

Commit

Permalink
- fix gallery navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen committed Apr 24, 2024
1 parent 76773fb commit d97adbf
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ public override string ToString()
new GalleryPageFactory(() => new ImageButtonCoreGalleryPage(), "Image Button Gallery"),
new GalleryPageFactory(() => new ImageCoreGalleryPage(), "Image Gallery"),
new GalleryPageFactory(() => new KeyboardScrollingGridGallery(), "Keyboard Scrolling Gallery - Grid with Star Row"),
new GalleryPageFactory(() => new KeyboardScrollingNonScrollingPageLargeTitlesGallery(), "Keyboard Scrolling Gallery - NonScrolling Page / Large Titles"),
new GalleryPageFactory(() => new KeyboardScrollingNonScrollingPageSmallTitlesGallery(), "Keyboard Scrolling Gallery - NonScrolling Page / Small Titles"),
new GalleryPageFactory(() => new KeyboardScrollingNonScrollingPageLargeTitlesGallery(), "Keyboard Scrolling Gallery - NonScrolling Page / Large Titles"),
new GalleryPageFactory(() => new KeyboardScrollingNonScrollingPageSmallTitlesGallery(), "Keyboard Scrolling Gallery - NonScrolling Page / Small Titles"),
new GalleryPageFactory(() => new KeyboardScrollingScrollingPageLargeTitlesGallery(), "Keyboard Scrolling Gallery - Scrolling Page / Large Titles"),
new GalleryPageFactory(() => new KeyboardScrollingScrollingPageSmallTitlesGallery(), "Keyboard Scrolling Gallery - Scrolling Page / Small Titles"),
new GalleryPageFactory(() => new LabelCoreGalleryPage(), "Label Gallery"),
new GalleryPageFactory(() => new LabelCoreGalleryPage(), "Label Gallery"),
new GalleryPageFactory(() => new ListViewCoreGalleryPage(), "ListView Gallery"),
new GalleryPageFactory(() => new PickerCoreGalleryPage(), "Picker Gallery"),
new GalleryPageFactory(() => new ProgressBarCoreGalleryPage(), "Progress Bar Gallery"),
Expand Down Expand Up @@ -152,29 +152,28 @@ async Task PushPage(Page contentPage)
}

readonly Dictionary<string, GalleryPageFactory> _titleToPage;
public async Task<bool> PushPage(string pageTitle)
public Task<bool> NavigateToGalleryPage(string pageTitle)
{
if (_titleToPage.TryGetValue(pageTitle.ToLowerInvariant(), out GalleryPageFactory pageFactory))
{
var page = pageFactory.Realize();

await PushPage(page);
return true;
this.Window.Page = new NavigationPage(page);
return Task.FromResult(true);
}

return false;
return Task.FromResult(false);
}

public async Task<bool> NavigateToTest(string pageTitle)
{
var testCaseScreen = new TestCases.TestCaseScreen();
if (!testCaseScreen.TryToNavigateTo(pageTitle))
if (testCaseScreen.TryToNavigateTo(pageTitle))
{
return false;
return true;
}
else if (await PushPage(pageTitle))
else if (await NavigateToGalleryPage(pageTitle))
{
// Navigates to gallery page
return true;
}

return false;
Expand Down
43 changes: 25 additions & 18 deletions src/Controls/samples/Controls.Sample.UITests/Issues/Issue16499.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,37 @@ namespace Maui.Controls.Sample.Issues
[Issue(IssueTracker.Github, 16499, "Crash when using NavigationPage.TitleView and Restarting App", PlatformAffected.Android)]
public class Issue16499 : NavigationPage
{
public Issue16499() : base(new ContentPage())
public Issue16499() : base(new MainPage())
{
var contentPage = new ContentPage();
var navPage = new NavigationPage(contentPage);
}

NavigationPage.SetTitleView(contentPage, new Label());
public class MainPage : ContentPage
{
public MainPage() : base()
{
var contentPage = new ContentPage();
var navPage = new NavigationPage(contentPage);

NavigatedTo += Issue16499_NavigatedTo;
NavigationPage.SetTitleView(contentPage, new Label());

async void Issue16499_NavigatedTo(object sender, NavigatedToEventArgs e)
{
NavigatedTo -= Issue16499_NavigatedTo;
await Navigation.PushModalAsync(navPage);
await Navigation.PopModalAsync();
await Navigation.PushModalAsync(navPage);
await Navigation.PopModalAsync();
((ContentPage)CurrentPage).Content = new VerticalStackLayout()
NavigatedTo += Issue16499_NavigatedTo;

async void Issue16499_NavigatedTo(object sender, NavigatedToEventArgs e)
{
new Label()
NavigatedTo -= Issue16499_NavigatedTo;
await Navigation.PushModalAsync(navPage);
await Navigation.PopModalAsync();
await Navigation.PushModalAsync(navPage);
await Navigation.PopModalAsync();
Content = new VerticalStackLayout()
{
Text = "If the app didn't crash this test was a success",
AutomationId = "SuccessLabel"
}
};
new Label()
{
Text = "If the app didn't crash this test was a success",
AutomationId = "SuccessLabel"
}
};
}
}
}
}
Expand Down
41 changes: 24 additions & 17 deletions src/Controls/samples/Controls.Sample.UITests/Issues/Issue17347.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,38 @@ namespace Maui.Controls.Sample.Issues
[Issue(IssueTracker.Github, 17347, "Setting a new TitleView on an already created page crashes iOS", PlatformAffected.iOS)]
public class Issue17347 : NavigationPage
{
public Issue17347() : base(new ContentPage())
public Issue17347() : base(new MainPage())
{
}

var navPage = new NavigationPage(new MainPage());
var label = new Label() { Text = "NavigatedTo Has Not Fired" };
NavigatedTo += Issue16499_NavigatedTo;
((ContentPage)CurrentPage).Content = new VerticalStackLayout()
public class MainPage : ContentPage
{
public MainPage()
{
label
};
var navPage = new NavigationPage(new TestPage());
var label = new Label() { Text = "NavigatedTo Has Not Fired" };
Content = new VerticalStackLayout()
{
label
};

async void Issue16499_NavigatedTo(object sender, NavigatedToEventArgs e)
{
label.Text = "Navigated to Has Fired";
NavigatedTo -= Issue16499_NavigatedTo;
NavigatedTo += Issue16499_NavigatedTo;

async void Issue16499_NavigatedTo(object sender, NavigatedToEventArgs e)
{
label.Text = "Navigated to Has Fired";
NavigatedTo -= Issue16499_NavigatedTo;

await Navigation.PushModalAsync(navPage);
await navPage.Navigation.PushAsync(new MainPage());
await navPage.Navigation.PushAsync(new MainPage());
await navPage.Navigation.PopAsync();
await navPage.Navigation.PopAsync();
await Navigation.PushModalAsync(navPage);
await navPage.Navigation.PushAsync(new TestPage());
await navPage.Navigation.PushAsync(new TestPage());
await navPage.Navigation.PopAsync();
await navPage.Navigation.PopAsync();
}
}
}

public partial class MainPage : ContentPage
public partial class TestPage : ContentPage
{
Label TopView;
static int i = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override void FixtureTeardown()
base.FixtureTeardown();
try
{
this.Back();
this.Reset();
}
catch (Exception e)
{
Expand Down
11 changes: 0 additions & 11 deletions src/Controls/tests/UITests/UtilExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,6 @@ public static void NavigateTo(this IApp app, string text)
app.WaitForNoElement(goToTestButtonId, "Timed out waiting for Go To Test button to disappear", TimeSpan.FromMinutes(1));
}

public static void NavigateToIssues(this IApp app)
{
app.WaitForElement(goToTestButtonId, "Timed out waiting for Go To Test button to appear", TimeSpan.FromMinutes(2));

app.WaitForElement("SearchBar");
app.ClearText("SearchBar");

app.Click(goToTestButtonId);
app.WaitForElement("TestCasesIssueList");
}

public static int CenterX(this Rectangle rect)
{
return rect.X + rect.Width / 2;
Expand Down

0 comments on commit d97adbf

Please sign in to comment.