460 Commits

Author SHA1 Message Date
Adlai Holler
337e908390 Make Description Functions Dealloc-Safe (#2241)
* Make description functions dealloc-safe

* Make -debugDescription also dealloc-safe
2016-09-13 17:48:31 -07:00
Adlai Holler
8c380d1601 Don't crash in production on invalid subnode insert (#2231) 2016-09-12 10:29:31 -07:00
Harry Shamansky
59fbfb682d Measure performance for ASCellNode layout (#2209)
* Measure performance for ASCellNode layout

* Address Adlai and Levi's feedback:
* Move to ASDisplayNode level
* Lock around setting/getting measurement options and results
* Record all measurement passes and report times as an array
* Only add relevant entries to the performanceMetrics dictionary
* Rebase

* Store sum and count instead of array

* Rename ScopeTimerDataPoint to ScopeTimerSum

* Address Levi's feedback

* Address Adlai's feedback
2016-09-09 10:38:13 -07:00
John Engelhart
8c2f3f666f Fixes unsafe use of asyncdisplaykit_node. (#2207)
The previous code used either a `@property` with `assign, nonatomic` semantics, or a `__unsafe_unretained` (non-atomic) ivar pointer to an instance for `asyncdisplaykit_node`.

This commit changes those access so that they have the equivalent of `weak, atomic` semantics.

- `_ASDisplayView.mm`
  - Removes the `_node` ivar that was qualified with `__unsafe_unretained`.
  - Removes `@synthesize asyncdisplaykit_node = _node;`.
  - All direct uses of `_node` were replaced with:
    - Creates a strong reference via `ASDisplayNode *node = _asyncdisplaykit_node;`.
    - `s/_node/node/`.
    - These changes were made even if there's a single use of `_asyncdisplaykit_node` as a consistency / defensive measure so that anyone editing this code in the future does not accidentally use a `weak` reference twice.

- `ASDisplayNode.mm`
  - Getters and setters for `asyncdisplaykit_node` were changed from `nonatomic, assign` semantics to the equivalent of `atomic, weak` semantics.
  - `weak` semantics were implemented by using a `ASWeakProxy` object.
  - `objc_setAssociatedObject` was changed from `OBJC_ASSOCIATION_ASSIGN` to `OBJC_ASSOCIATION_RETAIN` (the `atomic` version of retain).

- `ASDisplayNode+FrameworkPrivate.h`
  - Changed the `@property` declarations for `asyncdisplaykit_node` from `nonatomic, assign` to `atomic, weak`.
    - The actual getters and setters are implemented in `ASDisplayNode.mm`, which were changed accordingly.
2016-09-08 17:27:49 -07:00
Adlai Holler
bc59b96ca9 [ASDisplayNode] Add onDidLoad Method to Perform Work When Loaded (#2128)
* [ASDisplayNode] Add `onDidLoad:` method

* Prevent user from rasterizing wrapper nodes – they can't be reloaded in the future
2016-09-08 14:18:35 -07:00
Michael Schneider
0d8518912e Initial commit to throw an exception if manually adding / removing subnodes if node has automaticallyManagesSubnodes enabled (#2214) 2016-09-08 11:59:57 -07:00
Adlai Holler
5593bfa4d1 [ASDisplayNode] Majorly Improve Descriptions (#2208)
* Up our description game big time

* Couple tweaks

* Explain logic

* Fix indentation
2016-09-07 20:11:27 -07:00
Michael Schneider
0aeefaf25f [Layout] Automatic measurement on layout fixes (#2206)
* Don't measure range managed nodes automatically in the layout pass

* Fix auto measure a node mid transition
2016-09-07 12:46:05 -07:00
Michael Schneider
8897614f0e [Layout] Layout API based on content area (#2110)
* Initial commit for adding a size constraint to ASLayoutable's

* Some more commits

* Fix sample projects in extra/

* Remove preferredFrameSize test of ASEditableTextNode

* Remove preferredFrameSize from examples_extra

* Add deprecation warning to -[ASDisplayNode preferredFrameSize]

* Add deprecation warning to -[ASDisplayNode measureWithSizeRange:]

* Commit

* Commit

* Remove ASRelativeSizeRange

* Make ASRelativeSize private

* Adjust examples

* Improve setting of -[ASLayoutable size] with points or fractions

* Add ASWrapperLayoutSpec

* Improve creation of ASRelativeDimension

* Add `preferredFrameSize` back and add deprecated logging

* Add `layoutSpecBlock` setter and getter and add locking for it

* Add better documentation and fix macros to create ASRelativeDimension

* Create new ASSizeRangeMake with just a CGSize as parameter

* Update Kitten and Social App Layout example

* Add layoutThatFits: and deprecate measure:

* Rename ASRelativeDimension to ASDimension

* Fix examples for ASDimension renaming

* Remove fancy height and width setter

* Fix ASDimension helper

* Rename -[ASLayout layoutableObject] to -[ASLayout layoutable]

* Update layout related methods and more clearer documentation around how to use it

* Deprecate old ASLayout class constructors

* Don't unnecessary recalculate layout if constrained or parent size did not change

* Use shared pointer for ASDisplayNodeLayout

* Fix rebase conflicts

* Add documentation and move implementation in mm file of ASDisplayNodeLayout

* Fix test errors

* Rename ASSize to ASLayoutableSize

* Address comments

* Rename setSizeFromCGSize to setSizeWithCGSize

* Improve inline functions in ASDimension

* Fix rebase conflicts
2016-09-07 08:44:48 -07:00
Hannah Troisi
03c21830a5 improve layoutSpecThatFits: assertion message (#2201) 2016-09-06 11:42:59 -07:00
Michael Schneider
9b823ebdc9 Add better exception message for adding or removing ASDisplayNode's in layoutSpecThatFits: (#2183) 2016-09-02 14:58:19 -07:00
Adlai Holler
33a680255c [ASDisplayNode] Add Convenience Interface State Accessors (#2168)
* Finish renaming fetchData range, add convenience accessors

* Update example

* Update new tests
2016-09-01 16:44:16 -07:00
Michael Schneider
f8e135a1be Add old transition API back but allow call from background thread (#2135) 2016-09-01 16:09:59 -07:00
Adlai Holler
6db9bf39f1 Turn on collection update validation by default (#2174) 2016-08-31 22:20:23 -07:00
Garrett Moon
0c5288d033 [ASDisplayNode] Dealloc _pendingViewState if range managed (#2155)
* Dealloc _pendingViewState if range managed

_ASPendingState objects can add up very quickly when adding
many nodes. This is especially an issue in large collection views
and table views. This needs to be weighed against the cost of
reallocing a _ASPendingState. So in range managed nodes we
delete the pending state, otherwise we just clear it.

* Adlai's comments
2016-08-31 16:47:10 -07:00
Michael Schneider
027358fc6b [Layout] Automatic measure pass in layout pass if not happened before (#2163)
* Automatic measure pass in layout pass if not happened before

If no measure pass happened or the bounds changed between layout passes we manually trigger a measurement pass for the node using a size range equal to whatever bounds were provided to the node

* Add test method that ensures that on a second layout pass with same bounds, layoutSpecThatFits: / layoutSpecBlock is not called
2016-08-31 16:45:02 -07:00
Adlai Holler
284975ecec Fix Case Where Node Is Deallocated While Visible (#2171)
* Attempt to reproduce supplementary crash

* Get closer with supplementary issue testing

* Alright! We have a repro!

* The investigation continues

* Fixed!
2016-08-31 15:50:39 -07:00
Michael Schneider
ba5dc984d7 Check if subnodes where modified during layoutSpecThatFits: (#2164) 2016-08-28 16:55:42 -07:00
Garrett Moon
645aa6f24b [ASDisplayNode] Renamed range update callbacks (#2130)
* Renamed range update callbacks

We finally settled on

didEnter/ExitDisplayState
didEnter/ExitPreloadState
didEnter/ExitVisibleState

This change is meant to unify the range update methods to relate to each
other and hopefully be a bit more self explanatory.

* Guarantee interface callbacks happen on main.

* move fetchData / clearFetchedData to default implementations

* Move deprecated methods to new deprecated category

* Don't bring in cocoapod change.

* Nits

* Capetalize
2016-08-26 20:18:38 -07:00
Garrett Moon
8032758176 Fixes a deadlock caused by walking up the heirarchy. (#2147)
* Fixes a deadlock caused by walking up the heirarchy.

* Use scope locker / unlocker and add a comment.

* Add comment about calling __setNeedsLayout without the lock.
2016-08-26 14:09:38 -07:00
Yue-Wang-Google
1951954ba5 remove non unicode char (#2109)
see https://github.com/facebook/AsyncDisplayKit/issues/2108
2016-08-19 17:51:41 -07:00
Adlai Holler
00af76226d [ASDisplayNode] Clarify logic around calling setNeedsDisplay (#2094) 2016-08-18 09:45:43 -07:00
Michael Schneider
ee87695fc8 Don't use the default layout transition animation of no animation is wanted (#2075) 2016-08-15 17:23:02 -07:00
Michael Schneider
11215bf97f [Automatic Hierarchy Management] Rename IHM to automatic hierarchy management and move out of beta header (#2066)
* Rename automaticHierarchy to automaticallyManagesSubnodes

* Comment adjustments
2016-08-15 12:06:06 -07:00
Michael Schneider
adcc9afb5a [Layout Transition] Add default fade in / out layout transition (#2052)
* Add default fade in / out layout transition

* Add example for layout transition

* Update for recent layout transition API changes

* To be able to do a layoutTransition the node needs to be loaded

* Rename layoutTransitionDuration to defaultLayoutTransitionDuration

* Expose default layout transition duration delay and options

* Use `UIViewAnimationOptionBeginFromCurrentState` for initial defaultLayoutTransitionOptions
2016-08-13 17:35:20 -07:00
Michael Schneider
32058815f2 Move Transition Layout API out of beta header and remove shouldMeasureAsync from API
shouldMeasureAsync is enabled by default now.
2016-08-10 10:30:25 -07:00
Adlai Holler
49b65fd783 Revert "Fix if pending layout will be deallocated (#2038)" (#2051)
This reverts commit 2804d50220dabebc62b088b17d5ffe2347da1e36.
2016-08-09 16:10:21 -07:00
Michael Schneider
2804d50220 Fix if pending layout will be deallocated (#2038)
The pending layout transition needs to stay alive at least until applySubnodeInsertions did finish execute as it can happen that with Implicit Hierarchy Management new nodes gonna be added that internally call setNeedsLayout what will invalidate and deallocate the transition in the middle of inserting nodes
2016-08-05 10:25:50 -07:00
Adlai Holler
01c8dc3dc2 [ASDisplayNode] Assert that user doesn't reuse layout specs (#2036) 2016-08-04 16:54:48 -07:00
Michael Schneider
d5cbe33686 Revert "[ASLayoutSpec] Use childrenMap directly to prevent creating an NSArray within ASDK Part 2 (#2021)"
This reverts commit d5a7c195226925e483c74fb210120d15ff423378.
2016-08-02 10:10:36 -07:00
Michael Schneider
d5a7c19522 [ASLayoutSpec] Use childrenMap directly to prevent creating an NSArray within ASDK Part 2 (#2021)
* Revert "Revert "[ASLayoutSpec] Use childrenMap directly to prevent creating an NSArray within ASDK (#1937)""

This reverts commit 735b4ebd0872483044d98a5d05b43324e76fc8d4.

* Fix crash and add exception for mutating while using fast enumeration of ASLayoutSpec children

NSFastEnumeration is potentially quite dangerous in the wrong hands. In particular, it does not provide a safe mechanism for you to return temporary objects directly, and it does not provide any guarantee that you will be called when the enumeration has completed; therefore if we generate temporaries and store them in an instance variable, we will not necessarily be able to clean them up! This means fast enumeration methods should never be called within an autorelease pool or the autorelease pool be drained within the fast enumeration loop.

The reason is we store references to objects in the stackBuf struct by casting the child pointer to __autoreleasing id. If we pop the autorelease pool between calls to -countByEnumeratingWithState:objects:count:, it will die in a messy explosion of pointer dereferences and EXC_BAD_ACCESS.

* Add tests for ASDisplayNode and ASLayoutSpec fast enumeration
2016-08-01 18:08:48 -07:00
Michael Schneider
3a1a987dbe Fix not propagating updating and propagating down the layout transition id if a subnode is added (#2018)
If a node was added to a supernode, the supernode could be in a layout pending state. All of the hierarchy state properties related to the transition need to be copied over as well as propagated down the subtree. This is especially important as with Implicit Hierarchy Management adding subnodes can happen while a transition is in fly
2016-08-01 09:44:02 -07:00
Scott Goodson
735b4ebd08 Revert "[ASLayoutSpec] Use childrenMap directly to prevent creating an NSArray within ASDK (#1937)"
Something interesting going on here with ARC / Objective-C++ that we are investigating and will re-land.

This reverts commit c90ed08d1073701e2c7f8a2677d460c140f05264.
2016-07-31 18:43:20 -07:00
appleguy
965fe05c11 [ASDisplayNode] Ensure that nil can never be returned from -measureWithSizeRange: (#2014)
* [ASDisplayNode] Ensure that nil can never be returned from -measureWithSizeRange:

This can happen in rare cases when multiple relayouts occur while a transition is being measured.

* [ASDisplayNode] Use ternary operator style for nil check.
2016-07-30 18:04:08 -07:00
Michael Schneider
c90ed08d10 [ASLayoutSpec] Use childrenMap directly to prevent creating an NSArray within ASDK (#1937)
* Use childrenMap directly to prevent creating an NSArray in ASDK for ASLayoutSpec children

* Add locking for parent property in ASLayoutSpec

* Remove unnecessary import

* Add newline

* Add NSFastEnumeration to ASEnvironment and ASDisplayNode / ASLayoutSpec

* Change NSMutableArray initializer to arrayWithCapacity:

* Move ASLayoutSpec+Private.h into Private folder

Fixes building with Swift

* Remove lock for ASLayoutSpec parent
2016-07-29 10:53:31 -07:00
Michael Schneider
678df37017 [Layout Transition API] Simplify applying layout transition (#1886)
* Simplify applying layout transition in preparation for bigger layout transition API work

* Change from apply to complete in if layout transitions are involved and _applyLayout: to _setCalculatedLayout: for layout

* Change to applySubnodeInsertions and applySubnodeRemovals

* Change from completeTransition to commitTransition and flip logic around when to trampoline to the main thread for implicit hierarchy management

* More internal API improvements

* Fix merge conflicts

* Rename _layout to _calculatedLayout
2016-07-29 10:52:55 -07:00
ricky
f0b1f12160 [ASEnvironmentTraitCollection] default user interface idiom to UIUserInterfaceIdiomUnspecified (#1998)
* [ASEnvironmentTraitCollection] default user interface idiom to ASEnvironmentTraitCollection

UIUserInterfaceIdiomUnspecified is -1 so we were actually defaulting our trait collection to UIUserInterfaceIdiomPhone (which is 0).

* Fix a few places where we weren’t using the default method to create the base traits
2016-07-28 10:03:32 -07:00
Hannah Troisi
f5b3a282af Fix Pinterest Xcode 7.3.1 Analyzer Warnings (#1988) 2016-07-27 08:23:16 -07:00
Michael Schneider
4b9ee3c64d Don't crash if inserting a nil node 2016-07-21 14:41:19 -07:00
Adlai Holler
8cde594de3 [ASDataController] Add validation logic to the change set to throw exceptions on invalid updates (#1894)
[_ASHierarchyChangeSet] Oopsy daisy

[ASDataController] Tweak our update validation

[ASHierarchyChangeSet] Fix bugs

Finish up some stuff

[ASDataController] Put some stuff back

[ASChangeSetDataController] Always use changeset

[ASDataController] Put other stuff back

[_ASHierarchyChangeSet] Use fast enumeration

[_ASHierarchyChangeSet] Fix assertion format strings, return on fail so we don't crash in production

[ASDataController] Store data source item counts as vector rather than NSArray

[ASDataController] Build some tests for the update validation

[ASDataController] Fix issues with update validation

Get rid of new file

[ASDataController] Suppress changeset validation before initial reload

[ASDataController] Make invalid update log vs. exception publicly toggleable
2016-07-21 14:37:51 -07:00
Scott Goodson
8644c03ab8 Revert "[ASDisplayNode] Short circuit measure calls that have a zero-area constrainedSize. (#1939)"
This reverts commit 3664ca67cb06647233e6fdcaf934d440ab433f06.
2016-07-16 16:12:50 -07:00
appleguy
74bf376b2f [ASDisplayNode] Rename _propertyLock to __instanceLock__ to avoid subclass naming collisions. (#1941) 2016-07-16 15:32:13 -07:00
appleguy
3664ca67cb [ASDisplayNode] Short circuit measure calls that have a zero-area constrainedSize. (#1939)
* [ASDisplayNode] Short circuit measure calls that have a zero-area constrainedSize.

  // If the constrainedSize is completely zero-area, then there is no possibility for layout calculations to be successful.
  // This also avoids the issue of an inset being applied to 0, creating negative frame values.

* [ASDisplayNode] Fix to shouldMeasure change.

* One more fix.
2016-07-16 15:31:51 -07:00
Michael Schneider
9729b61dde Add whitespace 2016-07-15 13:19:06 -07:00
Michael Schneider
fcfce5128d Grab propertyLock to get supportsRangeManagedInterfaceState and for asking dirty layout status 2016-07-15 13:19:06 -07:00
Michael Schneider
4447ae4bd4 Move ASPerformBlockOnBackgroundThread as it already calls the method inline if it's on the main thread 2016-07-15 11:41:10 -07:00
Michael Schneider
729766a365 Add convenience functions to create relative sizes with percentage 2016-07-15 10:51:45 -07:00
Michael Schneider
359785ac92 [ASDisplayNode] Add automatic measurement before layout (#1725)
* Add automatic measurement before layout

* Remove code not needed or addressed in a different PR

* Adjust comments and rename __layoutSublayouts to __layoutSubnodes

* Check before setting up a placeholder layer if the node should have a placeholder
2016-07-14 21:51:40 -07:00
Michael Schneider
a8c5ac138d [ASDisplayNode] Always layout nodes on a background thread (#1907)
* Always layout nodes on a background thread

* Remove semaphore in ASDataController for allocating nodes and layout

* Fix variable not used error

* Remove overhead to create subarray of contexts of nodes while layout nodes

* Remove extra allocation of allocatedNodes and indexPaths array
2016-07-14 21:35:58 -07:00
Michael Schneider
dc2255d5d8 Fix setNeedsLayout triggered from subnode will not trigger relayout 2016-07-12 09:26:40 -07:00