-
-
Notifications
You must be signed in to change notification settings - Fork 5
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 65d279d
Showing
21 changed files
with
1,021 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,9 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/config/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc |
8 changes: 8 additions & 0 deletions
8
.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
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,18 @@ | ||
// swift-tools-version: 5.8 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "MijickGridView", | ||
platforms: [ | ||
.iOS(.v14) | ||
], | ||
products: [ | ||
.library(name: "MijickGridView", targets: ["MijickGridView"]), | ||
], | ||
targets: [ | ||
.target(name: "MijickGridView", dependencies: [], path: "Sources"), | ||
.testTarget(name: "MijickGridViewTests", dependencies: ["MijickGridView"], path: "Tests") | ||
] | ||
) |
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,154 @@ | ||
<br> | ||
|
||
<p align="center"> | ||
<img alt="GridView Logo" src="https://github.com/Mijick/GridView/assets/23524947/a2a565a2-cc51-4e24-8d77-331e1742784a" width="88%""> | ||
</p> | ||
|
||
|
||
<h3 style="font-size: 5em" align="center"> | ||
Layouts made simple | ||
</h3> | ||
|
||
<p align="center"> | ||
Lay out your data in the blink of an eye. Keep your code clean | ||
</p> | ||
|
||
<p align="center"> | ||
<a href="https://github.com/Mijick/GridView-Demo" rel="nofollow">Try demo we prepared</a> | ||
</p> | ||
|
||
|
||
<br> | ||
|
||
<p align="center"> | ||
<img alt="Library in beta version" src="https://github.com/Mijick/Navigattie/assets/23524947/b698aaac-4a91-431b-a7ef-f1dda28304b6"/> | ||
<img alt="Designed for SwiftUI" src="https://github.com/Mijick/Navigattie/assets/23524947/822de7e5-481e-49c0-b55b-653ac0de86bb"/> | ||
<img alt="Platforms: iOS" src="https://github.com/Mijick/Navigattie/assets/23524947/58399b94-5fa0-4c29-9013-ba52f6c3b63e"/> | ||
<img alt="Release: 0.3.0" src="https://github.com/Mijick/GridView/assets/23524947/73e2265e-140b-433b-a563-32f328a6a1d5"/> | ||
<a href="https://www.swift.org/package-manager"> | ||
<img alt="Swift Package Manager: Compatible" src="https://github.com/Mijick/Navigattie/assets/23524947/a4876e58-6a26-40c3-97bb-b5e6f69423d9"/> | ||
</a> | ||
<img alt="License: MIT" src="https://github.com/Mijick/Navigattie/assets/23524947/de233cae-4517-462a-86ac-5618f91b1d4a"/> | ||
</p> | ||
|
||
<p align="center"> | ||
<a href="https://github.com/Mijick/GridView/stargazers"> | ||
<img alt="Stars" src="https://github.com/Mijick/Navigattie/assets/23524947/f9d35612-7925-4b8e-99ad-74c983f59293"/> | ||
</a> | ||
<a href="https://twitter.com/MijickTeam"> | ||
<img alt="Follow us on Twitter" src="https://github.com/Mijick/Navigattie/assets/23524947/2d4d094e-36fa-48c5-8f92-46f5c1ce5c82"/> | ||
</a> | ||
<a href=mailto:team@mijick.com?subject=Hello> | ||
<img alt="Let's work together" src="https://github.com/Mijick/Navigattie/assets/23524947/803e0227-41fc-4d65-8ccb-ce5dfc1b4319"/> | ||
</a> | ||
<img alt="Made in Kraków" src="https://github.com/Mijick/Navigattie/assets/23524947/f18e87d5-6684-4aa6-9339-757e9b3fd83b"/> | ||
</p> | ||
|
||
|
||
<p align="center"> | ||
<img alt="GridView Examples" src="https://github.com/Mijick/GridView/assets/23524947/d25760d8-6623-4751-bcdd-8250ad3664f4"/> | ||
</p> | ||
|
||
<br> | ||
|
||
GridView is a free, and open-source library for SwiftUI that makes creating grids easier and much cleaner. | ||
* **Improves code quality.** Create a grid using `GridView` constructor - simply pass your data and we'll deal with the rest. Simple as never! | ||
* **Designed for SwiftUI.** While developing the library, we have used the power of SwiftUI to give you powerful tool to speed up your implementation process. | ||
|
||
<br> | ||
|
||
# Getting Started | ||
### ✋ Requirements | ||
|
||
| **Platforms** | **Minimum Swift Version** | | ||
|:----------|:----------| | ||
| iOS 14+ | 5.0 | | ||
|
||
### ⏳ Installation | ||
|
||
#### [Swift Package Manager][spm] | ||
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 Navigattie as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`. | ||
|
||
```Swift | ||
dependencies: [ | ||
.package(url: "https://github.com/Mijick/GridView", branch(“main”)) | ||
] | ||
``` | ||
<br> | ||
|
||
# Usage | ||
### 1. Call initialiser | ||
To declare a Grid for your data set, call the constructor: | ||
|
||
```Swift | ||
struct ContentView: View { | ||
private let data = [SomeData]() | ||
|
||
var body: some View { | ||
GridView(data, id: \.self) { element in | ||
SomeItem(element: element) | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### 2. Customise Grid | ||
Your GridView can be customised by calling `configBuilder` inside the initialiser: | ||
|
||
```Swift | ||
struct ContentView: View { | ||
private let data = [SomeData]() | ||
|
||
var body: some View { | ||
GridView(data, id: \.self, content: SomeItem.init, configBuilder: { $0 | ||
.insertionPolicy(.fill) | ||
.columns(4) | ||
.verticalSpacing(12) | ||
}) | ||
} | ||
} | ||
``` | ||
|
||
|
||
### 3. Declare number of columns | ||
You can change the number of columns of an item by calling .columns of Item: | ||
```Swift | ||
struct ContentView: View { ... } | ||
struct SomeItem: View { | ||
... | ||
|
||
var body: some View { | ||
... | ||
.columns(2) | ||
} | ||
} | ||
``` | ||
|
||
|
||
<br> | ||
# Try our demo | ||
See for yourself how does it work by cloning [project][Demo] we created | ||
|
||
# License | ||
Navigattie is released under the MIT license. See [LICENSE][License] for details. | ||
|
||
<br><br> | ||
|
||
# Our other open source SwiftUI libraries | ||
[PopupView] - The most powerful popup library that allows you to present any popup | ||
<br> | ||
[Navigattie] - Easier and cleaner way of navigating through your app | ||
|
||
|
||
[MIT]: https://en.wikipedia.org/wiki/MIT_License | ||
[SPM]: https://www.swift.org/package-manager | ||
[Demo]: https://github.com/Mijick/GridView-Demo | ||
[License]: https://github.com/Mijick/GridView/blob/main/LICENSE | ||
|
||
[PopupView]: https://github.com/Mijick/PopupView | ||
[Navigattie]: https://github.com/Mijick/Navigattie |
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 @@ | ||
// | ||
// Array++.swift of MijickGridView | ||
// | ||
// Created by Tomasz Kurylik | ||
// - Twitter: https://twitter.com/tkurylik | ||
// - Mail: tomasz.kurylik@mijick.com | ||
// - GitHub: https://github.com/FulcrumOne | ||
// | ||
// Copyright ©2023 Mijick. Licensed under MIT License. | ||
|
||
|
||
import SwiftUI | ||
|
||
// MARK: - Removing Duplicates | ||
extension Array where Element: Hashable { | ||
func removingDuplicates() -> Self { Array(Set(self)) } | ||
} |
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 @@ | ||
// | ||
// Int++.swift of MijickGridView | ||
// | ||
// Created by Tomasz Kurylik | ||
// - Twitter: https://twitter.com/tkurylik | ||
// - Mail: tomasz.kurylik@mijick.com | ||
// - GitHub: https://github.com/FulcrumOne | ||
// | ||
// Copyright ©2023 Mijick. Licensed under MIT License. | ||
|
||
|
||
import SwiftUI | ||
|
||
extension Int { | ||
func toDouble() -> Double { .init(self) } | ||
func toCGFloat() -> CGFloat { .init(self) } | ||
} |
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 @@ | ||
// | ||
// Matrix.Item.swift of MijickGridView | ||
// | ||
// Created by Tomasz Kurylik | ||
// - Twitter: https://twitter.com/tkurylik | ||
// - Mail: tomasz.kurylik@mijick.com | ||
// - GitHub: https://github.com/FulcrumOne | ||
// | ||
// Copyright ©2023 Mijick. Licensed under MIT License. | ||
|
||
|
||
import SwiftUI | ||
|
||
extension Matrix { struct Item { | ||
var index: Int | ||
var value: CGFloat | ||
var columns: Int | ||
}} | ||
extension Matrix.Item: Hashable { | ||
func hash(into hasher: inout Hasher) { hasher.combine(index) } | ||
} | ||
extension Matrix.Item { | ||
var isEmpty: Bool { value == 0 } | ||
} | ||
|
||
|
||
// MARK: - Array | ||
extension [[Matrix.Item]] { | ||
subscript(_ position: Matrix.Position) -> Matrix.Item { | ||
get { self[position.row][position.column] } | ||
set { self[position.row][position.column] = newValue } | ||
} | ||
} |
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,45 @@ | ||
// | ||
// Matrix.Position.swift of MijickGridView | ||
// | ||
// Created by Tomasz Kurylik | ||
// - Twitter: https://twitter.com/tkurylik | ||
// - Mail: tomasz.kurylik@mijick.com | ||
// - GitHub: https://github.com/FulcrumOne | ||
// | ||
// Copyright ©2023 Mijick. Licensed under MIT License. | ||
|
||
|
||
import SwiftUI | ||
|
||
extension Matrix { struct Position { | ||
let row: Int | ||
let column: Int | ||
}} | ||
extension Matrix.Position: Comparable { | ||
static func < (lhs: Matrix.Position, rhs: Matrix.Position) -> Bool { | ||
if lhs.row == rhs.row { return lhs.column < rhs.column } | ||
return lhs.row < rhs.row | ||
} | ||
} | ||
|
||
// MARK: - Creating Item Range | ||
extension Matrix.Position { | ||
func createItemRange(_ item: Matrix.Item) -> Matrix.Range { .init(from: self, to: withColumn(column + item.columns - 1)) } | ||
} | ||
|
||
// MARK: - Helpers | ||
extension Matrix.Position { | ||
func withRow(_ rowIndex: Int) -> Self { .init(row: rowIndex, column: column) } | ||
func withColumn(_ columnIndex: Int) -> Self { .init(row: row, column: columnIndex) } | ||
|
||
func nextRow() -> Self { withRow(row + 1) } | ||
func nextColumn() -> Self { withColumn(column + 1) } | ||
|
||
func previousRow() -> Self { withRow(row - 1) } | ||
func previousColumn() -> Self { withColumn(column - 1) } | ||
} | ||
|
||
// MARK: - Objects | ||
extension Matrix.Position { | ||
static var zero: Self { .init(row: 0, column: 0) } | ||
} |
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,41 @@ | ||
// | ||
// Matrix.Range.swift of MijickGridView | ||
// | ||
// Created by Tomasz Kurylik | ||
// - Twitter: https://twitter.com/tkurylik | ||
// - Mail: tomasz.kurylik@mijick.com | ||
// - GitHub: https://github.com/FulcrumOne | ||
// | ||
// Copyright ©2023 Mijick. Licensed under MIT License. | ||
|
||
|
||
import SwiftUI | ||
|
||
extension Matrix { struct Range { | ||
var start: Position | ||
var end: Position | ||
|
||
init(from startPosition: Matrix.Position, to endPosition: Matrix.Position) { | ||
if startPosition > endPosition { fatalError("Start position must precede end position") } | ||
|
||
start = startPosition | ||
end = endPosition | ||
} | ||
}} | ||
|
||
extension Matrix.Range { | ||
func updating(newStart: Matrix.Position) -> Matrix.Range { | ||
let endIndexOffset = newStart.column + columns.count - 1 | ||
|
||
var range = self | ||
range.start = newStart | ||
range.end = newStart.withColumn(endIndexOffset) | ||
return range | ||
} | ||
} | ||
|
||
// MARK: - Helpers | ||
extension Matrix.Range { | ||
var rows: ClosedRange<Int> { start.row...end.row } | ||
var columns: ClosedRange<Int> { start.column...end.column } | ||
} |
Oops, something went wrong.