Hi Jxns,
changing Opacity
sounds like a good approach in general, but I’m afraid you’re doing it in a way that is not optimal. Adding an explicit backwards animation might also be the way to, but I don’t think that’s the right approach in this case either.
Here’s something that I threw together based on the code you shared, and I think you’ll find pretty cool. There are a few tricks to this, so I’ll explain.
First, I created a component for the loader itself, so that I have a little better abstraction level:
<Circle ux:Class="Loader" Width="120" Height="120" StartAngleDegrees="-45" EndAngleDegrees="45">
<Stroke Width="20" Color="Red" />
</Circle>
And then I use it in the app like so. Notice how I set the Visibility
to Hidden
and Opacity
to zero:
<Panel Clicked="{triggerBusy}" HitTestMode="LocalBounds">
<Loader ux:Name="ButtonLoader" Visibility="Hidden" Opacity="0" />
What I wanted to achieve was the loader to animate both in and out smoothly, all while spinning, to avoid any kind of visual jerkiness. This is where the Visibility
comes in handy, because we can Spin
the loader all the time it is visible:
<Circle ux:Class="Loader" Width="120" Height="120" StartAngleDegrees="-45" EndAngleDegrees="45">
<Stroke Width="20" Color="Red" />
<WhileVisible>
<Spin Frequency="1"/>
</WhileVisible>
</Circle>
And finally, we simply have to animate (both forward and back) as the Busy
state changes:
<Panel Clicked="{triggerBusy}" HitTestMode="LocalBounds">
<Loader ux:Name="ButtonLoader" Visibility="Hidden" Opacity="0" />
<Busy IsActive="false" ux:Name="busy"/>
<WhileBusy>
<Change ButtonLoader.Visibility="Visible" DelayBack="1" />
<Change ButtonLoader.Opacity="1" Duration="1" />
</WhileBusy>
</Panel>
And here’s the full code that you can copy-paste and run:
<App>
<JavaScript>
function triggerBusy() {
busy.activate();
setTimeout(function() {
busy.deactivate();
},2700);
}
module.exports = {
triggerBusy: triggerBusy
};
</JavaScript>
<Panel Clicked="{triggerBusy}" HitTestMode="LocalBounds">
<Loader ux:Name="ButtonLoader" Visibility="Hidden" Opacity="0" />
<Busy IsActive="false" ux:Name="busy"/>
<WhileBusy>
<Change ButtonLoader.Visibility="Visible" DelayBack="1" />
<Change ButtonLoader.Opacity="1" Duration="1" />
</WhileBusy>
</Panel>
<Circle ux:Class="Loader" Width="120" Height="120" StartAngleDegrees="-45" EndAngleDegrees="45">
<Stroke Width="20" Color="Red" />
<WhileVisible>
<Spin Frequency="1"/>
</WhileVisible>
</Circle>
</App>