Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dev/macos-actionsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Jun 7, 2024
2 parents 17ea9c6 + 93a1bc4 commit 3dbce49
Show file tree
Hide file tree
Showing 64 changed files with 435 additions and 389 deletions.
8 changes: 5 additions & 3 deletions eng/scripts/appium-install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ if (!(Test-Path $logsDir -PathType Container)) {
$AppiumHome = $env:APPIUM_HOME
Write-Output "APPIUM_HOME: $AppiumHome"

if (Test-Path $AppiumHome) {
Write-Output "Removing existing APPIUM_HOME Cache..."
Remove-Item -Path $AppiumHome -Recurse -Force
if ($AppiumHome) {
if (Test-Path $AppiumHome) {
Write-Output "Removing existing APPIUM_HOME Cache..."
Remove-Item -Path $AppiumHome -Recurse -Force
}
}

# Create the directory for appium home
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#nullable disable
using System;
using System.ComponentModel;
using CoreGraphics;
using ObjCRuntime;
Expand Down Expand Up @@ -26,20 +27,20 @@ public static UIBarButtonItem ToUIBarButtonItem(this ToolbarItem item, bool forc
sealed class PrimaryToolbarItem : UIBarButtonItem
{
readonly bool _forceName;
readonly ToolbarItem _item;
readonly WeakReference<ToolbarItem> _item;

public PrimaryToolbarItem(ToolbarItem item, bool forceName)
{
_forceName = forceName;
_item = item;
_item = new(item);

if (item.IconImageSource != null && !item.IconImageSource.IsEmpty && !forceName)
UpdateIconAndStyle();
UpdateIconAndStyle(item);
else
UpdateTextAndStyle();
UpdateIsEnabled();
UpdateTextAndStyle(item);
UpdateIsEnabled(item);

Clicked += (sender, e) => ((IMenuItemController)_item).Activate();
Clicked += OnClicked;
item.PropertyChanged += OnPropertyChanged;

if (item != null && !string.IsNullOrEmpty(item.AutomationId))
Expand All @@ -49,65 +50,76 @@ public PrimaryToolbarItem(ToolbarItem item, bool forceName)
this.SetAccessibilityLabel(item);
}

void OnClicked (object sender, EventArgs e)
{
if (_item.TryGetTarget(out var item))
{
((IMenuItemController)item).Activate();
}
}

protected override void Dispose(bool disposing)
{
if (disposing)
_item.PropertyChanged -= OnPropertyChanged;
if (disposing && _item.TryGetTarget(out var item))
item.PropertyChanged -= OnPropertyChanged;
base.Dispose(disposing);
}

void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (!_item.TryGetTarget(out var item))
return;

if (e.PropertyName == MenuItem.IsEnabledProperty.PropertyName)
UpdateIsEnabled();
UpdateIsEnabled(item);
else if (e.PropertyName == MenuItem.TextProperty.PropertyName)
{
if (_item.IconImageSource == null || _item.IconImageSource.IsEmpty || _forceName)
UpdateTextAndStyle();
if (item.IconImageSource == null || item.IconImageSource.IsEmpty || _forceName)
UpdateTextAndStyle(item);
}
else if (e.PropertyName == MenuItem.IconImageSourceProperty.PropertyName)
{
if (!_forceName)
{
if (_item.IconImageSource != null && !_item.IconImageSource.IsEmpty)
UpdateIconAndStyle();
if (item.IconImageSource != null && !item.IconImageSource.IsEmpty)
UpdateIconAndStyle(item);
else
UpdateTextAndStyle();
UpdateTextAndStyle(item);
}
}
#pragma warning disable CS0618 // Type or member is obsolete
else if (e.PropertyName == AutomationProperties.HelpTextProperty.PropertyName)
this.SetAccessibilityHint(_item);
this.SetAccessibilityHint(item);
else if (e.PropertyName == AutomationProperties.NameProperty.PropertyName)
this.SetAccessibilityLabel(_item);
this.SetAccessibilityLabel(item);
#pragma warning restore CS0618 // Type or member is obsolete
}

void UpdateIconAndStyle()
void UpdateIconAndStyle(ToolbarItem item)
{
if (_item?.IconImageSource == null)
if (item?.IconImageSource == null)
{
Image = null;
Style = UIBarButtonItemStyle.Plain;
}
else
{
_item.IconImageSource.LoadImage(_item.FindMauiContext(), result =>
item.IconImageSource.LoadImage(item.FindMauiContext(), result =>
{
Image = result?.Value;
Style = UIBarButtonItemStyle.Plain;
});
}
}

void UpdateIsEnabled()
void UpdateIsEnabled(ToolbarItem item)
{
Enabled = _item.IsEnabled;
Enabled = item.IsEnabled;
}

void UpdateTextAndStyle()
void UpdateTextAndStyle(ToolbarItem item)
{
Title = _item.Text;
Title = item.Text;
#pragma warning disable CA1416, CA1422 // TODO: [UnsupportedOSPlatform("ios8.0")]
Style = UIBarButtonItemStyle.Bordered;
#pragma warning restore CA1416, CA1422
Expand All @@ -117,16 +129,16 @@ void UpdateTextAndStyle()

sealed class SecondaryToolbarItem : UIBarButtonItem
{
readonly ToolbarItem _item;
readonly WeakReference<ToolbarItem> _item;

public SecondaryToolbarItem(ToolbarItem item) : base(new SecondaryToolbarItemContent())
{
_item = item;
UpdateText();
UpdateIcon();
UpdateIsEnabled();
_item = new(item);
UpdateText(item);
UpdateIcon(item);
UpdateIsEnabled(item);

((SecondaryToolbarItemContent)CustomView).TouchUpInside += (sender, e) => ((IMenuItemController)_item).Activate();
((SecondaryToolbarItemContent)CustomView).TouchUpInside += OnClicked;
item.PropertyChanged += OnPropertyChanged;

if (item != null && !string.IsNullOrEmpty(item.AutomationId))
Expand All @@ -136,34 +148,45 @@ public SecondaryToolbarItem(ToolbarItem item) : base(new SecondaryToolbarItemCon
this.SetAccessibilityLabel(item);
}

void OnClicked (object sender, EventArgs e)
{
if (_item.TryGetTarget(out var item))
{
((IMenuItemController)item).Activate();
}
}

protected override void Dispose(bool disposing)
{
if (disposing)
_item.PropertyChanged -= OnPropertyChanged;
if (disposing && _item.TryGetTarget(out var item))
item.PropertyChanged -= OnPropertyChanged;
base.Dispose(disposing);
}

void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (!_item.TryGetTarget(out var item))
return;

if (e.PropertyName == MenuItem.TextProperty.PropertyName)
UpdateText();
UpdateText(item);
else if (e.PropertyName == MenuItem.IconImageSourceProperty.PropertyName)
UpdateIcon();
UpdateIcon(item);
else if (e.PropertyName == MenuItem.IsEnabledProperty.PropertyName)
UpdateIsEnabled();
UpdateIsEnabled(item);
#pragma warning disable CS0618 // Type or member is obsolete
else if (e.PropertyName == AutomationProperties.HelpTextProperty.PropertyName)
this.SetAccessibilityHint(_item);
this.SetAccessibilityHint(item);
else if (e.PropertyName == AutomationProperties.NameProperty.PropertyName)
#pragma warning restore CS0618 // Type or member is obsolete
this.SetAccessibilityLabel(_item);
this.SetAccessibilityLabel(item);
}

void UpdateIcon()
void UpdateIcon(ToolbarItem item)
{
if (_item.IconImageSource != null && !_item.IconImageSource.IsEmpty)
if (item.IconImageSource != null && !item.IconImageSource.IsEmpty)
{
_item.IconImageSource.LoadImage(_item.FindMauiContext(), result =>
item.IconImageSource.LoadImage(item.FindMauiContext(), result =>
{
((SecondaryToolbarItemContent)CustomView).Image = result?.Value;
});
Expand All @@ -174,14 +197,14 @@ void UpdateIcon()
}
}

void UpdateIsEnabled()
void UpdateIsEnabled(ToolbarItem item)
{
((UIControl)CustomView).Enabled = _item.IsEnabled;
((UIControl)CustomView).Enabled = item.IsEnabled;
}

void UpdateText()
void UpdateText(ToolbarItem item)
{
((SecondaryToolbarItemContent)CustomView).Text = _item.Text;
((SecondaryToolbarItemContent)CustomView).Text = item.Text;
}

sealed class SecondaryToolbarItemContent : UIControl
Expand Down
43 changes: 30 additions & 13 deletions src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ await CreateHandlerAndAddToWindow<WindowHandlerStub>(shell, async (handler) =>
Assert.True(pageBounds.Height <= window.Height);
});
}
#endif

#if ANDROID || IOS || MACCATALYST
[Fact]
Expand Down Expand Up @@ -1014,18 +1015,7 @@ await CreateHandlerAndAddToWindow<ShellHandler>(shell, async (handler) =>
{
await OnLoadedAsync(shell.CurrentPage);

var page = new ContentPage
{
Title = "Page 2",
Content = new VerticalStackLayout
{
new Label(),
new Button(),
new Controls.ContentView(),
new ScrollView(),
new CollectionView(),
}
};
var page = new LeakyShellPage();
pageReference = new WeakReference(page);

await shell.Navigation.PushAsync(page);
Expand All @@ -1035,6 +1025,33 @@ await CreateHandlerAndAddToWindow<ShellHandler>(shell, async (handler) =>
await AssertionExtensions.WaitForGC(pageReference);
}

class LeakyShellPage : ContentPage
{
public LeakyShellPage()
{
Title = "Page 2";
Content = new VerticalStackLayout
{
new Label(),
new Button(),
new Controls.ContentView(),
new ScrollView(),
new CollectionView(),
};

var item = new ToolbarItem { Text = "Primary Item", Order = ToolbarItemOrder.Primary };
item.Clicked += OnToolbarItemClicked;
ToolbarItems.Add(item);

item = new ToolbarItem { Text = "Secondary Item", Order = ToolbarItemOrder.Secondary };
item.Clicked += OnToolbarItemClicked;
ToolbarItems.Add(item);
}

// Needs to be an instance method
void OnToolbarItemClicked(object sender, EventArgs e) { }
}

//HideSoftInputOnTapped doesn't currently do anything on windows
#if !WINDOWS
[Fact(DisplayName = "HideSoftInputOnTapped Doesn't Crash If Entry Is Still Focused After Window Is Null")]
Expand Down Expand Up @@ -1188,7 +1205,7 @@ await CreateHandlerAndAddToWindow<IWindowHandler>(shell, _ =>
Assert.Equal(count, appearanceObservers.Count); // Count doesn't increase
});
}
#endif

protected Task<Shell> CreateShellAsync(Action<Shell> action) =>
InvokeOnMainThreadAsync(() =>
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ public CollectionViewBoundMultiSelectionUITests(TestDevice device)
// ItemsFromViewModelShouldBeSelected (src\Compatibility\ControlGallery\src\Issues.Shared\CollectionViewBoundMultiSelection.cs)
[Test]
[Category(UITestCategories.CollectionView)]
[Ignore("Click does not find CollectionView elements.")]
[FailsOnAllPlatforms("Click does not find CollectionView elements.")]
public void ItemsFromViewModelShouldBeSelected()
{
this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.Android, TestDevice.iOS, TestDevice.Mac, TestDevice.Windows },
"Click does not find CollectionView elements.");

// Navigate to the selection galleries
VisitInitialGallery("Selection");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ public CollectionViewSingleBoundSelectionUITests(TestDevice device)
/*
// SelectionShouldUpdateBinding (src\Compatibility\ControlGallery\src\Issues.Shared\CollectionViewBoundSingleSelection.cs)
[Test]
[Ignore("Click does not find CollectionView elements")]
[FailsOnAllPlatforms("Click does not find CollectionView elements")]
[Description("Single Selection Binding")]
public void SelectionShouldUpdateBinding()
{
this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.Android, TestDevice.iOS, TestDevice.Mac, TestDevice.Windows },
"Click does not find CollectionView elements");
// Navigate to the selection galleries
VisitInitialGallery("Selection");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ public VisitAndUpdateItemsSourceUITests(TestDevice device)
[TestCase("DataTemplate", "VerticalGridCode", 19, 6)]
[TestCase("DataTemplate", "HorizontalGridCode", 19, 6)]
[Category(UITestCategories.CollectionView)]
[FailsOnWindows("This test is failing, likely due to product issue.")]
public void VisitAndUpdateItemsSource(string collectionTestName, string subGallery, int firstItem, int lastItem)
{
this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.Windows },
"This test is failing, likely due to product issue.");

try
{
VisitInitialGallery(collectionTestName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ protected override void FixtureSetup()

[Test]
[Category(UITestCategories.Gestures)]
[FailsOnAndroid("PointerGestureRecognizer doesn't work with mouse in Android")]
[FailsOnIOS("PointerGestureRecognizer doesn't work with mouse in iOS")]
public void PointerGestureTest()
{
this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.Android, TestDevice.iOS },
"PointerGestureRecognizer doesn't work with mouse in Android or iOS");

App.WaitForElement("TargetView");
App.EnterText("TargetView", "PointerGestureRecognizerEvents");
App.Tap("GoButton");
Expand Down
Loading

0 comments on commit 3dbce49

Please sign in to comment.