fabulous-dev / Fabulous

Declarative UI framework for cross-platform mobile & desktop apps, using MVU and F# functional programming
https://fabulous.dev
Apache License 2.0
1.14k stars 121 forks source link

Better support for Behaviors #832

Closed TimLariviere closed 2 years ago

TimLariviere commented 3 years ago

Fabulous does not natively let us extend an element with Xamarin.Forms.Behaviors. The only way, today, is to get access to the underlying Xamarin.Forms control through created and set the behavior directly there.

It would be nice to have a better integration for this.

Use case

See https://github.com/fsprojects/Fabulous/issues/827#issuecomment-752080906 for an example.

Proposal

type EntryBehavior() =
    inherit Xamarin.Forms.Behavior()
    (...)

type View with
    static member EntryBehavior() =
        let create () = new EntryBehavior()
        (...)

View.Entry(
    text = entryText,
    behaviors = [
        View.EntryBehavior() // behavior used here
    ]
)
TimLariviere commented 2 years ago

v2 now supports extension methods very easily. Closing this issue