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

Fixing Issue 73 #72

Merged
merged 2 commits into from Aug 2, 2018
Merged

Fixing Issue 73 #72

merged 2 commits into from Aug 2, 2018

Conversation

josephquigley
Copy link
Contributor

@josephquigley josephquigley commented Aug 2, 2018

Fixing Issue 73 so that it's possible to access the child bricks of a Brick instance.

Renamed Bricks.bricks to Bricks.childBricks to convey what the developer will be accessing.
Exposed UIView.lg_brickName so that you can bind views to bricks with children:

//Boilerplate for example
let name = "Example name"
let address = "Example address"

//BrickDataSource implemented
func update(_ targetView: UIView, with brick: Brick) {
    brick.childBricks?.forEach { brick in
        let viewsForBrick = ([targetView] + targetView.subviews)
            .filter({$0.lg_brickName == brick.name})
        
        for view in viewsForBrick {
            switch view {
            case let label as UILabel where brick == FooBrickBuilder.name:
                label.text = name
            case let label as UILabel where brick == FooBrickBuilder.address:
                label.text = address
            default: ()
            }
        }
    }
}

Now your UI binding code looks like the following:

let title = "title".build(UILabel.self).style([.numberOfLines(0), .text("Lorem Ipsum is simply dummy text of the printing industry")])
let description = "description".build(UILabel.self).style([.textColor(UIColor.lightGray), .numberOfLines(0), .font(UIFont.systemFont(ofSize: 14)), .text("Lorem Ipsum has been the industry's standard dummy text ever since the 1500s")])
let redBlock = "red".build().style(Style.redBlockStyle)
let greenBlock = "green".build().style(Style.greenBlockStyle)
let blueBlock = "blue".build(UIImageView.self).style(Style.blueBlockStyle + [Appearance.custom(["shadowColor": UIColor.brown, "shadowOpacity": Float(1.0)])])

let blocks = Brick.union("blocks", bricks: [
    redBlock.height(50),
    greenBlock.height(80),
    blueBlock.height(30)],
    axis: .horizontal, align: .top, distribution: .fillEqually, metrics: LayoutMetrics(10, 10, 10, 10, 10, 10)).style(Style.blocksStyle)

let brick = "details".build().bricks(title, description, blocks) {
    title, description, blocks in
    Layout(bricks: [title, description, blocks], axis: .vertical, align: .fill, distribution: .flow(3), metrics: LayoutMetrics(84, 20, 20, 20, 10, 10))
}

self.view.lg_configure(as: brick, updatingStrategy: .always)

// This example is assuming that ClassThatHandlesUpdates would
// change, say, the text of the UILabel created by the title brick
ClassThatHandlesUpdates().update(self.view, with: brick)

@josephquigley josephquigley changed the title Fixing Issue 71 Fixing Issue 73 Aug 2, 2018
@wangshengjia wangshengjia merged commit a4edceb into wangshengjia:master Aug 2, 2018
@wangshengjia
Copy link
Owner

Thanks for the PR, it makes sense.

Merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants