Skip to content

Define ViewBuildable protocol#1

Merged
cruisediary merged 6 commits into
mainfrom
feature/view-buildable
Nov 14, 2022
Merged

Define ViewBuildable protocol#1
cruisediary merged 6 commits into
mainfrom
feature/view-buildable

Conversation

@cruisediary

@cruisediary cruisediary commented Nov 11, 2022

Copy link
Copy Markdown
Contributor

Objective

  • To Make HypeUIs component be customizable and reusable using ViewBuildable
  • A reusable declarative UI means we can create design systems it self.
// Example

struct HeaderText: ViewBuildable {
    @Behavior var title: String

    func build() -> UIView {
        Text()
            .foregroundColor(UIColor.black)
            .font(UIFont.systemFont(ofSize: 20, weight: .bold))
            .linked($title, keyPath: \.text)
            .padding(.all, 24)
    }
}

struct FooterText: ViewBuildable {
    @Behavior var title: String

    func build() -> UIView {
        Text()
            .foregroundColor(UIColor.black)
            .font(UIFont.systemFont(ofSize: 20, weight: .regular))
            .linked($title, keyPath: \.text)
            .padding(.all, 24)
    }
}

struct ProfileView: ViewBuildable {
    @Behavior var country: String
    @Behavior var name: String

    func build() -> UIView {
        VStack {
            HStack(alignment: .center, spacing: 12) {
                Text("")
                    .linked($country, keyPath: \.text)
                    .font(UIFont.systemFont(ofSize: 20, weight: .regular))
                    .accessibilityIdentifier("country")
                Text("")
                    .linked($name, keyPath: \.text)
                    .font(UIFont.systemFont(ofSize: 20, weight: .regular))
                    .accessibilityIdentifier("name")
            }
        }
    }
}
  • Find specific subview using DFS Because UIViews are made up of compositions, they allow for depth-first searching.
  • Use ViewBuildable with ScrollView, Button, HStack, VStack, ZStack 😊

@cruisediary cruisediary added the enhancement New feature or request label Nov 11, 2022
@cruisediary cruisediary changed the title Define ViewBuildable protocol. Define ViewBuildable protocol Nov 11, 2022
@cruisediary cruisediary merged commit e04b00f into main Nov 14, 2022
@cruisediary cruisediary deleted the feature/view-buildable branch November 15, 2022 10:37
@cruisediary cruisediary self-assigned this Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant