Fabulous icon indicating copy to clipboard operation
Fabulous copied to clipboard

Add support for transitions when properties is changed

Open Dolfik1 opened this issue 3 years ago • 2 comments

It would be great to support animated transitions on changed properties.

The main idea is as follows: when property is changed in UpdateIncremental we should check if any transitions is attached to this property. If transition is attached to the property then we should invoke transition callback instead of modifying property value directly.

Take a look at small example:

type ITransition =
  abstract member Property: BindableProperty
  abstract member Execute: (View * obj * obj) -> unit

let transition<'a> property fn =
  { new ITransition with
      member x.Property = property
      member x.Execute(view, fromValue, toValue) =
        fn view (unbox fromValue) (unbox toValue) }
  

View.Frame(
  translationX = model.TranslationX,
  transitions = [
    transition<float> View.TranslationXProperty (fun view fromValue toValue -> 
        Animation((fun v -> view.TranslationX <- v), fromValue, toValue, Easing.CubicOut)
          .Commit(view, "MyAnimation", 16u, 200u))
  ]
)

Dolfik1 avatar Nov 17 '20 08:11 Dolfik1

@TimLariviere Will this still be possible with v2? It seems like an excellent way to work with animations

edgarfgp avatar Oct 26 '22 06:10 edgarfgp

I still don't know exactly how to incorporate animations in Fabulous. The issue with having functions inside the widgets is that we need to evaluate them all the time because we can't compare functions like we compare values.

This would require a mechanism to synchronize animations to avoid restarting an animation on each update.

TimLariviere avatar Nov 08 '22 09:11 TimLariviere