Element

  • A component represents a small reusable piece of code of element to be rendered. This behaves as all elements of UIKit’s UITableView and UICollectionView, and can be easily support SwiftUI by used in conjunction with the View protocol.

    Example for the simple component:

    struct Label: Component {
        var text: String
    
        init(_ text: String) {
            self.text = text
        }
    
        func renderContent() -> UILabel {
            return UILabel()
        }
    
        func render(in content: UILabel) {
            content.text = text
        }
    }
    

    Example for use with SwiftUI:

    extension Label: View {}
    
    struct ContentView: View {
        var body: some View {
            VStack {
                Text("This is SwiftUI view")
                Label("This is Carbon component")
            }
        }
    }
    
    See more

    Declaration

    Swift

    public protocol Component
  • Represents a component that can be uniquely identify.

    Example for the simple identified component:

    struct UserLabel: IdentifiableComponent {
        var id: Int64
        var name: String
    
        func renderContent() -> UILabel {
            return UILabel()
        }
    
        func render(in content: UILabel) {
            content.text = name
        }
    }
    
    See more

    Declaration

    Swift

    public protocol IdentifiableComponent : CellsBuildable, Component
  • Represents a section of list UI, containing header node, footer node and collection of cell nodes. This works as an intermediary for DifferenceKit.

    Example for simple section.

    Section(
        id: 0,
        header: Label("Header"),
        footer: Label("Footer"),
        cells: {
            Label("Cell 0")
                .identified(by: \.text)
    
            Label("Cell 1")
                .identified(by: \.text)
    
            Label("Cell 2")
                .identified(by: \.text)
        }
    )
    
    See more

    Declaration

    Swift

    public struct Section
  • An affordance for grouping component or section.

    Example for simple grouping of cells.

    Group {
        Label("Cell 0")
    
        Label("Cell 1")
    
        Label("Cell 2")
    }
    
    See more

    Declaration

    Swift

    public struct Group<Element>