469 Commits

Author SHA1 Message Date
Huy Nguyen
3ccc2f0f15 Introduce ASCollectionGalleryLayoutDelegate (#76)
* Implement ASCollectionGalleryLayoutDelegate
- It arranges items of the same size into a multi-line stack (say photo gallery or pager). It takes advantage of the fact that its items always have a fixed size to measure as few items as possible while still being able to track their positions at all time. This helps reduce startup/reloadData time, as well as memory footprint.
- It then uses a measure range, which also works as a allocate range, to figure out which items to measure ahead of time. And it guarantees that each item is scheduled to measure only once.
- Lastly, ASCollectionLayoutDelegate has some new methods that allow delegates to hook up and stay ahead of layout attributes requests from the backing view. ASCollectionGalleryLayoutDelegate for example uses these methods to ensure elements that have their layout attributes requested are always ready for consumption, and to measure more elements in the background.

* Handle items that span multiple pages and other improvements in gallery delegate

* Minor fixes

* Fix failing tests

* Fix custom collection example

* Implement missing method in gallery layout delegate

* Fix warnings

* Some improvements
- Collection layout delegates must have a crollable directions property.
- Simplify gallery delegate by not storing unmeasured attributes since calling measure on already measured elements should be cache hits and super fast.
- Abstact some code in gallery delegate to ASCollectionLayoutState+Private and _ASCollectionGalleryLayoutItem.
- Other improvements in gallery delegate

* Fix file licenses

* Move measure range logic to ASCollectionLayout

* Track unmeasured elements

* Remove pending layout in ASCollectionLayout

* Get back pending layout because the timing to latch new data is not ideal

* Add ASCollectionLayoutCache

* Fix file licenses

* Fix xcodeproj

* Add async collection layout to examples/ASCollectionView

* Measure method in ASCollectionLayout to be a class method

* Encourage more immutable states
- Make -calculateLayoutWithContext: to be class methods in ASDataControllerLayoutDelegate and ASCollectionLayoutDelegate.
- Add layout delegate class and layout cache to ASCollectionLayoutContext+Private, to be use by ASCollectionLayout only.
- ASDataController no longer allocates all nodes but lets ASCollectionLayout determine.
- Add scrollableDirections to the layout context since it's often needed by the layout pass. Otherwise users have to wrap it in an info object.
- Update built-in layout delegates and CustomCollectionView example.
- Publish ASHashing. It might be helpful for clients that implement custom collection info objects.

* Remove additionalInfo property in ASCollectionLayoutState

* ASCollectionLayoutState to correctly filter unmeasured elements

* Add ASHashing to umbrella header

* Fix file licenses

* Add ASDispatchAsync and use it in ASCollectionLayout

* Improve code comment in ASCollectionLayoutState
2017-07-14 18:50:26 +00:00
Adlai Holler
d00ed249e5 Introduce ASIntegerMap, improve our changeset handling #trivial (#405)
* Introduce ASIntegerMap, improve our changeset handling

Rename to ASIntegerMap

License header

* Add unit tests for ASIntegerMap

* Address nit
2017-07-05 13:29:02 -07:00
Adlai Holler
8ec4b312cf Overhaul our logging, add activity tracing support. (#399)
* Improve the os_log and os_activity integration

* Address feedback from Scott and Huy
2017-07-03 19:03:26 -07:00
appleguy
2cda73a334 [ASTextNode2] Provide compiler flag to enable ASTextNode2 for all usages. (#410)
* [ASTextNode2] Provide compiler flag to enable ASTextNode2 for all usages.

The runtime switch is helpful, but is too slow to be shipped in a large
production application where startup time is carefully optimized.

Although this doesn't pass text-related snapshot tests when enabled, it
does allow apps to rely on built-in components like ASButtonNode using
the same text stack as when they are manually creating ASTextNode2
instances.

A simpler approach would be to use a #define ASTextNode ASTextNode2,
but this would create unusual keyword highlighting in code referencing
ASTextNode. However, because it would be less invasive and this is
not on by default, we could do that instead if preferred.

* Update AsyncDisplayKit.h

* [ASTextNode2] Improve naming and documentation of ASTEXTNODE_EXPERIMENT_GLOBAL_ENABLE

* [ASTextNode2] CHANGELOG.md for #410.
2017-07-02 21:40:51 -07:00
Adlai Holler
fcb293e049 Fix issue where supplementary elements don't track section changes (#404)
* Fix collection view supplementary issue

* Add a fast-path

* Remove the old index path entry unconditionally

* Handle overwriting bug
2017-07-01 10:55:59 -07:00
Adlai Holler
58641a85ab Minor cleanup work (#402) 2017-06-30 16:26:19 +01:00
Huy Nguyen
c603ef0ef2 [ASLayout] Revisit the flattening algorithm (#395)
* Implement tests for the layout flattening process

* Refactor the flattening algorithm
- Remove flattened flag
- No more self check
- Stop traversing a layout tree branch when hits a displaynode node.
- Reuse as many existing ASLayout objects as possible

* Update changelog

* Ceil position values before comparing

* Explain why sublayout elements must be retained
2017-06-29 18:39:04 +01:00
Adlai Holler
5357d259fa Add new workspaces for tests for different integrations (#377) 2017-06-21 11:06:43 -07:00
Adlai Holler
4829a8643d Improve System Trace Implementation #trivial (#368)
* Improve the kdebug, system trace integration

* Remove superseded subsystem

* Address review comments

* Please the license header gods

* Address harder

* Fix node block retaining collection view
2017-06-19 10:14:39 -07:00
Adlai Holler
d9dec8fdf9 Fix memory leaks, add section-object support to new test harness (#360) 2017-06-16 09:25:16 -07:00
Adlai Holler
6b3f8f8ad7 Add support for keeping letting cell nodes update to new view models when reloaded. #trivial (#357)
* Add support for skipping reload if node decides it is compatible with new view model also

* Sort things right

* Put the order back

* No need for redundant expectation

* Fix license header

* Fix comment
2017-06-13 10:10:37 -07:00
Adlai Holler
c297060113 Add a unit test for double-initial-load issue (#352) 2017-06-12 13:13:49 -07:00
Adlai Holler
8af1538a5b Add a Flag to Disable Main Thread Assertions #trivial (#348)
* Add a thread-flag for disabling main thread assertions

* Fix the license header
2017-06-11 18:53:20 -05:00
Adlai Holler
69e69873cc Migrate to Latest OCMock, Demonstrate Improved Unit Testing (#347)
* Update OCMock 2.2 -> 3.4

* Clean up and port ASMultiplexImageNodeTests

* Clean up

* Be stricter about order

* Log change

* Update the licenses #important

* Update the license headers more
2017-06-11 11:41:30 -05:00
appleguy
b285ece35f [Yoga] Implement ASYogaLayoutSpec, a simplified integration strategy for Yoga. (#270)
* [Yoga] Implement ASYogaLayoutSpec, an experimental alternative to full-tree integration.

This approach allows us to avoid any ASDisplayNode.mm integration points.
However, it is not yet proven to be possible to achieve correctness with this approach.

The entry point (to start calculating), and the measurement function inputs, lack
the full expressiveness of ASSizeRange; we need to make sure that workarounds like
using style.minSize are successful in simulating the behavior of a full Yoga tree.

* [Yoga] Fix file comments, move towards <ASLayoutElement> support.

* [Yoga] Important fix for simplified, non-contiguous Yoga integration.

* [Yoga] Complete implementation of manual memory management (__bridge_transfer, YGNodeFree)
2017-05-29 15:39:24 -07:00
Michael Schneider
50af2e92db [IGListKit] Add IGListKit headers to public section of Xcode project (#286)
* Add IGListKit headers to public section of Xcode project

* Add changelog
2017-05-18 07:43:53 -07:00
Huy Nguyen
8c45eaefce [Batch Fetching] Add ASBatchFetchingDelegate (#281)
* Add ASBatchFetchingDelegate
- In addition to checking remaining leading screens, ASBatchFetching now also calculates a remaining time and consults its delegate if needed.
- The delegate can override the decision of ASBatchFetching, for example based on remaining time and average time of past batch requests.

* Fix up tests

* Update CHANGELOG
2017-05-17 13:26:30 +01:00
Michael Schneider
b32e69d64b [Layout] Extract layout implementation code into it's own subcategories (#272)
* Extract layout code into ASDisplayNode categories

* Category renaming and documentation

* Changelog

* Change header
2017-05-15 11:10:59 -07:00
Adlai Holler
d4725a51f2 Add Experimental Text Node Implementation (#259)
* Add experimental text node implementation, based on YYText

* Fix warnings and alert when unimplemented experimental features are used.

* Address feedback from review

* Extend the cthulog

* Update license headers
2017-05-14 12:02:07 -07:00
Adlai Holler
0143e3291a Improve Ancestry Handling, Avoid Assertion Failure (#246)
* Improve our handling of ancestry

* Increase chungalunga
2017-05-09 18:27:54 -07:00
Huy Nguyen
ca2885cf06 Implement ASPageTable (#81)
* Implement ASPageTable
- It is a screen page table that can be used to quickly filter out objects in a certain rect without checking each and every one of them.
- ASCollectionLayoutState generates and keeps a table that maps page to layout attributes within that page.
- ASCollectionLayout (and later, ASCollectionGalleryLayoutDelegate) consults its layout state for `layoutAttributesForElementsInRect:`. This ensures the method can return as quickly as possible, especially on a large data set (I heard some people have galleries with thousands of photos!).

* Address comments

* Handle items that span multiple pages

* Make danger happy
2017-05-04 12:43:02 +01:00
Adlai Holler
c671d2c6c6 Fix issues in the project file (#224) 2017-05-02 14:17:30 -07:00
Adlai Holler
a7656766f9 Make Cell Node Properties Atomic (#74)
* Make ASCellNode indexPath and supplementaryElementKind atomic

* Update the change log

* Fix licenses

* Be explicit with atomic

* Rename the protocol

* And the file
2017-05-02 14:09:12 -07:00
Adlai Holler
456dc8535d Simplify Hashing Code (#86)
* Simplify hashing

* Update chingling

* Update license
2017-04-29 15:23:00 -07:00
Adlai Holler
67387c0978 Build a Tips system (#19) 2017-04-19 19:51:24 -07:00
Phil Larson
3164d8d013 [ASCollectionNode] Add _ASCollectionReusableView container for supplementary nodes (#3255)
* Add _ASCollectionReusableView container for ASCollectionNode supplementary nodes with applyLayoutAttributes support

• Adds support for -[ASCellNode applyLayoutAttributes:] to supplementary nodes

* Ensure _ASCollectionReusableView has layoutAttributes if the collection view doesn’t set them

* Use correct layoutAttributes accessor for supplementary elements
2017-04-13 16:16:40 -07:00
Huy Nguyen
5ef1d2b541 Improve hash functions of image and text nodes (#3265)
* Improve hash functions of image and text nodes

* Move ASEqualityHashHelpers to Private/
2017-04-13 16:13:21 -07:00
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
Garrett Moon
8c3775f5e2 Need to check availability before use of macros. (#3254)
* Need to check availability before use of macros.

* Get rid of PCH and enforce macro definition.

* Remove prefix

* Switch to global warning instead, much better.
2017-04-10 15:06:40 -07:00
Huy Nguyen
75ad248f8c Fix failing build in XCode 8.3 (#3241) 2017-04-04 14:37:45 -07:00
Michael Schneider
1f042e960d [ASNetworkImageNode] Improve locking (#3187)
* Locking improvements for ASNetworkImageNode

* Fix typo

* Address comments

* Address comments

* Change comment to kick build
2017-03-28 10:42:59 +01:00
Michael Schneider
dae3a72d4b [Tests] Add launch image back for test host app (#3171)
* Add launch image back

* Add TestHostResources back to BUCK file

* Use the new launch image in Buck
2017-03-13 09:10:55 -07:00
Adlai Holler
a0e67a8b15 ASMultidimensionalArrayUtils -> ASTwoDimensionalArrayUtils (#3157)
* Requery subarray count less in ASMultidimensionalArrayUtils

* Simplify (gut) ASMultidimensionalArrayUtils

* Remove weird change

* Add bounds-checking for graceful failure
2017-03-10 14:33:30 +00:00
Adlai Holler
d59ea3902d Initial Work for Range Controller to Support Supplementary Elements (#3140)
* Initial work supporting supplementaries in range controller

* Rename indexPathForElementIfItem
2017-03-06 10:11:00 -08:00
Adlai Holler
93809bd4e7 Add a Convenience Property to Get Owning View Controller (#3076)
* Add a convenience property -closestViewController

* Address comments
2017-03-02 11:51:16 -08:00
Adlai Holler
7763356b8a Replace IGListKit Method Macros with Actual Methods (#3094)
* Replace IGListKit macros with methods

* Remove docs in impl

* Update example
2017-02-27 11:08:39 -08:00
Huy Nguyen
421a896713 Clean up snapshot test cases (#3091)
* Clean up snapshot test cases:
- Drop 32bit snapshots
- Update iOS 9 snapshots and move some others to the correct directory
- Remove `setUp` overrides in subclasses of `ASLayoutSpecSnapshotTestCase` that set `recordMode` flag. Doing so in multiple places make it difficult to enable/dis
able the flag for all layout spec test cases. It can always be overridden locally if need
to.
- Fix BUCK build

* Fix testThatOnDidLoadThrowsIfCalledOnLoadedOffMain of ASDisplayNodeTests
2017-02-27 09:14:40 -08:00
Adlai Holler
73ca6ab514 Shuffle & Cleanup Stuff (#3080) 2017-02-26 18:14:13 -08:00
Huy Nguyen
e48edef4e7 [ASStackLayoutSpec] Implement flex wrap (#2914)
* Implement flex wrap

* Add tests for content alignments

* Revert unnecessary changes

* More flex wrap tests

* Define FB_REFERENCE_IMAGE_DIR in scheme

* Clean up ASStackPositionedLayout
2017-02-26 11:48:32 -08:00
Adlai Holler
9c82ae9284 Add ASRectTable (#3077) 2017-02-24 16:38:17 -08:00
Adlai Holler
1775bf29f5 ASDataController: Adopt ASElementMap (#3073)
* Build ASElementMap and use it

* Keep building!

* Clean up

* Restrict ASDataController subclassing

* Clean up more

* More rearranging

* Dear lord it's time for bed

* Make things clearer

* Sadly remove subclassing restriction for ASDataController

* Remove dead initializer
2017-02-24 13:23:29 -08:00
Adlai Holler
86dd918143 Promote ASIndexedNodeContext -> ASCollectionElement (#3061)
* Remove indexPath field from ASIndexedNodeContext

* Rename ASIndexedNodeContext -> ASCollectionItem

* Name it ASCollectionElement
2017-02-22 16:55:02 -08:00
Huy Nguyen
74c6cca0b6 [ASDataController] Refactor ASDataController (#3017)
* Refactor ASDataController

Check optional methods in ASDataControllerSource

* Reimplement reloadData

* Refactor new code
- No more new/inserted contexts flag
- Encapsulate code shared between reloadData and updateWithChangeSet
- Remove dataControllerWillDeleteAllData delegate method
- Hierarchy changes no longer needs to conform to NSCopying
- Reword TODOs

* Forgot to call completion block of reloadData :P

* Completion block of -[ASDataController reloadDataWithCompletion:] is nullable

* Data queried from ASCollectionNode and ASTableNode should be in UIKit index space
- This helps to avoid immature node allocation, especially when node virtualization is a thing
- However, this means that -reloadDataInitiallyIfNeeded in ASCollectionNode and ASTableNode must wait until all updates are finished.

* ASDataController shouldn't assume that allocated nodes were also laid out

* Revert "Data queried from ASCollectionNode and ASTableNode should be in UIKit index space"

This reverts commit 7bc977b3808a92f484b297781d0f5b30aa258e17.

* -nodeAtIndexPath: of ASDataController now forces node allocation, with the assumption that clients absolutely need it.
- Revisit this when node virtualization is implemented.

* ASDataController only grab changeSet.completionHandler when needed because it'll be niled out

* Fix ASTableViewTests related to reloadData

* Fix testThatDeletedItemsAreMarkedInvisible in ASCollectionViewTests

* Minor changes in ASCollectionView and ASTableView

* ASCollectionView and ASTableView shouldn't call [super reloadData] before their data controller does anything

* Address comments

* Fuse reloadData into -updateWithChangeSet: of ASDataController

* reloadData shouldn't be called as if it's inside a batch
- It can't be used in conjuntion with other updates.
- Calling it inside a batch update during the initial load can cause data inconsistency thrown by UICollectionView/UITableView

* Refactor ASDataControllerDelegate and ASRangeControllerDelegate
- Replace delegate methods in these protocols with -willUpdateWithChangeSet and -didUpdateWithChangeSet.
- ASRangeController, ASCollectionView and ASTableView are simplified because of this.

* Fix mismatch between sorting orders in ASDataController

* Forgot to call completion handler of reload change sets

* Make sure ASCollectionView is compatible with the behavior of UICollectionView's reloadData
- Since UICollectionView's reloadData doesn't requery data source but defers until the next layout pass,  we need to wait until then to update range controller and do batch fetching.
- `-[ASCollectionView waitUntilAllUpdatesAreCommited]` needs to force a layout pass to make sure
everything is ready after it returns.

* testSectionIndexHandling of ASTableViewTests should only check visible nodes. Other nodes will be re-measured later.

* ASTableView is not ready until the first layout pass finished

* Address comments

* Bug fixes
2017-02-22 13:50:07 -08:00
Adlai Holler
fab98b32ef Fix Pager Node Issues (#3028)
* Fix pager node and deprecate zeroContentInsets flag

* Do it with the visible state callback

* There we are

* Put viewController in node debug description
2017-02-14 14:10:51 -08:00
Adlai Holler
bbc1aecf95 Deprecate shouldRasterizeDescendants (#3024)
* Deprecate shouldRasterizeDescendants

* Set superclass right
2017-02-13 13:34:53 -08:00
Michael Schneider
2dca7a0c8d [Debug] Remove not used code around visualizing layout specs (#2991)
* Remove not used code around visualizing layout specs

* This is sad to see but let’s remove the LayoutSpecPlayground for now
2017-02-10 13:09:09 -08:00
appleguy
f91265757e [Yoga] Initial commit for supporting Yoga-powered layout calculation. (#2982)
* [Yoga + AsyncDisplayKit] Initial commit for supporting Yoga-powered layout calculation.

Because this results in ASLayout objects, it preserve support for automaticallyManagesSubnodes
as well as the animated transition system. More work remains to vet performance of the new mode,
and it will remain in +Beta for the forseeable future.

I'm not sure that this should ever be used as the primary ASDK layout system, but it should remain an
option for some apps to experiment with if they require an implementation that more strictly mirrors
W3C standard Flexbox.

* [Yoga] Improve usage of ASHierarchyState to ensure simultaneous yoga layouts can't happen.

* [Yoga] Strictly minimize the impact of the Yoga integration on existing code.

Created new file ASDisplayNode+Yoga.mm, reduced size and number of integration points in core code.

* [Yoga] Figured out how to further reduce ASDisplayNode.mm impact by allocating _yogaNode in property accessor, and changing all accesses to use the property.
2017-02-09 16:10:29 -08:00
Michael Schneider
f21254593d [Layout] Add extensibility support to ASLayoutElementStyle (#2975)
* Add extensibility support to ASLayoutElementStyle

* Fix some typo
2017-02-07 10:34:09 -08:00
Adlai Holler
86b669dc38 Improve TableLayoutController: Simplify, Fix Crash & Improve Perf (#2969)
* Refactor FlowLayoutController -> TableLayoutController

* Use most conservative row index path
2017-02-05 18:24:15 -08:00
Scott Goodson
f71eba77af [ASCollectionView] Finish support for interoperability with base-class UICollectionViewCells.
This also supports supplementary nodes. It builds off of Adlai's .interop flag but makes necessary
improvements for all of the delegate methods to work in practice with heterogenous cell types.
2017-02-04 20:40:44 -08:00