All Projects → apptekstudios → Ascollectionview

apptekstudios / Ascollectionview

Licence: mit
A SwiftUI collection view with support for custom layouts, preloading, and more.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Ascollectionview

Skeletonview
☠️ An elegant way to show users that something is happening and also prepare them to which contents they are awaiting
Stars: ✭ 10,804 (+1130.52%)
Mutual labels:  swift-package-manager, uicollectionview
Swiftdatatables
A Swift Data Table package, display grid-like data sets in a nicely formatted table for iOS. Subclassing UICollectionView that allows ordering, and searching with extensible options.
Stars: ✭ 287 (-67.31%)
Mutual labels:  grid, uicollectionview
PagedLists
Paginated UITableView and UICollectionViews for iOS.
Stars: ✭ 69 (-92.14%)
Mutual labels:  uicollectionview, swift-package-manager
Vbpiledview
Simple and beautiful stacked UIView to use as a replacement for an UITableView, UIImageView or as a menu
Stars: ✭ 164 (-81.32%)
Mutual labels:  uicollectionview, collectionview
Carlenscollectionviewlayout
An easy-to-use Collection View Layout for card-like animation.
Stars: ✭ 478 (-45.56%)
Mutual labels:  uicollectionview, collectionview
Chatlayout
ChatLayout is an alternative solution to MessageKit. It uses custom UICollectionViewLayout to provide you full control over the presentation as well as all the tools available in UICollectionView. It supports dynamic cells and supplementary view sizes.
Stars: ✭ 184 (-79.04%)
Mutual labels:  uicollectionview, collectionview
Containercontroller
UI Component. This is a copy swipe-panel from app: Apple Maps, Stocks. Swift version
Stars: ✭ 273 (-68.91%)
Mutual labels:  swift-package-manager, collectionview
SNCollectionViewLayout
Collection View Layouts is a set of custom flow layouts for iOS which imitate general data grid approaches for mobile apps.
Stars: ✭ 100 (-88.61%)
Mutual labels:  uicollectionview, collectionview
Kddraganddropcollectionview
This component allows for the transfer of data items between collection views through drag and drop
Stars: ✭ 476 (-45.79%)
Mutual labels:  uicollectionview, collectionview
Bouncylayout
Make. It. Bounce.
Stars: ✭ 4,035 (+359.57%)
Mutual labels:  uicollectionview, collectionview
Collectionviewslantedlayout
A CollectionView Layout displaying a slanted cells
Stars: ✭ 2,029 (+131.09%)
Mutual labels:  uicollectionview, 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 (-19.25%)
Mutual labels:  uicollectionview, collectionview
Squareflowlayout
🌄 UICollectionViewLayout subclass inspired by Instagram Discover page style layout.
Stars: ✭ 142 (-83.83%)
Mutual labels:  uicollectionview, collectionview
Expandable Collection View Kit
🗂 Expandable, hierarchical, flexible, declarative UICollectionView with diffable data sources & SwiftUI-like tree items builder [Swift 5.1, iOS & iPadOS 13].
Stars: ✭ 69 (-92.14%)
Mutual labels:  swift-package-manager, uicollectionview
Flowlayout
UICollectionView WaterFlowLayout. 瀑布流.
Stars: ✭ 94 (-89.29%)
Mutual labels:  uicollectionview, collectionview
Ehhorizontalselectionview
Horizontal table view style controller
Stars: ✭ 346 (-60.59%)
Mutual labels:  uicollectionview, collectionview
Datasources
💾 🔜📱 Type-safe data-driven CollectionView, TableView Framework. (We can also use ASCollectionNode)
Stars: ✭ 553 (-37.02%)
Mutual labels:  uicollectionview, collectionview
Verticalcardswiper
A marriage between the Shazam Discover UI and Tinder, built with UICollectionView in Swift.
Stars: ✭ 830 (-5.47%)
Mutual labels:  uicollectionview, collectionview
Datagrid
Gem to create tables grids with sortable columns and filters
Stars: ✭ 921 (+4.9%)
Mutual labels:  grid
Pulsarkit
PulsarKit is a simple and beautiful wrapper around the official UICollectionView API written in pure Swift
Stars: ✭ 8 (-99.09%)
Mutual labels:  uicollectionview

Contributors Forks Stargazers Issues MIT License Build status

ASCollectionView

A SwiftUI implementation of UICollectionView & UITableView. Here's some of its useful features:

  • supports preloading and onAppear/onDisappear.
  • supports cell selection, with automatic support for SwiftUI editing mode.
  • supports autosizing of cells.
  • supports the new UICollectionViewCompositionalLayout, and any other UICollectionViewLayout
  • supports removing separators for ASTableView.
  • supports directly using FetchedResults as a data source

Pull requests and suggestions welcome :)

Report Bug · Suggest a feature

Table of Contents

Screenshots from demo app

Getting Started

ASCollectionView is a swift package.

Alternatively, if you're unable to use SPM for some reason, you can import it using cocoapods: pod 'ASCollectionView-SwiftUI', '~> 1.3'

Usage

Basic example - single section:

import ASCollectionView
import SwiftUI

struct SingleSectionExampleView: View {
	@State var dataExample = (0 ..< 30).map { $0 }
	
	var body: some View
	{
		ASCollectionView(data: dataExample, dataID: \.self) { item, _ in
			Color.blue
				.overlay(Text("\(item)"))
		}
		.layout {
			.grid(layoutMode: .adaptive(withMinItemSize: 100),
				  itemSpacing: 5,
				  lineSpacing: 5,
				  itemSize: .absolute(50))
		}
	}
}

Multiple sections with unique data sources

Below is an example of how to include a collection view with two sections (each with their own data source). For an extended example with a custom compositional layout see here. Or for more in-depth examples download the demo project included in this repo.

import SwiftUI
import ASCollectionView

struct ExampleView: View {
    @State var dataExampleA = (0 ..< 21).map { $0 }
    @State var dataExampleB = (0 ..< 15).map { "ITEM \($0)" }
    
    var body: some View
    {
        ASCollectionView
		{
			ASCollectionViewSection(
				id: 0,
				data: dataExampleA,
				dataID: \.self)
			{ item, _ in
				Color.blue
					.overlay(
						Text("\(item)")
					)
			}
			ASCollectionViewSection(
				id: 1,
				data: dataExampleB,
				dataID: \.self)
			{ item, _ in
				Color.green
					.overlay(
						Text("Complex layout - \(item)")
					)
			}
			.sectionHeader
			{
				Text("Section header")
					.padding()
					.frame(maxWidth: .infinity, alignment: .leading) //Fill width and align text to the left
					.background(Color.yellow)
			}
			.sectionFooter
			{
				Text("This is a section footer!")
					.padding()
			}
		}
		.layout { sectionID in
			switch sectionID {
				case 0:
				// Here we use one of the provided convenience layouts
				return .grid(layoutMode: .adaptive(withMinItemSize: 100),
							 itemSpacing: 5,
							 lineSpacing: 5,
							 itemSize: .absolute(50))
				default:
				return ASCollectionLayoutSection { environment in
					// ...
					// You could return any custom NSCollectionLayoutSection here. For an example see this file: /readmeAssets/SampleUsage.swift
					// ...
				}
			}
		}
	}
}

Supplementary Views

ASCollectionView has support for supplementary views. To add a supplementary view, use the sectionHeader, sectionFooter, or sectionSupplementary modifiers on your ASCollectionViewSection.

  • sectionHeader and sectionFooter set the supplementary for UICollectionView.elementKindSectionHeader and UICollectionView.elementKindSectionHeader respectively.
  • sectionSupplementary lets you specify any supplementaryKind.
ASCollectionViewSection(...) { ... }
	.sectionHeader
	{
		Text("Section header")
		.background(Color.yellow)
	}
	.sectionFooter
	{
		Text("Section footer")
		.background(Color.blue)
	}
        .sectionSupplementary(ofKind: "someOtherSupplementaryKindRequestedByYourLayout") {
                Text("Section supplementary")
		.background(Color.green)
        }

Decoration Views

A UICollectionViewLayout can layout decoration views that do not relate to the data (eg. a section background). These cannot be configured so you must provide a View struct that can be initialised using .init().

  • To enforce this requirement, your view must conform to the Decoration protocol. The only requirement of this is an initialiser with no arguments.
  • You must register the view type with the layout.
  • See the Reminders screen of the Demo app for a working example.

Declaring a swift view conforming to Decoration:

struct GroupBackground: View, Decoration
{
	let cornerRadius: CGFloat = 12
	var body: some View
	{
		RoundedRectangle(cornerRadius: cornerRadius)
			.fill(Color(.secondarySystemGroupedBackground))
	}
}

Registering the decoration type with the layout (ASCollectionLayout):

var layout: ASCollectionLayout<Section>
{
	ASCollectionLayout<Section>
	{ 
            // ... Here is an example of including a decoration in a compositional layout.
            let sectionBackgroundDecoration = NSCollectionLayoutDecorationItem.background(elementKind: "groupBackground")
            sectionBackgroundDecoration.contentInsets = section.contentInsets
            section.decorationItems = [sectionBackgroundDecoration]
            // ...
}
.decorationView(GroupBackground.self, forDecorationViewOfKind: "groupBackground") //REGISTER the decoration view type

Layout

  • There is inbuilt support for the new UICollectionViewCompositionalLayout.
    • You can define layout on a per-section basis, including the use of a switch statement if desired.
    • Work in progress: There are some useful methods that allow for easy definition of list and grid-based layouts (including orthogonal grids).

Define layout for all sections:

ASCollectionView(...) { ... }
.layout {
    ASCollectionLayoutSection { layoutEnvironment in
    	//Construct and return a NSCollectionLayoutSection here
    }
}

Define layout per section:

ASCollectionView(...) { ... }
.layout { sectionID in
    switch sectionID {
    case .userSection:
        return ASCollectionLayoutSection { layoutEnvironment in
            //Construct and return a NSCollectionLayoutSection here
        }
    }
    case .postSection:
        return ASCollectionLayoutSection { layoutEnvironment in
            //Construct and return a NSCollectionLayoutSection here
        }
    }
}

Use a custom UICollectionViewLayout:

ASCollectionView(...) { ... }
.layout {
    let someCustomLayout = CustomUICollectionViewLayout()
    someCustomLayout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
    return someCustomLayout
}

Other tips

  • You can use an enum as your SectionID (rather than just an Int), this lets you easily determine the layout of each section.
  • See the demo project for more in-depth usage examples.
  • Please note that you should only use @State for transient visible state in collection view cells. Anything you want to persist long-term should be stored in your model.

Todo

See the open issues for a list of proposed features (and known issues).

License

Distributed under the MIT License. See LICENSE for more information.

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].