{"action":"created","issue":{"url":"https://api.github.com/repos/Instagram/IGListKit/issues/829","repository_url":"https://api.github.com/repos/Instagram/IGListKit","labels_url":"https://api.github.com/repos/Instagram/IGListKit/issues/829/labels{/name}","comments_url":"https://api.github.com/repos/Instagram/IGListKit/issues/829/comments","events_url":"https://api.github.com/repos/Instagram/IGListKit/issues/829/events","html_url":"https://github.com/Instagram/IGListKit/issues/829","id":238178828,"number":829,"title":"[QUESTION] there is a way to use IGListBindingSectionController with embedded section controller for horizontal view? ","user":{"login":"kleiberjp","id":8697226,"avatar_url":"https://avatars1.githubusercontent.com/u/8697226?v=4","gravatar_id":"","url":"https://api.github.com/users/kleiberjp","html_url":"https://github.com/kleiberjp","followers_url":"https://api.github.com/users/kleiberjp/followers","following_url":"https://api.github.com/users/kleiberjp/following{/other_user}","gists_url":"https://api.github.com/users/kleiberjp/gists{/gist_id}","starred_url":"https://api.github.com/users/kleiberjp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kleiberjp/subscriptions","organizations_url":"https://api.github.com/users/kleiberjp/orgs","repos_url":"https://api.github.com/users/kleiberjp/repos","events_url":"https://api.github.com/users/kleiberjp/events{/privacy}","received_events_url":"https://api.github.com/users/kleiberjp/received_events","type":"User","site_admin":false},"labels":[{"id":438144356,"url":"https://api.github.com/repos/Instagram/IGListKit/labels/question","name":"question","color":"D10869","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2017-06-23T15:37:42Z","updated_at":"2017-08-26T21:24:10Z","closed_at":"2017-08-26T21:24:10Z","body":"## New issue checklist\r\n\r\n- [x] I have reviewed the [`README`](https://github.com/Instagram/IGListKit/blob/master/README.md) and [documentation](http://instagram.github.io/IGListKit)\r\n- [x] I have searched [existing issues](https://github.com/Instagram/IGListKit/issues) and this is not a duplicate\r\n\r\n### General information\r\n\r\n- `IGListKit` version: 3.0.0\r\n- iOS version(s): 10.3\r\n- CocoaPods/Carthage version: 1.0.0\r\n- Xcode version: 8.3\r\n- Devices/Simulators affected:\r\n- Reproducible in the demo project? (Yes/No): no\r\n- Related issues: none\r\n\r\n### Debug information\r\n\r\n```bash\r\n# Please include debug logs using the following lldb command:\r\npo [IGListDebugger dump]\r\n```\r\n\r\nI see the awesome for the protocol IGListBindingSectionController, but i have tried hard to used in a cell that use embedded section controller for an horizontal scroll view, and the cell inside this one be the clickable for select and binding, but to make update it reload everything and doesn't work like the example of calendar\r\n\r\nthis is what i'm trying to do \r\n\r\n<img width=\"374\" alt=\"captura de pantalla 2017-06-23 a la s 10 44 20\" src=\"https://user-images.githubusercontent.com/8697226/27489660-f8042326-5800-11e7-9438-81205af6357f.png\">\r\n\r\ninstead the original that was vertical alignment, so in context this is what i've tried\r\n\r\n```\r\nfunc sectionController(_ sectionController: ListBindingSectionController<ListDiffable>, cellForViewModel viewModel: Any, at index: Int) -> UICollectionViewCell {\r\n        let cellClass: AnyClass\r\n        if viewModel is MonthItems {\r\n            let cell = collectionContext!.dequeueReusableCell(of: EmbeddedCollectionViewCell.self, for: self, at: index) as! EmbeddedCollectionViewCell\r\n            cell.configure(on: adapter, delegate: self)\r\n            return cell    \r\n        } else if viewModel is MonthTitleViewModel {\r\n            cellClass = MonthTitleCell.self\r\n        } else {\r\n            cellClass = LabelCell.self\r\n        }\r\n        return collectionContext?.dequeueReusableCell(of: cellClass, for: self, at: index) ?? UICollectionViewCell()\r\n    }\r\n```\r\n\r\nthe `EmbeddedCollectionViewCell.self ` will work for horizontal items, and i pass the objects because doesn't find another way. So the cell will looks, something like\r\n\r\n```\r\nimport IGListKit\r\n\r\nprotocol MonthDaySelectDelegate: class {\r\n    \r\n    func didSelect(object: Any?)\r\n}\r\n\r\nfinal class EmbeddedCollectionViewCell: UICollectionViewCell {\r\n\r\n    lazy var collectionView: UICollectionView = {\r\n        let layout = UICollectionViewFlowLayout()\r\n        layout.scrollDirection = .horizontal\r\n        let view = UICollectionView(frame: .zero, collectionViewLayout: layout)\r\n        view.backgroundColor = .clear\r\n        view.alwaysBounceVertical = false\r\n        view.alwaysBounceHorizontal = true\r\n        self.contentView.addSubview(view)\r\n        return view\r\n    }()\r\n\r\n    fileprivate weak var delegate: MonthDaySelectDelegate?\r\n    fileprivate weak var listAdapter: ListAdapter?\r\n    \r\n    fileprivate var monthItem: MonthItems?\r\n    \r\n    override func layoutSubviews() {\r\n        super.layoutSubviews()\r\n        collectionView.frame = contentView.frame\r\n    }\r\n    \r\n    func configure(on adapter: ListAdapter, delegate: MonthDaySelectDelegate?) {\r\n        adapter.collectionView = collectionView\r\n        adapter.dataSource = self\r\n        \r\n        self.listAdapter = adapter\r\n        self.delegate = delegate\r\n    }\r\n}\r\n\r\nextension EmbeddedCollectionViewCell: ListBindable {\r\n    \r\n    func bindViewModel(_ viewModel: Any) {\r\n        guard let data = viewModel as? MonthItems else { return }\r\n        self.monthItem = data\r\n        self.listAdapter?.performUpdates(animated: false, completion: nil)\r\n    }\r\n}\r\n\r\n//MARK: ListAdapterDataSource\r\nextension EmbeddedCollectionViewCell: ListAdapterDataSource {\r\n    \r\n    // MARK: ListAdapterDataSource\r\n    \r\n    func objects(for listAdapter: ListAdapter) -> [ListDiffable] {\r\n        guard let month = monthItem else { return [] }\r\n        return [month]\r\n    }\r\n    \r\n    func listAdapter(_ listAdapter: ListAdapter, sectionControllerFor object: Any) -> ListSectionController {\r\n        let controller = DayCalendarSectionController()\r\n        controller.delegate = delegate\r\n        return controller\r\n    }\r\n    \r\n    func emptyView(for listAdapter: ListAdapter) -> UIView? { return nil }\r\n}\r\n\r\n\r\n//MARK: Day Section Controller\r\nfinal class DayCalendarSectionController: ListBindingSectionController<ListDiffable> {\r\n    \r\n    fileprivate var delegate: MonthDaySelectDelegate?\r\n\r\n    override init() {\r\n        super.init()\r\n        dataSource = self\r\n        selectionDelegate = self\r\n    }\r\n}\r\n\r\nextension DayCalendarSectionController: ListBindingSectionControllerDataSource {\r\n    \r\n    func sectionController(_ sectionController: ListBindingSectionController<ListDiffable>, viewModelsFor object: Any) -> [ListDiffable] {\r\n        guard let monthItem = object as? MonthItems else { return [] }\r\n        return monthItem.days\r\n    }\r\n    \r\n    func sectionController(_ sectionController: ListBindingSectionController<ListDiffable>, cellForViewModel viewModel: Any, at index: Int) -> UICollectionViewCell {\r\n        return collectionContext!.dequeueReusableCell(of: CalendarDayCell.self, for: self, at: index) as! CalendarDayCell\r\n    }\r\n    \r\n    func sectionController(_ sectionController: ListBindingSectionController<ListDiffable>, sizeForViewModel viewModel: Any, at index: Int) -> CGSize {\r\n        guard let container = collectionContext?.containerSize else { return .zero }\r\n        let square = container.width/7\r\n        \r\n        return CGSize(width: square, height: container.height)\r\n    }\r\n    \r\n}\r\n\r\n\r\nextension DayCalendarSectionController: ListBindingSectionControllerSelectionDelegate {\r\n    \r\n    func sectionController(_ sectionController: ListBindingSectionController<ListDiffable>, didSelectItemAt index: Int, viewModel: Any) {\r\n        delegate?.didSelect(object: viewModel)\r\n    }\r\n}\r\n```\r\n\r\nand on section controller where create the cell implement delegate for update data\r\n\r\n```\r\nextension MonthSectionController: MonthDaySelectDelegate {\r\n    \r\n    func didSelect(object: Any?) {\r\n        guard let dayViewModel = object as? Potato else { return }\r\n        if dayViewModel.day == selectedDay {\r\n            selectedDay = -1\r\n        } else {\r\n            selectedDay = dayViewModel.day\r\n        }\r\n        update(animated: true)\r\n    }\r\n}\r\n``` \r\n\r\nbut doesn't have the same behavior because the embedded section cell, before update always put on initial index, and don't stay on the selected index\r\n\r\nif there are a way for make it, i appreciate it?\r\n"},"comment":{"url":"https://api.github.com/repos/Instagram/IGListKit/issues/comments/325162681","html_url":"https://github.com/Instagram/IGListKit/issues/829#issuecomment-325162681","issue_url":"https://api.github.com/repos/Instagram/IGListKit/issues/829","id":325162681,"user":{"login":"rnystrom","id":739696,"avatar_url":"https://avatars2.githubusercontent.com/u/739696?v=4","gravatar_id":"","url":"https://api.github.com/users/rnystrom","html_url":"https://github.com/rnystrom","followers_url":"https://api.github.com/users/rnystrom/followers","following_url":"https://api.github.com/users/rnystrom/following{/other_user}","gists_url":"https://api.github.com/users/rnystrom/gists{/gist_id}","starred_url":"https://api.github.com/users/rnystrom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rnystrom/subscriptions","organizations_url":"https://api.github.com/users/rnystrom/orgs","repos_url":"https://api.github.com/users/rnystrom/repos","events_url":"https://api.github.com/users/rnystrom/events{/privacy}","received_events_url":"https://api.github.com/users/rnystrom/received_events","type":"User","site_admin":false},"created_at":"2017-08-26T21:24:10Z","updated_at":"2017-08-26T21:24:10Z","body":"Gonna close due to inactivity, but @heumn this is really awesome looking. Thank you for helping out here!!"}}
{"actor":{"display_login":"rnystrom"}}