Skip to content

Commit

Permalink
Merge pull request #55 from RakuyoKit/feature/epoxy
Browse files Browse the repository at this point in the history
Feature/epoxy
  • Loading branch information
rakuyoMo authored Jul 8, 2024
2 parents 09ebf87 + ad93fe9 commit a5d5658
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Sources/Core/Extensions/UICollectionView+RAK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,38 @@ extension Extendable where Base: UICollectionView {
}
}
}

extension Extendable where Base: UICollectionView {
public func deselectRowIfNeeded(
with transitionCoordinator: UIViewControllerTransitionCoordinator?,
animated: Bool
) {
guard let selectedIndexPaths = base.indexPathsForSelectedItems else { return }

guard let coordinator = transitionCoordinator else {
deselectItems(at: selectedIndexPaths, animated: animated)
return
}

coordinator.animate(
alongsideTransition: { _ in
deselectItems(at: selectedIndexPaths, animated: true)
},
completion: { context in
guard context.isCancelled else { return }

for selectedIndexPath in selectedIndexPaths {
base.selectItem(at: selectedIndexPath, animated: false, scrollPosition: [])
}
}
)
}

private func deselectItems(at selectedIndexPaths: [IndexPath], animated: Bool) {
for selectedIndexPath in selectedIndexPaths {
base.deselectItem(at: selectedIndexPath, animated: true)
base.delegate?.collectionView?(base, didDeselectItemAt: selectedIndexPath)
}
}
}
#endif
35 changes: 35 additions & 0 deletions Sources/Core/Extensions/UITableView+RAK.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// UITableView+RAK.swift
// RakuyoKit
//
// Created by Rakuyo on 2024/7/8.
// Copyright © 2024 RakuyoKit. All rights reserved.
//

#if !os(watchOS)
import UIKit

extension Extendable where Base: UITableView {
public func deselectRowIfNeeded(
with transitionCoordinator: UIViewControllerTransitionCoordinator?,
animated: Bool
) {
guard let selectedIndexPath = base.indexPathForSelectedRow else { return }

guard let coordinator = transitionCoordinator else {
base.deselectRow(at: selectedIndexPath, animated: animated)
return
}

coordinator.animate(
alongsideTransition: { _ in
base.deselectRow(at: selectedIndexPath, animated: true)
},
completion: { context in
guard context.isCancelled else { return }
base.selectRow(at: selectedIndexPath, animated: false, scrollPosition: .none)
}
)
}
}
#endif
1 change: 1 addition & 0 deletions Sources/Epoxy/CollectionView/CollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ open class CollectionView: EpoxyCollectionView.CollectionView {
override public init(layout: UICollectionViewLayout, configuration: CollectionViewConfiguration = .shared) {
super.init(layout: layout, configuration: configuration)

autoDeselectItems = false
showsVerticalScrollIndicator = false
showsHorizontalScrollIndicator = false
}
Expand Down
8 changes: 8 additions & 0 deletions Sources/Epoxy/CollectionView/Tools/SectionEdgeInsets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public enum SectionEdgeInsets {
/// Custom spacing for all four sides.
case all(top: CGFloat, leading: CGFloat, bottom: CGFloat, trailing: CGFloat)

/// Same spacing as `.insetGrouped` style `UITableView`
///
/// (top: 0, leading: 20, bottom: 35, trailing: 20)
case groupCard

/// Fully customized using `EdgeInsets`.
case custom(RAKCore.EdgeInsets)

Expand Down Expand Up @@ -67,6 +72,9 @@ extension SectionEdgeInsets {
case .all(let top, let leading, let bottom, let trailing):
.init(top: top, leading: leading, bottom: bottom, trailing: trailing)

case .groupCard:
.init(top: 0, leading: 20, bottom: 35, trailing: 20)

case .custom(let edge):
edge.directionalEdgeInsets
}
Expand Down

0 comments on commit a5d5658

Please sign in to comment.