-
Notifications
You must be signed in to change notification settings - Fork 750
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18294 from unoplatform/dev/dr/inertia
fix: Restore inertia
- Loading branch information
Showing
13 changed files
with
321 additions
and
117 deletions.
There are no files selected for viewing
32 changes: 9 additions & 23 deletions
32
...mplesApp/UITests.Shared/Windows_UI_Input/GestureRecognizerTests/Manipulation_Inertia.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,12 @@ | ||
<Page | ||
x:Class="UITests.Windows_UI_Input.GestureRecognizerTests.Manipulation_Inertia" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:UITests.Windows_UI_Input.GestureRecognizerTests" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
x:Class="UITests.Windows_UI_Input.GestureRecognizerTests.Manipulation_Inertia" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:runtimeTests="using:RuntimeTests.Tests.Windows_UI_Xaml_Input.TestPages" | ||
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 | ||
Background="Orange" | ||
ManipulationMode="All" | ||
ManipulationInertiaStarting="InertiaStarting" | ||
ManipulationDelta="ManipDelta"> | ||
|
||
<Rectangle | ||
x:Name="_element" | ||
Width="200" | ||
Height="200" | ||
Fill="DeepPink" | ||
RenderTransformOrigin=".5,.5" /> | ||
|
||
<Button VerticalAlignment="Top" HorizontalAlignment="Right" Content="Reset" Click="Reset" /> | ||
</Grid> | ||
<runtimeTests:Manipulation_Inertia /> | ||
</Page> |
62 changes: 1 addition & 61 deletions
62
...esApp/UITests.Shared/Windows_UI_Input/GestureRecognizerTests/Manipulation_Inertia.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,16 @@ | ||
using System; | ||
using System.Linq; | ||
using Windows.Foundation; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Input; | ||
using Microsoft.UI.Xaml.Media; | ||
using Uno.UI.Samples.Controls; | ||
|
||
#if HAS_UNO_WINUI || WINAPPSDK | ||
using Microsoft.UI.Input; | ||
#else | ||
using Windows.Devices.Input; | ||
using Windows.UI.Input; | ||
#endif | ||
|
||
namespace UITests.Windows_UI_Input.GestureRecognizerTests | ||
{ | ||
[Sample("Gesture Recognizer")] | ||
[Sample("Gesture Recognizer", IsManualTest = true)] | ||
public sealed partial class Manipulation_Inertia : Page | ||
{ | ||
public Manipulation_Inertia() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
|
||
private long _inertiaStart = 0; | ||
|
||
private void InertiaStarting(object sender, ManipulationInertiaStartingRoutedEventArgs e) | ||
{ | ||
_inertiaStart = DateTimeOffset.UtcNow.Ticks; | ||
|
||
//e.TranslationBehavior.DesiredDisplacement = 5; | ||
//e.TranslationBehavior.DesiredDeceleration = .00001; | ||
|
||
Log(@$"[INERTIA] Inertia starting: {F(default, e.Delta, e.Cumulative, e.Velocities)} | ||
tr: ↘={e.TranslationBehavior.DesiredDeceleration} | ⌖={e.TranslationBehavior.DesiredDisplacement} | ||
θ: ↘={e.RotationBehavior.DesiredDeceleration} | ⌖={e.RotationBehavior.DesiredRotation} | ||
s: ↘={e.ExpansionBehavior.DesiredDeceleration} | ⌖={e.ExpansionBehavior.DesiredExpansion}"); | ||
} | ||
|
||
private void ManipDelta(object sender, ManipulationDeltaRoutedEventArgs e) | ||
{ | ||
if (!(_element.RenderTransform is CompositeTransform tr)) | ||
{ | ||
_element.RenderTransform = tr = new CompositeTransform(); | ||
} | ||
|
||
tr.TranslateX = e.Cumulative.Translation.X; | ||
tr.TranslateY = e.Cumulative.Translation.Y; | ||
tr.Rotation = e.Cumulative.Rotation; | ||
tr.ScaleX = e.Cumulative.Scale; | ||
tr.ScaleY = e.Cumulative.Scale; | ||
|
||
Log( | ||
$"[DELTA] {F(e.Position, e.Delta, e.Cumulative, e.Velocities)} " | ||
+ (e.IsInertial ? $"{TimeSpan.FromTicks(DateTimeOffset.UtcNow.Ticks - _inertiaStart).TotalMilliseconds} ms" : "")); | ||
} | ||
|
||
private void Reset(object sender, RoutedEventArgs e) | ||
{ | ||
_element.RenderTransform = new CompositeTransform(); | ||
} | ||
|
||
private static string F(Point position, ManipulationDelta delta, ManipulationDelta cumulative, ManipulationVelocities velocities) | ||
=> $"@=[{position.X:000.00},{position.Y:000.00}] " | ||
+ $"| X=(Σ:{cumulative.Translation.X:' '000.00;'-'000.00} / Δ:{delta.Translation.X:' '00.00;'-'00.00} / c:{velocities.Linear.X:F2}) " | ||
+ $"| Y=(Σ:{cumulative.Translation.Y:' '000.00;'-'000.00} / Δ:{delta.Translation.Y:' '00.00;'-'00.00} / c:{velocities.Linear.Y:F2}) " | ||
+ $"| θ=(Σ:{cumulative.Rotation:' '000.00;'-'000.00} / Δ:{delta.Rotation:' '00.00;'-'00.00} / c:{velocities.Angular:F2}) " | ||
+ $"| s=(Σ:{cumulative.Scale:000.00} / Δ:{delta.Scale:00.00} / c:{velocities.Expansion:F2}) " | ||
+ $"| e=(Σ:{cumulative.Expansion:' '000.00;'-'000.00} / Δ:{delta.Expansion:' '00.00;'-'00.00} / c:{velocities.Expansion:F2})"; | ||
|
||
private static void Log(string text) | ||
=> global::System.Diagnostics.Debug.WriteLine(text); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Input/Given_GestureRecognizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Windows.Foundation; | ||
using Windows.UI.Input.Preview.Injection; | ||
using FluentAssertions; | ||
using RuntimeTests.Tests.Windows_UI_Xaml_Input.TestPages; | ||
using Uno.Extensions; | ||
using Uno.UI.RuntimeTests.Helpers; | ||
|
||
#if WINAPPSDK | ||
using Uno.UI.Toolkit.Extensions; | ||
#endif | ||
|
||
#if HAS_UNO_WINUI || WINAPPSDK | ||
using PointerDeviceType = Microsoft.UI.Input.PointerDeviceType; | ||
#else | ||
using PointerDeviceType = Windows.Devices.Input.PointerDeviceType; | ||
#endif | ||
|
||
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Input | ||
{ | ||
[TestClass] | ||
public class Given_GestureRecognizer | ||
{ | ||
[TestMethod] | ||
[RunsOnUIThread] | ||
#if !HAS_INPUT_INJECTOR || (!HAS_UNO_WINUI && !WINAPPSDK) // Requires pointer injection and WinUI API | ||
[Ignore("This test is not supported on this platform.")] | ||
#endif | ||
#if !WINAPPSDK | ||
[DataRow(PointerDeviceType.Mouse)] | ||
#endif | ||
[DataRow(PointerDeviceType.Touch)] | ||
public async Task When_ManipulateWithVelocity_Then_InertiaKicksIn(PointerDeviceType type) | ||
{ | ||
var sample = new Manipulation_Inertia(); | ||
await UITestHelper.Load(sample); | ||
|
||
var started = false; | ||
var completed = new TaskCompletionSource(); | ||
var completedTimeout = new CancellationTokenSource(15000); | ||
using var _ = completedTimeout.Token.Register(() => completed.TrySetException(new TimeoutException("Cannot get complete in given delay."))); | ||
sample.IsRunningChanged += (snd, isRunning) => | ||
{ | ||
if (isRunning) | ||
{ | ||
started = true; | ||
} | ||
else | ||
{ | ||
completed.TrySetResult(); | ||
} | ||
}; | ||
|
||
var origin = sample.Element.GetAbsoluteBounds().GetCenter(); | ||
var pointer = (InputInjector.TryCreate() ?? throw new InvalidOperationException("Input injection is not supported on this device")).GetPointer(type); | ||
pointer.Press(origin); | ||
pointer.MoveTo(new Point(origin.X, origin.Y + 25), steps: 100); // 1 step per ms! | ||
|
||
started.Should().Be(true, "Manipulation should have started."); | ||
|
||
pointer.Release(); | ||
|
||
await completed.Task; | ||
|
||
sample.Validate().Should().BeTrue(); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Input/TestPages/Manipulation_Inertia.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<Page | ||
x:Class="RuntimeTests.Tests.Windows_UI_Xaml_Input.TestPages.Manipulation_Inertia" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" | ||
HorizontalAlignment="Stretch" | ||
VerticalAlignment="Stretch"> | ||
|
||
<Grid Background="Orange"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition /> | ||
<ColumnDefinition Width="Auto" /> | ||
</Grid.ColumnDefinitions> | ||
|
||
<Grid | ||
ManipulationMode="All" | ||
ManipulationStarting="ManipStarting" | ||
ManipulationInertiaStarting="InertiaStarting" | ||
ManipulationDelta="ManipDelta" | ||
ManipulationCompleted="ManipCompleted" | ||
Background="Transparent"> | ||
|
||
<Rectangle | ||
x:Name="_element" | ||
Width="200" | ||
Height="200" | ||
Fill="DeepPink" | ||
RenderTransformOrigin=".5,.5" /> | ||
|
||
<TextBlock x:Name="Output" VerticalAlignment="Top" FontSize="8" Text="Swipe the pink square, observe it to move WITH INERTIA, then click the validate button to ensure logs are valid." /> | ||
</Grid> | ||
|
||
<StackPanel Grid.Column="1" Background="#33000000" VerticalAlignment="Stretch" Padding="5" Spacing="5"> | ||
<Button HorizontalAlignment="Stretch" Content="Reset" Click="Reset" /> | ||
<Button HorizontalAlignment="Stretch" Content="Validate" Click="Validate" /> | ||
</StackPanel> | ||
</Grid> | ||
</Page> |
Oops, something went wrong.