Manage button scrolls to bottom to reveal actions (#1327)

* new prototype of managing UX

* add tested helper for calculating item width without hanging chad

* adjust math to even last row when theres a chad
This commit is contained in:
Ryan Nystrom
2018-01-02 07:15:48 -05:00
committed by GitHub
parent 47342c862b
commit 56864889a7
7 changed files with 236 additions and 52 deletions

View File

@@ -0,0 +1,44 @@
//
// IssueManagingNavSectionController.swift
// Freetime
//
// Created by Ryan Nystrom on 1/1/18.
// Copyright © 2018 Ryan Nystrom. All rights reserved.
//
import UIKit
import IGListKit
protocol IssueManagingNavSectionControllerDelegate: class {
func didSelect(managingNavController: IssueManagingNavSectionController)
}
final class IssueManagingNavSectionController: ListSectionController {
private weak var delegate: IssueManagingNavSectionControllerDelegate?
init(delegate: IssueManagingNavSectionControllerDelegate) {
self.delegate = delegate
}
override func sizeForItem(at index: Int) -> CGSize {
guard let containerWidth = collectionContext?.containerSize.width
else { fatalError("Collection context must be set") }
return CGSize(
width: floor(containerWidth / 2),
height: Styles.Sizes.labelEventHeight
)
}
override func cellForItem(at index: Int) -> UICollectionViewCell {
guard let cell = collectionContext?.dequeueReusableCell(of: IssueManagingExpansionCell.self, for: self, at: index) as? IssueManagingExpansionCell
else { fatalError("Cannot dequeue cell") }
return cell
}
override func didSelectItem(at index: Int) {
collectionContext?.deselectItem(at: index, sectionController: self, animated: true)
delegate?.didSelect(managingNavController: self)
}
}

View File

@@ -61,7 +61,6 @@ PeopleViewControllerDelegate {
private let model: IssueDetailsModel
private let client: GithubClient
private var expanded = false
private var updating = false
init(model: IssueDetailsModel, client: GithubClient) {
@@ -172,26 +171,23 @@ PeopleViewControllerDelegate {
let result = issueResult
else { fatalError("Object not correct type") }
var models: [ListDiffable] = [IssueManagingExpansionModel(expanded: expanded)]
if expanded {
models += [
Action.labels,
Action.milestone,
Action.assignees,
var models: [ListDiffable] = [
Action.labels,
Action.milestone,
Action.assignees,
]
if object.pullRequest {
models.append(Action.reviewers)
}
switch result.status.status {
case .closed: models.append(Action.reopen)
case .open: models.append(Action.close)
case .merged: break // can't do anything
}
if result.status.locked {
models.append(Action.unlock)
} else {
models.append(Action.lock)
}
if object.pullRequest {
models.append(Action.reviewers)
}
switch result.status.status {
case .closed: models.append(Action.reopen)
case .open: models.append(Action.close)
case .merged: break // can't do anything
}
if result.status.locked {
models.append(Action.unlock)
} else {
models.append(Action.lock)
}
return models
}
@@ -203,19 +199,18 @@ PeopleViewControllerDelegate {
) -> CGSize {
guard let containerWidth = collectionContext?.containerSize.width
else { fatalError("Collection context must be set") }
switch viewModel {
case is IssueManagingExpansionModel:
let width = floor(containerWidth / 2)
return CGSize(width: width, height: Styles.Sizes.labelEventHeight)
default:
// justify-align cells to a max of 4-per-row
let itemsPerRow = CGFloat(min(self.viewModels.count - 1, 4))
let width = floor(containerWidth / itemsPerRow)
return CGSize(
width: width,
height: IssueManagingActionCell.height
)
}
let height = IssueManagingActionCell.height
let width = HangingChadItemWidth(
index: index,
count: viewModels.count,
containerWidth: containerWidth,
desiredItemWidth: height
)
return CGSize(
width: width,
height: height
)
}
func sectionController(
@@ -223,12 +218,7 @@ PeopleViewControllerDelegate {
cellForViewModel viewModel: Any,
at index: Int
) -> UICollectionViewCell & ListBindable {
let cellClass: AnyClass
switch viewModel {
case is IssueManagingExpansionModel: cellClass = IssueManagingExpansionCell.self
default: cellClass = IssueManagingActionCell.self
}
guard let cell = collectionContext?.dequeueReusableCell(of: cellClass, for: self, at: index) as? UICollectionViewCell & ListBindable
guard let cell = collectionContext?.dequeueReusableCell(of: IssueManagingActionCell.self, for: self, at: index) as? IssueManagingActionCell
else { fatalError("Cell not bindable") }
return cell
}
@@ -247,15 +237,7 @@ PeopleViewControllerDelegate {
let cell = collectionContext?.cellForItem(at: index, sectionController: self)
else { return }
if let cell = cell as? IssueManagingExpansionCell {
expanded = !expanded
cell.animate(expanded: expanded)
updating = true
update(animated: trueUnlessReduceMotionEnabled, completion: { [weak self] _ in
self?.updating = false
})
} else if viewModel === Action.labels {
if viewModel === Action.labels {
let controller = newLabelsController()
present(controller: controller, from: cell)
} else if viewModel === Action.milestone {