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

Using custom card (with embedded view + autolayout) freezes unless CardCellMargins left/right not set to 0 #85

Open
st34m3dr1c3 opened this issue Sep 2, 2018 · 1 comment

Comments

@st34m3dr1c3
Copy link

st34m3dr1c3 commented Sep 2, 2018

First off, I want to say that this library is fantastic!

On to the problem:
I am using a stack of custom cards, one of which simply has a chart view embedded inside (taken from the iOS Charts library). However, using this card will cause the app to freeze unless I set the left and right margins to nonzero in the CardsViewController, e.g. with the following application:


let theme = CardPartsMintTheme()
        theme.cardCellMargins = UIEdgeInsets(top: 100, left: 15, bottom: 100, right: 15)
        theme.cardsViewContentInsetTop = 15
        theme.cardsLineSpacing = 15
        theme.apply()

However, doing so means that the cards cannot hug the edge of the screen. As mentioned previously, setting the insets to default (0 for left and right) causes the app to freeze.

See snippet for my custom card below, which has a chart embedded inside:

public class PAChartCardPartView : UIView, CardPartView {
var chart:CombinedChartView?

public init() {
        super.init(frame: CGRect.zero)
        self.chart = CombinedChartView(frame: CGRect.zero)
        self.chart?.translatesAutoresizingMaskIntoConstraints = false
        self.view.addSubview(self.chart!)
        self.chart?.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 0).isActive = true
        self.chart?.bottomAnchor.constraint(equalTo: (self.view.bottomAnchor), constant: 0).isActive = true
        self.chart?.leadingAnchor.constraint(equalTo: (self.view.leadingAnchor), constant: 0).isActive = true
        self.chart?.trailingAnchor.constraint(equalTo: (self.view.trailingAnchor), constant: 0).isActive = true
    }
    
    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

Is it possible to use this card without having to use nonzero left and right insets? Any help or insight would be greatly appreciated. Thanks!

@st34m3dr1c3
Copy link
Author

st34m3dr1c3 commented Sep 2, 2018

I'd also like to add that making the chart the CardPart (instead of creating a general UIView CardPart and embedding the chart inside) also creates the same problem. Works fine on the default Mint theme in which the left and right insets are nonzero, but will freeze on the Turbo theme where the left and right insets are zero.

class ChartCardPartView : CombinedChartView, CardPartView {
    
    public var margins: UIEdgeInsets = CardParts.theme.cardPartMargins

    public init() {
        super.init(frame: CGRect.zero)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

See the resulting chart implementation in the CardsViewController:

class MainViewController: CardsViewController {

...

let chart = ChartCardPartView()

...

func setupChartView() {
       chart.addConstraint(NSLayoutConstraint(item: chart, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1, constant: 300))
       chart.addConstraint(NSLayoutConstraint(item: chart, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1, constant: 300))
}

override func viewDidLoad() {
...
       super.viewDidLoad()
...
       setupChartView()
}

...

}

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

1 participant