Git Product home page Git Product logo

datasourcekit's People

Contributors

dvlprliu avatar ishkawa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

datasourcekit's Issues

Introduce data structure for sections

Currently, declarations of contents of UITableView are expressed by [CellDeclaration]. One idea to support sections is expressing sections by some type like [TableViewSectionDeclaration<CellDeclaration>].

struct TableViewSectionDeclaration<CellDeclaration> {
    let headerTitle: String?
    let footerTitle: String?
    let cellDeclarations: [CellDeclaration]
    
    init(
        headerTitle: String? = nil,
        footerTitle: String? = nil,
        declareCells: @escaping (@escaping (CellDeclaration) -> Void) -> Void) {
        ...
    }
}

With TableViewSectionDeclaration<CellDeclaration>, a conformer may look like:

class ViewController: SectionsDeclarator {
    enum CellDeclaration {
        case a, b
    }

    func declareSections(_ section: (TableViewSectionDeclaration<CellDeclaration>) -> Void) {
        section(TableViewSectionDeclaration(headerTitle: "A") { cell in
            cell(.a)
        })

        section(TableViewSectionDeclaration(headerTitle: "B") { cell in
            cell(.b)
            cell(.b)
            cell(.b)
        })
    }
}

Is UIStackView out of scope?

I have a list view which is UIStackView added on UIScrollView and I want to use DataSourceKit with it.
I tried to define my own DataSource class for using with UIStackView, but CellBinder's configureCell(_:) is internal so I gave up.

I like the concept of DataSourceKit and I think it is useful also for UIStackView and other kind of list view. Do you have a plan to support other than UITableView and UICollectionView?

Just a question

Maybe I'm missing something but...

The dataSource declaration seems to be a straight forward mapping from enum value to cell type which always have the same structure. I think it's possible to move that mapping to the CellsDeclarator (and CellDeclaration) like the code shown below. You just have to make sure the makeBinder function is called when you call the cell function. This would make the code cleaner and even more compact.

    enum CellDeclaration: Equatable {
        case outline(BindableCell.Type, Venue)
        case sectionHeader(BindableCell.Type, String)
        case review(BindableCell.Type, Review)
        case relatedVenue(BindableCell.Type, Venue)
    }
    
    struct Data: CellsDeclarator {
        var venue: Venue
        var reviews: [Review]
        var relatedVenues: [Venue]

        func declareCells(_ cell: (CellDeclaration) -> Void) {
            cell(.outline(VenueOutlineCell.self, venue))

            if !reviews.isEmpty {
                cell(.sectionHeader(SectionHeaderCell.self, "Reviews"))
                for review in reviews {
                    cell(.review(ReviewCell.self, review))
                }
            }
            
            if !relatedVenues.isEmpty {
                cell(.sectionHeader(SectionHeaderCell.self, "Related Venues"))
                for relatedVenue in relatedVenues {
                    cell(.relatedVenue(RelatedVenueCell.self, relatedVenue))
                }
            }
        }
    }

How to reload data after append new data or state?

Hi @ishkawa ,

I need your help, i'm trying to insert new data or cell, but when i run collectionView.reloadData(), nothing happen,

final class AdvancedVenueDetailViewController: UIViewController {
    @IBOutlet private weak var collectionView: UICollectionView!
    
    private let dataSource = CollectionViewDataSource<AdvancedVenueDetailViewState.CellDeclaration> { cellDeclaration in
        switch cellDeclaration {
        case .outline(let venue):
            return VenueOutlineCell.makeBinder(value: venue)
        case .sectionHeader(let title):
            return SectionHeaderCell.makeBinder(value: title)
        case .review(let review):
            return ReviewCell.makeBinder(value: review)
        case .relatedVenue(let venue):
            return RelatedVenueCell.makeBinder(value: venue)
        }
    }
    
    private var state = AdvancedVenueDetailViewState()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let layout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
        layout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
        collectionView.dataSource = dataSource
        dataSource.cellDeclarations = state.cellDeclarations
        
        DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
            self.state.reviews.append(Review(authorImage: #imageLiteral(resourceName: "Kaminarimon_at_night"), authorName: "Yosuke Ishikawa", body: "Lorem ipsum."))
            self.collectionView.reloadData()
        }
    }
}

please help me :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.