Do we need to add states to create simple animations such as ScaleTo, FadeTo, etc on tap?
Even if RxAnimations or AnimationController class are the primary way to create animations in MauiReactor, aren't strictly required.
Take for example how we can create an animated button: we want the user to see a scale animation when clicking over a widget (Image, Button, etc).
Apart from RxAnimation, we can easily just call the ScaleTo view extension method over the native control to achieve the same effect.
Following, we'll see possible implementations:
Use a component, with a layout control containing the Children element and animate it when tapped:
class AnimatedComponent: Component
{
private Func<Task>? _action;
private MauiControls.Grid? _containerGrid;
public AnimatedComponent OnTapped(Func<Task> action)
{
_action = action;
return this;
}
public override VisualNode Render()
{
return new Grid(grid => _containerGrid = grid)
{
Children()
}
.OnTapped(async () =>
{
if (_containerGrid != null && _action != null)
{
await MauiControls.ViewExtensions.ScaleTo(_containerGrid, 0.7);
await _action.Invoke();
await MauiControls.ViewExtensions.ScaleTo(_containerGrid, 1.0);
}
});
}
}Create an extension function for the MauiReactor widget that realizes the animation:
Create a component that renders just one child animated when tapped:
Let's put everything on a page to show the same resulting effect of each variation:

PreviousDoes this support ObservableCollection for CollectionView?NextHow to deal with custom dialogs/popups?
Last updated
Was this helpful?