intuit / CardParts

A reactive, card-based UI framework built on UIKit for iOS developers.
Other
2.52k stars 225 forks source link

CardPartTableView doesn't have a top margin, even when manually set #148

Closed tcheek-bw closed 5 years ago

tcheek-bw commented 5 years ago

Hi,

When working with a single CardPartTableView, I would expect there to be a top margin of about 10.0 or so, but there is no margin. In the documentation it states that cards have a default margin all around them, but that doesn't seem to be true for the top margin of the first card in the view. As a result, this is what it looks like: image

I've tried implementing the NoTopBottomMarginsCardTrait protocol on my CardPartsViewController subclass, and manually implementing the requiresNoTopBottomMargins() method to return false, but no change. I tried to manually create a CardPartSpacerView(height: 30.0) called aboveSpacerPart and included that in my array passed to setupCardParts([]), but that didn't make any difference either. I even tried to manually set the margins on the CardPartTableView to this: tableViewPart.margins = UIEdgeInsets(top: 10.0, left: 14.0, bottom: 14.0, right: 10.0). For some reason, it doesn't seem like I can get there to be a margin on top of this CardPartTableView. Any reason why that might be so?

croossin commented 5 years ago

@hoidofyolen Can you attach a screenshot of the debug view hierarchy? Are you still facing this issue?

tcheek-bw commented 5 years ago

Yes, still seeing this issue. Is this what you mean by debug view hierarchy? It's the only place I know that has debug information without hitting a breakpoint. image

tcheek-bw commented 5 years ago

Nevermind, I found it. Here's what I think is the culprit constraint:

image

croossin commented 5 years ago

Very interesting... let me take a look and get back to you!

croossin commented 5 years ago

@hoidofyolen If you clone this repo and run the example app and in MainViewController.swift comment out all of the cards except for the CardPartTableViewCardController() and run, do you still see the same issue? Maybe this is only happening for ViewControllers pushed on the navigation stack.

badrinathvm commented 5 years ago

@hoidofyolen i am looking in to this issue, alternatively u can add a CardPartSpaceView(height:10) and then add the CardPartTableView in the navigationController. some thing like below

setupCardParts([CardPartSpaceView(height:10),CardPartTableView() ])

badrinathvm commented 5 years ago

@hoidofyolen just did a sanity check , works as expected , see the below code and attached screenshot.

class TestViewController: CardPartsViewController {
    let cardPartTableView = CardPartTableView()
    let viewModel = CardPartTableViewModel()

    override func viewDidLoad() {

        self.view.backgroundColor = UIColor.gray
        cardPartTableView.margins.top = 120.0

        viewModel.listData.asObservable().bind(to: cardPartTableView.tableView.rx.items) { tableView, index, data in

            guard let cell = tableView.dequeueReusableCell(withIdentifier: "CellId", for: IndexPath(item: index, section: 0)) as? CardPartTableViewCell else { return UITableViewCell() }

            cell.leftTitleLabel.text = data

            return cell
            }.disposed(by: bag)

        setupCardParts([cardPartTableView])
    }
}

Simulator Screen Shot - iPhone X - 2019-07-31 at 19 44 44

tcheek-bw commented 5 years ago

When I implemented your line cardPartTableView.margins.top = 120.0, I got this: image

I am able to supplement the space in the top margin by using the spacer view. This is how I did it:

class SpacerViewController: CardsViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        loadCards(cards: [SpacerCardController()])
    }

}
class SpacerCardController: CardPartsViewController, NoTopBottomMarginsCardTrait, TransparentCardTrait {

    override func viewDidLoad() {

        super.viewDidLoad()

        setupCardParts([CardPartSpacerView(height: 8)])

    }

    func requiresNoTopBottomMargins() -> Bool {
        return true
    }

}
tcheek-bw commented 5 years ago

No, the problem is still there, but I was able to use the temporary solution of using a transparent spacer view. But this shouldn't be the long-term solution for the platform.

croossin commented 5 years ago

Of course not. However, we are not able to reproduce the issue. We are seeing the top margin work appropriately. Is there possibly other constraints you are setting?

tcheek-bw commented 5 years ago

I don't have any other constraints set, as you can see from my screenshots. I think a little more effort should be put into trying to reproduce this issue, since it happens consistently for me. Maybe it has to do with having the view controller wrapped in a navigation controller?

croossin commented 5 years ago

@hoidofyolen We will continue to look into this issue