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

Corner radius & shadow #17

Closed
zdnk opened this issue Jul 21, 2016 · 5 comments
Closed

Corner radius & shadow #17

zdnk opened this issue Jul 21, 2016 · 5 comments

Comments

@zdnk
Copy link
Contributor

zdnk commented Jul 21, 2016

How do I setup corner radius if I want shadow at the same time?

public class NavigationCommandView: ComponentView {


    public override func construct() -> ComponentNodeType {
        layer.shadowRadius = 3
        layer.shadowOffset = CGSize(width: 0, height: 0)
        layer.shadowColor = UIColor.blackColor().CGColor
        layer.shadowOpacity = 0.6

        return ComponentNode<UIView>().configure({ (view: UIView) -> Void in
            ....
        })
    }

    override public func layoutSubviews() {
        super.layoutSubviews()

        layer.cornerRadius = bounds.size.height / 2
        layer.masksToBounds = true
    }

}

This wont work because maskToBounds makes shadow invisible because of the mask. And I cannot set conernerRadius to CoMponentNodes view because I dont know its size just yet.

@alexdrone
Copy link
Owner

Just assign those properties (shadowRadius and such) inside the configuration closure.

@alexdrone
Copy link
Owner

let me know if it works! :)

@zdnk
Copy link
Contributor Author

zdnk commented Jul 25, 2016

I cannot because I dont know the size of the view so i cannot do bounds.size.height / 2 calc. The size is calculated based on children. At the time of configuration would occur, size would be (0, 0).

@wokalski
Copy link

It looks like something like react-native's onLayout is needed.

@alexdrone
Copy link
Owner

Will add the onLayout callback soon!

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

No branches or pull requests

3 participants