Skip to content

Commit

Permalink
Automated dotnet-format update (xamarin#13297)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Make sure all the UIViews is iOS are added at the correct hierarchy (xamarin#13300) fixes xamarin#13295

* Fix layout of FlyoutContent

* - fix ui tests
  • Loading branch information
github-actions[bot] authored and Tim Dittmar committed Jan 8, 2021
1 parent c54ed94 commit 669221c
Show file tree
Hide file tree
Showing 8 changed files with 491 additions and 21 deletions.
@@ -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
}
}

0 comments on commit 669221c

Please sign in to comment.