CosmicMind / Material

A UI/UX framework for creating beautiful applications.
http://cosmicmind.com
MIT License
11.98k stars 1.26k forks source link

layoutShadowPath() causing custom shadowPath to be overridden #242

Closed xemacobra closed 8 years ago

xemacobra commented 8 years ago

Hey again,

I've been trying to set a custom shadowPath to a MaterialCollectionViewCell. Unfortunately, it was not working after a bit of digging I found the problem in the following line of code.

https://github.com/CosmicMind/Material/blob/85585b427234fdd798e85e1ae392e1475dc9044a/Sources/MaterialCollectionViewCell.swift#L628

    /// Sets the shadow path.
    internal func layoutShadowPath() {
        if shadowPathAutoSizeEnabled {
            if .None == depth {
                shadowPath = nil
            } else if nil == shadowPath {
                shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath
            } else {
                animate(MaterialAnimation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath, duration: 0))
            }
        }
    }

I think this is not in MaterialCollectionViewCell alone but in most the Material Views. Not sure what this line does exactly but my guess would be that it maybe needs to use the shadowPath instead of a hardcoded one. Something like this:

    /// Sets the shadow path.
    internal func layoutShadowPath() {
        if shadowPathAutoSizeEnabled {
            if .None == depth {
                shadowPath = nil
            } else if nil == shadowPath {
                shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath
            } else {
                animate(MaterialAnimation.shadowPath(shadowPath!, duration: 0))
            }
        }
    }

Please let me know if this is a correct solution or not. Thanks

daniel-jonathan commented 8 years ago

Try setting this to false shadowPathAutoSizeEnabled = false and then set your path. This way the code block won't have any effect. The last line, is actually to animate the shadowPath on transitions, when you want it to automatically adjust, otherwise, the shadowPath stays where positioned when the item moves.

xemacobra commented 8 years ago

Thanks. Man, you're fast.

daniel-jonathan commented 8 years ago

Let me know if it works :)

xemacobra commented 8 years ago

Yes, it did. Thanks a lot.

daniel-jonathan commented 8 years ago

Awesome, all the best!