48 Commits

Author SHA1 Message Date
Garrett Moon
ae2b3af967 Revert "Add setNeedsLayout to yoga tree changes. (#1361)"
This reverts commit babd81bd23f24ad1e16785e2ad550d724e98c0a3.
2019-03-14 10:32:47 -07:00
Adlai Holler
9cd0d58373
Rename ASDN C++ namespace to AS (#1366)
* Rename ASDN C++ namespace to "AS." Referring to the framework as ASDisplayNode is pretty out-dated and verbose. See CoreAnimation which usees CA for their internal namespace.

More using

* More cases
2019-03-09 12:14:58 -08:00
Michael Schneider
07becd0fc8
Cleanup Yoga Categories (#1364) 2019-03-06 07:37:40 -08:00
Adlai Holler
17dbd8e1e5
Optimize _assertSubnodeState (#1352)
* Optimize _assertSubnodeState

This method is actually pretty painful in today's world. In one iPad mini trace, the first page of nodes spent 6.6ms in this call, just in time profiler.

* Clean it up, check count

* Check the right value
2019-03-04 21:07:31 -08:00
Kevin
babd81bd23 Add setNeedsLayout to yoga tree changes. (#1361) 2019-03-04 17:33:28 -08:00
Kevin
50e8dbfb9c Do not lock the nodeController if we are not locking to root. (#1360)
Doing so leaves it locked when we elsewhere explicitly unlock the node to ascend.
2019-03-04 17:20:47 -08:00
Kevin
1410b29b63 Lock up to yogaRoot during layout to avoid deadlocks. (#1356)
* Lock up to yogaRoot during layout to avoid dead lock.

1) lock to root for tree
2) lock self to change parent (& consequently root)
3) Implement ASLocking (tryLock) on ASNodeController
4) add lockPair to try-lock node & controller together
5) lock controllers if they exist in lockToRoot...

Disable some asserts due to lock to root. :(

LL# No commands remaining.

* Add macro so non-Yoga still builds :)

* wut
2019-03-03 08:05:01 -08:00
Kevin
affa588654 Correct some dereferences in as_log_verbose invocations (#1317) 2019-02-14 09:22:38 -08:00
Michael Schneider
d4efe95ec5
Improve separation of code for layout method types (#1305)
* Improve separation of code for layout method types

* Address PR comments

- Delegate to layout spec engine if the node is a layout spec node but yoga engine was asked for calculate the layout
- Change ASLayoutType to ASLayoutEngineType
- Improve layout engine fall through code
2019-01-28 07:41:49 -08:00
Adlai Holler
2a4b77b6d5
Remove let and var macros now that we're all-C++ (#1312)
* Remove let and var macros now that we're all-C++

* Another fix

* More!

* And more!
2019-01-17 10:16:53 -08:00
Michael Schneider
a34f45355e Revert #1023 (#1204)
We will revert #1023. The current solution introduces problems if we are unlocking before calling _completePendingLayoutTransition. _completePendingLayoutTransition needs to be happening in one transaction if called from _u_measureNodeWithBoundsIfNecessary.
2018-11-03 12:32:15 -07:00
Michael Schneider
097790317e
Yoga integration improvements (#1187)
* Thread safety for Yoga layout

* Support baseline alignments for ASYogaLayout

* Refactor ASLayoutElementYogaBaselineFunc to not require yogaParent (its parent style is set into a private var on ASLayoutElementStyle before layout instead)

* Only set the accessibility element if the view is loaded

* Add nodeWillCalculateLayout to ASNodeController

* Update Changelog

* Address first comments
2018-10-24 10:27:58 -07:00
Michael Schneider
1d78a3d07f Directly use __instanceLock__ to lock / unlock without having to create and destroy a MutextUnlocker (#1185) 2018-10-23 05:30:54 -10:00
Michael Schneider
a3763c9c91
Fix crash if setting attributed text on multiple threads (#1141) 2018-10-09 07:39:38 -07:00
Michael Zuccarino
9588692361 Clean up timing of layout tree flattening/ copying of unflattened tree for Weaver (#1157)
* Simpler Huy fix for more efficient delayed flattening of the layout tree

* Nit

* Remove pbx changes

* Update CHANGELOG.md

* Add note about change in timing of _flattenedLayout capture
2018-10-03 14:49:15 -07:00
Adlai Holler
ceed2d2008 Remove reliance on shared_ptr for ASDisplayNodeLayouts (#1131)
* Remove reliance on shared_ptr for ASDisplayNodeLayouts

* Fix up

* Fix in yoga

* Back to let

* Returns inner pointer

* Trivial change to kick the CI
2018-09-19 11:23:19 -07:00
appleguy
465abb1ded [License] Simplify the Texture license to be pure Apache 2 (removing ASDK-Licenses). (#1077)
* [License] Simplify the Texture license to be pure Apache 2 (removing ASDK-Licenses)

With permission of the Facebook Open Source team, we are simplifying the Texture
license so that clients can rely on the Apache 2 terms that most of Texture is
already covered by. This means that code originally forked from AsyncDisplayKit
will be re-licensed from "BSD 3-clause + PATENTS v2" to Apache 2 without a
PATENTS file.

After getting confirmation that the updates to these core files look good, we'll
propagate this new license header to all files (in this same PR) and get sign-off
from all parties before landing.

* [License] Update all Texture source files to be pure Apache 2.

* Changelog entry for Apache 2 license update.

* Revert "[License] Update all Texture source files to be pure Apache 2."

This reverts commit ffa0fbbba9717d871dd16c4b07539f2f8208fc2b.

* [License] Update all Texture source files to be pure Apache 2, maintaining copyrights.

* [License] Update CONTRIBUTING, README, Podspec & Dangerfile.
2018-08-28 07:39:18 -07:00
Huy Nguyen
0dc97fbb2f
Stricter locking assertions (#1024)
- Rename `ASDisplayNodeAssertLockUnownedByCurrentThread` to `ASAssertUnlocked`, and `ASDisplayNodeAssertLockOwnedByCurrentThread` to `ASAssertLocked` -> shorter and hopefully easier to distinguish between the two.
- Add assertions to `_locked_` and `_u_` (i.e "unlocked") methods.
- Turn `CHECK_LOCKING_SAFETY` flag on by default. After #1022 and #1023, we're in a good shape to actually enforce locked/unlocked requirements of internal methods. Our test suite passed, and we'll test more at Pinterest after the sync this week.
- Fix ASVideoNode to avoid calling `play` while holding the lock. That method inserts a subnode and must be called lock free.
- Simplify `_loaded(node)` to only nil-check `_layer` because regardless of whether the node is view or layer backed, the layer should always be set if loaded. Use it throughout.
- Other minor changes.
2018-07-13 14:58:16 -07:00
Kevin
8986838b48 Add move detection and support to ASLayoutTransition (#1006)
* Add move detection and support to ASLayoutTransition

...and NSArray+Diffing.
Add some tests.

* Update CHANGELOG.md

* Update CHANGELOG.md

* Update ASLayout+IGListKit.h

* Update ASLayout+IGListKit.mm

* Use std collections to avoid NSNumber boxing

* Update ASLayoutTransition.mm

* Code review updates.

* Use `unordered_multimap` on stack instead of unordered_map<id,queue> on heap
* Remove notFound BOOL (use NSNotFound sentinel value) and put some vars inside the if (insertions/moves) loop
* Don't copy defaultCompare block (redundant under ARC)
* Whitespace
* Remove unneeded mutableCopy-s in ArrayDiffingTests

* Code review updates.

* Type _subnodeMoves pair.first to ASDisplayNode * instead of id
* C++ enumeration
* unowned refs for adding previousLayout nodes to _subnodeMoves
* Remove unreleated ASDynamicCast that is probably right though

* Add commentary to NSArray+Diffing.h; make multimap elements unowned

* Use std::make_pair, optimize ASLayout+IGListKit

* Oops I thought I had added these headers but nope

* Simplify simplify

* Diff subnodes instead of sublayouts

* Another randomized test with actual ASLayouts
2018-07-13 10:19:03 -07:00
Huy Nguyen
814fc382c7
Make sure -_completePendingLayoutTransition is called without the node's instance lock #trivial (#1023)
This is because committing the layout transition (aka `-_completeLayoutTransition:`) results in subnode insertions and removals which must be called lock-free.
2018-07-12 11:26:26 -07:00
Michael Schneider
55abeed743
Introduce let / var macros and some further cleanup (#1012)
* Introduce let / var and some further cleanup

* Address first comments

* Update changelog

* Move the const before auto
2018-07-10 09:37:53 -07:00
Adlai Holler
a11506564a
Reduce usage of autorelease pools (#968)
* Reduce reliance on the autorelease pool

* changelog

* A few more places

* Use it in another place
2018-06-15 10:15:25 -07:00
Max Wang
5c13cbe7a2 Fix method name typo in _locked_isLayoutTransitionInvalid #trivial (#963) 2018-06-12 08:56:37 +01:00
Huy Nguyen
b9ae6c4fa8
[ASDisplayNode] Fix an issue that causes a node to sometimes return an outdated calculated size or size range (#808) 2018-05-21 18:36:19 +01:00
Adlai Holler
0f9b1e6789
Make objects conform to NSLocking (#851)
* Make display node, layout spec, and style conform to NSLocking so that users/subclasses can access their locks

* Update the changelog

* Align slashes

* Put it back, when we're in ASDisplayNode

* Go a little further

* Put back the changes I didn't mean to commit

* Kick the CI

* Fix yoga build

* Put back non-locking change

* Address comments from Scott
2018-03-25 10:46:04 -07:00
Huy Nguyen
e2478fc799
[ASDisplayNode layout] Fix an issue that sometimes causes a node's pending layout to not be applied (#792)
* [ASDisplayNode layout] Fix an issue that causes a node's pending layout to not be applied

- Since the implementation of layout version (#428), if a node's pending and calculated layouts have the same current version as well as the same constrained size, the 2 layouts are considered equal and can be used interchangeably. A layout version check between the 2 layouts was added in #695. This PR adds a missing constrained size check.
- If the pending layout has the same version but a different constrained size compare to the calculated layout's, we can assume that the pending layout is newer and should be preferred over the calculated one. That is because layout operations always register their new layout as pending, which then (immediately or eventually) get applied to the node as calculated layout.
2018-02-12 21:04:58 +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
Huy Nguyen
b01fac35b6
[ASDisplayNode+Layout] Ensure a pending layout is applied once (#695)
Before:
  - Even if a pending layout was applied before, it'll be unnecessarily applied again in next layout passes and cause `-calculatedLayoutDidChange` being called multiple times.

After:
  - If a pending layout was applied, the calculated layout will not be ignored but reused, if possible, in next layout passes.

Test plan: testSetNeedsLayoutAndNormalLayoutPass in #424.
2017-12-01 13:11:17 +00: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
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
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
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
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
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
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
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
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
81def94f6f [ASTraitCollection] Convert ASPrimitiveTraitCollection from lock to atomic. (#355)
* [ASTraitCollection] Convert ASPrimitiveTraitCollection from lock to atomic.

This resolves a deadlock case: https://github.com/TextureGroup/Texture/issues/353

* [ASTraitCollection] Use assignment operator instead of .store() for C++ atomic.
2017-06-14 13:55:52 -07:00
Adlai Holler
c9e4b98a55 Upgrade ASLayoutElementContext to an Object #trivial (#344)
* Upgrade ASLayoutElementContext to an object

* Address feedback from Huy
2017-06-10 00:25:39 -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
appleguy
00013aadab [ASDisplayNode+Layout] Add check for orphaned nodes after layout transition to clean up. (#336)
It is rare that this code has any effect, but I've discovered a case in which it occurs.

This task tracks moving this code to a DEBUG-only assertion: https://github.com/TextureGroup/Texture/issues/335
2017-06-06 12:38:37 -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