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

Fixed the invalidating heights animation #164

Merged
merged 1 commit into from
Jul 28, 2017

Conversation

jay18001
Copy link
Contributor

Closed #153

@@ -218,6 +218,12 @@ open class BrickCell: BaseBrickCell {
_brick.brickCellTapDelegate?.didTapBrickCell(self)
}

open override func apply(_ layoutAttributes: UICollectionViewLayoutAttributes) {
UIView.animate(withDuration: UIView.inheritedAnimationDuration, animations: {
Copy link
Contributor

Choose a reason for hiding this comment

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

There shouldn't be a UIView.animate for every apply

@jay18001 jay18001 force-pushed the invalidating-heights-animated branch 3 times, most recently from 96a669d to 4ca390e Compare July 24, 2017 20:20
@@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed?

Copy link
Contributor Author

@jay18001 jay18001 Jul 25, 2017

Choose a reason for hiding this comment

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

I think this is an artifact from Xcode 9

}

let size = BrickSize(width: .ratio(ratio: 1), height: newHeight)
self.brickCollectionView.resizeBrick(with: BrickIdentifiers.titleLabel, newSize: size)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we wrap it in an animation block? That way it's a good documentation on how to animate this

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the idea is that its already implicitly animated since it delegates to performUpdates function which also does this. wrapping it in an animation block doesn't have any effect if you just want the default animation parameters

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, there is a default animation, warping it in an animation block only changes the the duration.

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand, but it would be good to demonstrate how to change the duration (and animation options)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, no big deal

@@ -234,7 +234,27 @@ open class BrickCollectionView: UICollectionView {
self.collectionViewLayout.invalidateLayout(with: BrickLayoutInvalidationContext(type: .invalidate))
}, completion: completion)
}


open func resizeBrick(with identifier: String, newSize: BrickSize, completion: ((Bool) -> Void)? = nil) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also supply an optional index as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure

brick.size = newSize
}

self.collectionViewLayout.invalidateLayout(with: BrickLayoutInvalidationContext(type: .invalidate))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not, removing


open func resizeBrick(with identifier: String, newSize: BrickSize, completion: ((Bool) -> Void)? = nil) {
self.performBatchUpdates({
if let indexPath = self.indexPathsForBricksWithIdentifier(identifier).first {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should hold a reference to the fetched indexPahts, so we can use them later. Also, why are we only doing first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The index path may have changed after the invalidateLayout so we have to get it again

Copy link
Contributor

Choose a reason for hiding this comment

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

Why would the indexPaths have changed?

Copy link
Contributor Author

@jay18001 jay18001 Jul 27, 2017

Choose a reason for hiding this comment

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

It would because we we calling invalidate layout but now since we don't that that's no longer an issue

open override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
guard self._brick.height.isEstimate(withValue: nil) else {
return layoutAttributes
}

let preferred = layoutAttributes.copy() as! UICollectionViewLayoutAttributes
let preferred = layoutAttributes
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we revert this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't seem to have any side effects by the looks of it

@jay18001 jay18001 force-pushed the invalidating-heights-animated branch from 4ca390e to 3359fd5 Compare July 25, 2017 17:44
@codecov-io
Copy link

codecov-io commented Jul 25, 2017

Codecov Report

Merging #164 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #164   +/-   ##
=======================================
  Coverage   93.42%   93.42%           
=======================================
  Files          39       39           
  Lines        4107     4107           
  Branches      333      332    -1     
=======================================
  Hits         3837     3837           
  Misses        269      269           
  Partials        1        1
Impacted Files Coverage Δ
Source/ViewControllers/BrickCollectionView.swift 95.41% <ø> (-0.01%) ⬇️
...rs/BrickCollectionView+BrickLayoutDataSource.swift 100% <100%> (ø) ⬆️
Source/Layout/BrickFlowLayout.swift 91.37% <100%> (-0.09%) ⬇️
Source/Cells/BrickCell.swift 98.49% <100%> (+0.01%) ⬆️

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 dab2eb3...0ac6344. Read the comment docs.

@jay18001 jay18001 force-pushed the invalidating-heights-animated branch from 3359fd5 to 4a3b004 Compare July 27, 2017 20:48

open func resizeBrick(with identifier: String, index: Int? = nil, newSize: BrickSize, completion: ((Bool) -> Void)? = nil) {
self.performBatchUpdates({
if let indexPath = self.indexPathsForBricksWithIdentifier(identifier, index: index).first,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we only taking the first one? Should we just make index non-optional then?

@@ -149,7 +149,7 @@ open class ImageBrickCell: GenericBrickCell, Bricklike, AsynchronousResizableCel
fileprivate var imageLoaded = false
fileprivate var currentImageURL: URL? = nil

@IBOutlet public weak var imageView: UIImageView!
@IBOutlet weak var imageView: UIImageView!
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this changed?

@jay18001 jay18001 force-pushed the invalidating-heights-animated branch from 4a3b004 to 0ac6344 Compare July 27, 2017 21:13
@rubencagnie rubencagnie merged commit bb7128a into master Jul 28, 2017
wfsttam added a commit to wfsttam/brickkit-ios that referenced this pull request Sep 15, 2017
…-archive#164. This fixes issue where scrolling in a carousel that used collection brick caused cells above to re-size to a smaller size than what was already calculated
rubencagnie added a commit that referenced this pull request Sep 18, 2017
@jay18001 jay18001 deleted the invalidating-heights-animated branch November 2, 2017 18:26
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.

None yet

4 participants