Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Make sure all the UIViews in iOS are added at the correct hierarchy #13300

Merged
merged 2 commits into from Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,182 @@
using System;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;


#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif

namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.None, 0, "Shell Flyout Background",
PlatformAffected.All)]
#if UITEST
[NUnit.Framework.Category(UITestCategories.Shell)]
[NUnit.Framework.Category(UITestCategories.ManualReview)]
#endif
public class ShellFlyoutBackground : TestShell
{
public ShellFlyoutBackground()
{
}

protected override void Init()
{
AddFlyoutItem(CreateContentPage(), "Item 1");
AddFlyoutItem(CreateContentPage(), "Item 2");

FlyoutBackgroundImage = "photo.jpg";
FlyoutBackgroundImageAspect = Aspect.AspectFill;
}

ContentPage CreateContentPage()
{
var layout = new StackLayout()
{
Children =
{
new Label()
{
AutomationId = "PageLoaded",
Text = "Toggle Different Options to Verify Flyout Behaves as Expected"
},
new Button()
{
Text = "Toggle Image",
Command = new Command(() =>
{
if(FlyoutBackgroundImage == null)
FlyoutBackgroundImage = "photo.jpg";
else
FlyoutBackgroundImage = null;
})
},
new Button()
{
Text = "Toggle Red Color",
Command = new Command(() =>
{
FlyoutBackground = null;
if(FlyoutBackgroundColor == Color.Default)
FlyoutBackgroundColor = Color.Red;
else
FlyoutBackgroundColor = Color.Default;
})
},
new Button()
{
// Broken on iOS 14
Text = "Toggle Red Color With Alpha",
Command = new Command(() =>
{
FlyoutBackground = null;
if(FlyoutBackgroundColor == Color.Default)
FlyoutBackgroundColor = Color.Red.MultiplyAlpha(0.7);
else
FlyoutBackgroundColor = Color.Default;
})
},
new Button()
{
Text = "Toggle Brush",
Command = new Command(() =>
{
RadialGradientBrush radialGradientBrush = new RadialGradientBrush(
new GradientStopCollection()
{
new GradientStop(Color.Red, 0.1f),
new GradientStop(Color.DarkBlue, 1.0f),
});

FlyoutBackgroundColor = Color.Default;
if(FlyoutBackground != null)
FlyoutBackground = null;
else
FlyoutBackground = radialGradientBrush;
})
},
new Button()
{
Text = "Toggle Flyout Content",
Command = new Command(() =>
{
if (FlyoutContent is ScrollView)
FlyoutContent = null;
else if (FlyoutContent == null)
FlyoutContent = new Label()
{
AutomationId = "LabelContent",
Text = "Only Label"
};
else
FlyoutContent = new ScrollView()
{
AutomationId = "ScrollViewContent",
Content = new Label() { Text = "Label inside ScrollView" }
};
}),
AutomationId = "ToggleFlyoutContent"
},
new Button()
{
Text = "Toggle Header/Footer",
Command = new Command(() =>
{
if (FlyoutHeader == null)
{
FlyoutFooter =
new BoxView()
{
BackgroundColor = Color.Purple,
HeightRequest = 50
};

FlyoutHeader =
new BoxView()
{
BackgroundColor = Color.Blue,
HeightRequest = 50
};
}
else
{
FlyoutHeader = FlyoutFooter = null;
}
}),
AutomationId = "ToggleHeaderFooter"
}
}
};

Button aspectBackgroundChange = null;
aspectBackgroundChange = new Button()
{
Text = $"Change Flyout Background Image Aspect: {FlyoutBackgroundImageAspect}",
Command = new Command(() =>
{
int inc = (int)FlyoutBackgroundImageAspect;
inc++;

if (inc >= Enum.GetNames(typeof(Aspect)).Length)
{
inc = 0;
}

FlyoutBackgroundImageAspect = (Aspect)inc;
aspectBackgroundChange.Text = $"Change Flyout Background Image Aspect: {FlyoutBackgroundImageAspect}";
})
};

layout.Children.Add(aspectBackgroundChange);

return new ContentPage()
{
Content = layout
};
}
}
}
@@ -0,0 +1,140 @@
using System;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;


#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif

namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.None, 0, "Shell Flyout Content Offsets Correctly",
PlatformAffected.All)]
#if UITEST
[NUnit.Framework.Category(UITestCategories.Shell)]
[NUnit.Framework.Category(UITestCategories.UwpIgnore)]
#endif
public class ShellFlyoutContentOffset : TestShell
{
public ShellFlyoutContentOffset()
{
}

protected override void Init()
{
AddFlyoutItem(CreateContentPage(), "Item 1");
FlyoutFooter = new Button()
{
HeightRequest = 200,
AutomationId = "CloseFlyout",
Command = new Command(() => FlyoutIsPresented = false),
Text = "Close Flyout"
};
}

ContentPage CreateContentPage()
{
var layout = new StackLayout()
{
Children =
{
new Label()
{
AutomationId = "PageLoaded",
Text = "Toggle through the 3 variations of flyout content and verify they all offset the same. Toggle the Header/Footer and then verify again",
},
new Button()
{
Text = "Toggle Flyout Content",
Command = new Command(() =>
{
if (FlyoutContent is ScrollView)
FlyoutContent = null;
else if (FlyoutContent == null)
FlyoutContent = new Label()
{
AutomationId = "LabelContent",
Text = "Only Label"
};
else
FlyoutContent = new ScrollView()
{
Content = new Label()
{
AutomationId = "ScrollViewContent",
Text = "Label inside ScrollView"
}
};
}),
AutomationId = "ToggleFlyoutContent"
},
new Button()
{
Text = "Toggle Header",
Command = new Command(() =>
{
if (FlyoutHeader == null)
{
FlyoutHeader =
new BoxView()
{
BackgroundColor = Color.Blue,
HeightRequest = 50
};
}
else
{
FlyoutHeader = FlyoutFooter = null;
}
}),
AutomationId = "ToggleHeader"
}
}
};

return new ContentPage()
{
Content = layout
};
}

#if UITEST
[Test]
public void FlyoutContentOffsetsCorrectly()
{
RunningApp.WaitForElement("PageLoaded");
var flyoutLoc = GetLocationAndRotateToNextContent("Item 1");
var labelLoc = GetLocationAndRotateToNextContent("LabelContent");
var scrollViewLoc = GetLocationAndRotateToNextContent("ScrollViewContent");

Assert.AreEqual(flyoutLoc, labelLoc, "Label Offset Incorrect");
Assert.AreEqual(flyoutLoc, scrollViewLoc, "ScrollView Offset Incorrect");
}

[Test]
public void FlyoutContentOffsetsCorrectlyWithHeader()
{
RunningApp.Tap("ToggleHeader");
GetLocationAndRotateToNextContent("Item 1");
var labelLoc = GetLocationAndRotateToNextContent("LabelContent");
var scrollViewLoc = GetLocationAndRotateToNextContent("ScrollViewContent");

Assert.AreEqual(labelLoc, scrollViewLoc, "ScrollView Offset Incorrect");
}

float GetLocationAndRotateToNextContent(string automationId)
{
ShowFlyout();
var y = RunningApp.WaitForElement(automationId)[0].Rect.Y;
RunningApp.Tap("CloseFlyout");
RunningApp.Tap("ToggleFlyoutContent");

return y;
}
#endif
}
}
@@ -0,0 +1,68 @@
using System;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;


#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif

namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.None, 0, "Shell Flyout Content With Zero Margin offsets correctly",
PlatformAffected.All)]
#if UITEST
[NUnit.Framework.Category(UITestCategories.Shell)]
#endif
public class ShellFlyoutContentWithZeroMargin : TestShell
{
public ShellFlyoutContentWithZeroMargin()
{
}

protected override void Init()
{
AddFlyoutItem(CreateContentPage(), "Item 1");
FlyoutContent = new Label()
{
Text = "I should not be offset by the safe area",
AutomationId = "FlyoutLabel",
Margin = new Thickness(0)
};
}

ContentPage CreateContentPage()
{
var layout = new StackLayout()
{
Children =
{
new Label()
{
AutomationId = "PageLoaded",
Text = "Open Flyout. Content should not obey safe area",
}
}
};

return new ContentPage()
{
Content = layout
};
}

#if UITEST && __IOS__
[Test]
public void FlyoutContentIgnoresSafeAreaWithZeroMargin()
{
RunningApp.WaitForElement("PageLoaded");
this.ShowFlyout();
var flyoutLoc = RunningApp.WaitForElement("FlyoutLabel")[0].Rect.Y;
Assert.AreEqual(0, flyoutLoc);
}
#endif
}
}