Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inserting/deleting items from middle of a brickCollectionView #149

Conversation

ethan-riback
Copy link
Contributor

Items can now be inserted and deleted from anywhere in the brickCollectionView and the collectionView will be responsive to the change.

@codecov-io
Copy link

codecov-io commented Jul 11, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@a78005e). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #149   +/-   ##
=========================================
  Coverage          ?   93.49%           
=========================================
  Files             ?       39           
  Lines             ?     3181           
  Branches          ?        0           
=========================================
  Hits              ?     2974           
  Misses            ?      207           
  Partials          ?        0
Impacted Files Coverage Δ
Source/Layout/BrickFlowLayout.swift 93.07% <100%> (ø)
Source/Layout/BrickAppearBehavior.swift 100% <100%> (ø)
Source/ViewControllers/BrickCollectionView.swift 95.36% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a78005e...88d16ee. Read the comment docs.

}

extension SegmentHeaderBrickDataSource {
func configure(cell: SegmentHeaderBrickCell) {/*Optional*/}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an old brick. Ideally, we should use GenericBrick<UISegementedControl>...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this to generic brick

return ["No animation", "From top", "From bottom", "Fade in"]
}

var insertToIndex: Int {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable name is a bit confusing, feels more like a function name. Can you call it more indexToInsertTo?

@@ -49,47 +67,38 @@ class InsertBrickViewController: BrickApp.BaseBrickController, HasTitle {
self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(InsertBrickViewController.insertBrick))

let section = BrickSection(Section, bricks: [
SegmentHeaderBrick(dataSource: self, delegate: self),
LabelBrick(BrickIdentifiers.repeatLabel, backgroundColor: UIColor.lightGray, dataSource: self)
BrickSection(bricks: [SegmentHeaderBrick("AppearSegmentHeaderBrick", dataSource: self, delegate: self),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make the string into constants?
Can you also align the bricks, so it's a bit more readable?

        let section = BrickSection(Section, bricks: [
            BrickSection(bricks: [
                        SegmentHeaderBrick("AppearSegmentHeaderBrick", dataSource: self, delegate: self),
                        SegmentHeaderBrick("InsertSegmentHeaderBrick", dataSource: self, delegate: self)
            ]),
            LabelBrick(BrickIdentifiers.repeatLabel, height: .fixed(size: 37), backgroundColor: UIColor.lightGray, dataSource: self)
            ], inset: 10, edgeInsets: UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

} else {
data.insert(newElement, at: index)
}
updateRepeatCounts(fixedInsertedIndexPaths: [IndexPath(item: index + 1, section: 1)])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BrickKit is designed so the consumer doesn't need to know about indexPaths, so this concerns me a bit. I probably want the API to be a bit more in the trend of

insertItem(for identifier: String, atIndex index: Int)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this

@@ -12,7 +12,9 @@ import BrickKit
private let Section = "Section"

class InsertBrickViewController: BrickApp.BaseBrickController, HasTitle {


var data: [String] = ["Brick 1"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repeated bricks have the title let newElement = "BRICK \(data.count + 1)". So this should be upper case String

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

var titles: [String] {
return ["No animation", "From top", "From bottom"]
var appearTitles: [String] {
return ["No animation", "From top", "From bottom", "Fade in"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look good on an iPhone 5(S). Can we abbreviate these a bit more?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@ethan-riback ethan-riback force-pushed the dynamically-insert-and-delete-from-collection-view branch 2 times, most recently from de070cc to fc7d529 Compare July 14, 2017 14:46
…ctionView and the collectionView will be responsive to the change.
@ethan-riback ethan-riback force-pushed the dynamically-insert-and-delete-from-collection-view branch from fc7d529 to 88d16ee Compare July 14, 2017 14:59
@rubencagnie rubencagnie merged commit 8766e73 into wayfair-archive:master Jul 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants