227 Commits

Author SHA1 Message Date
Adlai Holler
d2adb8f126 Rename -[ASCellNode viewModel] to -[ASCellNode nodeViewModel] to avoid collisions (#499)
* Rename -[ASCellNode viewModel] -> -[ASCellNode nodeViewModel] to avoid breaking existing code

* Update test

* Update the changelog
2017-08-07 11:04:31 -07:00
Huy Nguyen
69a915356d [ASStackLayoutSpec] Fix interitem spacing not being reset on new lines and add snapshot tests #trivial (#491)
* Add snapshot tests for interitem and interline spacings of stack spec

* Improve comment

* Make sure item spacings are properly considered and reset on new lines, snapshot tests included
2017-08-06 13:20:33 +01:00
Christian Selig
10efa31abd iOS 11 UITableView automatic height estimation fix (#485)
* Add iOS 11 checks.

* Negate iOS 11 automatic table height estimatation

* Negate iOS 11 automatic estimated table row heights

* Add note about iOS 11 estimated height behavior
2017-08-04 18:06:30 +01:00
Huy Nguyen
3c6b836571 Make sure _locked_constrainedSizeForLayoutPass is called with the lock held (#488) 2017-08-04 16:24:05 +01:00
Huy Nguyen
27abc771e0 [Layout Transition] Avoid calling didComplete method if pending layout transition is nil (#490)
* Avoid calling didComplete method if pending layout transition is nil

* Update CHANGELOG
2017-08-04 16:22:39 +01:00
Flo
ba08ae1318 [ASStackLayoutSpec] Flex wrap fix and lineSpacing property (#472)
* ASStackUnpositionedLayout: Take spacing into account when laying out a wrapped stack.

* ASStackLayoutSpec: Add the lineSpacing property.

* Update CHANGELOG.md.
2017-08-03 11:24:08 +01:00
appleguy
9a14f279aa [ASNodeController] Add -nodeDidLayout callback. Allow switching retain behavior at runtime. (#470)
With these changes, I'd also like to propose that we move ASNodeController
out of Beta (renaming the files without +Beta). Let me know what you think!

Because we don't support ASNodeController directly in ASCV / ASTV, it is still
important to allow flipping the ownership in certain cases (in particular, for
root CellNodeController objects that should follow the lifecycle of the
ASCellNode rather than owning the ASCellNode).
2017-07-27 01:07:53 -07:00
Adlai Holler
01c14f0fc2 Invalidate layouts more aggressively when transitioning with animation (#476)
* Be more aggressive at invalidating layouts during transitions, add a debug method, fix some build errors when verbose logging

* Add a changelog entry
2017-07-26 22:27:58 -07:00
Huy Nguyen
8b397cd04e [Layout transition] Invalidate calculated layout if transitioning using the same size range (#464)
* Invalidate the calculated layout transitioning using the same size range
- It's possible that -transitionLayoutWithSizeRange: can be called with the same size range used for previous layout passes. In that case, it's necessary to invalidate the current layout to avoid it being reused later on in the process.

* Fix CHANGELOG
2017-07-24 11:00:43 -07:00
Huy Nguyen
01715f09d8 [ASDisplayNode] Fix infinite layout loop (#455)
* Fix infinite layout loop

- The problem will occur if a node does either of the followings:
1. Keeps using a stale pending layout over a calculated layout
2. Doesn't update the next layout's version after calling _setNeedsLayoutFromAbove.

* Update CHANGELOG
2017-07-18 19:44:27 +00:00
Huy Nguyen
6880ed4aa9 Add ASPagerNode+Beta to umbrella header (#454) 2017-07-18 17:05:59 +00:00
Huy Nguyen
78c133e44c [ASCollectionLayout] Add ASCollectionGalleryLayoutSizeProviding (#451)
* Add ASCollectionGalleryLayoutSizeProviding
- This allows users to return different sizes based on certain conditions, such as the collection node's bounds or grid constants.
- ASPagerNode will also act as a size provider to ensure all pages have an up-to-date size that is its bounds.

* Update CHANGELOG

* ASPagerNode to use gallery layout delegate if told to
2017-07-18 10:08:12 +00:00
Huy Nguyen
7af8f91e62 Remove unused flow layout reference in ASPagerNode (#452) 2017-07-17 21:01:00 +00:00
Huy Nguyen
eb5bde0791 [ASDataController ] Merge willUpdateWithChangeSet and didUpdateWithChangeSet delegate methods #trivial (#445)
* Merge willUpdateWithChangeSet and didUpdateWithChangeSet delegate methods into one
- After #420, there is no change occurs between those 2 methods. Having them separately doesn't achieve anything and can cause confusions.

* Minor change
2017-07-17 11:43:31 +00:00
Huy Nguyen
292dc3c70b [ASDataController] Clean up (#443)
* Clean up ASDataController
- Parameters passed to ASDataControllerCompletionBlock are no longer used. Remove them.
- The value returned by _allocateNodesFromElements:andLayout:completion is not used. Remove it.
- Elements are not allocated and measured in batches anymore. Remove the code that does batch allocation.
- Remove RETURN_IF_NO_DATASOURCE. It's used only once and is not worth it.

* Remove +parallelProcessorCount

* Update CHANGELOG
2017-07-17 11:42:52 +00:00
Huy Nguyen
7302816b2f [ASDataController] Avoid asking for size ranges of soon-to-be-delete elements during relayouts (#442)
* ASDataController to avoid asking for size ranges of soon-to-be-deleted elements during relayouts

* Remove outdated TODOs
2017-07-17 11:37:40 +00:00
appleguy
5115f660c8 [ASCollectionView] Add delegate bridging and index space translation for missing UICollectionViewLayout properties. (#440)
* [ASCollectionView] Add delegate bridging and index space translation for missing UICollectionViewLayout properties

This is a first attempt at resolving #438.

I know there is already one similar method to do indexPath conversions, and that the #define for
accessing properties on the UICollectionViewFlowLayout should probably be moved somewhere else.

Looking for feedback on the general direction here. In particular, I'm a bit surprised that so much
has changed in how these calls occur, as I believe especially constrainedSizeForNodeAtIndexPath: is
now called with inconsistent index path spaces (but was not before this PR landed in March:
https://github.com/facebookarchive/AsyncDisplayKit/pull/3136/files)

Since the impact of mixing the spaces is fairly serious (can cause crashes), I'm also wondering if
I am misinterpreting some aspects of the code, or if maybe the crashing impact wasn't noticed yet.

* [ASCollectionView] Cleanup and final changes for UIKit passthrough fixes.
2017-07-17 11:30:46 +00:00
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
appleguy
dc06cadb8a [ASDisplayNode] Fix some gaps in the bridging of new contents* properties. (#435)
I audited this more carefully and found some gaps in my PR from yesterday.

This also ensures the grouping and ordering of all the contents properties
is consistent across all of the places they appear.

In the future, it would be great to make the #define macros more sophisticated
so that we can add property bridging with fewer lines changed, and for
objects besides ASDisplayNode too!
2017-07-13 09:53:51 +00:00
Adlai Holler
1fa498873e Use a sentinel NSUInteger for node layout data #trivial (#428)
* Use a sentinel NSUInteger for node layout data

* Add a comment

* Address feedback from @appleguy
2017-07-10 12:10:04 +00:00
appleguy
bc361caf5e [ASDisplayNode] Allow setting stretchable contents on nodes; add bridged properties. (#429)
This makes it much easier to use the ASCoreAnimationExtras method which offers by
far the most efficient way to display a stretchable image.

In the future, we should move that function to UIImage+ASConvenience or another
header where it can be more easily found and enjoyed!
2017-07-09 10:54:39 -07:00
Brandon Kase
554c688eba Workaround clang4.0 <stdatomic.h> initialization (#426)
Texture fails to build with this error on clang 4.0:

```
external/Texture/pod_support/Headers/Public/AsyncDisplayKit/ASDispatch.h:32:35: error: illegal initializer type 'atomic_size_t' (aka '_Atomic(size_t)')
  __block atomic_size_t counter = ATOMIC_VAR_INIT(0);
                                  ^
In module 'std' imported from external/Texture/pod_support/Headers/Public/AsyncDisplayKit/ASStackUnpositionedLayout.h:18:
/private/var/tmp/_bazel_bkase/a00d4cbe29902fb63d5778cc19944cd2/external/clang40/bin/../include/c++/v1/atomic:1839:30: note: expanded from macro 'ATOMIC_VAR_INIT'
                             ^
1 error generated.
```

See
http://techqa.info/programming/question/38233019/Initializing-an--atomic-int--with-a-braced-constant--Is-this-valid-C-code--If-so-why-does-it-not-compile-in-clang-

Replacing the intialization with just 0 (and not the macro fixes the
error). For now this is safe because the macro just expands to the
value.
2017-07-07 16:29:50 -07:00
Huy Nguyen
e78d70eec4 [ASCollectionView] Small improvements (#407)
* Minor refactors in ASCollectionView and its private cell classes
- `_ASCollectionReusableView` and `_ASCollectionViewCell` no longer expose getters for their collection element and cell node properties. This is to make sure that clients can only obtain elements from the visible map which is always the source of truth.
- Since the map can return `nil` for an element request, it's much safer to check and avoid adding/removing a nil pointer to an `NSArray`.
- Since we use a special way to check whether an object of kind of `_ASCollectionViewCell` or `_ASCollectionReusableView`, based on the assumption that these classes are subclass restricted, I added cast-or-return  macros in the header files, closer to where the restrictions are declared.

* Add ASDynamicCastStrict

* Add element and node properties back to _ASCollectionReusableView and _ASCollectionViewCell

* Assert unexpected nil elements

* Always mark an element visible even if it is backed by an UIKit / non-_ASCollection* view

* Fix typo

* Remove unnecessary changes

* Dump mistakes

* Update CHANGELOG

* Can't track visibility of elements backed by non-_AS views
2017-07-06 17:38:23 +00:00
Huy Nguyen
f1b07d97b6 Add missing import in ASDisplayNode+AsyncDisplay (#423) 2017-07-06 14:53:51 +00:00
appleguy
a68f3c5aa9 [ASCollectionElement] Add checks for nil element, prior to other PRs landing. (#421) 2017-07-05 14:14:35 -07: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
appleguy
03592e0669 [ASDisplayNode] -didEnterPreloadState does not need to call -layoutIfNeeded #trivial (#411)
This was originally added for ASCollectionNode and ASTableNode preloading to work
as intended when nested inside of another ASRangeController-powered node. Indeed,
it is still necessary to trigger layout on these UIKit-backed components in order
for their own ASRangeControllers to start preparing content within them.

However, unlike the comment suggests, it is *not* necessary to do this for image
nodes. ASNetworkImageNode has only one .URL, and does not use the .bounds or
.calculatedLayout at all during loading. Even the ASMultiplexImageNode does not
use the .bounds, and the ASMapNode uses .calculatedLayout instead of .bounds.

This change has important performance benefits. In particular, it avoids
layouts that would occur on the main thread, often including text sizing,
and also can result in redundant layout passes (even during a layout pass that
triggers a node to enter the preload range, it may force its own layout early).

It would be great to test this change with Pinterest to confirm its safety, but
based on a full audit of the framework codebase, the only possibility that I
see for a regression is if app implementations of -didEnterPreloadState make
direct use of .bounds instead of .calculatedLayout (which is easy to fix).
2017-07-05 19:07:43 +00:00
Huy Nguyen
ed9a3cc2e0 [ASDataController] Apply new visible map inside batch updates block (#420)
* ASDataController to apply new visible map inside batch updates block

* Update CHANGELOG

* Sorry, put up a PR that doesn't even build LOL
2017-07-05 19:04:17 +00:00
Huy Nguyen
4a1aea2373 [ASDataController] Fix a crash in table view caused by executing an empty change set during layoutSubviews (#416)
* Fix a crash in table view caused by executing an empty change set during layoutSubviews
- Previously, when a change set is empty, `ASDataController` forwards the change set to its delegate right away, without dispatching to its editing queue and then back to main.
- This behaviour can potentially cause bad internal states in UITableView which trigger a crash reported in https://github.com/TextureGroup/Texture/issues/83.
- Fix by still reusing the existing pending map, because the data source's state has not changed, but go through the editing queue and main queue tunnel.

* Update CHANGELOG
2017-07-05 17:55:44 +00:00
Tyler Neveldine
cf870dc8e9 [ASVideoPlayerNode] Check that the video player's delegate implements the didTapFullScreenButtonNode method before calling it #trivial (#418) 2017-07-05 12:10:58 +00:00
appleguy
fb6cad941f [ASDisplayNode+Layout] In layoutThatFits:, check and use _pending layout if valid. (#413)
I believe this check is supposed to be here. Unit tests pass with it in place.
Without it, calling layoutThatFits: (as ASDataController does) and then calling
it again later (as ASCollectionNode does when answering the sizeForItem: call)
will recompute the layout, potentially on main.

This seems to have more of an impact / benefit for Yoga layouts, but I don't think
its benefit is exclusive to them.
2017-07-05 10:02:38 +00: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
appleguy
c70a97d28f [ASTextNode2] Add initial implementation for link handling. (#396)
* [ASTextNode2] Add initial implementation for link handling.

This is a fairly basic first step to achieving feature parity between ASTextNode2
and ASTextNode. It does not yet do the 9-box detection of links, and there is
other code from ASTextNode that could be shared to improve this.

However, in the interest of getting a shippable implementation running as soon
as possible, I'm hoping to quickly refine this. Then we can continue improving
it based on the original ASTextNode with the benefit of testing UI against it.

* [ASTextNode2] Refine implementation of link handling.
2017-07-02 19:50:59 -07:00
appleguy
1d1a3787c2 [Yoga] Refine the handling of measurement functions when Yoga is used. (#408)
This ensures that measure funcs are not set for container / empty spacer
nodes, because Yoga has more internal capabilities than layoutThatFits:
knows about.

Avoid need for the main layout pass to directly call setup for measure
funcs, by making it an implicit part of .yogaLayoutInProgress =.

Tear down the measure func after the layout pass to avoid retain cycle.
2017-07-02 13:01:07 -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
Huy Nguyen
23ee9de615 If a layout has no sublayouts, don't bother initializing its rect table (#394) 2017-06-29 15:09:49 +01:00
Huy Nguyen
f7a6b7ae84 Fix documentation of ASLayout retainSublayoutLayoutElements (#393) 2017-06-28 16:14:05 +01:00
Michael Schneider
f257193e69 Fix compiling ASDimension if Yoga enabled (#389)
Exposes the <UIKit/UIGeometry.h> otherwise under some circumstances UIEdgeInsets is not defined.
2017-06-26 16:59:24 -07:00
Benjamin Chang
b14ea8b95d Comments to reflect code in ASTableNode performBatchUpdates #trival (#388) 2017-06-26 17:01:10 +01:00
Huy Nguyen
6113a33904 Remove unnecessary frame setting in ASCellNode (#387) 2017-06-25 14:59:50 +01:00
Huy Nguyen
df01adc116 ASDimensionMake to be more lenient #trivial (#382)
* ASDimensionMake to be more lenient

Don't throw assertion when the string is invalid

* Fix unit test
2017-06-23 15:14:39 +01:00
Huy Nguyen
992df78801 Gate orphaned node detector behind YOGA flag #trivial (#380)
* Gate orphaned node detector behind YOGA flag

* Tiny indentation change
2017-06-22 19:12:41 +01:00
Huy Nguyen
e264bb7eb0 [Event Log] Log ASM flag when modify subnodes #trivial (#379)
* Log ASM flag when add subnode

* Log other subnode modifications as well
2017-06-22 07:30:51 -07:00
Hannah Troisi
2dca3e5e76 [ASDataController] Add event logging for transaction queue flush duration #trivial (#334)
* Add event logging for transaction queue flush duration

* address @appleguy's comments

* Improve formatting of Event Log messages

* Small indentation fix in ASDataController
2017-06-21 22:09:35 +01:00
Adlai Holler
326925839d Fix double-load issue with ASCollectionNode (#372)
* Fix double-reload issue with ASCollectionNode

* Add a message to the change pile

* Fix some license headers

* Address feedback
2017-06-19 14:18:56 -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
appleguy
8c33a617ed [Yoga] Delete YOGA_TREE_CONTIGOUS gating and permanently enable. (#370)
[Yoga] Delete YOGA_TREE_CONTIGOUS gating and permanently enable. #trivial
2017-06-18 18:18:59 -07:00