From b79462c9e8efe9eaa81b37190f6666e8e79218d4 Mon Sep 17 00:00:00 2001 From: Stephane Delcroix Date: Mon, 7 May 2018 14:22:56 +0200 Subject: [PATCH] [All] ScaleX and ScaleY (#1280) * [*] ScaleX and ScaleY * Use scaleX and scaleY in sendViewBatchUpdate * use scaleX and scaleY parameters in SendViewBatchUpdate --- .../platform/android/FormsViewGroup.java | 14 ++++--- .../GalleryPages/ScaleRotate.cs | 37 +++++++++++++++--- Xamarin.Forms.Core/VisualElement.cs | 23 ++++++++--- .../Jars/formsviewgroup.jar | Bin 2291 -> 2307 bytes .../VisualElementTracker.cs | 31 +++++++++------ .../VisualElementTracker.cs | 7 ++-- .../VisualElementTracker.cs | 8 ++-- 7 files changed, 85 insertions(+), 35 deletions(-) diff --git a/AndroidNative/FormsViewGroup/src/main/java/com/xamarin/forms/platform/android/FormsViewGroup.java b/AndroidNative/FormsViewGroup/src/main/java/com/xamarin/forms/platform/android/FormsViewGroup.java index 6f7cd93a808..45c7a048d4f 100644 --- a/AndroidNative/FormsViewGroup/src/main/java/com/xamarin/forms/platform/android/FormsViewGroup.java +++ b/AndroidNative/FormsViewGroup/src/main/java/com/xamarin/forms/platform/android/FormsViewGroup.java @@ -80,7 +80,8 @@ public void sendBatchUpdate ( float rotation, float rotationX, float rotationY, - float scale, + float scaleX, + float scaleY, float translationX, float translationY){ setPivotX (pivotX); @@ -96,8 +97,8 @@ public void sendBatchUpdate ( setRotation (rotation); setRotationX (rotationX); setRotationY (rotationY); - setScaleX (scale); - setScaleY (scale); + setScaleX (scaleX); + setScaleY (scaleY); setTranslationX (translationX); setTranslationY (translationY); } @@ -112,7 +113,8 @@ public static void sendViewBatchUpdate ( float rotation, float rotationX, float rotationY, - float scale, + float scaleX, + float scaleY, float translationX, float translationY){ view.setPivotX (pivotX); @@ -128,8 +130,8 @@ public static void sendViewBatchUpdate ( view.setRotation (rotation); view.setRotationX (rotationX); view.setRotationY (rotationY); - view.setScaleX (scale); - view.setScaleY (scale); + view.setScaleX (scaleX); + view.setScaleY (scaleY); view.setTranslationX (translationX); view.setTranslationY (translationY); } diff --git a/Xamarin.Forms.Controls/GalleryPages/ScaleRotate.cs b/Xamarin.Forms.Controls/GalleryPages/ScaleRotate.cs index e189f839606..18276d814b0 100644 --- a/Xamarin.Forms.Controls/GalleryPages/ScaleRotate.cs +++ b/Xamarin.Forms.Controls/GalleryPages/ScaleRotate.cs @@ -39,19 +39,41 @@ public ScaleRotate() scaleSlider.SetBinding(Slider.ValueProperty, new Binding("Scale", BindingMode.TwoWay)); + // Label and Slider for ScaleX property. + Label scaleXSliderValue = new Label { + VerticalTextAlignment = TextAlignment.Center + }; + Grid.SetRow(scaleXSliderValue, 1); + Grid.SetColumn(scaleXSliderValue, 0); + + Slider scaleXSlider = new Slider { + Maximum = 10 + }; + Grid.SetRow(scaleXSlider, 1); + Grid.SetColumn(scaleXSlider, 1); + + // Set Bindings. + scaleXSliderValue.BindingContext = scaleXSlider; + scaleXSliderValue.SetBinding(Label.TextProperty, + new Binding("Value", BindingMode.OneWay, null, null, "ScaleX = {0:F1}")); + + scaleXSlider.BindingContext = label; + scaleXSlider.SetBinding(Slider.ValueProperty, + new Binding("ScaleX", BindingMode.TwoWay)); + // Label and Slider for Rotation property. Label rotationSliderValue = new Label { VerticalTextAlignment = TextAlignment.Center }; - Grid.SetRow(rotationSliderValue, 1); + Grid.SetRow(rotationSliderValue, 2); Grid.SetColumn(rotationSliderValue, 0); Slider rotationSlider = new Slider { Maximum = 360 }; - Grid.SetRow(rotationSlider, 1); + Grid.SetRow(rotationSlider, 2); Grid.SetColumn(rotationSlider, 1); // Set Bindings. @@ -68,7 +90,7 @@ public ScaleRotate() { VerticalTextAlignment = TextAlignment.Center }; - Grid.SetRow(anchorxStepperValue, 2); + Grid.SetRow(anchorxStepperValue, 3); Grid.SetColumn(anchorxStepperValue, 0); Stepper anchorxStepper = new Stepper @@ -77,7 +99,7 @@ public ScaleRotate() Minimum = -1, Increment = 0.5 }; - Grid.SetRow(anchorxStepper, 2); + Grid.SetRow(anchorxStepper, 3); Grid.SetColumn(anchorxStepper, 1); // Set bindings. @@ -94,7 +116,7 @@ public ScaleRotate() { VerticalTextAlignment = TextAlignment.Center }; - Grid.SetRow(anchoryStepperValue, 3); + Grid.SetRow(anchoryStepperValue, 4); Grid.SetColumn(anchoryStepperValue, 0); Stepper anchoryStepper = new Stepper @@ -103,7 +125,7 @@ public ScaleRotate() Minimum = -1, Increment = 0.5 }; - Grid.SetRow(anchoryStepper, 3); + Grid.SetRow(anchoryStepper, 4); Grid.SetColumn(anchoryStepper, 1); // Set bindings. @@ -130,6 +152,7 @@ public ScaleRotate() new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, + new RowDefinition { Height = GridLength.Auto }, }, ColumnDefinitions = { @@ -140,6 +163,8 @@ public ScaleRotate() { scaleSliderValue, scaleSlider, + scaleXSliderValue, + scaleXSlider, rotationSliderValue, rotationSlider, anchorxStepperValue, diff --git a/Xamarin.Forms.Core/VisualElement.cs b/Xamarin.Forms.Core/VisualElement.cs index 604dc09a456..8ba01c542c7 100644 --- a/Xamarin.Forms.Core/VisualElement.cs +++ b/Xamarin.Forms.Core/VisualElement.cs @@ -48,7 +48,11 @@ public partial class VisualElement : Element, IAnimatable, IVisualElementControl public static readonly BindableProperty RotationYProperty = BindableProperty.Create("RotationY", typeof(double), typeof(VisualElement), default(double)); - public static readonly BindableProperty ScaleProperty = BindableProperty.Create("Scale", typeof(double), typeof(VisualElement), 1d); + public static readonly BindableProperty ScaleProperty = BindableProperty.Create(nameof(Scale), typeof(double), typeof(VisualElement), 1d); + + public static readonly BindableProperty ScaleXProperty = BindableProperty.Create(nameof(ScaleX), typeof(double), typeof(VisualElement), 1d); + + public static readonly BindableProperty ScaleYProperty = BindableProperty.Create(nameof(ScaleY), typeof(double), typeof(VisualElement), 1d); public static readonly BindableProperty IsVisibleProperty = BindableProperty.Create("IsVisible", typeof(bool), typeof(VisualElement), true, propertyChanged: (bindable, oldvalue, newvalue) => ((VisualElement)bindable).OnIsVisibleChanged((bool)oldvalue, (bool)newvalue)); @@ -266,10 +270,19 @@ public double RotationY set { SetValue(RotationYProperty, value); } } - public double Scale - { - get { return (double)GetValue(ScaleProperty); } - set { SetValue(ScaleProperty, value); } + public double Scale { + get => (double)GetValue(ScaleProperty); + set => SetValue(ScaleProperty, value); + } + + public double ScaleX { + get => (double)GetValue(ScaleXProperty); + set => SetValue(ScaleXProperty, value); + } + + public double ScaleY { + get => (double)GetValue(ScaleYProperty); + set => SetValue(ScaleYProperty, value); } public Style Style diff --git a/Xamarin.Forms.Platform.Android.FormsViewGroup/Jars/formsviewgroup.jar b/Xamarin.Forms.Platform.Android.FormsViewGroup/Jars/formsviewgroup.jar index 10719e2d3bcc3dc0cef3c000cb3cad5ebfa0de30..9e0bb69e97eb2bcb0440dfdb7de01f7e679ecdca 100644 GIT binary patch delta 1533 zcmV5rYztYJbgDTXz#x6yB%Jy;DjlX@pWNSHpmWi-?+9Ezp!`i%3duh&oB8 z%|JR6lS$|Z0_Bc(ee;Pwzzb_>Sjz{0fIrIRx6e${G^O62Y*xR1=bSy?-sjtU(%=91 z^*16qMn6VqKjj$m40?q2(E`I_7*OCngW(GAU1caTEHRi27JoyD;WLIZLxsU+s4~jVUGyf5ueb^eAzPciJWEH2uPgfzsq*=z_cLWX)CV_>X|T1{ake^ ztCy#=Y!N$KCV#A)R-D$#2CuzMpItC2f{st*tfj=VwuDnNv0#;#Dv452vza9t*;2ec zZRpp=%T~3N6co(4c?E6Tup~hzH?FsNP_>O>V$`C<@JS(?XVFd4d<71tx_%Pqh@|WbF3;Z7LKRo4}V8*zGmd@!lWCMDd{;uy#?J^ zEZA%IL=nH-v@(9PNMe}{wNQM%Ar{OPG;>kU3+k)rc6wdQeero|K}{=GQC{ETi-J1i z2QV2?%S_|G<(yu!r>ttOFjkYNgR92W(6z**WgC_$50m^{hh7u3ed8EG-5FcUU7gfQ z-n1x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xRONd>@X@6fv-B%EK z6|2|e&Tf09Hg~pw)eG`?7U&{amt epsilon || Math.Abs(translationY) > epsilon) transform = transform.Translate(translationX, translationY, 0); - if (Math.Abs(scale - 1) > epsilon) - transform = transform.Scale(scale); + if (Math.Abs(scaleX - 1) > epsilon || Math.Abs(scaleY - 1) > epsilon) + transform = transform.Scale(scaleX, scaleY, scale); // not just an optimization, iOS will not "pixel align" a view which has m34 set if (Math.Abs(rotationY % 180) > epsilon || Math.Abs(rotationX % 180) > epsilon)