Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions iBox/Sources/BoxList/BoxListView.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,6 +43,9 @@ class BoxListView: UIView {
$0.backgroundColor = .clear
$0.separatorColor = .clear
$0.rowHeight = 50
$0.estimatedSectionHeaderHeight = 0
$0.estimatedSectionFooterHeight = 0
$0.estimatedRowHeight = 0
}

private let emptyStackView = UIStackView().then {
Expand DownExpand Up@@ -150,6 +153,7 @@ class BoxListView: UIView {

return cell
}
boxListDataSource.defaultRowAnimation = .top
boxListDataSource.delegate = self
}

Expand DownExpand Up@@ -184,6 +188,13 @@ class BoxListView: UIView {
guard var snapshot = self?.boxListDataSource.snapshot() else { return }
snapshot.reloadItems(idArray)
self?.boxListDataSource.apply(snapshot)
case .openCloseFolder(boxList: let boxList, section: let section, isEmpty: let isEmpty):
self?.applySnapshot(with: boxList)
self?.tableView.layoutIfNeeded()
if !isEmpty {
let indexPath = IndexPath(row: NSNotFound, section: section)
self?.tableView.scrollToRow(at: indexPath, at: .top, animated: true)
}
}
}.store(in: &cancellables)
}
Expand DownExpand Up@@ -422,15 +433,18 @@ class BoxListDataSource: UITableViewDiffableDataSource<BoxListSectionViewModel.I
weak var delegate: BoxListDataSourceDelegate?

override func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {

delegate?.moveCell(at: sourceIndexPath, to: destinationIndexPath)

guard let src = itemIdentifier(for: sourceIndexPath),
sourceIndexPath != destinationIndexPath else { return }

var snap = snapshot()
if let dest = itemIdentifier(for: destinationIndexPath) {
snap.moveItem(src, beforeItem:dest)
if sourceIndexPath.section == destinationIndexPath.section && sourceIndexPath.row < destinationIndexPath.row {
snap.moveItem(src, afterItem: dest)
} else {
snap.moveItem(src, beforeItem:dest)
}
} else {
snap.deleteItems([src])
snap.appendItems([src], toSection: snap.sectionIdentifiers[destinationIndexPath.section])
Expand Down
4 changes: 3 additions & 1 deletion iBox/Sources/BoxList/BoxListViewModel.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,7 @@ class BoxListViewModel {
}

var sectionsToReload = Set<BoxListSectionViewModel.ID>()
var rowsToReload = Set<BoxListCellViewModel.ID>()
var isEditing = false
var favoriteId: UUID? = nil

Expand All@@ -37,6 +38,7 @@ class BoxListViewModel {
case reloadSections(idArray: [BoxListSectionViewModel.ID])
case reloadRows(idArray: [BoxListCellViewModel.ID])
case editStatus(isEditing: Bool)
case openCloseFolder(boxList: [BoxListSectionViewModel], section: Int, isEmpty: Bool)
}

let input = PassthroughSubject<Input, Never>()
Expand All@@ -62,7 +64,7 @@ class BoxListViewModel {
}
case let .folderTapped(section):
boxList[section].isOpened.toggle()
output.send(.sendBoxList(boxList: boxList))
output.send(.openCloseFolder(boxList: boxList, section: section, isEmpty: boxList[section].boxListCellViewModelsWithStatus.isEmpty))
case let .deleteBookmark(indexPath):
deleteBookmark(at: indexPath)
case let .toggleFavorite(indexPath):
Expand Down
1 change: 0 additions & 1 deletion iBox/Sources/Favorite/FavoriteView.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,7 +40,6 @@ class FavoriteView: UIView {
// MARK: - Setup Methods

private func setupProperty() {
guard let webView else { return }
backgroundColor = .backgroundColor
}

Expand Down