@@ -45,7 +45,7 @@ public static CompositionSpriteShape TranslatePath(
45
45
else if ( context . ObjectFactory . IsUapApiAvailable ( nameof ( PathKeyFrameAnimation ) , versionDependentFeatureDescription : "Path animation" ) )
46
46
{
47
47
// PathKeyFrameAnimation was introduced in 6 but was unreliable until 11.
48
- Animate . Path ( context , path , fillType , geometry , nameof ( geometry . Path ) , nameof ( geometry . Path ) ) ;
48
+ Animate . Path ( context , PopulatePathGeometriesToTheSameSize ( path ) , fillType , geometry , nameof ( geometry . Path ) , nameof ( geometry . Path ) ) ;
49
49
isPathApplied = true ;
50
50
}
51
51
}
@@ -63,6 +63,42 @@ public static CompositionSpriteShape TranslatePath(
63
63
return result ;
64
64
}
65
65
66
+ static TrimmedAnimatable < PathGeometry > PopulatePathGeometriesToTheSameSize ( TrimmedAnimatable < PathGeometry > original )
67
+ {
68
+ int maxSegments = Math . Max ( original . KeyFrames . Select ( x => x . Value . BezierSegments . Count ) . Max ( ) , original . InitialValue . BezierSegments . Count ) ;
69
+ int minSegments = Math . Min ( original . KeyFrames . Select ( x => x . Value . BezierSegments . Count ) . Min ( ) , original . InitialValue . BezierSegments . Count ) ;
70
+
71
+ // If all PathGeometry objects have the same number of segments -> Composition API can animate this.
72
+ if ( minSegments == maxSegments )
73
+ {
74
+ return original ;
75
+ }
76
+
77
+ original . Context . Issues . PathAnimationHasDifferentNumberOfSegments ( ) ;
78
+
79
+ Func < PathGeometry , PathGeometry > populatePathGeometry = ( PathGeometry pathGeometry ) => {
80
+ List < BezierSegment > segments = pathGeometry . BezierSegments . ToList ( ) ;
81
+
82
+ while ( segments . Count < maxSegments )
83
+ {
84
+ var p = segments . Last ( ) . ControlPoint1 ;
85
+ segments . Add ( new BezierSegment ( p , p , p , p ) ) ;
86
+ }
87
+
88
+ return new PathGeometry ( new Sequence < BezierSegment > ( segments . AsEnumerable ( ) ) , pathGeometry . IsClosed ) ;
89
+ } ;
90
+
91
+ // If some PathGeometry ogjects have different number of segments -> Composition API can't animate this,
92
+ // we are using a workaround: populate path geometries to the same size, with the 0-length segments at the end.
93
+ var newKeyFrames = new List < KeyFrame < PathGeometry > > ( ) ;
94
+ foreach ( var keyframe in original . KeyFrames )
95
+ {
96
+ newKeyFrames . Add ( new KeyFrame < PathGeometry > ( keyframe . Frame , populatePathGeometry ( keyframe . Value ) , keyframe . SpatialBezier , keyframe . Easing ) ) ;
97
+ }
98
+
99
+ return new TrimmedAnimatable < PathGeometry > ( original . Context , populatePathGeometry ( original . InitialValue ) , newKeyFrames ) ;
100
+ }
101
+
66
102
// If the given path is equivalent to a static path with an animated offset, convert
67
103
// the path to that form and apply it to the given geometry and shape.
68
104
static bool TryApplyPathAsStaticPathWithAnimatedOffset (
0 commit comments