TimLariviere / Fabulous-new

Fabulous v2 - Work in progress
https://timothelariviere.com/Fabulous-new/
Other
41 stars 3 forks source link

ScrollView + Extensions #84

Closed edgarfgp closed 2 years ago

edgarfgp commented 2 years ago

This PR adds ScrollView extension based on https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/scrollview

Open questions :

Using V1 :

V2 : I think we cn get acess to those animated scrolling methods like this

public System.Threading.Tasks.Task ScrollToAsync (double x, double y, bool animated);
let ScrollToAsync =
    Attributes.define<struct (float * float * bool)>
        "ScrollView_ScrollToAsync"
        (fun newValueOpt node ->
            let scrollView = node.Target :?> ScrollView
            match newValueOpt with
            | ValueNone ->
                scrollView.ScrollToAsync(0, 0, false)
                |> Async.AwaitTask
                |> Async.Start
            | ValueSome (x, y, animated) ->
                scrollView.ScrollToAsync(x, y, animated)
                |> Async.AwaitTask
                |> Async.Start)

There is a second overload for the ScrollToAsync that receives an Xamarin.Forms.Element

public System.Threading.Tasks.Task ScrollToAsync (Xamarin.Forms.Element element, Xamarin.Forms.ScrollToPosition position, bool animated);

For this one we could use the same approach as the ViewRef approach done in #81

TimLariviere commented 2 years ago

I like that idea of having a .scrollTo(x, y) / .scrollToAnimated(x, y) The only problem I see with it is we need a way to make it optional, the new DSL makes it a little bit harder...

For ScrollToElement, we do need ViewRef indeed

edgarfgp commented 2 years ago

This works as expected

[<Extension>]
    static member inline scrollTo(this: WidgetBuilder<'msg, #IScrollView>, x: float, y: float, animated: bool) =
        this.AddScalar(ScrollView.ScrollToAsync.WithValue((x, y, animated)))
edgarfgp commented 2 years ago

If you are happy with my proposal we can wait for #81 to be merged and then use it here . Or we can leave for the different PR 😀

edgarfgp commented 2 years ago

We could even enable all the animation methods in : https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.viewextensions?view=xamarin-forms

TimLariviere commented 2 years ago

That's a good idea! :)