Skip to content

Commit 109463c

Browse files
authored
Fixed visibility property for visuals with shadow (#492)
1 parent a48c222 commit 109463c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

source/LottieToWinComp/Effects.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ public static Visual ApplyDropShadow(
242242
result.Size = size;
243243
result.Children.Add(blurResult);
244244

245+
// We need to transfer "IsVisible" property from source to result
246+
// because result is now the root visual for both shadow and source.
247+
// Otherwise "IsVisible" property will be applied only to source.
248+
TransferIsVisibleProperty(context, source, result);
249+
245250
// Check if ShadowOnly can be false
246251
if (!dropShadowEffect.IsShadowOnly.IsAlways(true))
247252
{
@@ -267,6 +272,37 @@ public static Visual ApplyDropShadow(
267272
return result;
268273
}
269274

275+
static void TransferIsVisibleProperty(TranslationContext context, Visual source, Visual target)
276+
{
277+
// Here we are transfering default value of "IsVisible" to target
278+
target.IsVisible = source.IsVisible;
279+
source.IsVisible = null;
280+
281+
// Here we are transfering "isVisible" animation to target
282+
foreach (var animator in source.Animators.ToList())
283+
{
284+
if (animator.AnimatedProperty != nameof(source.IsVisible))
285+
{
286+
continue;
287+
}
288+
289+
if (animator.Animation is KeyFrameAnimation_)
290+
{
291+
Animate.WithKeyFrame(context, target, animator.AnimatedProperty, (KeyFrameAnimation_)animator.Animation);
292+
}
293+
else if (animator.Animation is ExpressionAnimation)
294+
{
295+
Animate.WithExpression(target, (ExpressionAnimation)animator.Animation, animator.AnimatedProperty);
296+
}
297+
else
298+
{
299+
throw new ArgumentException("IsVisible animation should be KeyFrameAnimation_ or ExpressionAnimation");
300+
}
301+
302+
source.StopAnimation(animator.AnimatedProperty);
303+
}
304+
}
305+
270306
static Vector3 VectorFromRotationAndDistance(Rotation direction, double distance) =>
271307
VectorFromRotationAndDistance(direction.Radians, distance);
272308

0 commit comments

Comments
 (0)