Animations
Animations provide a way to make adjustments to the UI in response to user actions over a pre-determined amount of time.
Animations in Rock Mobile Shell are provided by the Xamanimation library. That page has some samples and screenshots to give you a few ideas of what you can build. But we'll give you some information on how to build it here.

Defining Animations

Let's talk about simple animations first. Animations are referenced by name and defined in the Resources of an element. In order to access an animation, it must be defined in a ancestor of where you are trying to reference it. Said another way, let's suppose you have the following XAML defined:
1
<ScrollView>
2
<StackLayout>
3
<Label x:Name="myLabel" Text="Hello Rock!" />
4
</StackLayout>
5
</ScrollView>
Copied!
If you wanted to apply an animation to the label called myLabel then you would need to define it on either the StackLayout or the ScrollView. As long as it's defined above the element you are going to be referencing it from then you are fine. You cannot define it on the element itself.
So let's take an example of what this might look like:
1
<ScrollView>
2
<StackLayout>
3
<StackLayout.Resources>
4
<Rock:FadeToAnimation x:Key="FadeOut"
5
Target="{x:Reference myLabel}"
6
Duration="2000"
7
Opacity="0" />
8
</StackLayout.Resources>
9
​
10
<Label x:Name="myLabel" Text="Hello Rock!" />
11
</StackLayout>
12
</ScrollView>
Copied!
This defines an animation that references myLabel as the target of the changes it will be making. The animation is going to be changing the Opacity property of the label over a duration of 2,000 milliseconds (2 seconds). Finally, it will change the opacity of the label from it's current opacity to the target opacity of 0. Note, this only defines the animation, it doesn't actually trigger it.
These types of animation definitions let you target specific visual elements with a pre-defined animation style.

Starting Animations

Okay we were able to define an animation but we need to start it somehow. You have two choices when it comes to triggering an animation.
    1.
    Trigger style in response to the user doing something.
    2.
    Automatically when the view loads (behavior style).
Let's modify our example above but include a trigger style activator based on the user tapping a button:
1
<ScrollView>
2
<StackLayout>
3
<StackLayout.Resources>
4
<Rock:FadeToAnimation x:Key="FadeOut"
5
Target="{x:Reference myLabel}"
6
Duration="2000"
7
Opacity="0" />
8
</StackLayout.Resources>
9
​
10
<Label x:Name="myLabel" Text="Hello Rock!" />
11
​
12
<Button Text="Fade">
13
<Button.Triggers>
14
<EventTrigger Event="Clicked">
15
<Rock:BeginAnimation Animation="{StaticResource FadeOut}" />
16
</EventTrigger>
17
</Button.Triggers>
18
</Button>
19
</StackLayout>
20
</ScrollView>
Copied!
We've added a button and a BeginAnimation trigger to it that starts the FadeOut animation we previously defined. Now, when the user taps the Fade button, the label above will slowly fade out over 2 seconds.
Another way we could define this is by behavior. Suppose we wanted the text to automatically fade out after the page loads? To do that we would use a BeginAnimationBehavior instead:
1
<ScrollView>
2
<StackLayout>
3
<StackLayout.Resources>
4
<Rock:FadeToAnimation x:Key="FadeOut"
5
Target="{x:Reference myLabel}"
6
Duration="2000"
7
Opacity="0" />
8
</StackLayout.Resources>
9
​
10
<Label x:Name="myLabel" Text="Hello Rock!">
11
<Label.Behaviors>
12
<Rock:BeginAnimationBehavior Animation="{StaticResource FadeOut}" />
13
</Label.Behaviors>
14
</Label>
15
</StackLayout>
16
</ScrollView>
Copied!
The way behaviors work is that they begin when the element they are attached to are themselves attached to their parent element. Because there might be a delay between when this happens and when the page itself becomes fully visible, there is a hard coded 250 millisecond delay before the referenced animation actually begins.

Stopping Animations

You can also provide the ability to stop an animation by using a trigger. Technically, the library also supports stopping an animation using a behavior, but in our use case those don't actually make sense. If you are curious though, it is available as EndAnimationBehavior. But here is an example of two buttons, one to start and one to stop an animation.
1
<ScrollView>
2
<StackLayout>
3
<StackLayout.Resources>
4
<Rock:FadeToAnimation x:Key="FadeOut"
5
Target="{x:Reference myLabel}"
6
Duration="2000"
7
Opacity="0" />
8
</StackLayout.Resources>
9
​
10
<Label x:Name="myLabel" Text="Hello Rock!" />
11
​
12
<Button Text="Start Fade">
13
<Button.Triggers>
14
<EventTrigger Event="Clicked">
15
<Rock:BeginAnimation Animation="{StaticResource FadeOut}" />
16
</EventTrigger>
17
</Button.Triggers>
18
</Button>
19
​
20
<Button Text="Stop Fade">
21
<Button.Triggers>
22
<EventTrigger Event="Clicked">
23
<Rock:EndAnimation Animation="{StaticResource FadeOut}" />
24
</EventTrigger>
25
</Button.Triggers>
26
</Button>
27
</StackLayout>
28
</ScrollView>
Copied!

Triggered Animations

Triggered animations are ones that are, well, triggered by some user interaction. Until the user activates that trigger event, such as tapping a button, the animation remains idle.
All of the animations in this section support the following properties.
Property
Type
Description
Target
VisualElement
A reference to the targetted element to be animated.
Duration
string
The duration of the animation, in milliseconds. Defaults to 1000.
Easing
EasingType
The easing to use when calculating the animation curve: BounceIn, BounceOut, CubicIn, CubicInOut, CubicOut, Linear, SinIn, SinInOut, SinOut, SprintIn, SpringOut. Defaults to Linear.
Delay
int
A delay in milliseconds before the animation will begin. Defaults to 0.
RepeatForever
bool
Repeats the animation until stopped. Defaults to false.

BounceInAnimation

Animates the Scale and Opacity of the target to make it appear.
Note
This animation ignores the Easing property.
Example
1
<Rock:BounceInAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Duration="2000" />
Copied!

BounceOutAnimation

Animates the Scale and Opacity of the target to make it disappear.
Note
This animation ignores the Easing property.
Example
1
<Rock:BounceOutAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Duration="2000" />
Copied!

BackgroundColorAnimation

Animates the BackgroundColor of the target from it's current value to a new color.
Property
Type
Description
ToColor
Color
The target color that the BackgroundColor will be transitioned to.
Note
This animation ignores the Easing property.
Example
1
<Rock:BackgroundColorAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Duration="2000"
4
ToColor="#ee7725" />
Copied!

ColorAnimation

Animates the specified property of the target, which must be of type Color, between two values.
Property
Type
Description
From
Color
The value that the property will be transitioned from. If not set then the current property value is used.
Property
string
The name of the property to be animated.
To
Color
The value that the property will be transitioned to.
Example
1
<Rock:ColorAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Property="TextColor"
4
Duration="2000"
5
To="#ee7725" />
Copied!

CornerRadiusAnimation

Animates the specified property of the target, which must be of type CornerRadius, between two values.
Property
Type
Description
From
CornerRadius
The value that the property will be transitioned from. If not set then the current property value is used.
Property
string
The name of the property to be animated.
To
CornerRadius
The value that the property will be transitioned to.
Example
1
<Rock:CornerRadiusAnimation x:Key="Demo"
2
Target="{x:Reference myBox}"
3
Property="CornerRadius"
4
Duration="2000"
5
To="15,15,5,5" />
Copied!

DoubleAnimation

Animates the specified property, which must be of type double, of the target between two values.
Property
Type
Description
From
double
The value that the property will be transitioned from. If not set then the current property value is used.
Property
string
The name of the property to be animated.
To
double
The value that the property will be transitioned to.
Example
1
<Rock:DoubleAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Property="Opacity"
4
Duration="2000"
5
To="0.5" />
Copied!

FadeInAnimation

Animates the Opacity and Y position of the element to make it visible. As the element is faded in it will also slide down or up to its final position.
Property
Type
Description
Direction
string
The vertical movement direction of the element: Up or Down. Defaults to Up.
Note
This animation ignores the Easing property.
Example
1
<Rock:FadeInAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Duration="2000"
4
Direction="Down" />
Copied!

FadeToAnimation

Animates the Opacity of the target from it's current value to a new value.
Property
Type
Description
Opacity
double
The target opacity that the element should have once the animation finished. This value should be between 0 and 1.0.
Example
1
<Rock:FadeToAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Duration="2000"
4
Opacity="0.25" />
Copied!

FadeOutAnimation

Animates the Opacity and Y position of the element to make it invisible. As the element is faded in it will also slide down or up from its current position.
Property
Type
Description
Direction
string
The vertical movement direction of the element: Up or Down. Defaults to Up.
Note
This animation ignores the Easing property.
Example
1
<Rock:FadeOutAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Duration="2000"
4
Direction="Down" />
Copied!

FlipAnimation

Animates the Opacity and RotationY axis of the element to make it visible. As the element is faded in it will also rotate along it's y-axis (that is, it will grow from a single vertical line to full-width) as if a card were being turned 90 degrees.
Property
Type
Description
Direction
string
The horizontal rotation direction of the element: Left or Right. Defaults to Right.
Note
This animation ignores the Easing property.
Example
1
<Rock:FlipAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Duration="2000"
4
Direction="Left" />
Copied!

HeartAnimation

Animates the Scale of the target to simulate a heart beat, growing and shrinking slighly.
Note
This animation ignores the Easing property.
Example
1
<Rock:HeartAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Duration="1000" />
Copied!

IntAnimation

Animates the specified property of the target, which must be of type int, between two values.
Property
Type
Description
From
int
The value that the property will be transitioned from. If not set then the current property value is used.
Property
string
The name of the property to be animated.
To
int
The value that the property will be transitioned to.
Example
1
<Rock:IntAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Property="TabIndex"
4
Duration="2000"
5
To="12" />
Copied!

JumpAnimation

Animates the TranslationY of the target to cause it to jump up and down.
Note
This animation ignores the Easing property.
Example
1
<Rock:JumpAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Duration="2000" />
Copied!

RelRotateToAnimation

Animates the Rotation of the target to spin the element by the number of degrees. This rotation happens along the Z-axis, meaning it it does not distort the element's perspective at all.
Property
Type
Description
Rotation
double
The delta angle that the target should be rotated by (positive or negative number).
Example
1
<Rock:RelRotateToAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Duration="2000"
4
Rotation="-45" />
Copied!

RelScaleToAnimation

Animates the Scale of the target to make the element appear larger or smaller than it normally would.
Property
Type
Description
Scale
double
The delta amount that the target should be scaled by.
Example
1
<Rock:RelScaleToAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Duration="2000"
4
Scale="0.8" />
Copied!

RotateToAnimation

Animates the Rotatation of the target to spin the element to the specified final rotation value. This rotation happens along the Z-axies, meaning it does not distort the element's perspective at all.
Property
Type
Description
Rotation
double
The absolute angle that the target should be rotated to.
Example
1
<Rock:RotateToAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Duration="2000"
4
Rotation="180" />
Copied!

RotateXToAnimation

Animates the RotationX of the target to shift the perspective of the element.
Property
Type
Description
Rotation
double
The absolute angle that the target should be rotated to.
Example
1
<Rock:RotateXToAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Duration="2000"
4
Rotation="90" />
Copied!

RotateYToAnimation

Animates the RotationY of the target to shift the perspective of the element.
Property
Type
Description
Rotation
double
The absolute angle that the target should be rotated to.
Example
1
<Rock:RotateYToAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Duration="2000"
4
Rotation="90" />
Copied!

ScaleToAnimation

Animates the Scale of the target to make the element appear larger or smaller than it normally would.
Property
Type
Description
Scale
double
The absolute value that the target should be scaled to, a value of 1 means normal scale.
Example
1
<Rock:ScaleToAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Duration="2000"
4
Scale="1.2" />
Copied!

ShakeAnimation

Animates the TranslationX target to make it appear as if it were being shaken back and forth.
Note
This animation ignores the Easing property.
Example
1
<Rock:ShakeAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Duration="2000" />
Copied!

ThicknessAnimation

Animates the specified property of the target, which must be of type Thickness, between two values.
Property
Type
Description
From
Thickness
The value that the property will be transitioned from. If not set then the current property value is used.
Property
string
The name of the property to be animated.
To
Thickness
The value that the property will be transitioned to.
Example
1
<Rock:ThicknessAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Property="Margin"
4
Duration="2000"
5
To="15" />
Copied!

TranslateAnimation

Animates the TranslationX and TranslationY properties of the target to shift the element around from it's normal position.
Property
Type
Description
TranslateX
double
The value that the element should be shifted to on the x-axis.
TranslateY
double
The value that the element should be shifted to on the y-axis.
Example
1
<Rock:TranslateAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Duration="2000"
4
TranslateX="30"
5
TranslateY="-15" />
Copied!

TurnstileInAnimation

Animates the RotationY and Opacity properties of the target to give a turnstyle effect to the element appearing on screen.
Note
This animation ignores the Easing property.
Example
1
<Rock:TurnstileInAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Duration="2000" />
Copied!

TurnstileOutAnimation

Animates the RotationY and Opacity properties of the target to give a turnstyle effect to the element disappearing from the screen.
Note
This animation ignores the Easing property.
Example
1
<Rock:TurnstileOutAnimation x:Key="Demo"
2
Target="{x:Reference myLabel}"
3
Duration="2000" />
Copied!

GroupAnimation

This is a special animation that does not conform to the common properties mentioned prevoiusly. This element simply lets you group animations so that they can be triggered at the same time. Animations to be grouped together can be added as child elements.
Example
1
<Rock:GroupAnimation x:Key="FadeOut">
2
<Rock:FadeToAnimation Target="{x:Reference myLabel}"
3
Duration="2000"
4
Opacity="0" />
5
<Rock:FadeToAnimation Target="{x:Reference myButton}"
6
Duration="2000"
7
Opacity="0" />
8
</Rock:StoryBoard>
Copied!

Passive Animations

A passive animation is one that is always active and updates continuously whenever the property it uses to track progress changes. One example usage of this might be a slider that is used to specify the color of something. As the slider moves from one side to the other, the color slowly changes from one color to the other.
All of the animations in this section support the following properties.
Property
Type
Description
Property
string
The name of the property to be animated.
Progress
double
The current value being tracked.
Minimum
double
The minimum value to clamp Progress to. Defaults to 0.
Maximum
double
The maximum value to clamp Progress to. Defaults to 100.
Easing
EasingType
The easing to use when calculating the animation curve: BounceIn, BounceOut, CubicIn, CubicInOut, CubicOut, Linear, SinIn, SinInOut, SinOut, SprintIn, SpringOut. Defaults to Linear.

AnimateProgressColor

Animates the Color-type property between the From and To values.
Property
Type
Description
From
Color
The value to use when Progress is less than or equal to Minimum.
To
Color
The value to use when Progress is greater than or equal to Maximum.
Example
1
<StackLayout>
2
<Slider x:Name="mySlider" Minimum="0" Maximum="100" />
3
​
4
<BoxView Color="Blue" HeightRequest="100">
5
<BoxView.Behaviors>
6
<Rock:AnimateProgressColor Property="Color"
7
From="Red"
8
To="Green"
9
Progress="{Binding Path=Value, Source={x:Reference mySlider}}" />
10
</BoxView.Behaviors>
11
</BoxView>
12
</StackLayout>
Copied!

AnimateProgressCornerRadius

Animates the CornerRadius-type property between the From and To values.
Property
Type
Description
From
CornerRadius
The value to use when Progress is less than or equal to Minimum.
To
CornerRadius
The value to use when Progress is greater than or equal to Maximum.
Example
1
<StackLayout>
2
<Slider x:Name="mySlider" Minimum="0" Maximum="100" />
3
​
4
<BoxView Color="Blue" HeightRequest="100">
5
<BoxView.Behaviors>
6
<Rock:AnimateProgressCornerRadius Property="CornerRadius"
7
From="15,15,5,5"
8
To="5,5,15,15"
9
Progress="{Binding Path=Value, Source={x:Reference mySlider}}" />
10
</BoxView.Behaviors>
11
</BoxView>
12
</StackLayout>
Copied!

AnimateProgressDouble

Animates the double-type property between the From and To values.
Property
Type
Description
From
double
The value to use when Progress is less than or equal to Minimum.
To
double
The value to use when Progress is greater than or equal to Maximum.
Example
1
<StackLayout>
2
<Slider x:Name="mySlider" Minimum="0" Maximum="100" />
3
​
4
<BoxView Color="Blue" HeightRequest="100">
5
<BoxView.Behaviors>
6
<Rock:AnimateProgressDouble Property="HeightRequest"
7
From="25"
8
To="200"
9
Progress="{Binding Path=Value, Source={x:Reference mySlider}}" />
10
</BoxView.Behaviors>
11
</BoxView>
12
</StackLayout>
Copied!

AnimateProgressInt

Animates the int-type property between the From and To values.
Property
Type
Description
From
int
The value to use when Progress is less than or equal to Minimum.
To
int
The value to use when Progress is greater than or equal to Maximum.
Example
1
<StackLayout>
2
<Slider x:Name="mySlider" Minimum="0" Maximum="100" />
3
​
4
<BoxView Color="Blue" HeightRequest="100">
5
<BoxView.Behaviors>
6
<Rock:AnimateProgressInt Property="TabIndex"
7
From="0"
8
To="15"
9
Progress="{Binding Path=Value, Source={x:Reference mySlider}}" />
10
</BoxView.Behaviors>
11
</BoxView>
12
</StackLayout>
Copied!

AnimateProgressThickness

Animates the Thickness-type property between the From and To values.
Property
Type
Description
From
int
The value to use when Progress is less than or equal to Minimum.
To
int
The value to use when Progress is greater than or equal to Maximum.
Example
1
<StackLayout>
2
<Slider x:Name="mySlider" Minimum="0" Maximum="100" />
3
​
4
<BoxView Color="Blue" HeightRequest="100">
5
<BoxView.Behaviors>
6
<Rock:AnimateProgressThickness Property="Margin"
7
From="0"
8
To="20,20,10,10"
9
Progress="{Binding Path=Value, Source={x:Reference mySlider}}" />
10
</BoxView.Behaviors>
11
</BoxView>
12
</StackLayout>
Copied!

Load Animations

EntranceTransition

Provides the animated transition behavior on controls when they first appear. You can use this on individual objects or on containers of objects. In the latter case, child elements will animate into view in sequence rather than all at the same time.
Property
Type
Description
Duration
int
The speed in milliseconds for which each child element is animated into view.
Example
1
<StackLayout>
2
​
3
<StackLayout.Behaviors>
4
<Rock:EntranceTransition Duration="1000"/>
5
</StackLayout.Behaviors>
6
7
<Label Text="Title"
8
StyleClass="h3" />
9
10
<Rock:ContainedCard Image="https://yourserver.com/image-grandtetonfence.jpg"
11
Tagline="DESTINATIONS"
12
Title="Start Your Adventure">
13
Bring to the table win-win survival strategies to ensure...
14
</Rock:ContainedCard>
15
16
</StackLayout>
Copied!
Last modified 5mo ago