Skip to content

Commit 1ffdf13

Browse files
committed
Fixed header action button.
1 parent 478a59d commit 1ffdf13

File tree

8 files changed

+46
-13
lines changed

8 files changed

+46
-13
lines changed

Example App/NativeUIKit.xcodeproj/xcshareddata/xcschemes/watchOS Example.xcscheme

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,33 +54,46 @@
5454
debugDocumentVersioning = "YES"
5555
debugServiceExtension = "internal"
5656
allowLocationSimulation = "YES">
57-
<BuildableProductRunnable
58-
runnableDebuggingMode = "0">
57+
<RemoteRunnable
58+
runnableDebuggingMode = "2"
59+
BundleIdentifier = "com.apple.Carousel"
60+
RemotePath = "/(null)">
5961
<BuildableReference
6062
BuildableIdentifier = "primary"
6163
BlueprintIdentifier = "F4C33E2F26C932C8001A28B1"
6264
BuildableName = "watchOS Example.app"
6365
BlueprintName = "watchOS Example"
6466
ReferencedContainer = "container:NativeUIKit.xcodeproj">
6567
</BuildableReference>
66-
</BuildableProductRunnable>
68+
</RemoteRunnable>
6769
</LaunchAction>
6870
<ProfileAction
6971
buildConfiguration = "Release"
7072
shouldUseLaunchSchemeArgsEnv = "YES"
7173
savedToolIdentifier = ""
7274
useCustomWorkingDirectory = "NO"
7375
debugDocumentVersioning = "YES">
74-
<BuildableProductRunnable
75-
runnableDebuggingMode = "0">
76+
<RemoteRunnable
77+
runnableDebuggingMode = "2"
78+
BundleIdentifier = "com.apple.Carousel"
79+
RemotePath = "/(null)">
7680
<BuildableReference
7781
BuildableIdentifier = "primary"
7882
BlueprintIdentifier = "F4C33E2F26C932C8001A28B1"
7983
BuildableName = "watchOS Example.app"
8084
BlueprintName = "watchOS Example"
8185
ReferencedContainer = "container:NativeUIKit.xcodeproj">
8286
</BuildableReference>
83-
</BuildableProductRunnable>
87+
</RemoteRunnable>
88+
<MacroExpansion>
89+
<BuildableReference
90+
BuildableIdentifier = "primary"
91+
BlueprintIdentifier = "F4C33E2F26C932C8001A28B1"
92+
BuildableName = "watchOS Example.app"
93+
BlueprintName = "watchOS Example"
94+
ReferencedContainer = "container:NativeUIKit.xcodeproj">
95+
</BuildableReference>
96+
</MacroExpansion>
8497
</ProfileAction>
8598
<AnalyzeAction
8699
buildConfiguration = "Debug">

NativeUIKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = 'NativeUIKit'
4-
s.version = '1.2.5'
4+
s.version = '1.2.6'
55
s.summary = 'Mimicrated views and controls to native Apple appearance.'
66
s.homepage = 'https://github.com/ivanvorobei/NativeUIKit'
77
s.source = { :git => 'https://github.com/ivanvorobei/NativeUIKit.git', :tag => s.version }

Sources/NativeUIKit/Collection/LargeHeader/NativeLargeHeaderCollectionView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ open class NativeLargeHeaderCollectionView: SPCollectionReusableView {
4545

4646
static public func size(for item: NativeLargeHeaderItem, in collectionView: UICollectionView) -> CGSize {
4747
let view = NativeLargeHeaderView()
48-
view.configure(with: item)
48+
view.configure(with: item, section: .zero)
4949
view.setWidthAndFit(width: collectionView.layoutWidth)
5050
return .init(width: collectionView.frame.width, height: view.frame.height)
5151
}

Sources/NativeUIKit/Collection/LargeHeader/SPDiffableCollectionHeaderFooterProvider+LargeHeader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extension SPDiffableCollectionDataSource.HeaderFooterProvider {
2929
return SPDiffableCollectionDataSource.HeaderFooterProvider.init { collectionView, kind, indexPath, item in
3030
guard let header = item as? NativeLargeHeaderItem else { return nil }
3131
let view = collectionView.dequeueReusableSupplementaryView(withCalss: NativeLargeHeaderCollectionView.self, kind: kind, for: indexPath)
32-
view.headerView.configure(with: header)
32+
view.headerView.configure(with: header, section: indexPath.section)
3333
return view
3434
}
3535
}

Sources/NativeUIKit/Table/LargeHeader/NativeLargeHeaderView+SPDiffable.swift renamed to Sources/NativeUIKit/Table/LargeHeader/NativeLargeHeaderViewExtension.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ import UIKit
22

33
extension NativeLargeHeaderView {
44

5-
open func configure(with item: NativeLargeHeaderItem) {
5+
func configure(with item: NativeLargeHeaderItem, section: Int) {
66
titleLabel.text = item.title
77
if let actionTitle = item.actionTitle {
88
button.setTitle(actionTitle)
9+
diffableButtonAction = {
10+
item.action?(item, .init(row: .zero, section: section))
11+
}
912
}
1013
}
1114
}

Sources/NativeUIKit/Table/LargeHeader/SPDiffableTableCellProvider+LargeHeader.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ import SPDiffable
2727
extension SPDiffableTableDataSource.HeaderFooterProvider {
2828

2929
public static var largeHeader: SPDiffableTableDataSource.HeaderFooterProvider {
30-
return SPDiffableTableDataSource.HeaderFooterProvider() { (tableView, indexPath, item) -> UIView? in
30+
return SPDiffableTableDataSource.HeaderFooterProvider() { (tableView, section, item) -> UIView? in
3131
guard let header = item as? NativeLargeHeaderItem else { return nil }
3232
let view = NativeLargeHeaderView()
33-
view.configure(with: header)
33+
view.configure(with: header, section: section)
3434
return view
3535
}
3636
}

Sources/NativeUIKit/Views/NativeLargeHeaderView.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#if canImport(UIKit) && (os(iOS))
2323
import UIKit
2424
import SparrowKit
25+
import SPDiffable
2526

2627
open class NativeLargeHeaderView: SPView {
2728

@@ -44,7 +45,7 @@ open class NativeLargeHeaderView: SPView {
4445

4546
open override func commonInit() {
4647
super.commonInit()
47-
layoutMargins = .init(top: 32, left: .zero, bottom: 14, right: .zero)
48+
layoutMargins = .init(top: NativeLayout.Spaces.default_double, left: .zero, bottom: 14, right: .zero)
4849
insetsLayoutMarginsFromSafeArea = false
4950
preservesSuperviewLayoutMargins = false
5051
addSubviews(titleLabel, button)
@@ -76,5 +77,21 @@ open class NativeLargeHeaderView: SPView {
7677
layoutSubviews()
7778
return .init(width: superSize.width, height: titleLabel.frame.maxY + layoutMargins.bottom)
7879
}
80+
81+
// MARK: - Private
82+
83+
var diffableButtonAction: (()->Void)? = nil {
84+
didSet {
85+
if let _ = diffableButtonAction {
86+
self.button.addTarget(self, action: #selector(self.diffableButtonTargetAction), for: .touchUpInside)
87+
} else {
88+
self.button.removeTargetsAndActions()
89+
}
90+
}
91+
}
92+
93+
@objc func diffableButtonTargetAction() {
94+
self.diffableButtonAction?()
95+
}
7996
}
8097
#endif

0 commit comments

Comments
 (0)