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

View Transformations #717

Merged
merged 26 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ff6203e
Implement View Transformations
jsuarezruiz May 11, 2021
a605639
Added PortHandler attribute
jsuarezruiz May 11, 2021
1ba6485
Updated UnitTests ViewStub
jsuarezruiz May 11, 2021
07a4540
Merge remote-tracking branch 'origin/release/6.0.1xx-preview4' into t…
mattleibow May 13, 2021
8df6126
Move to iOS specific file
mattleibow May 13, 2021
1ba3887
Added more iOS tests
mattleibow May 13, 2021
ce9fe30
remove the return
mattleibow May 13, 2021
6953f41
Fix the tests
mattleibow May 13, 2021
4167796
Fixed transformations tests
jsuarezruiz May 14, 2021
0db3937
Update transformations if height/width changes
jsuarezruiz May 14, 2021
751cadf
Update anchors if size changes
jsuarezruiz May 17, 2021
b00a5b2
Merge branch 'release/6.0.1xx-preview4' into transformations
jsuarezruiz May 21, 2021
a3db9fe
Merge remote-tracking branch 'origin/main' into transformations
mattleibow May 25, 2021
e49b1ed
Raise the Frame action
mattleibow May 25, 2021
6f94617
changes
mattleibow May 25, 2021
b9b14dd
oops
mattleibow May 25, 2021
c7f3ef6
fixes
mattleibow May 25, 2021
cb0a1ed
Visibility and Opacity are separate to transform
mattleibow May 25, 2021
173cfc3
not needed
mattleibow May 25, 2021
fc12a37
Don't update the frame when changing the transform
mattleibow May 26, 2021
e083006
Transform the wrapped view
mattleibow May 26, 2021
324fb78
Merge remote-tracking branch 'origin/main' into transformations
mattleibow May 26, 2021
adf8404
Added animations sample
jsuarezruiz May 28, 2021
8a85633
Fix resizing weirdness when applying transforms on iOS
hartez May 28, 2021
70528f0
roll back this one
mattleibow May 31, 2021
0676fc3
Merge remote-tracking branch 'origin/main' into transformations
mattleibow May 31, 2021
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
8 changes: 8 additions & 0 deletions src/Compatibility/Core/src/Android/VisualElementTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ void SetElement(VisualElement oldElement, VisualElement newElement)
}
}

[PortHandler]
void UpdateAnchorX()
{
VisualElement view = _renderer.Element;
Expand All @@ -278,6 +279,7 @@ void UpdateAnchorX()
aview.PivotX = target;
}

[PortHandler]
void UpdateAnchorY()
{
VisualElement view = _renderer.Element;
Expand Down Expand Up @@ -400,6 +402,7 @@ void UpdateOpacity()
Performance.Stop(reference);
}

[PortHandler]
void UpdateRotation()
{
VisualElement view = _renderer.Element;
Expand All @@ -408,6 +411,7 @@ void UpdateRotation()
aview.Rotation = (float)view.Rotation;
}

[PortHandler]
void UpdateRotationX()
{
VisualElement view = _renderer.Element;
Expand All @@ -416,6 +420,7 @@ void UpdateRotationX()
aview.RotationX = (float)view.RotationX;
}

[PortHandler]
void UpdateRotationY()
{
VisualElement view = _renderer.Element;
Expand All @@ -424,6 +429,7 @@ void UpdateRotationY()
aview.RotationY = (float)view.RotationY;
}

[PortHandler]
void UpdateScale()
{
VisualElement view = _renderer.Element;
Expand All @@ -433,6 +439,7 @@ void UpdateScale()
aview.ScaleY = (float)view.Scale * (float)view.ScaleY;
}

[PortHandler]
void UpdateTranslationX()
{
VisualElement view = _renderer.Element;
Expand All @@ -441,6 +448,7 @@ void UpdateTranslationX()
aview.TranslationX = _context.ToPixels(view.TranslationX);
}

[PortHandler]
void UpdateTranslationY()
{
VisualElement view = _renderer.Element;
Expand Down
4 changes: 3 additions & 1 deletion src/Compatibility/Core/src/WinUI/VisualElementTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ static void UpdateOpacity(VisualElement view, FrameworkElement frameworkElement)
frameworkElement.Opacity = view.Opacity;
}

[PortHandler]
static void UpdateRotation(VisualElement view, FrameworkElement frameworkElement)
{
double anchorX = view.AnchorX;
Expand Down Expand Up @@ -767,7 +768,8 @@ static void UpdateRotation(VisualElement view, FrameworkElement frameworkElement
}
}
}


[PortHandler]
static void UpdateScaleAndRotation(VisualElement view, FrameworkElement frameworkElement)
{
double anchorX = view.AnchorX;
Expand Down
1 change: 1 addition & 0 deletions src/Compatibility/Core/src/iOS/VisualElementTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ void SetElement(VisualElement oldElement, VisualElement newElement)
}
}

[PortHandler("Partially ported")]
void UpdateNativeControl()
{
Performance.Start(out string reference);
Expand Down
31 changes: 31 additions & 0 deletions src/Controls/samples/Controls.Sample/Pages/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ void SetupMauiLayout()
verticalStack.Add(CreateResizingButton());

AddTextResizeDemo(verticalStack);
verticalStack.Add(CreateTransformations());

verticalStack.Add(new Label { Text = " ", Padding = new Thickness(10) });
var label = new Label { Text = "End-aligned text", BackgroundColor = Colors.Fuchsia, HorizontalTextAlignment = TextAlignment.End };
Expand All @@ -74,6 +75,8 @@ void SetupMauiLayout()
new Button
{
Text = "Push a Page",
Rotation = 15,
Scale = 1.5,
Command = new Command(async () =>
{
await Navigation.PushAsync(new SemanticsPage());
Expand Down Expand Up @@ -357,6 +360,34 @@ IView CreateSampleGrid()
return layout;
}

IView CreateTransformations()
{
var label = new Button
{
BackgroundColor = Colors.Red,
TextColor = Colors.White,
Text = "Transformations",
WidthRequest = 200,
HeightRequest = 40
};

var rotationSlider = new Slider
{
Minimum = -360,
Maximum = 360
};

rotationSlider.ValueChanged += (sender, e) => label.Rotation = e.NewValue;

var verticalStack = new VerticalStackLayout
{
rotationSlider,
label,
};

return verticalStack;
}

void AddTextResizeDemo(Microsoft.Maui.ILayout layout)
{
var resizeTestButton = new Button { Text = "Resize Test" };
Expand Down
3 changes: 1 addition & 2 deletions src/Core/src/Core/IFrameworkElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Primitives;


namespace Microsoft.Maui
{
/// <summary>
/// Represents a framework-level set of properties, events, and methods for .NET MAUI elements.
/// </summary>
public interface IFrameworkElement
public interface IFrameworkElement : ITransform
mattleibow marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// Gets a value indicating whether this FrameworkElement is enabled in the user interface.
Expand Down
63 changes: 63 additions & 0 deletions src/Core/src/Core/ITransform.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
namespace Microsoft.Maui
{
/// <summary>
/// Provides functionality to be able to apply transformations to a View.
/// </summary>
public interface ITransform
{
/// <summary>
/// Gets the X translation delta of the element.
/// </summary>
double TranslationX { get; }

/// <summary>
/// Gets the Y translation delta of the element.
/// </summary>
double TranslationY { get; }

/// <summary>
/// Gets the scale factor applied to the element.
/// </summary>
double Scale { get; }

/// <summary>
/// Gets the scale about the X-axis factor applied to the element.
/// </summary>
double ScaleX { get; }

/// <summary>
/// Gets the scale about the Y-axis factor applied to the element.
/// </summary>
double ScaleY { get; }

/// <summary>
/// Gets the rotation (in degrees) about the Z-axis (affine rotation)
/// when the element is rendered.
/// </summary>
double Rotation { get; }

/// <summary>
/// Gets the rotation (in degrees) about the X-axis (perspective rotation)
/// when the element is rendered.
/// </summary>
double RotationX { get; }

/// <summary>
/// Gets the rotation (in degrees) about the Y-axis (perspective rotation)
/// when the element is rendered.
/// </summary>
double RotationY { get; }

/// <summary>
/// Gets the X component of the center point for any transform, relative
/// to the bounds of the element.
/// </summary>
double AnchorX { get; }

/// <summary>
/// Gets the Y component of the center point for any transform, relative
/// to the bounds of the element.
/// </summary>
double AnchorY { get; }
}
}
4 changes: 4 additions & 0 deletions src/Core/src/Handlers/Editor/EditorHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ protected override MauiTextView CreateNativeView()

protected override void ConnectHandler(MauiTextView nativeView)
{
base.ConnectHandler(nativeView);

nativeView.Changed += OnChanged;
nativeView.ShouldChangeText += OnShouldChangeText;
}

protected override void DisconnectHandler(MauiTextView nativeView)
{
base.DisconnectHandler(nativeView);

nativeView.Changed -= OnChanged;
nativeView.ShouldChangeText -= OnShouldChangeText;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Core/src/Handlers/Entry/EntryHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ protected override MauiTextField CreateNativeView()

protected override void ConnectHandler(MauiTextField nativeView)
{
base.ConnectHandler(nativeView);

nativeView.ShouldReturn = OnShouldReturn;
nativeView.EditingChanged += OnEditingChanged;
nativeView.EditingDidEnd += OnEditingEnded;
Expand All @@ -30,6 +32,8 @@ protected override void ConnectHandler(MauiTextField nativeView)

protected override void DisconnectHandler(MauiTextField nativeView)
{
base.DisconnectHandler(nativeView);

nativeView.EditingChanged -= OnEditingChanged;
nativeView.EditingDidEnd -= OnEditingEnded;
nativeView.TextPropertySet -= OnTextPropertySet;
Expand Down
4 changes: 4 additions & 0 deletions src/Core/src/Handlers/Slider/SliderHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ public partial class SliderHandler : ViewHandler<ISlider, UISlider>

protected override void ConnectHandler(UISlider nativeView)
{
base.ConnectHandler(nativeView);

nativeView.ValueChanged += OnControlValueChanged;
nativeView.AddTarget(OnTouchDownControlEvent, UIControlEvent.TouchDown);
nativeView.AddTarget(OnTouchUpControlEvent, UIControlEvent.TouchUpInside | UIControlEvent.TouchUpOutside);
}

protected override void DisconnectHandler(UISlider nativeView)
{
base.DisconnectHandler(nativeView);

nativeView.ValueChanged -= OnControlValueChanged;
nativeView.RemoveTarget(OnTouchDownControlEvent, UIControlEvent.TouchDown);
nativeView.RemoveTarget(OnTouchUpControlEvent, UIControlEvent.TouchUpInside | UIControlEvent.TouchUpOutside);
Expand Down
4 changes: 4 additions & 0 deletions src/Core/src/Handlers/Stepper/StepperHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ protected override UIStepper CreateNativeView()

protected override void ConnectHandler(UIStepper nativeView)
{
base.ConnectHandler(nativeView);

nativeView.ValueChanged += OnValueChanged;
}

protected override void DisconnectHandler(UIStepper nativeView)
{
base.DisconnectHandler(nativeView);

nativeView.ValueChanged -= OnValueChanged;
}

Expand Down
4 changes: 4 additions & 0 deletions src/Core/src/Handlers/Switch/SwitchHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ protected override UISwitch CreateNativeView()

protected override void ConnectHandler(UISwitch nativeView)
{
base.ConnectHandler(nativeView);

nativeView.ValueChanged += OnControlValueChanged;
}

protected override void DisconnectHandler(UISwitch nativeView)
{
base.DisconnectHandler(nativeView);

nativeView.ValueChanged -= OnControlValueChanged;
}

Expand Down
4 changes: 4 additions & 0 deletions src/Core/src/Handlers/TimePicker/TimePickerHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ protected override MauiTimePicker CreateNativeView()

protected override void ConnectHandler(MauiTimePicker nativeView)
{
base.ConnectHandler(nativeView);

if (nativeView != null)
nativeView.ValueChanged += OnValueChanged;
}

protected override void DisconnectHandler(MauiTimePicker nativeView)
{
base.DisconnectHandler(nativeView);

if (nativeView != null)
{
nativeView.RemoveFromSuperview();
Expand Down
52 changes: 51 additions & 1 deletion src/Core/src/Handlers/View/ViewHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,61 @@ partial void DisconnectingHandler(NativeView? nativeView)
if (nativeView.IsAlive() && AccessibilityDelegate != null)
{
AccessibilityDelegate.Handler = null;
AndroidX.Core.View.ViewCompat.SetAccessibilityDelegate(nativeView, null);
ViewCompat.SetAccessibilityDelegate(nativeView, null);
AccessibilityDelegate = null;
}
}

public static void MapTranslationX(IViewHandler handler, IView view)
{
((NativeView?)handler.NativeView)?.UpdateTranslationX(view);
}

public static void MapTranslationY(IViewHandler handler, IView view)
{
((NativeView?)handler.NativeView)?.UpdateTranslationY(view);
}

public static void MapScale(IViewHandler handler, IView view)
{
((NativeView?)handler.NativeView)?.UpdateScale(view);
}

public static void MapScaleX(IViewHandler handler, IView view)
{
((NativeView?)handler.NativeView)?.UpdateScaleX(view);
}

public static void MapScaleY(IViewHandler handler, IView view)
{
((NativeView?)handler.NativeView)?.UpdateScaleY(view);
}

public static void MapRotation(IViewHandler handler, IView view)
{
((NativeView?)handler.NativeView)?.UpdateRotation(view);
}

public static void MapRotationX(IViewHandler handler, IView view)
{
((NativeView?)handler.NativeView)?.UpdateRotationX(view);
}

public static void MapRotationY(IViewHandler handler, IView view)
{
((NativeView?)handler.NativeView)?.UpdateRotationY(view);
}

public static void MapAnchorX(IViewHandler handler, IView view)
jsuarezruiz marked this conversation as resolved.
Show resolved Hide resolved
{
((NativeView?)handler.NativeView)?.UpdateAnchorX(view);
}

public static void MapAnchorY(IViewHandler handler, IView view)
{
((NativeView?)handler.NativeView)?.UpdateAnchorY(view);
}

static partial void MappingSemantics(IViewHandler handler, IView view)
{
if (view.Semantics != null &&
Expand Down
Loading