Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define ViewBuildable protocol #1

Merged
merged 6 commits into from
Nov 14, 2022
Merged

Define ViewBuildable protocol #1

merged 6 commits into from
Nov 14, 2022

Conversation

cruisediary
Copy link
Member

@cruisediary cruisediary commented Nov 11, 2022

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