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.15k stars 122 forks source link

View.CollectionView has invalid types for header\footer #755

Closed Liminiens closed 3 years ago

Liminiens commented 4 years ago

Currently they have a type of obj, but the doc states that you can put there text or view.

So, currently this program will successfully show text in first collection view, but will show .ToString() in second one instead of view itself.

open Fabulous
open Fabulous.XamarinForms
open Xamarin.Forms

module App = 
  type Model = 
    { Text: string } 

  type Msg = 
    | Ignore

  let initModel = { Text = "Hello there" }

  let init () = initModel, Cmd.none

  let update msg model =
    match msg with
    | Ignore -> 
      model, Cmd.none

  let view (model: Model) dispatch =
    View.ContentPage(
      padding = Thickness(16.),
      content =
        View.StackLayout(
          spacing = 8.,
          orientation = StackOrientation.Vertical,
          children = [
            View.CollectionView(
              header = model.Text,
              footer = model.Text,
              items = [View.Label("Test")]
            )
            View.CollectionView(
              header = View.Label(model.Text),
              footer = View.Label(model.Text),
              items = [View.Label("Test")]
            )
          ]
        )
    )

  // Note, this declaration is needed if you enable LiveUpdate
  let program = XamarinFormsProgram.mkProgram init update view

type App () as this = 
  inherit Application ()

  let runner = App.program |> XamarinFormsProgram.run this |> ignore

image

Maybe there should be two new types, like:

type StructuredItemsViewHeader =
  | Text of string
  | View of ViewElement

type StructuredItemsViewFooter =
  | Text of string
  | View of ViewElement

and two separate update functions for them? I don't know if there is better naming for them, but two these prorties lie in StructuredItemsView and may be used somethere else.

App with repro:

Headers.zip