forked from unoplatform/uno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support ternary operator and relational operators in Expression…
…Animation
- Loading branch information
1 parent
a1a6402
commit 927fed4
Showing
8 changed files
with
217 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
....UI.Composition/Composition/ExpressionAnimationParser/AnimationTernaryExpressionSyntax.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Numerics; | ||
|
||
namespace Microsoft.UI.Composition; | ||
|
||
internal sealed class AnimationTernaryExpressionSyntax : AnimationExpressionSyntax | ||
{ | ||
private readonly AnimationExpressionSyntax _condition; | ||
private readonly AnimationExpressionSyntax _whenTrue; | ||
private readonly AnimationExpressionSyntax _whenFalse; | ||
|
||
public AnimationTernaryExpressionSyntax(AnimationExpressionSyntax condition, AnimationExpressionSyntax whenTrue, AnimationExpressionSyntax whenFalse) | ||
{ | ||
_condition = condition; | ||
_whenTrue = whenTrue; | ||
_whenFalse = whenFalse; | ||
} | ||
|
||
public override object Evaluate(ExpressionAnimation expressionAnimation) | ||
{ | ||
var value = _condition.Evaluate(expressionAnimation); | ||
if (value is not bool valueBool) | ||
{ | ||
throw new Exception($"Ternary expression condition evaluated to '{value}'. It must evaluate to a bool value."); | ||
} | ||
|
||
if (valueBool) | ||
{ | ||
return _whenTrue.Evaluate(expressionAnimation); | ||
} | ||
|
||
return _whenFalse.Evaluate(expressionAnimation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters