Skip to content

Commit 62cb357

Browse files
committed
Remove animation.expressions
1 parent 2c0a031 commit 62cb357

File tree

1 file changed

+58
-59
lines changed

1 file changed

+58
-59
lines changed

Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System.Numerics;
99
using System.Threading;
1010
using System.Threading.Tasks;
11-
using Microsoft.Toolkit.Uwp.UI.Animations.Expressions;
1211
using Microsoft.Toolkit.Uwp.UI.Extensions;
1312
using Windows.Foundation;
1413
using Windows.UI.Composition;
@@ -439,11 +438,12 @@ private async Task CreateModuloExpression(ScrollViewer scrollViewer = null)
439438
/// <param name="scrollOrientation">The ScrollOrientation</param>
440439
private void CreateModuloExpression(ScrollViewer scrollViewer, double imageWidth, double imageHeight, ScrollOrientation scrollOrientation)
441440
{
442-
const string offsetXParam = "offsetX";
443-
const string offsetYParam = "offsetY";
444-
const string imageWidthParam = "imageWidth";
445-
const string imageHeightParam = "imageHeight";
446-
const string speedParam = "speed";
441+
const string pParam = "p";
442+
const string offsetXParam = pParam + ".offsetX";
443+
const string offsetYParam = pParam + ".offsetY";
444+
const string imageWidthParam = pParam + ".imageWidth";
445+
const string imageHeightParam = pParam + ".imageHeight";
446+
const string speedParam = pParam + ".speed";
447447

448448
if (_containerVisual == null)
449449
{
@@ -453,90 +453,89 @@ private void CreateModuloExpression(ScrollViewer scrollViewer, double imageWidth
453453
var compositor = _containerVisual.Compositor;
454454

455455
// Setup the expression
456-
ExpressionNode expressionX = null;
457-
ExpressionNode expressionY = null;
458-
ExpressionNode expressionXVal;
459-
ExpressionNode expressionYVal;
456+
var expressionX = compositor.CreateExpressionAnimation();
457+
var expressionY = compositor.CreateExpressionAnimation();
460458

461459
var propertySetModulo = compositor.CreatePropertySet();
462-
propertySetModulo.InsertScalar(imageWidthParam, (float)imageWidth);
463-
propertySetModulo.InsertScalar(offsetXParam, (float)OffsetX);
464-
propertySetModulo.InsertScalar(imageHeightParam, (float)imageHeight);
465-
propertySetModulo.InsertScalar(offsetYParam, (float)OffsetY);
466-
propertySetModulo.InsertScalar(speedParam, (float)ParallaxSpeedRatio);
460+
propertySetModulo.InsertScalar("imageHeight", (float)imageWidth);
461+
propertySetModulo.InsertScalar("offsetX", (float)OffsetX);
462+
propertySetModulo.InsertScalar("imageWidth", (float)imageHeight);
463+
propertySetModulo.InsertScalar("offsetY", (float)OffsetY);
464+
propertySetModulo.InsertScalar("speed", (float)ParallaxSpeedRatio);
467465

468-
var propertySetNodeModulo = propertySetModulo.GetReference();
466+
expressionX.SetReferenceParameter(pParam, propertySetModulo);
467+
expressionY.SetReferenceParameter(pParam, propertySetModulo);
469468

470-
var imageHeightNode = propertySetNodeModulo.GetScalarProperty(imageHeightParam);
471-
var imageWidthNode = propertySetNodeModulo.GetScalarProperty(imageWidthParam);
469+
var imageHeightNode = imageHeightParam;
470+
var imageWidthNode = imageWidthParam;
471+
472+
string expressionXVal;
473+
string expressionYVal;
472474
if (scrollViewer == null)
473475
{
474-
var offsetXNode = ExpressionFunctions.Ceil(propertySetNodeModulo.GetScalarProperty(offsetXParam));
475-
var offsetYNode = ExpressionFunctions.Ceil(propertySetNodeModulo.GetScalarProperty(offsetYParam));
476+
var offsetXNode = "Ceil(" + offsetXParam + ")";
477+
var offsetYNode = "Ceil(" + offsetYParam + ")";
476478

477479
// expressions are created to simulate a positive and negative modulo with the size of the image and the offset
478-
expressionXVal = ExpressionFunctions.Conditional(
479-
offsetXNode == 0,
480-
0,
481-
ExpressionFunctions.Conditional(
482-
offsetXNode < 0,
483-
-(ExpressionFunctions.Abs(offsetXNode - (ExpressionFunctions.Ceil(offsetXNode / imageWidthNode) * imageWidthNode)) % imageWidthNode),
484-
-(imageWidthNode - (offsetXNode % imageWidthNode))));
485-
486-
expressionYVal = ExpressionFunctions.Conditional(
487-
offsetYNode == 0,
488-
0,
489-
ExpressionFunctions.Conditional(
490-
offsetYNode < 0,
491-
-(ExpressionFunctions.Abs(offsetYNode - (ExpressionFunctions.Ceil(offsetYNode / imageHeightNode) * imageHeightNode)) % imageHeightNode),
492-
-(imageHeightNode - (offsetYNode % imageHeightNode))));
480+
expressionXVal =
481+
$"{offsetXNode} == 0 " +
482+
$"? 0 " +
483+
$": {offsetXNode} < 0 " +
484+
$"? -(Abs({offsetXNode} - (Ceil({offsetXNode} / {imageWidthNode}) * {imageWidthNode})) % {imageWidthNode}) " +
485+
$": -({imageWidthNode} - ({offsetXNode} % {imageWidthNode}))";
486+
487+
expressionYVal =
488+
$"{offsetYNode} == 0 " +
489+
$"? 0 " +
490+
$": {offsetYNode} < 0 " +
491+
$"? -(Abs({offsetYNode} - (Ceil({offsetYNode} / {imageHeightNode}) * {imageHeightNode})) % {imageHeightNode}) " +
492+
$": -({imageHeightNode} - ({offsetYNode} % {imageHeightNode}))";
493493
}
494494
else
495495
{
496496
// expressions are created to simulate a positive and negative modulo with the size of the image and the offset and the ScrollViewer offset (Translation)
497497
var scrollProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer);
498-
var scrollPropSet = scrollProperties.GetSpecializedReference<ManipulationPropertySetReferenceNode>();
499-
500-
var speed = propertySetNodeModulo.GetScalarProperty(speedParam);
501-
var xCommon = ExpressionFunctions.Ceil((scrollPropSet.Translation.X * speed) + propertySetNodeModulo.GetScalarProperty(offsetXParam));
502-
expressionXVal = ExpressionFunctions.Conditional(
503-
xCommon == 0,
504-
0,
505-
ExpressionFunctions.Conditional(
506-
xCommon < 0,
507-
-(ExpressionFunctions.Abs(xCommon - (ExpressionFunctions.Ceil(xCommon / imageWidthNode) * imageWidthNode)) % imageWidthNode),
508-
-(imageWidthNode - (xCommon % imageWidthNode))));
509-
510-
var yCommon = ExpressionFunctions.Ceil((scrollPropSet.Translation.Y * speed) + propertySetNodeModulo.GetScalarProperty(offsetYParam));
511-
expressionYVal = ExpressionFunctions.Conditional(
512-
yCommon == 0,
513-
0,
514-
ExpressionFunctions.Conditional(
515-
yCommon < 0,
516-
-(ExpressionFunctions.Abs(yCommon - (ExpressionFunctions.Ceil(yCommon / imageHeightNode) * imageHeightNode)) % imageHeightNode),
517-
-(imageHeightNode - (yCommon % imageHeightNode))));
498+
expressionX.SetReferenceParameter("s", scrollProperties);
499+
expressionY.SetReferenceParameter("s", scrollProperties);
500+
501+
var speed = speedParam;
502+
var xCommon = $"Ceil((s.Translation.X * {speed}) + {offsetXParam})";
503+
expressionXVal =
504+
$"{xCommon} == 0 " +
505+
"? 0 " +
506+
$": {xCommon} < 0 " +
507+
$"? -(Abs({xCommon} - (Ceil({xCommon} / {imageWidthNode}) * {imageWidthNode})) % {imageWidthNode}) " +
508+
$": -({imageWidthNode} - ({xCommon} % {imageWidthNode}))";
509+
510+
var yCommon = $"Ceil((s.Translation.Y * {speed}) + {offsetYParam})";
511+
expressionYVal =
512+
$"{yCommon} == 0 " +
513+
"? 0 " +
514+
$": {yCommon} < 0 " +
515+
$"? -(Abs({yCommon} - (Ceil({yCommon} / {imageHeightNode}) * {imageHeightNode})) % {imageHeightNode}) " +
516+
$": -({imageHeightNode} - ({yCommon} % {imageHeightNode}))";
518517
}
519518

520519
if (scrollOrientation == ScrollOrientation.Horizontal || scrollOrientation == ScrollOrientation.Both)
521520
{
522-
expressionX = expressionXVal;
521+
expressionX.Expression = expressionXVal;
523522

524523
if (scrollOrientation == ScrollOrientation.Horizontal)
525524
{
526525
// In horizontal mode we never move the offset y
527-
expressionY = (ScalarNode)0.0f;
526+
expressionY.Expression = "0";
528527
_containerVisual.Offset = new Vector3((float)OffsetY, 0, 0);
529528
}
530529
}
531530

532531
if (scrollOrientation == ScrollOrientation.Vertical || scrollOrientation == ScrollOrientation.Both)
533532
{
534-
expressionY = expressionYVal;
533+
expressionY.Expression = expressionYVal;
535534

536535
if (scrollOrientation == ScrollOrientation.Vertical)
537536
{
538537
// In vertical mode we never move the offset x
539-
expressionX = (ScalarNode)0.0f;
538+
expressionX.Expression = "0";
540539
_containerVisual.Offset = new Vector3(0, (float)OffsetX, 0);
541540
}
542541
}

0 commit comments

Comments
 (0)