Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
paololeonardi committed Oct 27, 2019
0 parents commit f54a010
Show file tree
Hide file tree
Showing 185 changed files with 5,790 additions and 0 deletions.
90 changes: 90 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3

## Obj-C/Swift specific
*.hmap

## App packaging
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
# Package.resolved
# *.xcodeproj
#
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
.swiftpm

.build/

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
#
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build/

# Accio dependency management
Dependencies/
.accio/

# fastlane
#
# It is recommended to not store the screenshots in the git repo.
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output

# Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/
Binary file added Assets/demo1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Paolo Leonardi

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.
33 changes: 33 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// swift-tools-version:5.1

//
// Copyright © 2019 Paolo Leonardi.
//
// Licensed under the MIT license. See the LICENSE file for more info.
//

import PackageDescription

let package = Package(
name: "WaterfallGrid",
platforms: [
.iOS(.v13),
.macOS(.v10_15),
.tvOS(.v13),
.watchOS(.v6)
],
products: [
.library(
name: "WaterfallGrid",
targets: ["WaterfallGrid"]),
],
dependencies: [],
targets: [
.target(
name: "WaterfallGrid",
dependencies: []),
.testTarget(
name: "WaterfallGridTests",
dependencies: ["WaterfallGrid"]),
]
)
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# WaterfallGrid

A waterfall grid layout view for SwiftUI.

<center>
<img src="Assets/demo1.png"/>
</center>

## Features

- [x] Items fill the most available vertical space.
- [x] Columns number different per device orientation.
- [x] Spacing and grid padding customizable.
- [x] Items update can be animated.

## Requirements

- iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 6.0+
- Xcode 11.0+
- Swift 5.1+

## Installation

### Swift Package Manager

The [Swift Package Manager](https://swift.org/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 WaterfallGrid as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.

```swift
dependencies: [
.package(url: "https://github.com/paololeonardi/WaterfallGrid.git"))
]
```

## Usage

```swift
WaterfallGrid(images, columns: 2) { image in
Image(image.name)
.resizable()
.aspectRatio(contentMode: .fit)
}
```

```swift
WaterfallGrid((0..<cards.count),
id: \.self,
columnsInPortrait: 2,
columnsInLandscape: 3,
spacing: 8,
vPadding: 8,
hPadding: 8,
animation: .easeInOut
) { index in
CardView(card: self.cards[index])
}
```

## Versions

For the versions available, see the [tags on this repository](https://github.com/paololeonardi/WaterfallGrid/tags).

## Author
* [Paolo Leonardi](https://github.com/paololeonardi) ([@paololeonardi](https://twitter.com/paololeonardi))

## Credits
WaterfallGrid was ispired by the following projects:

* QGrid - https://github.com/Q-Mobile/QGrid
* Grid - https://github.com/SwiftUIExtensions/Grid
* The SwiftUI Lab - https://swiftui-lab.com

## License

WaterfallGrid is available under the MIT license. See the [LICENSE](LICENSE) file for more info.

22 changes: 22 additions & 0 deletions Sources/WaterfallGrid/ElementPreference.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Copyright © 2019 Paolo Leonardi.
//
// Licensed under the MIT license. See the LICENSE file for more info.
//

import SwiftUI

struct ElementPreferenceData: Equatable {
let id: AnyHashable
let size: CGSize
}

struct ElementPreferenceKey: PreferenceKey {
typealias Value = [ElementPreferenceData]

static var defaultValue: [ElementPreferenceData] = []

static func reduce(value: inout [ElementPreferenceData], nextValue: () -> [ElementPreferenceData]) {
value.append(contentsOf: nextValue())
}
}
21 changes: 21 additions & 0 deletions Sources/WaterfallGrid/PositiveNumber.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Copyright © 2019 Paolo Leonardi.
//
// Licensed under the MIT license. See the LICENSE file for more info.
//

import Foundation

@propertyWrapper
struct PositiveNumber {
private var value: Int = 1

var wrappedValue: Int {
get { value }
set { value = max(1, newValue) }
}

init(wrappedValue initialValue: Int) {
self.wrappedValue = initialValue
}
}
17 changes: 17 additions & 0 deletions Sources/WaterfallGrid/PreferenceSetter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Copyright © 2019 Paolo Leonardi.
//
// Licensed under the MIT license. See the LICENSE file for more info.
//

import SwiftUI

struct PreferenceSetter<ID: Hashable>: View {
var id: ID
var body: some View {
return GeometryReader { geometry in
Color.clear
.preference(key: ElementPreferenceKey.self, value: [ElementPreferenceData(id: AnyHashable(self.id), size: geometry.size)])
}
}
}
Loading

0 comments on commit f54a010

Please sign in to comment.