-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f54a010
Showing
185 changed files
with
5,790 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)]) | ||
} | ||
} | ||
} |
Oops, something went wrong.