ra1028 / Carbon

🚴 A declarative library for building component-based user interfaces in UITableView and UICollectionView.

Home Page:https://ra1028.github.io/Carbon

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mismatched header types

wousser opened this issue · comments

Checklist

Expected Behavior

In RC2 it was possible two show a different heading based on a flag

Current Behavior

In RC4 this behavior is not possible anymore. Resulting in this error:
Result values in '? :' expression have mismatching types 'TodayEmpty' and 'TodayHeader'

Detailed Description (Include Screenshots)

Section(
                id: "contactToday",
                header: state.today.isEmpty
                    ? TodayEmpty() : TodayHeader(),
                cells: { }
)

Both are Component:
struct TodayEmpty : Component
struct TodayHeader : Component

Environment

  • Carbon version:
    RC4
  • Swift version:

Is this possible in RC4 and onwards?

In the new Todo example, I see

if state.todos.isEmpty {
                Section(id: ID.task, header: TodoEmpty())
            }
            else {
                Section(
                    id: ID.task,
                    header: Header("TASKS (\(state.todos.count))"),
                    cells: { }
)

Is the correct way from now on to specify a Section for each header?

@wousser
Generic parameters require the same type for both components at compile time.
This follows the specification of SwiftUI.
Until rc2, ViewNode has played the role of type-erasure, but that isn't the case now.
You can use AnyComponent instead.

Section(
    id: "contactToday",
    header: state.today.isEmpty
        ? AnyComponent(TodayEmpty()) 
        : AnyComponent(TodayHeader()),
    cells: { ... }
)