Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions eng/cake/dotnet.cake
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ Task("VS")
Error("!!!!BUILD TASKS FAILED: !!!!!");
}

UseLocalNuGetCacheFolder();

StartVisualStudioForDotNet6();
});

Expand Down Expand Up @@ -568,6 +570,23 @@ void SetDotNetEnvironmentVariables()
SetEnvironmentVariable("MSBuildDebugEngine", "1");
}

void UseLocalNuGetCacheFolder(bool reset = false)
{
var temp = Context.Environment.GetSpecialPath(SpecialPath.LocalTemp);
var packages = temp.Combine("Microsoft.Maui.Cache/NuGet/packages");

EnsureDirectoryExists(packages);

CleanDirectories(packages.FullPath + "/microsoft.maui.*");
CleanDirectories(packages.FullPath + "/microsoft.aspnetcore.*");

if (reset)
CleanDirectories(packages.FullPath);

SetEnvironmentVariable("RestorePackagesPath", packages.FullPath);
SetEnvironmentVariable("NUGET_PACKAGES", packages.FullPath);
}

void StartVisualStudioForDotNet6()
{
string sln = Argument<string>("sln", null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.Views;
using Android.Views.Animations;
using AndroidX.CardView.Widget;
using AndroidX.Core.View;
using Microsoft.Maui.Controls.Platform;
Expand Down Expand Up @@ -52,7 +53,6 @@ public static IPropertyMapper<Frame, FrameRenderer> Mapper
public static CommandMapper<Frame, FrameRenderer> CommandMapper
= new CommandMapper<Frame, FrameRenderer>(ViewRenderer.VisualElementRendererCommandMapper);


float _defaultElevation = -1f;
float _defaultCornerRadius = -1f;

Expand All @@ -68,6 +68,8 @@ public static CommandMapper<Frame, FrameRenderer> CommandMapper
public event EventHandler<VisualElementChangedEventArgs>? ElementChanged;
public event EventHandler<PropertyChangedEventArgs>? ElementPropertyChanged;

const double LegacyMinimumFrameSize = 20;

public FrameRenderer(Context context) : this(context, Mapper)
{
}
Expand Down Expand Up @@ -96,17 +98,28 @@ protected Frame? Element
}
}

Size IViewHandler.GetDesiredSize(double widthMeasureSpec, double heightMeasureSpec)
Size IViewHandler.GetDesiredSize(double widthConstraint, double heightConstraint)
{
double minWidth = 20;
if (Primitives.Dimension.IsExplicitSet(widthMeasureSpec) && !double.IsInfinity(widthMeasureSpec))
minWidth = widthMeasureSpec;
var virtualView = (this as IViewHandler)?.VirtualView;
if (virtualView is null)
{
return Size.Zero;
}

var minWidth = virtualView.MinimumWidth;
var minHeight = virtualView.MinimumHeight;

double minHeight = 20;
if (Primitives.Dimension.IsExplicitSet(widthMeasureSpec) && !double.IsInfinity(heightMeasureSpec))
minHeight = heightMeasureSpec;
if (!Primitives.Dimension.IsExplicitSet(minWidth))
{
minWidth = LegacyMinimumFrameSize;
}

if (!Primitives.Dimension.IsExplicitSet(minHeight))
{
minHeight = LegacyMinimumFrameSize;
}

return VisualElementRenderer<Frame>.GetDesiredSize(this, widthMeasureSpec, heightMeasureSpec,
return VisualElementRenderer<Frame>.GetDesiredSize(this, widthConstraint, heightConstraint,
new Size(minWidth, minHeight));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ protected virtual void LoadRenderers()

if (item == currentItem)
{
_containerArea.AddSubview(renderer.PlatformView);
_containerArea.AddSubview(renderer.ViewController.View);
_currentContent = currentItem;
_currentIndex = i;
}
Expand Down
65 changes: 31 additions & 34 deletions src/Controls/tests/DeviceTests/ControlsHandlerTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,8 @@ protected override MauiAppBuilder ConfigureBuilder(MauiAppBuilder mauiAppBuilder
return mauiAppBuilder.ConfigureTestBuilder();
}

protected void SetupShellHandlers(IMauiHandlersCollection handlers)
{
handlers.TryAddHandler(typeof(Controls.Shell), typeof(ShellHandler));
handlers.TryAddHandler<Layout, LayoutHandler>();
handlers.TryAddHandler<Image, ImageHandler>();
handlers.TryAddHandler<Label, LabelHandler>();
handlers.TryAddHandler<Page, PageHandler>();
handlers.TryAddHandler(typeof(Toolbar), typeof(ToolbarHandler));
handlers.TryAddHandler(typeof(MenuBar), typeof(MenuBarHandler));
handlers.TryAddHandler(typeof(MenuBarItem), typeof(MenuBarItemHandler));
handlers.TryAddHandler(typeof(MenuFlyoutItem), typeof(MenuFlyoutItemHandler));
handlers.TryAddHandler(typeof(MenuFlyoutSubItem), typeof(MenuFlyoutSubItemHandler));
handlers.TryAddHandler<ScrollView, ScrollViewHandler>();

#if WINDOWS
handlers.TryAddHandler(typeof(ShellItem), typeof(ShellItemHandler));
handlers.TryAddHandler(typeof(ShellSection), typeof(ShellSectionHandler));
handlers.TryAddHandler(typeof(ShellContent), typeof(ShellContentHandler));
#endif
}
protected void SetupShellHandlers(IMauiHandlersCollection handlers) =>
handlers.SetupShellHandlers();

protected THandler CreateHandler<THandler>(IElement view)
where THandler : IElementHandler, new()
Expand Down Expand Up @@ -99,6 +81,29 @@ protected Task<TValue> GetValueAsync<TValue>(IElement view, Func<IPlatformViewHa
});
}

IWindow CreateWindowForContent(IElement view)
{
IWindow window;

if (view is IWindow w)
window = w;
else if (view is Page page)
window = new Controls.Window(page);
else
window = new Controls.Window(new ContentPage() { Content = (View)view });

return window;
}

protected Task CreateHandlerAndAddToWindow(IElement view, Action action)
{
return CreateHandlerAndAddToWindow<IWindowHandler>(CreateWindowForContent(view), handler =>
{
action();
return Task.CompletedTask;
});
}

protected Task CreateHandlerAndAddToWindow<THandler>(IElement view, Action<THandler> action)
where THandler : class, IElementHandler
{
Expand All @@ -117,23 +122,10 @@ protected Task CreateHandlerAndAddToWindow<THandler>(IElement view, Func<THandle

return InvokeOnMainThreadAsync(async () =>
{
IWindow window = null;
IWindow window = CreateWindowForContent(view);

var application = mauiContext.Services.GetService<IApplication>();

if (view is IWindow w)
{
window = w;
}
else if (view is Page page)
{
window = new Controls.Window(page);
}
else
{
window = new Controls.Window(new ContentPage() { Content = (View)view });
}

if (application is ApplicationStub appStub)
{
appStub.SetWindow((Window)window);
Expand All @@ -150,6 +142,9 @@ await SetupWindowForTests<THandler>(window, async () =>
{
IView content = window.Content;

if (content is FlyoutPage fp)
content = fp.Detail;

if (content is IPageContainer<Page> pc)
{
content = pc.CurrentPage;
Expand Down Expand Up @@ -180,6 +175,8 @@ await SetupWindowForTests<THandler>(window, async () =>
await action((THandler)window.Content.Handler);
else if (window.Content is ContentPage cp && typeof(THandler).IsAssignableFrom(cp.Content.Handler.GetType()))
await action((THandler)cp.Content.Handler);
else if (typeof(THandler).IsAssignableFrom(typeof(WindowHandler)))
throw new Exception($"Use IWindowHandler instead of WindowHandler for CreateHandlerAndAddToWindow");
else
throw new Exception($"I can't work with {typeof(THandler)}");

Expand Down
58 changes: 57 additions & 1 deletion src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.iOS.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
using System.Threading.Tasks;
using Microsoft.Maui.Controls;
using Microsoft.Maui.DeviceTests.TestCases;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.Platform;
using UIKit;
using Xunit;

namespace Microsoft.Maui.DeviceTests
{
Expand Down Expand Up @@ -36,5 +41,56 @@ int GetPlatformSelectionLength(EntryHandler entryHandler)

return -1;
}

[Category(TestCategory.Entry)]
[Collection(ControlsHandlerTestBase.RunInNewWindowCollection)]
public partial class EntryTestsWithWindow : ControlsHandlerTestBase
{
[Theory]
[ClassData(typeof(ControlsPageTypesTestCases))]
public async Task NextMovesToNextEntry(string page)
{
EnsureHandlerCreated(builder =>
{
ControlsPageTypesTestCases.Setup(builder);
builder.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler(typeof(Entry), typeof(EntryHandler));
});
});

var entry1 = new Entry
{
Text = "Entry 1",
ReturnType = ReturnType.Next
};

var entry2 = new Entry
{
Text = "Entry 2",
ReturnType = ReturnType.Next
};

ContentPage contentPage = new ContentPage()
{
Content = new VerticalStackLayout()
{
entry1,
entry2
}
};

Page rootPage = ControlsPageTypesTestCases.CreatePageType(page, contentPage);
Page hostPage = new ContentPage();

await CreateHandlerAndAddToWindow(hostPage, async () =>
{
await hostPage.Navigation.PushModalAsync(rootPage);
KeyboardAutoManager.GoToNextResponderOrResign(entry1.ToPlatform());
await AssertionExtensions.Wait(() => entry2.IsFocused);
Assert.True(entry2.IsFocused);
});
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System.Threading.Tasks;
using Java.Lang;
using Microsoft.Maui.Controls;
using Xunit;
using Xunit.Sdk;

namespace Microsoft.Maui.DeviceTests
{
Expand All @@ -21,5 +25,23 @@ public override Task ContainerViewRemainsIfShadowMapperRunsAgain()
// https://github.com/dotnet/maui/pull/12218
return Task.CompletedTask;
}

public override async Task ReturnsNonEmptyNativeBoundingBox(int size)
{
// Frames have a legacy hard-coded minimum size of 20x20
var expectedSize = Math.Max(20, size);
var expectedBounds = new Graphics.Rect(0, 0, expectedSize, expectedSize);

var view = new Frame()
{
HeightRequest = size,
WidthRequest = size
};

var nativeBoundingBox = await GetValueAsync(view, handler => GetBoundingBox(handler));
Assert.NotEqual(nativeBoundingBox, Graphics.Rect.Zero);

AssertWithinTolerance(expectedBounds.Size, nativeBoundingBox.Size);
}
}
}
Loading