Commit Graph
119 Commits
Author SHA1 Message Date
Huy Nguyen 7d365c7d07 Introduce ASCollectionLayout and friends (#3130)
* Introduce ASCollectionViewLayout
- `ASCollectionViewLayout` is an async `UICollectionViewLayout` that encapsulates its layout calculation logic into a separate thread-safe object which can be used ahead of time and/or on multiple threads.
- `ASDataController` now can prepare for a new layout resulted from a change set before `ASCollectionView` even knows about it. By the time the change set it ready to be consumed by `ASCollectionView`, its new layout is also ready.
- New `ASCollectionViewLayoutCalculating` protocol that is simple and generic enough that many types of calculators can be built on top. `ASCollectionViewLayoutSpecCalculator` conforms to `ASCollectionViewLayoutCalculating` protocol and can be backed by any layout spec (e.g `ASStackLayoutSpec`, `PIMasonryLayoutSpec`, etc). We can even build a `ASCollectionViewLayoutYogaCalculator` that uses Yoga internally.
- A built-in `ASCollectionViewFlowLayoutCalculator` that is a subclass of `ASCollectionViewLayoutSpecCalculator` and uses a multi-threaded multi-line `ASStackLayoutSpec` internally. The result is a performant and thread-safe flow layout calculator.
- Finally, `ASCollectionViewLayout` can be subclassed to handle a specific type of calculator with optimizations implemented based on the knowledge of such calculator. For example, `ASCollectionViewFlowLayout` can have a highly optimized implementation of `-layoutAttributesForElementsInRect:`.

Protocolize layout calculator providing and consuming

Add flex wrap documentation

Add a `multithreaded` flag to ASStackLayoutSpec that forces it to dispatch even if it's off main
- Update ASCollectionViewFlowLayoutSpecCalculator to use that flag.

Minor change in ASCollectionViewLayout

Implement Mosaic layout calculator

Minor change

Fix project file

Rename and fix project file

Skip fetching constrained size only if a layout calculator is available

Update examples/ASCollectionView

Remove unnecessary change in ASTableView

Address comments

Rename collection view calculator protocols

Minor changes after rebasing with master

Add ASLegacyCollectionLayoutCalculator for backward compatibility

Remove ASCollectionLayoutSpecCalculator

Remove ASLegacyCollectionLayoutCalculator

Introduce ASCollectionLayout
- A wrapper object that contains content size and an element to rect table.
- Collection layout calculators to return this new object instead of an ASLayout.

Before adding a content cache

Finishing hooking up ASCollectionLayoutDataSource to ASCollectionNode

Stash

Finish ASCollectionLayout

Rough impl of ASCollectionFlowLayout

Revert changes in CustomCollectionView example

Move ASRectTable back to Private

* Rename ASCollectionContentAttributes to ASCollectionLayoutState

* Address other comments

* Introduce ASCollectionLayoutDelegate and make ASCollectionLayout private

* Address comments

* API tweaks:
- Replace `-layoutContextWithElementMap:` in ASCollectionLayoutDelegate with `-additionalInfoForLayoutWithElements:`. The returned object is then stored in ASCollectionLayoutContext for later lookups.
- ASCollectionLayoutContext has no public initializer.
- ASDataControllerLayoutDelegate no longer requires a context of type ASCollectionLayoutContext but simply an `id`. This helps decouple ASDataController and ASCollectionLayout.
- Rename `elementMap` to `elements`.
- Rename `visibleMap` to `visibleElements`.
- Other minor changes.

* Rename ASCGSizeHash to ASHashFromCGSize

* Make sure to call super in -[ASCollectionLayout prepareLayout]

* Update example/ASCollectionView to use ASCollectionFlowLayoutDelegate

* Remove unnecessary change
2017-04-12 11:13:44 +01:00
Adlai Holler fcbbea51a6 Fix the Initialization Hierarchy (#3207)
* Fix the initializers setup

* Update Swift example

* Remove incorrect comment

* Add one to ASTableNode
2017-03-28 11:48:20 -07:00
Huy Nguyen 0f50cd02c9 Fix locking situation of layout transition (#3217)
- It's not safe to hold the lock of a supernode and:
  - Edit states of its subnodes
  - Call subclass hooks
  - Run completion block
  - Run animation, which can trigger layout passes on subnodes, especially if one of them is a collection view.
2017-03-24 10:35:43 -07:00
Huy Nguyen ead2086f96 Fix deadlock while laying out subnodes (#3218) 2017-03-24 10:35:34 -07:00
Adlai Holler d3d0f7be09 Add Support for the Run Loop Queue to be Weak (#3214)
* Add support for the run loop queue to be weak

* Go back to using a deque for itemsToProcess

* Update comment
2017-03-23 15:43:31 -07:00
Michael Schneider bc05227631 Check in layout transition if the supernode is still the node that is executing the transition (#3181)
We have to check in this case if the supernode of the subnode is indeed the _node that executes a layout transition. It can happen that a node already did a layout transition and added this subnode, in this case the subnode would would be removed from the new node instead of _node.
2017-03-15 13:20:01 -07:00
Huy Nguyen 7a11c4b32b Fix recursive description of ASDisplayNode (#3186)
- Before this commit:
  - Bridged properties are accessed to construct a recursive description without considering thread affinity.
  - We have multiple methods that does the same thing: generates a debug description.
- After this commit:
  - Bridged properties are accessed without triggering thread affinity assertions.
  - We have only one method that provides debug description of a node. It is then used to construct a recursive description.
2017-03-15 18:20:19 +00:00
Michael Schneider ef2ed54d0b [ASDisplayNode] Add locking to view and layer in ASDisplayNode (#3179)
* Add locking to view and layer in ASDisplayNode

* Another approach

* Some more

* Address comments
2017-03-15 09:05:38 -07:00
Michael Schneider e6ee24debc [ASDisplayNode] Improve locking in ASDisplayNode (#3172)
* Improve locking in ASDisplayNode

* Address first bunch of comments

* Changed `view` and `layer` methods for locking

* Adress comments
2017-03-14 07:27:34 -07:00
Huy Nguyen 21953c97ef -actionForLayer:forKey: of ASDisplayNode should return nil to avoid the node being animated by CA when it's being moved from one supernode to another (#3146)
This reverts commit 1d21c0bd55 introduced in #3063.
2017-03-08 14:02:12 +00:00
Michael Schneider cbd8714260 Fix crashes while subclassing ASDisplayNode and subclasses in Swift (#3143) 2017-03-07 07:36:08 -08:00
Adlai Holler 0de270fdfb Revert "Improve designated initializer usage (#3132)"
This reverts commit eaa875c7f2.
2017-03-03 15:31:28 -08:00
Michael Schneider eaa875c7f2 Improve designated initializer usage (#3132)
* Improve designated initializer usage

* Some more changes

* Add some whitespace

* Fix some warning
2017-03-03 14:49:34 -08:00
Michael Schneider 62d7e14ce1 Improve measurement code for cell nodes (#3119) 2017-03-03 09:24:04 -08:00
Michael Schneider 62c5138676 [ASDisplayNode] Fix node is showing up as black box if wrapping an UIActivityIndicatorView (#3121)
* Set the node to not opaque if it’s wrapping an UIActivityIndicatorView

* Add check for subclass of UIVisualEffectView to see if the node needs to be opaque
2017-03-02 08:57:17 -08:00
Michael Schneider 67baa44fb5 Fix -Wdocumentation warnings (#3113) 2017-03-01 11:25:37 -08:00
Garrett Moon 06b0cba68d It doesn't appear that this method needs to be protected by thread affinity? It has locking and is backed by an ivar, not UIKit. (#3107) 2017-03-01 10:57:18 -08:00
Michael Schneider 973630adc6 [ASCellNode] New way to measure ASCellNode's if layout was invalidated (#3099)
* New way to informing interaction delegate if ASCellNode get’s a setNeedsLayout call

* Remove nodeDidGetNeedsLayout as optional and better check if cell updates need to happen

* Differentiate between letting a normal display node and a cell node know that the size could have changed

* Check for _interactionDelegate is nil

* Add nullability to out pointer

* Adress comments and some renaming
2017-02-27 17:19:01 -08:00
Adlai Holler 73ca6ab514 Shuffle & Cleanup Stuff (#3080) 2017-02-26 18:14:13 -08:00