Swiftpack.co - antoniopantaleo/APDynamicGrid as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by antoniopantaleo.
antoniopantaleo/APDynamicGrid 1.1.1
A SwiftUI Package for an easy grid management
⭐️ 33
🕓 49 weeks ago
iOS
.package(url: "https://github.com/antoniopantaleo/APDynamicGrid.git", from: "1.1.1")

APDynamicGrid

License Badge iOS Version Badge iPadOS Version Badge Swift Version Badge

AP

Overview

APDynamicGrid is a SwiftUI package that helps you create consistent and animatable grids. The DynamicGrid View preserves the same widtsrc="https://raw.github.com/antoniopantaleo/APDynamicGrid/master/justing the last elements consistently.

Demo

Usage

Define your model adopting the Hashable and Identifiable protocols

struct Entry : Identifiable, Hashable {
  let id = UUID()
  // ...
}

and wrap it with the @State decorator

var body : some View {
  
  private @State var entries : [Entry]
  // number of columns is a @State var too
  private @State var columns : Int
  
  ScrollView {
    DynamicGrid(columns: $columns, data: $entries) { entry in 
      MyCustomCell(entry: entry)
    }
  }
}

Entries can be animated registering a @Namespace using their unique id

var body : some View {
  
  private @State var entries : [Entry]
  private @State var columns : Int
  // 1. add a namespace
  private @Namespace var namespace
  
  ScrollView {
    DynamicGrid(columns: $columns, data: $entries) { entry in 
      MyCustomCell(entry: entry)
      // 2. register the namespace
      .matchedGeometryEffect(id: entry.id, in: namespace)
    }
    // 3. apply animations
    .animation(.default)
  }
}

Installation

Xcode Project

You have to select File -> Swift Packages -> Add Package Dependency and enter the repository url https://github.com/antoniopantaleo/APDynamicGrid.git

Swift Package Manager

You have to add the package as a dependency in your Package.swift file

let package = Package(
    //...
    dependencies: [
        .package(url: "https://github.com/antoniopantaleo/APDynamicGrid.git", upToNextMajor(from: "1.0.0")),
    ],
    //...
)

License

MIT

GitHub

link
Stars: 33
Last commit: 49 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

v1.1.1
49 weeks ago

This patch add missing asset in README

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics