Giter Site home page Giter Site logo

hitendradeveloper / collectionstack-swiftui Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 45 KB

CollectionStack is designed to solve limitation of HStack and VStack in SwiftUI, it grows horizontally first, then vertically if next element could not fit horizontally.

Swift 100.00%
hstack swift swift-package-manager swiftui vstack collectionstack

collectionstack-swiftui's Introduction

CollectionStack-SwiftUI

CollectionStack is designed to solve limitation of HStack and VStack in SwiftU, it grows horizontally first, then vertically if next element could not fit horizontally.

How to use in code?

struct App: Identifiable {
	var name: String
	var id: String { return name }
}

let apps: [App] = [
	"youtube", "podcast", "twitter",
	"facebook", "instagram",
	"free form", "github desktop", "source tree"
].map(App.init(name: ))
				
//you can wrap this CollectionStack into ScrollView as well if you want scrolling				
CollectionStack(apps) { app in
	Button {
		print("Selected tag := \(app.name)")
	} label: {
		Text(app.name)
			.font(.system(.callout, design: .rounded, weight: .regular))
	}
	.buttonStyle(.bordered)
	.padding(.trailing, 8)
	.padding(.bottom, 8)
}

Output of above sample code

Example output

CollectionStack

is generic SwiftUI View over data and content

Data

The collection of underlying identified data that CollectionStack uses to create views dynamically.

Content

A function to create content on demand using the underlying data. It's a mapper function which maps Data to some View.

Public API is consistent same as ForEach of SwiftUI

/// Creates an instance that uniquely identifies and creates views across
/// updates based on the identity of the underlying data.
///
/// It's important that the `id` of a data element doesn't change unless you
/// replace the data element with a new data element that has a new
/// identity. If the `id` of a data element changes, the content view
/// generated from that data element loses any current state and animations.
///
/// - Parameters:
///   - data: The identified data that the ``CollectionStack`` instance uses to
///     create views dynamically.
///   - content: The view builder that creates views dynamically.

public init(_ data: Data, @ViewBuilder content: @escaping (Data.Element) -> Content)

Requirements

Platform Minimum Swift Version Installation Status
iOS 13.0+ 5.0 Swift Package Manager, Manual Fully Tested
macOS 10.15+ 5.0 Swift Package Manager, Manual Fully Tested
tvOS 13.0+ 5.0 Swift Package Manager, Manual Fully Tested
watchOS 6.0+ 5.0 Swift Package Manager, Manual Fully Tested

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding CollectionStack-SwiftUI as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/hitendradeveloper/CollectionStack-SwiftUI.git", .upToNextMajor(from: "1.0.0"))
]

License

CollectionStack-SwiftUI is released under the MIT license.

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.