Skip to content

Unable to animate the Canvas.Top or Canvas.Left attached properties #12301

Closed

Description

@BrianDT

Current behavior

Animation of the canvas top or left attached properties does not work on WASM, Android and iOS.


    <Storyboard x:Name="SimpleStoryboard">
        <DoubleAnimation Storyboard.TargetName="Thing" 
                         Storyboard.TargetProperty="(Canvas.Top)"
                         From="{x:Bind VM.Y, Mode=OneWay}" To="20.0" Duration="0:0:5"/>
    </Storyboard>

On button press

this.SimpleStoryboard.Begin();

Works perfectly well on WinUI

Expected behavior

In the sample the red ball should animate vertically up the screen.

How to reproduce it (as minimally and precisely as possible)

Reproduced in sample at https://github.com/BrianDT/UnoCanvasOffsetAnimationIssue

Workaround

Adding EnableDependentAnimation="true" to the DoubleAnimation works for WASM and iOS

Works on UWP/WinUI

Yes

Environment

Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia, Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia

NuGet package version(s)

4.8.33

Affected platforms

All targets

IDE

Visual Studio 2022

IDE version

17.5.5

Relevant plugins

None

Anything else we need to know?

Activity

  1. added
    difficulty/tbd
    kind/bug
    triage/untriaged
    on May 15, 2023
  2. Youssef1313 commented on May 15, 2023

    @Youssef1313
    Member

    Looks like a dupe of #8613

  3. added
    project/animations 🎡
    and removed
    triage/untriaged
    on May 15, 2023
  4. BrianDT commented on May 16, 2023

    @BrianDT
    Author

    Looks like a dupe of #8613

    @Youssef1313 Superficially looks the same but actually not. #8613 suggests that if you add
    EnableDependentAnimation="true"

    To the DoubleAnimation then the problem can be worked around.
    This works for WASM but is not true for Android where the EnableDependentAnimation has no effect and it still does not work. Jury is still out on iOS.

    Even for WASM, there is no suggestion under #8613 that anybody has raised a WinUI issue indicating that WinUI should require the EnableDependentAnimation property set to work, which makes be thing that if WinUI is correct the workaround is just covering up what is still an issue.

  5. added
    difficulty/medium 🤔
    and removed
    difficulty/tbd
    on May 16, 2023
  6. changed the title [-]Unable to animate the canvas top or left attached properties on WASM, Android, iOS[/-] [+]Unable to animate the `Canvas.Top` or `Canvas.Left` attached properties[/+] on May 16, 2023
  7. MartinZikmund commented on May 16, 2023

    @MartinZikmund
    Member

    Yes, will close #8613 in favor of this one, as it is more broad, affecting all targets

  8. dr1rrb commented on May 16, 2023

    @dr1rrb
    Member

    @BrianDT The EnableDependentAnimation is a UWP/WInUI flag which is false by default and indicates if animations that are invalidating the layout (i.e. causing Measure/Arrange phases) are allowed or not (cf. https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.media.animation.doubleanimation.enabledependentanimation?view=winrt-22621#whats-considered-a-dependent-animation).

    I assume that this flag has to be set to true to animate the Canvas.<X|Y> on Windows, and we should align Uno's behavior with Windows (even if currently we are not running animation independently of the UI thread on Skia and Wasm).

    Gets or sets a value that declares whether animated properties that are considered dependent animations should be permitted to use this animation declaration.
  9. BrianDT commented on May 19, 2023

    @BrianDT
    Author

    @dr1rrb I absolutely agree that Uno's behavior should align with Windows, that was the point I was trying to make. The point is that Windows Does Not Require the EnableDependentAnimation flag set for the animation to run, so I was questioning why it was required in Uno.

  10. BrianDT commented on May 20, 2023

    @BrianDT
    Author

    A sequence of changes to the sample has enabled the iOS build to be investigated. The path has been shortened, the provisioning profile has been reset and changes from the latest templates incorporated.
    The sample now shows that if EnableDependentAnimation="true" the iOS build executes as expected.
    Therefore, in summary:
    Windows OK
    Android Fail
    iOS OK with workaround
    WASM OK with workaround

  11. dr1rrb commented on May 25, 2023

    @dr1rrb
    Member

    @dr1rrb I absolutely agree that Uno's behavior should align with Windows, that was the point I was trying to make. The point is that Windows Does Not Require the EnableDependentAnimation flag set for the animation to run, so I was questioning why it was required in Uno.

    Indeed, animating (Canvas.<Top|Left>) is working on windows even if the EnableDependentAnimation is not set to true ... I was convinced that this should be considered as a dependent animation. And apparently when we implemented the animations in Uno we did the same mistake. This is definitely a bug in uno (and will probably require a refactor of the Canvas to make sure to be able to runs those animation independently).

    For reference :

    An animation is independent if it has any of these characteristics:

    • The Duration of the animation is 0 seconds (see Warning)
    • The animation targets UIElement.Opacity
    • The animation targets a sub-property value of these UIElement properties: Transform3D, RenderTransform, Projection, Clip
    • The animation targets Canvas.Left or Canvas.Top
    • The animation targets a Brush value and uses a SolidColorBrush, animating its Color
    • The animation is an ObjectAnimationUsingKeyFrames

    https://learn.microsoft.com/en-us/windows/apps/design/motion/storyboarded-animations#dependent-and-independent-animations

    About the fact that the animation is not working on Android (even with the flag), this is strange and probably another bug ... do you have anything in the log?

    BTW as a workaround (and a more performant approach for iOS and Android considering current support in uno), you should consider to use RenderTransform instead of Canvas.<Top|Left>.

    Learn how to use storyboarded animations to change the value of a dependency property as a function of time.
  12. BrianDT commented on May 26, 2023

    @BrianDT
    Author

    @dr1rrb The suggestion to use a Translation Transform for the animation is a good one. This works absolutely fine on Windows and WASM, but has a minor issue on Android and a slightly bigger issue on iOS.

    The sample has been updated to include the alternative animation. In the sample only the Translate.Y is animated.

    On Android when the animation completes the Translate.X is set to 0 so the target object that has been moved shifts to the left of the screen.

    On iOS the Translate.X is set to 0 as soon as the animation starts so the target object moves up the left-hand side of the screen.

  13. dr1rrb commented on Jun 5, 2023

    @dr1rrb
    Member

    @BrianDT Damn just realized that you are probably facing a known issue where animating 2 properties of the same object on those platforms causes some trouble https://github.com/unoplatform/uno/blob/master/doc/articles/features/working-with-animations.md#general-guidelines :/

    The workaround is to have a layer for each animated value:

    <Border>
        <Border.RenderTransform>
            <TranslateTransform x:Name="xTransform" X="0" />
        </Border.RenderTransform>
        <Border>
            <Border.RenderTransform>
                <TranslateTransform x:Name="yTransform" Y="0" />
            </Border.RenderTransform>
    
            <Your_Content />
    
        </Border>
    </Border>

    ... which is incredibly ugly :/

    You should upvote this #12530

    GitHub
    Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported. - uno/working-with-animations.md at master · unoplatform/uno
  14. self-assigned this
    on Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

difficulty/medium 🤔kind/bugproject/animations 🎡

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions