This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Bug] Correct the transformation calculation of views #11933
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6f26b5e
Placeholder page
mattleibow a9637a1
Added the test case
mattleibow 5dae5df
Update the sample for more options
mattleibow 89ce9c1
Do not scale the translation
mattleibow aee099b
Fix the ordering of the scale/rotate/translate matrices
mattleibow 2d69b8d
Fix the iOS transform order
mattleibow ddf355f
Merge branch '5.0.0' into mattleibow/fix-11931
mattleibow 133b6d7
Fix the order of the scale and rotation on Tizen backend (#12105)
rookiejava b76cf4d
Merge branch '5.0.0' into mattleibow/fix-11931
mattleibow dd47539
Merge branch '5.0.0' into mattleibow/fix-11931
mattleibow bcbea84
not just UWP
mattleibow e5150dc
Merge branch '5.0.0' into mattleibow/fix-11931
mattleibow e1ea132
Adding some platform tests
mattleibow 2acd0ce
Add Android tests
mattleibow 2deca28
Undo test filter
mattleibow 2f0680e
Sometimes iOS can't round
mattleibow 12c3ba8
Cast to double just in case
mattleibow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue11931.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,109 @@ | ||
<controls:TestContentPage xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:controls="clr-namespace:Xamarin.Forms.Controls" | ||
x:Class="Xamarin.Forms.Controls.Issues.Issue11931" | ||
Title="Issue 11931"> | ||
|
||
<controls:TestContentPage.Resources> | ||
<ResourceDictionary> | ||
<Style TargetType="Button"> | ||
<Setter Property="HorizontalOptions" Value="Start" /> | ||
<Setter Property="WidthRequest" Value="100" /> | ||
<Setter Property="BackgroundColor" Value="#EE888888" /> | ||
<Setter Property="FontSize" Value="12" /> | ||
<Setter Property="HeightRequest" Value="32" /> | ||
<Setter Property="Padding" Value="0" /> | ||
<Setter Property="Margin" Value="0" /> | ||
<Setter Property="CornerRadius" Value="0" /> | ||
<Setter Property="Rotation" Value="{Binding Value, Source={x:Reference rotation}}" /> | ||
</Style> | ||
<Style TargetType="BoxView"> | ||
<Setter Property="VerticalOptions" Value="Fill" /> | ||
<Setter Property="HorizontalOptions" Value="Start" /> | ||
<Setter Property="WidthRequest" Value="1" /> | ||
<Setter Property="Color" Value="LightGray" /> | ||
</Style> | ||
<Style TargetType="Label"> | ||
<Setter Property="HorizontalOptions" Value="Start" /> | ||
</Style> | ||
</ResourceDictionary> | ||
</controls:TestContentPage.Resources> | ||
|
||
<StackLayout> | ||
<Label Padding="12" BackgroundColor="Black" TextColor="White" | ||
HorizontalOptions="Fill" | ||
Text="The buttons should completely cover the bright red boxes" /> | ||
|
||
<Slider x:Name="rotation" Minimum="-180" Maximum="180" /> | ||
|
||
<ScrollView VerticalOptions="FillAndExpand" Orientation="Both"> | ||
<Grid Margin="0" Padding="55,5,5,5"> | ||
<BoxView Margin="0,0,0,0" /> | ||
<BoxView Margin="50,0,0,0" /> | ||
<BoxView Margin="100,0,0,0" Color="Black" /> | ||
<BoxView Margin="150,0,0,0" /> | ||
<BoxView Margin="200,0,0,0" Color="Black" WidthRequest="3" /> | ||
<BoxView Margin="250,0,0,0" /> | ||
<BoxView Margin="300,0,0,0" Color="Black" /> | ||
<BoxView Margin="350,0,0,0" /> | ||
|
||
<Grid> | ||
<Label Text="0" /> | ||
<Label Text="50" Margin="50,0,0,0" /> | ||
<Label Text="100" Margin="100,0,0,0" /> | ||
<Label Text="150" Margin="150,0,0,0" /> | ||
<Label Text="200" Margin="200,0,0,0" /> | ||
<Label Text="250" Margin="250,0,0,0" /> | ||
<Label Text="300" Margin="300,0,0,0" /> | ||
<Label Text="350" Margin="350,0,0,0" /> | ||
</Grid> | ||
|
||
<Grid Margin="0,30,0,0"> | ||
<StackLayout Spacing="6"> | ||
<Label Text=" " /> | ||
|
||
<BoxView Color="Red" Margin="0,0,0,0" WidthRequest="100" HeightRequest="32" /> | ||
<BoxView Color="Red" Margin="-50,0,0,0" WidthRequest="200" HeightRequest="32" /> | ||
<BoxView Color="Red" Margin="0,0,0,0" WidthRequest="200" HeightRequest="32" /> | ||
|
||
<Label Text=" " /> | ||
|
||
<BoxView Color="Red" Margin="200,0,0,0" WidthRequest="100" HeightRequest="32" /> | ||
<BoxView Color="Red" Margin="150,0,0,0" WidthRequest="200" HeightRequest="32" /> | ||
<BoxView Color="Red" Margin="200,0,0,0" WidthRequest="200" HeightRequest="32" /> | ||
|
||
<Label Text=" " /> | ||
|
||
<StackLayout Spacing="16" Margin="0,8,0,0"> | ||
<BoxView Color="Red" Margin="50,0,0,0" WidthRequest="400" HeightRequest="64" /> | ||
<BoxView Color="Red" Margin="200,0,0,0" WidthRequest="400" HeightRequest="64" /> | ||
</StackLayout> | ||
</StackLayout> | ||
|
||
<StackLayout Spacing="6"> | ||
<Label Text="simple scale X" BackgroundColor="#AAFFFFFF" /> | ||
|
||
<Button Text="default" ScaleX="1" TranslationX="0" /> | ||
<Button Text="scale 2x" ScaleX="2" TranslationX="0" /> | ||
<Button Text="left scale 2x" ScaleX="2" TranslationX="0" AnchorX="0" /> | ||
|
||
<Label Text="Scale X then translate X to 200" BackgroundColor="#AAFFFFFF" /> | ||
|
||
<Button Text="default" ScaleX="1" TranslationX="200" /> | ||
<Button Text="scale 2x" ScaleX="2" TranslationX="200" /> | ||
<Button Text="left scale 2x" ScaleX="2" TranslationX="200" AnchorX="0" /> | ||
|
||
<Label Text="Scale 2x then scale X then translate to 200" BackgroundColor="#AAFFFFFF" /> | ||
|
||
<StackLayout Spacing="48" Margin="0,24,0,0"> | ||
<Button Text="scale 2x" Scale="2" ScaleX="2" TranslationX="200" /> | ||
<Button Text="left scale 2x" Scale="2" ScaleX="2" TranslationX="200" AnchorX="0" /> | ||
</StackLayout> | ||
</StackLayout> | ||
</Grid> | ||
|
||
</Grid> | ||
</ScrollView> | ||
</StackLayout> | ||
|
||
</controls:TestContentPage> |
36 changes: 36 additions & 0 deletions
36
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue11931.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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Xamarin.Forms.Internals; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Shapes; | ||
using System.Collections.Generic; | ||
|
||
#if UITEST | ||
using Xamarin.UITest; | ||
using NUnit.Framework; | ||
using Xamarin.Forms.Core.UITests; | ||
#endif | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
#if UITEST | ||
[Category(UITestCategories.ViewBaseTests)] | ||
#endif | ||
[Preserve(AllMembers = true)] | ||
[Issue( | ||
IssueTracker.Github, 11931, | ||
"[Bug] View translation is incorrectly calculated", | ||
PlatformAffected.All)] | ||
public partial class Issue11931: TestContentPage | ||
{ | ||
public Issue11931() | ||
{ | ||
#if APP | ||
InitializeComponent(); | ||
#endif | ||
} | ||
|
||
protected override void Init() | ||
{ | ||
|
||
} | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
Xamarin.Forms.Platform.Android.UnitTests/TransformationTests.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,41 @@ | ||
using System.Collections; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using NUnit.Framework.Internal; | ||
|
||
namespace Xamarin.Forms.Platform.Android.UnitTests | ||
{ | ||
[TestFixture] | ||
public class TransformationTests : PlatformTestFixture | ||
{ | ||
static IEnumerable TransformationCases | ||
{ | ||
get | ||
{ | ||
foreach (var element in BasicElements) | ||
{ | ||
element.TranslationX = 10.0; | ||
element.TranslationY = 30.0; | ||
element.Rotation = 248.0; | ||
element.Scale = 2.0; | ||
element.ScaleX = 2.0; | ||
yield return CreateTestCase(element); | ||
} | ||
} | ||
} | ||
|
||
[Test, Category("Transformation"), TestCaseSource(nameof(TransformationCases))] | ||
[Description("View transformation should match renderer transformation")] | ||
public async Task TransformationConsistent(View element) | ||
{ | ||
var expected = (Context.ToPixels(10d), Context.ToPixels(30d), 248d, 4d, 2d); | ||
var actual = await GetRendererProperty(element, ver => | ||
{ | ||
var v = ver.View; | ||
return (v.TranslationX, v.TranslationY, v.Rotation, v.ScaleX, v.ScaleY); | ||
}, requiresParent: true); | ||
|
||
Assert.That(actual, Is.EqualTo(expected)); | ||
} | ||
} | ||
} |
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
50 changes: 50 additions & 0 deletions
50
Xamarin.Forms.Platform.UAP.UnitTests/TransformationTests.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,50 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using Windows.UI.Xaml; | ||
using WCompositeTransform = Windows.UI.Xaml.Media.CompositeTransform; | ||
|
||
namespace Xamarin.Forms.Platform.UAP.UnitTests | ||
{ | ||
[TestFixture] | ||
public class TransformationTests : PlatformTestFixture | ||
{ | ||
static IEnumerable TransformationCases | ||
{ | ||
get | ||
{ | ||
foreach (var element in BasicViews) | ||
{ | ||
element.TranslationX = 10.0; | ||
element.TranslationY = 30.0; | ||
element.Rotation = 248.0; | ||
element.Scale = 2.0; | ||
element.ScaleX = 2.0; | ||
yield return CreateTestCase(element); | ||
} | ||
} | ||
} | ||
|
||
[Test, Category("Transformation"), TestCaseSource(nameof(TransformationCases))] | ||
[Description("View transformation should match renderer transformation")] | ||
public async Task TransformationConsistent(View view) | ||
{ | ||
var expected = (10d, 30d, 248d, 4d, 2d); | ||
var actual = await GetRendererProperty(view, ver => | ||
{ | ||
var t = GetTransform(ver.ContainerElement); | ||
return (t.TranslateX, t.TranslateY, t.Rotation, t.ScaleX, t.ScaleY); | ||
}); | ||
Assert.That(actual, Is.EqualTo(expected)); | ||
} | ||
|
||
WCompositeTransform GetTransform(FrameworkElement fe) | ||
{ | ||
if (fe.RenderTransform is WCompositeTransform transform) | ||
return transform; | ||
|
||
throw new Exception("No rotation found"); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️