Skip to content

Commit 8ec1c07

Browse files
committed
Add new move functions
1 parent 82f337b commit 8ec1c07

7 files changed

+38
-35
lines changed

RELEASE_NOTES.md

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ Until then, deprecated features may be removed in the next minor version.
66

77

88

9+
## 0.7.1
10+
11+
### 💡 New features
12+
13+
* `Deck` has new `move` functions.
14+
15+
16+
917
## 0.7
1018

1119
### 💡 New features

Sources/DeckKit/Animations/DeckShuffleAnimation.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ import SwiftUI
1313

1414
To use this animation, first create a `@StateObject` in the
1515
view that should use the animation, then bind the animation
16-
to your deck item views using the `withDeckShuffleAnimation`
17-
view modifier, then call `shuffle` to shuffle the deck with
18-
a nice shuffle animation.
16+
to your item views, using a `withShuffleAnimation` modifier,
17+
then call `shuffle` to perform an animated shuffle.
1918
*/
2019
public class DeckShuffleAnimation: ObservableObject {
2120

Sources/DeckKit/Deck.swift

+21-22
Original file line numberDiff line numberDiff line change
@@ -25,59 +25,58 @@ public struct Deck<Item: DeckItem>: Identifiable, Equatable {
2525
public init(
2626
id: UUID = UUID(),
2727
name: String = "",
28-
items: [Item]) {
28+
items: [Item]
29+
) {
2930
self.id = id
3031
self.name = name
3132
self.items = items
3233
}
3334

34-
/**
35-
The unique id of the deck.
36-
*/
35+
/// The unique id of the deck.
3736
public let id: UUID
3837

39-
/**
40-
The name of the deck.
41-
*/
38+
/// The name of the deck.
4239
public let name: String
4340

44-
/**
45-
The items that are added to the deck.
46-
*/
41+
/// The items that are added to the deck.
4742
public var items: [Item]
4843
}
4944

5045
public extension Deck {
5146

52-
/**
53-
The index of a certain item, if any.
54-
*/
47+
/// The index of a certain item, if any.
5548
func index(of item: Item) -> Int? {
5649
items.firstIndex { $0.id == item.id }
5750
}
5851

59-
/**
60-
Move an item to the back of the deck.
61-
*/
52+
/// Move the first item to the back of the deck.
53+
mutating func moveFirstItemToBack() {
54+
guard let item = items.first else { return }
55+
moveToBack(item)
56+
}
57+
58+
/// Move the last item to the front of the deck.
59+
mutating func moveLastItemToFront() {
60+
guard let item = items.last else { return }
61+
moveToFront(item)
62+
}
63+
64+
/// Move an item to the back of the deck.
6265
mutating func moveToBack(_ item: Item) {
6366
guard let index = index(of: item) else { return }
6467
let topItem = items.remove(at: index)
6568
items.append(topItem)
6669
}
6770

68-
/**
69-
Move an item to the front of the deck.
70-
*/
71+
/// Move an item to the front of the deck.
7172
mutating func moveToFront(_ item: Item) {
7273
guard let index = index(of: item) else { return }
7374
if items[0].id == item.id { return }
7475
let topItem = items.remove(at: index)
7576
items.insert(topItem, at: 0)
7677
}
7778

78-
/**
79-
Shuffle the deck.
80-
*/
79+
/// Shuffle the deck.
8180
mutating func shuffle() {
8281
items.shuffle()
8382
}

Sources/DeckKit/DeckView.swift

-6
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,10 @@ private extension DeckView {
134134

135135
private extension DeckView {
136136

137-
/**
138-
Move a certain item to the back of the stack.
139-
*/
140137
func moveItemToBack(_ item: ItemType) {
141138
deck.wrappedValue.moveToBack(item)
142139
}
143140

144-
/**
145-
Move a certain item to the front of the stack.
146-
*/
147141
func moveItemToFront(_ item: ItemType) {
148142
deck.wrappedValue.moveToFront(item)
149143
}

Sources/DeckKit/Favorites/Favoritable.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
/**
10-
This protocol can be implemented by anything that can be markes as a favorite.
10+
This protocol can be implemented by any type that should be
11+
able to be marked as a favorite.
1112
*/
1213
public protocol Favoritable: Identifiable {}

Sources/DeckKit/Favorites/FavoriteService.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
// Copyright © 2020-2023 Daniel Saidi. All rights reserved.
77
//
88

9+
import Foundation
10+
911
/**
10-
This protocol can be implemented by classes that can mark items as favorites.
12+
This service protocol can be implemented any types that can
13+
toggle the favorite state of ``Favoritable`` items.
1114
*/
1215
public protocol FavoriteService: AnyObject {
1316

Sources/DeckKit/PreviewCard.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import SwiftUI
1010
import CoreGraphics
1111

1212
/**
13-
This view can be used to presents a ``PreviewCard/Item``, and
14-
can be used as is or as a template for other cards.
13+
This view can be used as a preview template for other cards.
1514
*/
1615
struct PreviewCard: View {
1716

0 commit comments

Comments
 (0)