Skip to content

Commit 0d5ad55

Browse files
committed
updated actionable items.
1 parent fa079b5 commit 0d5ad55

File tree

11 files changed

+61
-49
lines changed

11 files changed

+61
-49
lines changed

Example Apps/iOS Example/Controllers/SideBarController.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ class SidebarController: SPDiffableSideBarController {
4343
SPDiffableSection(
4444
identifier: Section.tabs.rawValue,
4545
items: [
46-
SPDiffableSideBarItem(title: "Listen Now", image: UIImage(systemName: "play.circle"), action: { _ in }),
47-
SPDiffableSideBarItem(title: "Browse", image: UIImage(systemName: "square.grid.2x2"), action: { _ in }),
48-
SPDiffableSideBarItem(title: "Radio", image: UIImage(systemName: "dot.radiowaves.left.and.right"), action: { _ in }),
49-
SPDiffableSideBarItem(title: "Search", image: UIImage(systemName: "magnifyingglass"), action: { _ in
46+
SPDiffableSideBarItem(title: "Listen Now", image: UIImage(systemName: "play.circle"), action: { _, _ in }),
47+
SPDiffableSideBarItem(title: "Browse", image: UIImage(systemName: "square.grid.2x2"), action: { _, _ in }),
48+
SPDiffableSideBarItem(title: "Radio", image: UIImage(systemName: "dot.radiowaves.left.and.right"), action: { _, _ in }),
49+
SPDiffableSideBarItem(title: "Search", image: UIImage(systemName: "magnifyingglass"), action: { _, _ in
5050
print("action call 2")
5151
}),
52-
SPDiffableSideBarButton(title: "Button", image: UIImage(systemName: "plus.square.fill"), action: { [weak self] _ in
52+
SPDiffableSideBarButton(title: "Button", image: UIImage(systemName: "plus.square.fill"), action: { [weak self] _, _ in
5353
print("action call")
5454
guard let self = self else { return }
5555
let controller = UIViewController()
@@ -63,25 +63,25 @@ class SidebarController: SPDiffableSideBarController {
6363
identifier: Section.library.rawValue,
6464
header: SPDiffableSideBarHeader(text: "Library", accessories: [.outlineDisclosure()]),
6565
items: [
66-
SPDiffableSideBarItem(title: "Recently Added", image: UIImage(systemName: "clock"), action: { _ in }),
67-
SPDiffableSideBarItem(title: "Artists", image: UIImage(systemName: "music.mic"), action: { _ in }),
68-
SPDiffableSideBarItem(title: "Albums", image: UIImage(systemName: "rectangle.stack"), action: { _ in }),
69-
SPDiffableSideBarItem(title: "Songs", image: UIImage(systemName: "music.note"), action: { _ in }),
70-
SPDiffableSideBarItem(title: "Music Videos", image: UIImage(systemName: "tv.music.note"), action: { _ in }),
71-
SPDiffableSideBarItem(title: "TV & Movies", image: UIImage(systemName: "tv"), action: { _ in })
66+
SPDiffableSideBarItem(title: "Recently Added", image: UIImage(systemName: "clock"), action: { _, _ in }),
67+
SPDiffableSideBarItem(title: "Artists", image: UIImage(systemName: "music.mic"), action: { _, _ in }),
68+
SPDiffableSideBarItem(title: "Albums", image: UIImage(systemName: "rectangle.stack"), action: { _, _ in }),
69+
SPDiffableSideBarItem(title: "Songs", image: UIImage(systemName: "music.note"), action: { _, _ in }),
70+
SPDiffableSideBarItem(title: "Music Videos", image: UIImage(systemName: "tv.music.note"), action: { _, _ in }),
71+
SPDiffableSideBarItem(title: "TV & Movies", image: UIImage(systemName: "tv"), action: { _, _ in })
7272
])
7373
)
7474
content.append(
7575
SPDiffableSection(
7676
identifier: Section.playlists.rawValue,
7777
header: SPDiffableSideBarHeader(text: "Playlists", accessories: [.outlineDisclosure()]),
7878
items: [
79-
SPDiffableSideBarItem(title: "All Playlists", image: UIImage(systemName: "music.note.list"), action: { _ in }),
80-
SPDiffableSideBarItem(title: "Replay 2015", image: UIImage(systemName: "music.note.list"), action: { _ in }),
81-
SPDiffableSideBarItem(title: "Replay 2016", image: UIImage(systemName: "music.note.list"), action: { _ in }),
82-
SPDiffableSideBarItem(title: "Replay 2017", image: UIImage(systemName: "music.note.list"), action: { _ in }),
83-
SPDiffableSideBarItem(title: "Replay 2018", image: UIImage(systemName: "music.note.list"), action: { _ in }),
84-
SPDiffableSideBarItem(title: "Replay 2019", image: UIImage(systemName: "music.note.list"), action: { _ in })
79+
SPDiffableSideBarItem(title: "All Playlists", image: UIImage(systemName: "music.note.list"), action: { _, _ in }),
80+
SPDiffableSideBarItem(title: "Replay 2015", image: UIImage(systemName: "music.note.list"), action: { _, _ in }),
81+
SPDiffableSideBarItem(title: "Replay 2016", image: UIImage(systemName: "music.note.list"), action: { _, _ in }),
82+
SPDiffableSideBarItem(title: "Replay 2017", image: UIImage(systemName: "music.note.list"), action: { _, _ in }),
83+
SPDiffableSideBarItem(title: "Replay 2018", image: UIImage(systemName: "music.note.list"), action: { _, _ in }),
84+
SPDiffableSideBarItem(title: "Replay 2019", image: UIImage(systemName: "music.note.list"), action: { _, _ in })
8585
])
8686
)
8787
return content

Sources/SPDiffable/Collection/Models/SPDiffableSideBarButton.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import UIKit
2727
Colorful title usually.
2828
*/
2929
@available(iOS 14, *)
30-
open class SPDiffableSideBarButton: SPDiffableCollectionActionableItem {
30+
open class SPDiffableSideBarButton: SPDiffableActionableItem {
3131

3232
open var title: String
3333
open var image: UIImage?
@@ -39,6 +39,4 @@ open class SPDiffableSideBarButton: SPDiffableCollectionActionableItem {
3939
self.accessories = accessories
4040
super.init(identifier: identifier ?? title, action: action)
4141
}
42-
43-
public typealias Action = (_ indexPath: IndexPath) -> Void
4442
}

Sources/SPDiffable/Collection/Models/SPDiffableSideBarItem.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import UIKit
2727
For header use `SPDiffableSideBarHeader` class.
2828
*/
2929
@available(iOS 14, *)
30-
open class SPDiffableSideBarItem: SPDiffableCollectionActionableItem {
30+
open class SPDiffableSideBarItem: SPDiffableActionableItem {
3131

3232
open var title: String
3333
open var image: UIImage?
@@ -39,6 +39,4 @@ open class SPDiffableSideBarItem: SPDiffableCollectionActionableItem {
3939
self.accessories = accessories
4040
super.init(identifier: identifier ?? title, action: action)
4141
}
42-
43-
public typealias Action = (_ indexPath: IndexPath) -> Void
4442
}

Sources/SPDiffable/Collection/SPDiffableCollectionController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ open class SPDiffableCollectionController: UICollectionViewController {
6666
guard let item = diffableDataSource?.item(for: indexPath) else { return }
6767
diffableDelegate?.diffableCollectionView?(collectionView, didSelectItem: item, indexPath: indexPath)
6868
switch item {
69-
case let model as SPDiffableCollectionActionableItem:
70-
model.action?(indexPath)
69+
case let model as SPDiffableItemActionable:
70+
model.action?(item, indexPath)
7171
default:
7272
break
7373
}

Sources/SPDiffable/Collection/SPDiffableCollectionView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ open class SPDiffableCollectionView: UICollectionView, UICollectionViewDelegate
8282
guard let item = diffableDataSource?.item(for: indexPath) else { return }
8383
diffableDelegate?.diffableCollectionView?(collectionView, didSelectItem: item, indexPath: indexPath)
8484
switch item {
85-
case let model as SPDiffableCollectionActionableItem:
86-
model.action?(indexPath)
85+
case let model as SPDiffableActionableItem:
86+
model.action?(model, indexPath)
8787
default:
8888
break
8989
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ import UIKit
2424
/**
2525
SPDiffable: Actionable collection item model.
2626
*/
27-
open class SPDiffableCollectionActionableItem: SPDiffableItem {
27+
open class SPDiffableActionableItem: SPDiffableItem, SPDiffableItemActionable {
2828

2929
open var action: Action?
3030

3131
public init(identifier: String, action: Action? = nil) {
3232
self.action = action
3333
super.init(identifier: identifier)
3434
}
35-
36-
public typealias Action = (_ indexPath: IndexPath) -> Void
3735
}

Sources/SPDiffable/Models/SPDiffableItem.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,3 @@ open class SPDiffableItem: NSObject, NSCopying {
6767

6868
public typealias Identifier = String
6969
}
70-
71-
/**
72-
SPDiffable: Protocol for items which shoud have actions.
73-
In default controllers will be handled.
74-
*/
75-
public protocol SPDiffableItemActionable: AnyObject {
76-
77-
var action: Action? { get set }
78-
79-
typealias Action = (_ item: SPDiffableItem, _ indexPath: IndexPath) -> Void
80-
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// The MIT License (MIT)
2+
// Copyright © 2020 Ivan Vorobei (hello@ivanvorobei.by)
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in all
12+
// copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
// SOFTWARE.
21+
22+
import UIKit
23+
24+
/**
25+
SPDiffable: Protocol for items which shoud have actions.
26+
In default controllers will be handled.
27+
*/
28+
public protocol SPDiffableItemActionable: AnyObject {
29+
30+
var action: Action? { get set }
31+
32+
typealias Action = (_ item: SPDiffableItem, _ indexPath: IndexPath) -> Void
33+
}

Sources/SPDiffable/Table/Models/SPDiffableTableRow.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,20 @@ import UIKit
2828
By default if action is nil, selection style set to `.none`.
2929
If accessory is control, you can find reay-use class for it.
3030
*/
31-
open class SPDiffableTableRow: SPDiffableItem, SPDiffableItemActionable {
31+
open class SPDiffableTableRow: SPDiffableActionableItem {
3232

3333
open var text: String
3434
open var detail: String? = nil
3535
open var icon: UIImage? = nil
3636
open var selectionStyle: UITableViewCell.SelectionStyle
3737
open var accessoryType: UITableViewCell.AccessoryType
38-
public var action: Action?
3938

4039
public init(identifier: String? = nil, text: String, detail: String? = nil, icon: UIImage? = nil, accessoryType: UITableViewCell.AccessoryType = .none, selectionStyle: UITableViewCell.SelectionStyle = .none, action: Action? = nil) {
4140
self.text = text
4241
self.detail = detail
4342
self.icon = icon
4443
self.accessoryType = accessoryType
4544
self.selectionStyle = selectionStyle
46-
self.action = action
47-
super.init(identifier: identifier ?? text)
45+
super.init(identifier: identifier ?? text, action: action)
4846
}
4947
}

0 commit comments

Comments
 (0)