fabulous-dev / Fabulous.XamarinForms

Declarative UIs for Xamarin.Forms with F# and MVU, using Fabulous
https://docs.fabulous.dev/xamarinforms
Apache License 2.0
13 stars 1 forks source link

Add support for float32 properties which fixes corner radius for Frame #35

Closed kevkov closed 1 year ago

kevkov commented 1 year ago

The following view code adapted from the Counter example

    let view model =
        Application(
            ContentPage(
                "Stuff",
                Frame(
                    Button("Hello from Fabulous Xamarin.Forms, .NET 6.0 and F# 6.0!", Increment)
                        .verticalOptions(LayoutOptions.Center)
                        .horizontalOptions(LayoutOptions.Center)

                ).cornerRadius(50.)
                 .borderColor(Color.Red.ToFabColor())
            ).padding(Thickness(5.))
        )

does not set the corner radius on the Frame:

image

With the changes in this PR (and changing the corner radius value to 50.f) the Frame corner radius is set:

image

I found that if the value was narrowed to a float32 in defineSmallBindable then the corner radius was set as expected:

            | ValueSome v -> if bindableProperty.PropertyName = "CornerRadius" then
                                target.SetValue(bindableProperty,150.f)
                             else
                                target.SetValue(bindableProperty, v))

If the value is changed to a float then the corner radius is not set.

I did not establish why XF does not accept the value as a float.

The PR contains codecs for float32 which should possibly be in the Fabulous core project?

Note: there are only 4 properties in XF that are of type C# float/F# float32.

TimLariviere commented 1 year ago

Oh, I think I see the issue here. When set with the wrong data type, the bindable property ignores the new value without any warnings.

image

@kevkov Adding a new defineBindableFloat32 is definitely the right way to go for this.

TimLariviere commented 1 year ago

@kevkov I've released a new version of Fabulous with the PR you did so we can continue this PR :) https://www.nuget.org/packages/Fabulous/2.3.0

To be able to target this new version, you'll need to bump the version in several places:

The other template uses Fabulous as a transitive dependency, so we don't need to update it.

kevkov commented 1 year ago

Updated as required I hope.