All Projects → pourhadi → Collectionview

pourhadi / Collectionview

SwiftUI implementation of a collection view, similar to UICollectionView with UICollectionViewFlowLayout.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Collectionview

Compositional Layouts Kit
📏 A set of advanced compositional layouts for UICollectionView with examples [Swift 5.3, iOS 13].
Stars: ✭ 317 (+756.76%)
Mutual labels:  collectionview
Koloda
KolodaView is a class designed to simplify the implementation of Tinder like cards on iOS.
Stars: ✭ 4,998 (+13408.11%)
Mutual labels:  collectionview
Chainpagecollectionview
A custom View with fancy collectionView animation
Stars: ✭ 760 (+1954.05%)
Mutual labels:  collectionview
Bouncylayout
Make. It. Bounce.
Stars: ✭ 4,035 (+10805.41%)
Mutual labels:  collectionview
Carlenscollectionviewlayout
An easy-to-use Collection View Layout for card-like animation.
Stars: ✭ 478 (+1191.89%)
Mutual labels:  collectionview
Jxcategoryview
A powerful and easy to use category view (segmentedcontrol, segmentview, pagingview, pagerview, pagecontrol) (腾讯新闻、今日头条、QQ音乐、网易云音乐、京东、爱奇艺、腾讯视频、淘宝、天猫、简书、微博等所有主流APP分类切换滚动视图)
Stars: ✭ 5,561 (+14929.73%)
Mutual labels:  collectionview
Hfcardcollectionviewlayout
The HFCardCollectionViewLayout provides a card stack layout not quite similar like the apps Reminder and Wallet.
Stars: ✭ 281 (+659.46%)
Mutual labels:  collectionview
Ascollectionview
A SwiftUI collection view with support for custom layouts, preloading, and more.
Stars: ✭ 878 (+2272.97%)
Mutual labels:  collectionview
Collection View Layouts
A library that implements custom flow layouts for iOS apps
Stars: ✭ 491 (+1227.03%)
Mutual labels:  collectionview
Tysnapshotscroll
一句代码保存截图,将 UIScrollView UITableView UICollectionView UIWebView WKWebView 网页 保存 为 长图 查看。Save the scroll view page as an image,support UIScrollView,UITableView,UICollectionView,UIWebView,WKWebView.(Support iOS13)
Stars: ✭ 709 (+1816.22%)
Mutual labels:  collectionview
Bubblepictures
Bubble Pictures for iOS done in Swift
Stars: ✭ 434 (+1072.97%)
Mutual labels:  collectionview
Kddraganddropcollectionview
This component allows for the transfer of data items between collection views through drag and drop
Stars: ✭ 476 (+1186.49%)
Mutual labels:  collectionview
Diffabledatasources
💾 A library for backporting UITableView/UICollectionViewDiffableDataSource.
Stars: ✭ 601 (+1524.32%)
Mutual labels:  collectionview
Ehhorizontalselectionview
Horizontal table view style controller
Stars: ✭ 346 (+835.14%)
Mutual labels:  collectionview
Verticalcardswiper
A marriage between the Shazam Discover UI and Tinder, built with UICollectionView in Swift.
Stars: ✭ 830 (+2143.24%)
Mutual labels:  collectionview
Ascollectionview
Lightweight custom collection view inspired by Airbnb.
Stars: ✭ 283 (+664.86%)
Mutual labels:  collectionview
Datasources
💾 🔜📱 Type-safe data-driven CollectionView, TableView Framework. (We can also use ASCollectionNode)
Stars: ✭ 553 (+1394.59%)
Mutual labels:  collectionview
Swipeselectingcollectionview
A collection view subclass that enables swipe to select multiple cells just like in Photos app.
Stars: ✭ 34 (-8.11%)
Mutual labels:  collectionview
Modelassistant
Elegant library to manage the interactions between view and model in Swift
Stars: ✭ 26 (-29.73%)
Mutual labels:  collectionview
Cardslayout
⭐️ Custom card-designed CollectionView layout
Stars: ✭ 686 (+1754.05%)
Mutual labels:  collectionview

CollectionView

A SwiftUI implementation of a grid layout similar to UICollectionView with UICollectionViewFlowLayout.

Updates and documentation to follow.

Features

  • Bindings to the data source and selected items
  • Selection mode
  • Custom column count
  • Custom row height
  • Custom spacing
  • Block-based tap and long-press actions
  • @ViewBuilder to produce each item's view (cell)

Usage

Add import CollectionView to your SwiftUI file and add CollectionView(...) to your view hierarchy.

import SwiftUI
import CollectionView

struct CollectionView_Previews: PreviewProvider {
    struct ItemModel: Identifiable, Equatable {
        let id: Int
        let color: Color
    }
    
    @State static var items = [ItemModel(id: 0, color: Color.red),
                               ItemModel(id: 1, color: Color.blue),
                               ItemModel(id: 2, color: Color.green),
                               ItemModel(id: 3, color: Color.yellow),
                               ItemModel(id: 4, color: Color.orange),
                               ItemModel(id: 5, color: Color.purple)]
    
    @State static var selectedItems = [ItemModel]()
    @State static var selectionMode = false
    
    static var previews: some View {
        CollectionView(items: $items,
                       selectedItems: $selectedItems,
                       selectionMode: $selectionMode)
        { item, _ in
            Rectangle()
                .foregroundColor(item.color)
        }
    }
}

Screenshot

CollectionView init parameters

  • items: Binding<[Item]>

    Required.

    A binding to an array of values that conform to Identifiable and Equatable. This is the collection view's data source.

  • selectedItems: Binding<[Item]>

    Required.

    A binding to an array of values that conform to Identifiable and Equatable.

    When selectionMode is true, this will populate with the items selected by the user. When selectionMode is false, this will either be an empty array or be populated with the most-recently-selected item. Good to use for displaying / dismissing a child / detail view.

  • selectionMode: Binding<Bool>

    Required.

    A binding to a bool value. Set to true to set the collection view in to selection mode.

  • layout: CollectionView.Layout

    Not required. Default is CollectionView.Layout()

    Layout is a struct containing the layout information for the collection view, with the defaults:

    • itemSpacing: CGFloat = 2.0

    • numberOfColumns: Int = 3

    • rowHeight: CollectionView.RowHeight = .sameAsItemWidth

      An enum for setting the desired height for the collection view's rows.

      public typealias CollectionViewRowHeightBlock = (_ row: Int, _ rowMetrics: GeometryProxy, _ itemSpacing: CGFloat, _ numberOfColumns: Int) -> CGFloat
      
      public enum RowHeight {
          case constant(CGFloat)
          case sameAsItemWidth
          case dynamic(CollectionViewRowHeightBlock)
      }
       ```
      
    • rowPadding: EdgeInsets = EdgeInsets initialized with all zeros

    • scrollViewInsets: EdgeInsets = EdgeInsets initialized with all zeros

  • tapAction: ((Item, GeometryProxy) -> Void)?

    Not required. Defaults to nil.

    A block that will be called if an item is tapped on.

  • longPressAction: ((Item, GeometryProxy) -> Void)?

    Not required. Defaults to nil.

    A block that will be called after a successful long-press gesture on the item cell.

  • pressAction: ((Item, Bool) -> Void)?

    Not required. Defaults to nil.

    A block that will be called when a long-press gesture is possible, with a bool indicating whether the item is being pressed.

  • itemBuilder: @escaping (Item, _ itemMetrics: GeometryProxy) -> ItemContent)

    Required.

    A block that produces the view (cell) associated with a particular item.

Planned features:

  • Sections
  • Customizable selection style
  • ??

Installation

Swift Package Manager

You can use The Swift Package Manager to install this library.

import PackageDescription

let package = Package(
    name: "YOUR_PROJECT_NAME",
    targets: [],
    dependencies: [
        .package(url: "https://github.com/pourhadi/collectionview.git", .branch("master"))    
    ]
)

Note that the Swift Package Manager is still in early design and development, for more information checkout its GitHub Page.

License (MIT)

Copyright (c) 2019 - present Daniel Pourhadi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].