adospace / reactorui-maui

MauiReactor is a MVU UI framework built on top of .NET MAUI
MIT License
597 stars 50 forks source link

Do we need to add states to create simple animations such as ScaleTo, FadeTo etc on tap? #29

Closed AswinPG closed 1 year ago

AswinPG commented 1 year ago

In the xaml world I used to create an Animated Tap behavior to add animation and tapgesturerecognizer to any control. I can simply add the behavior to a control and a visual feedback such as scale in and out can be shown and at the same time tap gesture works too. Is there simple way to achieve this type of animated tap control in MauiReactor instead of creating a state each time ? From what I've seen you need to change the state to Animate the control

adospace commented 1 year ago

I suggest creating a reusable stateful component for that with a State property that you then animated using a RxAnimation; it's the usual way to do things in MVU approach. It also has numerous benefits in my opinion. Said that you still have the ability to take a reference to the native control and directly call View extensions methods like FateTo or ScaleTo() Documentation: https://adospace.gitbook.io/mauireactor/components/animation

AswinPG commented 1 year ago

Is it okay to use behaviors like this new Image(im=>{ im.Behaviors.Add(new AnimatedTapGesture(Navigate) { Scale = .9 }); })

adospace commented 1 year ago

You could, but it's not recommended. In MauiReactor you should write a component with a state and animate through it. Anyway in your code, it's better to clear all the behaviors before adding the new one, as MauiReactor could reuse the Image.

AswinPG commented 1 year ago

Got it. Thanks :)

adospace commented 1 year ago

I've further documented how to achieve this in a specific documentation article, please take a look here: https://adospace.gitbook.io/mauireactor/q-and-a/do-we-need-to-add-states-to-create-simple-animations-such-as-scaleto-fadeto-etc-on-tap