Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from unoplatform:master #144

Merged
merged 18 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using SamplesApp.UITests.TestFramework;
using Uno.UITest.Helpers;
using Uno.UITest.Helpers.Queries;

namespace SamplesApp.UITests.Windows_UI_Xaml_Controls.ThumbTests;

[TestFixture]
public partial class Tumb_CapturePreventScroll_Tests : SampleControlUITestBase
{
private const string _sample = "UITests.Windows_UI_Xaml_Controls.ThumbTests.Thumb_CapturePreventScroll";

[Test]
[AutoRetry]
[ActivePlatforms(Platform.iOS, Platform.Android)]
public void When_Drag_Then_DoesNotScroll()
{
Run(_sample);

var sut = _app.WaitForElement("SUT").Single().Rect;

_app.DragCoordinates(
sut.CenterX,
sut.CenterY,
sut.CenterX - 100,
sut.CenterY - 100);

var result = _app.Marked("Output").GetDependencyPropertyValue<string>("Text");

result.Should().Be("--none--");

// SANITY CHECK
// To validate that test is effectively testing something, let try to scroll bu clicking out of the thumb
_app.DragCoordinates(
sut.Right + 10,
sut.Bottom + 10,
sut.CenterX - 100,
sut.CenterY - 100);

result.Should().NotBe("--none--");
}
}
7 changes: 7 additions & 0 deletions src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -2566,6 +2566,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ThumbTests\Thumb_CapturePreventScroll.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ThumbTests\Thumb_DragEvents.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -7052,6 +7056,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\TextBox\Width_Affects_Delete_Button.xaml.cs">
<DependentUpon>Width_Affects_Delete_Button.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ThumbTests\Thumb_CapturePreventScroll.xaml.cs">
<DependentUpon>Thumb_CapturePreventScroll.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ThumbTests\Thumb_DragEvents.xaml.cs">
<DependentUpon>Thumb_DragEvents.xaml</DependentUpon>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Page
x:Class="UITests.Windows_UI_Xaml_Controls.ThumbTests.Thumb_CapturePreventScroll"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Windows_UI_Xaml_Controls.ThumbTests"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>
<ScrollViewer
HorizontalScrollMode="Enabled"
HorizontalScrollBarVisibility="Auto"
VerticalScrollMode="Enabled"
VerticalScrollBarVisibility="Auto"
Width="256"
Height="256"
ViewChanged="OnScrolled">
<Grid Width="1024" Height="1024" Background="DeepPink">
<Thumb x:Name="SUT" Width="32" Height="32" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="64" Background="DeepSkyBlue" />
</Grid>
</ScrollViewer>

<TextBlock x:Name="Output" VerticalAlignment="Bottom" HorizontalAlignment="Center" Text="--none--" />
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#nullable enable

using System;
using System.Linq;
using Microsoft.UI.Xaml.Controls;
using Uno.UI.Samples.Controls;

namespace UITests.Windows_UI_Xaml_Controls.ThumbTests;

[Sample("Thumb")]
public sealed partial class Thumb_CapturePreventScroll : Page
{
public Thumb_CapturePreventScroll()
{
this.InitializeComponent();
}

private void OnScrolled(object? sender, ScrollViewerViewChangedEventArgs e)
{
if (sender is ScrollViewer sv)
{
Output.Text = $"v: {sv.VerticalOffset:G2} | h: {sv.HorizontalOffset:G2}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,36 @@
using Microsoft.UI.Xaml.Controls.Primitives;
using Uno.UI.Samples.Controls;

namespace UITests.Windows_UI_Xaml_Controls.ThumbTests
namespace UITests.Windows_UI_Xaml_Controls.ThumbTests;

[Sample("Thumb", "Slider")]
public sealed partial class Thumb_DragEvents : Page
{
[Sample("Slider")]
public sealed partial class Thumb_DragEvents : Page
public Thumb_DragEvents()
{
public Thumb_DragEvents()
{
this.InitializeComponent();
}
this.InitializeComponent();
}

private void OnThumbDragStarted(object sender, DragStartedEventArgs e)
{
DragStartedOutput.Text = FormattableString.Invariant($"@x={e.HorizontalOffset:F2},@y={e.VerticalOffset:F2}");
}
private void OnThumbDragStarted(object sender, DragStartedEventArgs e)
{
DragStartedOutput.Text = FormattableString.Invariant($"@x={e.HorizontalOffset:F2},@y={e.VerticalOffset:F2}");
}

private void OnThumbDragDelta(object sender, DragDeltaEventArgs e)
{
private void OnThumbDragDelta(object sender, DragDeltaEventArgs e)
{
#if XAMARIN || __WASM__ // Total properties are uno only
DragDeltaOutput.Text = FormattableString.Invariant($"Δx={e.HorizontalChange:F2},Δy={e.VerticalChange:F2}|Σx={e.TotalHorizontalChange:F2},Σy={e.TotalVerticalChange:F2}");
DragDeltaOutput.Text = FormattableString.Invariant($"Δx={e.HorizontalChange:F2},Δy={e.VerticalChange:F2}|Σx={e.TotalHorizontalChange:F2},Σy={e.TotalVerticalChange:F2}");
#else
DragDeltaOutput.Text = FormattableString.Invariant($"Δx={e.HorizontalChange:F2},Δy={e.VerticalChange:F2}|Σx=0.0,Σy=0.0");
DragDeltaOutput.Text = FormattableString.Invariant($"Δx={e.HorizontalChange:F2},Δy={e.VerticalChange:F2}|Σx=0.0,Σy=0.0");
#endif
}
}

private void OnThumbDragCompleted(object sender, DragCompletedEventArgs e)
{
private void OnThumbDragCompleted(object sender, DragCompletedEventArgs e)
{
#if XAMARIN || __WASM__ // Total properties are uno only
DragCompletedOutput.Text = FormattableString.Invariant($"Δx={e.HorizontalChange:F2},Δy={e.VerticalChange:F2}|Σx={e.TotalHorizontalChange:F2},Σy={e.TotalVerticalChange:F2}");
DragCompletedOutput.Text = FormattableString.Invariant($"Δx={e.HorizontalChange:F2},Δy={e.VerticalChange:F2}|Σx={e.TotalHorizontalChange:F2},Σy={e.TotalVerticalChange:F2}");
#else
DragCompletedOutput.Text = FormattableString.Invariant($"Δx={e.HorizontalChange:F2},Δy={e.VerticalChange:F2}|Σx=0.0,Σy=0.0");
DragCompletedOutput.Text = FormattableString.Invariant($"Δx={e.HorizontalChange:F2},Δy={e.VerticalChange:F2}|Σx=0.0,Σy=0.0");
#endif
}
}
}
5 changes: 4 additions & 1 deletion src/Uno.Sdk/targets/Uno.Common.WinAppSdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
<SupportedOSPlatformVersion Condition=" $(SupportedOSPlatformVersion) == '' ">$(TargetPlatformMinVersion)</SupportedOSPlatformVersion>
<RuntimeIdentifiers Condition=" $(RuntimeIdentifiers) == '' ">win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<EnableCoreMrtTooling Condition=" $(EnableCoreMrtTooling) == '' AND '$(BuildingInsideVisualStudio)' != 'true' ">false</EnableCoreMrtTooling>
<EnableMsixTooling Condition=" $(EnableMsixTooling) == '' ">true</EnableMsixTooling>

<!-- Set EnableMsixTooling to true only for executables - setting this on class libraries prevents assets from being correctly copied to windows target -->
<EnableMsixTooling Condition=" $(EnableMsixTooling) == '' AND ('$(OutputType)' == 'WinExe' OR '$(OutputType)' == 'Exe') ">true</EnableMsixTooling>

<EnableWindowsTargeting Condition=" $(EnableWindowsTargeting) == '' ">true</EnableWindowsTargeting>
</PropertyGroup>

Expand Down
8 changes: 6 additions & 2 deletions src/Uno.Sdk/targets/winappsdk-workaround.targets
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<Project>
<!-- Workaround to avoid including Project XBFs in the PRI file: https://github.com/microsoft/microsoft-ui-xaml/issues/8857 -->
<Target Name="WinUI8857_AdjustGetPackagingOutput1" AfterTargets="GetMrtPackagingOutputs">
<Target Name="WinUI8857_AdjustGetPackagingOutput1"
AfterTargets="GetMrtPackagingOutputs"
Condition="'$(OutputType)' != 'WinExe'">
<Message Importance="high" Text="Applying NuGet packaging workaround for dependent PRI files exclusion" />
<ItemGroup>
<_OtherPriFiles Include="@(PackagingOutputs)" Condition="'%(Extension)' == '.pri' and ('%(PackagingOutputs.ReferenceSourceTarget)' == 'ProjectReference' or '%(PackagingOutputs.NugetSourceType)'=='Package')" />
<PackagingOutputs Remove="@(_OtherPriFiles)" />
</ItemGroup>
</Target>

<Target Name="WinUI8857_AdjustGetPackagingOutput2" BeforeTargets="AddPriPayloadFilesToCopyToOutputDirectoryItems">
<Target Name="WinUI8857_AdjustGetPackagingOutput2"
BeforeTargets="AddPriPayloadFilesToCopyToOutputDirectoryItems"
Condition="'$(OutputType)' != 'WinExe'">
<Message Importance="high" Text="Applying NuGet packaging workaround for dependent PRI files exclusion" />
<ItemGroup>
<_OtherPriFiles1 Include="@(_ReferenceRelatedPaths)" Condition="'%(Extension)' == '.pri' and ('%(_ReferenceRelatedPaths.ReferenceSourceTarget)' == 'ProjectReference' or '%(_ReferenceRelatedPaths.NugetSourceType)'=='Package')" />
Expand Down
4 changes: 2 additions & 2 deletions src/Uno.UI.Composition/Composition/Compositor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ public CompositionMaskBrush CreateMaskBrush()
public CompositionNineGridBrush CreateNineGridBrush()
=> new CompositionNineGridBrush(this);

internal void InvalidateRender() => InvalidateRenderPartial();
internal void InvalidateRender(Visual visual) => InvalidateRenderPartial(visual);

partial void InvalidateRenderPartial();
partial void InvalidateRenderPartial(Visual visual);
}
}
13 changes: 2 additions & 11 deletions src/Uno.UI.Composition/Composition/Compositor.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace Microsoft.UI.Composition;

public partial class Compositor
{
private bool _isDirty;

internal bool? IsSoftwareRenderer { get; set; }

internal void RenderRootVisual(SKSurface surface, ContainerVisual rootVisual)
Expand All @@ -19,18 +17,11 @@ internal void RenderRootVisual(SKSurface surface, ContainerVisual rootVisual)
throw new ArgumentNullException(nameof(rootVisual));
}

_isDirty = false;

rootVisual.RenderRootVisual(surface);
}

partial void InvalidateRenderPartial()
partial void InvalidateRenderPartial(Visual visual)
{
if (!_isDirty)
{
_isDirty = true;
// TODO: Invalidate each ContentRoot independently, including a root-specific dirty flag #8978
CoreApplication.QueueInvalidateRender();
}
CoreApplication.QueueInvalidateRender(visual.CompositionTarget);
}
}
16 changes: 8 additions & 8 deletions src/Uno.UI.Composition/Composition/Visual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public partial class Visual : CompositionObject, I3DTransformableObject
private bool _isVisible = true;
private float _opacity = 1.0f;
private CompositionCompositeMode _compositeMode;
private object? _compositionTarget; // this should be a Microsoft.UI.Xaml.Media.CompositionTarget

internal Visual(Compositor compositor) : base(compositor)
{
Expand Down Expand Up @@ -115,18 +116,17 @@ public Vector3 RotationAxis

public ContainerVisual? Parent { get; set; }

internal object? CompositionTarget
{
get => _compositionTarget ?? Parent?.CompositionTarget; // TODO: can this be cached?
set => _compositionTarget = value;
}

internal bool HasThemeShadow { get; set; }

private protected override void OnPropertyChangedCore(string? propertyName, bool isSubPropertyChange)
{
// TODO: Determine whether to invalidate renderer based on the fact whether we are attached to a CompositionTarget.
//bool isAttached = false;
//if (isAttached)
//{
// Compositor.InvalidateRender();
//}

Compositor.InvalidateRender();
Compositor.InvalidateRender(this);
}
}
}
2 changes: 1 addition & 1 deletion src/Uno.UI.Composition/Composition/Visual.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Vector2 AnchorPoint
set
{
SetProperty(ref _anchorPoint, value);
Compositor.InvalidateRender();
Compositor.InvalidateRender(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls;
[RunsOnUIThread]
public class Given_CalendarView
{
[TestMethod]
public async Task When_MinDate_Has_Different_Offset()
{
var calendarView = new CalendarView();
calendarView.MinDate = new DateTimeOffset(new DateTime(2010, 1, 1, 22, 0, 0), TimeSpan.Zero);
calendarView.MaxDate = new DateTimeOffset(new DateTime(2010, 1, 31), TimeSpan.FromHours(2));

await UITestHelper.Load(calendarView);
}

#if __WASM__
[TestMethod]
public async Task When_ItemCornerRadius()
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI.Tests/Windows_Globalization/When_Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void When_DateTimeOffset_Is_Next_Day_If_Converted_To_Utc()
var comparer = new DirectUI.DateComparer();
comparer.SetCalendarForComparison(calendar);
var result = comparer.CompareDay(offset, new DateTimeOffset(year: 2023, month: 5, day: 1, hour: 4, minute: 0, second: 0, TimeSpan.FromHours(0)));
Assert.AreEqual(0, result);
Assert.AreEqual(1, result);
}

[TestMethod]
Expand Down
9 changes: 8 additions & 1 deletion src/Uno.UI/DirectUI/DateComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,14 @@ private int CompareDate(

global::System.Diagnostics.Debug.Assert(m_spCalendar is { });

long delta = lhs.ToUniversalTime().Ticks - rhs.ToUniversalTime().Ticks;
// Uno specific: In WinUI, wf::DateTime is a struct that only has "UniversalTime" field.
// So, we need to call ToUniversalTime here.
// Failure to do so can cause issues when comparing dates like 2024/01/01 10:00:00 PM UTC+2 and 2024/01/02 12:00:00 AM UTC
// Both dates should be equal, but getUnit will return 1 and 2 indicating that the first date is smaller.
lhs = lhs.ToUniversalTime();
rhs = rhs.ToUniversalTime();

long delta = lhs.Ticks - rhs.Ticks;
if (delta < 0)
{
delta = -delta;
Expand Down
24 changes: 14 additions & 10 deletions src/Uno.UI/UI/Xaml/Application.skia.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
#nullable enable

using System;
using System.Diagnostics;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Metadata;
using Microsoft.UI.Xaml.Controls.Primitives;
using Windows.ApplicationModel;
using Windows.Graphics.Display;
using Windows.UI.Core;
using Uno.Foundation.Logging;
using System.Threading;
using System.Globalization;
using Windows.ApplicationModel.Core;
using Windows.Globalization;
using Microsoft.UI.Xaml.Media;
using Uno.UI.Dispatching;
using Uno.UI.Xaml.Core;

Expand All @@ -34,12 +30,20 @@ partial void InitializePartial()

_ = CoreDispatcher.Main.RunAsync(CoreDispatcherPriority.Normal, Initialize);

CoreApplication.SetInvalidateRender(() =>
CoreApplication.SetInvalidateRender(compositionTarget =>
{
var roots = CoreServices.Instance.ContentRootCoordinator.ContentRoots;
for (int i = 0; i < roots.Count; i++)
Debug.Assert(compositionTarget is null or CompositionTarget);

if (compositionTarget is CompositionTarget { Root: { } root })
{
roots[i].XamlRoot?.QueueInvalidateRender();
foreach (var cRoot in CoreServices.Instance.ContentRootCoordinator.ContentRoots)
{
if (cRoot?.XamlRoot is { } xRoot && ReferenceEquals(xRoot.VisualTree.RootElement.Visual, root))
{
xRoot.QueueInvalidateRender();
return;
}
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ void CreateLayer(Action<CompositionSpriteShape, SKPath> builder, string name)
}
);

compositor.InvalidateRender();
compositor.InvalidateRender(visual);

return disposables;
}
Expand Down
Loading
Loading