73 Commits

Author SHA1 Message Date
Huy Nguyen
ea547270f2
[ASDisplayNode] Force a layout pass on a visible node as soon as it enters preload state (#779)
This reverts commit 2e9858837251cf16c9ffd19ba2eaeaa1012c8977 (#751).

The reason we can't wait for the coming CA's layout pass is that cell node visibility events occur before the pass, at which time the cell's subnodes don't have correct frames for impression tracking.

The root cause of this problem is that, right now, cell node visible states are set by ASRangeController well before the layout pass of the hosting collection/table view. That means we're "jumping the gun". The more I think about this, the more I agree with @Adlai-Holler that we need to treat visible state differently. That is, a node should only be visible (and thus get visibility events) after it's fully loaded, it's view/layer attached to the hierarchy and laid out by a CA transaction. In other words, at the end of the CA layout pass. Such change needs time and effort to be thoroughly reviewed and tested. Until then, let's roll with this fix.
2018-01-31 15:35:14 +00:00
Michael Schneider
20e31f7d70
Fix synchronous state of node if +viewClass or +layerClass is overwritten #trivial (#776)
* Fix synchronous state of node if +viewClass is overwritten

* Also check for _layerClass overwrite for synchronous flag

* Update some code style
2018-01-31 07:07:38 -08:00
Adlai Holler
2e94bb8120
Improve no-copy rendering experiment, remove +load method (#771)
* Improve graphics contexts experiment

* Update changelog

* Remove extra space

* Add a unit test for screen scale

* Fix typo and use unique value
2018-01-30 14:18:37 -05:00
Huy Nguyen
2e98588372
[ASDisplayNode] Don't force a layout pass on a visible node that enters preload state (#751)
- After #706, a layout pass is forced on an ASM-enabled node that enters preload state to make sure that its subnodes can start preloading as well. However, when the node is visible, a (coalesced, thus more efficient) layout pass will be triggered by CA soon anyways, so rely on it instead.
2018-01-17 15:35:02 +00:00
Adlai Holler
1d105c2056
Add an experimental "no-copy" renderer (#741)
* Add "ASGraphicsContext" to skip copying our rendered images

* Zero the buffer before making a context

* Update license header

* Update dangerfile

* Make it a runtime flag

* Restore GState for good measure

* Free buffer if end without image

* Enable the experiment, and cut out the middle-man

* Fix typo
2018-01-13 19:19:08 -08:00
Huy Nguyen
5a4d569c56
Ensure an ASM enabled node applies its pending layout when enters preload state (#706)
This makes sure subnodes are inserted and start preloading right away, instead of waiting until the next layout pass of the supernode. Fixes #693.
2017-12-08 18:30:26 +00:00
Adlai Holler
0dc7002f0b Add unit tests for the layout engine (#424)
* Build testing platform & tests for the layout engine

* Add our license header to debugbreak.

* Remove thing

* Address review comments

* Beef up the logging

* Update -[ASLayout isEqual:]

* testLayoutTransitionWithAsyncMeasurement passes now

* Disable testASetNeedsLayoutInterferingWithTheCurrentTransition

* Fix build errors
2017-12-01 17:05:47 +00:00
Adlai Holler
ff608c92bf
[Minor Breaking API] Make deallocation queues more reliable (#651)
* Make our async deallocation functions take a double pointer, so we can be sure we've released before the queue drains

* Make it a class property

* Fix the return type

* Use a locker

* Improve release notes
2017-11-02 10:45:34 -07:00
Garrett Moon
255682da3d Fix a layout deadlock caused by holding the lock and going up the tree. (#638)
* Fix a layout deadlock caused by holding the lock and going up the tree.

* Add CHANGELOG message

* Huy's comments
2017-10-31 15:36:01 +00:00
Michael Schneider
a103bab00a Clear ivar after scheduling for main thread deallocation #trivial (#590)
* Clear ivar after scheduling for main thread deallocation

After scheduling the ivar for main thread deallocation we have clear out the ivar, otherwise we can run into a race condition where the main queue is drained earlier than this node is deallocated and the ivar is still deallocated on a background thread

* First clear and than schedule
2017-09-27 13:42:02 -07:00
appleguy
e330e57668 [ASCornerRounding] Introduce .cornerRoundingType: CALayer, Precomposited, or Clip Corners. (#465)
* [ASCornerRounding] Initial (untested) implementation of ASCornerRounding features.

* [ASCornerRounding] Working version of both clip corners and precomposited corners.

* [ASCornerRounding] Improve factoring and documentation of corner rounding features.

* [ASCornerRounding] Some final fixups.

* Add entry to changelog for .cornerRoundingType
2017-09-18 13:02:51 +01:00
appleguy
cfc48679ba [Yoga] Add insertYogaNode:atIndex: method. Improve handling of relayouts. (#469)
* [Yoga] Add insertYogaNode:atIndex: method. Improve handling of relayouts.

* Add new "version" parameter to Yoga initialization of ASDisplayNodeLayout C++ struct.
2017-09-17 22:45:39 -07:00
Huy Nguyen
786963c6a9 [ASDisplayNode] Deprecate -displayWillStart in favor of -displayWillStartAsynchronously: (#536)
* Deprecate -[ASDisplayNode displayWillStart] in favor of -displayWillStartAsynchronously:

* Minor change

* Fix CHANGELOG

* Update CHANGELOG.md

* Update CHANGELOG.md
2017-09-08 18:04:43 +01:00
Huy Nguyen
4ba6f451f6 [Cleanup] Remove deprecated APIs (#529)
* Remove preferredFrameSize

* Remove -measure:

* Remove -measureWithSizeRange:

* Remove ASLayoutable

* Remove .name

* Remove deprecated style forwardings

That includes following properties that are declared on ASDisplayNode and ASLayoutSpec: spacingBefore, spacingAfter, flexGrow, flexShrink, flexBasis, alignSelf, ascender, descender, sizeRange and layoutPosition.

* Remove usesImplicitHierarchyManagement

* Remove deprecated range update callbacks:
-visibilityDidChange:
-visibleStateDidChange:
-displayStateDidChange:
-loadStateDidChange:

* Remove -clearFetchedData

* Remove -cancelLayoutTransitionsInProgress

* Remve ASDisplayNode+Deprecated.h

* Remove ASLayoutRangeTypeRender and ASLayoutRangeTypeFetchData

* Remove -[ASTableView clearContents]

* Remove reloadDataImmediately

* Remove ASStaticLayoutSpec

* Remove ASDimensionDeprecated

* Remove optional -pagerNode:constrainedSizeForNodeAtIndex: delegate method in ASPagerDelegate

* Remove suppressesInvalidCollectionUpdateExceptions

* Remove -[ASCollectionViewLayoutInspector initWithCollectionView]

* Remove ASVideoPlayerNode.loadAssetWhenNodeBecomesVisible

* Update CHANGELOG

* Update license of ASLayoutSpecTests.m

* Update examples/PagerNode

* Remove ASEnvironmentTraitCollection

* Remove -ASViewController.nodeConstrainedSize

* More on removing ASLayoutable
2017-09-07 19:25:42 +01:00
appleguy
5cf05f3c17 [Accessibility] Add .isAccessibilityContainer property, allowing automatic aggregation of children's a11y labels. (#468)
After consulting Apple documentation and working with some a11y experts,
we've found that aggregating objects that have a11y labels but are not
themselves interactable is significantly preferred for these users.

It makes it much quicker to navigate scrolling content if VoiceOver only
stops to select entire cells, and then allows drilling down into the cell
to select individual components. This implementation achieves that behavior.

We should consider enabling isAccessibilityContainer by default on ASCellNode.
This would be an improvement for 95% of a11y use cases. Aggregation can be
enabled or disabled on any node.
2017-08-20 13:17:05 -07:00
Adlai Holler
42b5633bcc Avoid re-entrant call to self.view when applying initial pending state (#510)
* Avoid re-entrant call to .view

* Increment the changelog
2017-08-15 08:04:12 -07: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
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
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
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
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
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
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
appleguy
486410d7d6 [Yoga] Minimize number of nodes that have MeasureFunc set on them. (#369)
This has one important benefit: fixing the stretching behavior of spacer nodes.

In addition, it should help efficiency of Yoga and certainly minimize calls
to layoutThatFits:.

Next up for Yoga is a mostly-red diff, deleting the non-Contiguous code branches.
2017-06-18 18:18:12 -07:00
appleguy
55928f343d [Yoga] Rewrite YOGA_TREE_CONTIGUOUS mode with improved behavior and cleaner integration (#343)
* [Yoga] Rewrite YOGA_TREE_CONTIGUOUS mode with support for mixing with ASLayoutSpec.

After experimentation with the ASYogaLayoutSpec (or non-contiguous) approach to
integrating Yoga, test results and feedback from the authors of Yoga have shown
that this approach can't be made completely correct,

There are issues with some of the features required to represent Web-style
flexbox; in particular: padding, margins, and border handling have varience.

This diff is a first step towards a truly correct and elegant implementation of
Yoga integration with Texture. In addition to reducing the footprint of
the integration, which is an explicit goal of work at this stage, these changes
already support improved behavior - including mixing between ASLayoutSpecs
even as subnodes of Yoga layout-driven nodes, in addition to above them. Yoga
may be used for any set of nodes.

Because Yoga usage is limited at this time, it's safe to merge this diff and
further improvements will be refinements in this direction.

* [ASDKgram] Add Yoga layout implementation for PhotoCellNode.

* [Yoga] Final fixes for the upgraded implementation of the Contiguous layout mode.

* [Yoga] Add CHANGELOG.md entry and fix for Yoga rounding to screen scale.

* [Yoga] Minor cleanup to remove old comments and generalize utility methods.
2017-06-14 19:36:13 -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
Huy Nguyen
05e9bdd092 Small changes required by the coming layout debugger (#337)
* Small changes required by the layout debugger
- `ASDisplayNode` can be told to not flatten its layout immediately but later on. The unflattened layout is also stored in a separate property. It's needed for inspecting not only display nodes but also layout specs used to compute a layout tree.
- `ASLayout` can be told to always retain its sublayout elements. This is needed especially for layout specs since they are usually not retained after an ASLayout was computed.

* Update CHANGELOG

* Address comments
2017-06-08 10:47:50 -07:00
Adlai Holler
a9837f2dc8 Replace NSMutableSet with NSHashTable when Appropriate #trivial (#321)
* Use NSHashTable to avoid needless -hash and -isEqual: calls

* Mark debug-only methods as such for clarity

* Address feedback
2017-06-05 16:33:37 -07:00
Adlai Holler
4d0eeb64d8 Rejigger Cell Visibility Tracking (#317)
* Rejigger visible elements tracking

* Put the assertion back

* Remove unused stuff

* Make it stronk
2017-05-30 10:25:13 -07: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
appleguy
f7b9855da7 [ASDisplayNode] Revise assertion to log until Issue #145 is addressed. (#313)
[ASDisplayNode] Revise assertion to log until Issue #145 is addressed. #trivial
2017-05-29 10:59:11 -07:00
Michael Schneider
8a9c6e8145 Remove assertion in calculateSizeThatFits: and add a log event (#299) 2017-05-23 08:14:26 -07:00
Huy Nguyen
6aa5ad7703 Only call -layout and -layoutDidFinish if the node is already loaded (#285)
* Only call -layout and -layoutDidFinish if the node is already loaded

* Minor change

* Update CHANGELOG
2017-05-19 15:06:26 +01:00
Adlai Holler
7df1a20c5f Simplify Layout Transition State #trivial (#269)
* Port the changes to the latest master

* Remove extra s
2017-05-15 16:33:44 -07: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
9d84b9e635 Fix release builds (#271) 2017-05-14 15:52:06 -07:00
Adlai Holler
538a02f119 Simplify Override Checking, Only Do It When Assertions Are Enabled #trivial (#253)
* Simplify our override checking, only do it when assertions are enabled

* Move those functions under the ASSERTIONS_ENABLED check
2017-05-11 11:42:15 -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
Michael Schneider
4dbbba7d32 Remove instance method of -drawRect:withParameters:isCancelled:isRasterizing: (#232) 2017-05-09 14:02:33 -07:00
Michael Schneider
3738f1f6e2 [ASImageNode] Move to class method of displayWithParameters:isCancelled: for drawing (#244)
* Remove instance displayWithParameters:isCancelled:

* Address comments
2017-05-09 13:03:30 -07:00
Adlai Holler
80357b1c7c Don't use associated objects for ASDisplayNode.drawingPriority (#239) 2017-05-05 08:22:30 -07:00
Michael Schneider
82b7806473 [Layout] Remove finalLayoutElement (#96)
* Remove finalLayoutElement

* Add changelog

* Remove some documentation
2017-05-03 10:45:01 -07:00
Michael Schneider
b6734faa3b Extract ASLayoutElement and ASLayoutElementStylability into categories #trivial (#131)
* Initial move of code into layout category

* Cleanup

* Some more
2017-05-02 14:38:06 -07:00
Adlai Holler
b1e1bfda20 Improve Our Handling of Subnodes (#223)
* Improve the subnodes/fast enumeration situation

* Increment changlag

* Assert our subnodes match
2017-05-02 13:02:07 -07:00
Adlai Holler
4d5e3ce81e Tighten Rasterization API, Undeprecate It (#82)
* Tamp down the rasterization API, and undeprecate it

* Update license header

* Update chornglorg

* Address comments
2017-05-01 08:26:37 -07:00
appleguy
03a1aa2660 [ASDisplayNode] Implement a std::atomic-based flag system for superb performance (#89)
* [ASDisplayNode] Convert isSynchronous to an Objective-C atomic BOOL.

This reduces lock contention, and should also fix a very rarely seen deadlock.

* [ASDisplayNode] Implement a std::atomic-based flag system for superb performance

Although Objective-C atomics are equally fast, or better that std::atomic when
access through method calls, for the most intense use cases it is best to avoid
method calls entirely.

In ASDisplayNode, we could benefit significantly from avoiding both method calls
(already true today) but also avoid locking the mutex, for both CPU and contention
gains.

There will still be many methods that need locking for transactional
consistency - however, there are currently dozens of accessor methods that could
avoid frequent lock / unlock cycles with use of atomics, and other usages of the
ivars directly where locking could be delayed until after early-return conditions
are checked and passed.
2017-04-29 23:10:59 -07:00
appleguy
411817b58c [Yoga] Ensure that calculated layout is nil'd in invalidate*Layout (#87)
This is a simple additional fix to the last YOGA patch.
2017-04-29 15:06:23 -07:00