37 Commits

Author SHA1 Message Date
Garrett Moon
e3091737ca Enable ASRangeControllerUpdateRangeProtocol by default if view controller or node support it. (#2133) 2016-08-25 21:18:04 -07:00
ricky
b5b9eefe44 [ASViewController] Layout root node AFTER propagating all the traits (#2137)
Wait until all subnodes have the new trait collection before laying out the root node. The way I’m using `asyncTraitCollectionDidChange`, I sometimes call methods that call `setNeedsLayout` which causes a new layout pass to begin before the new trait collection has been propagated to all nodes. This leads to weird behavoir, like nodes being laid out twice in the same call stack!

This change won’t stop possibly unnecessary layout passes because of `asyncTraitCollectionDidChange`, but it will at least do a complete layout pass once we have propagated all traits.

Ultimately the solution to this problem (as Adlai pointed out) is to wait until the CA transaction commit to perform the actual layout.
2016-08-25 11:52:43 -07:00
ricky
c0be871812 [ASViewController] Propagate the traits on willTransitionToTraitCollection (#2115)
Previously we were only propagating the trait collection on `viewWillTransitionToSize` since it is called shortly after `willTransitionToTraitCollection`. However, some important things can happen in that time “shortly after” (like collection view layout). As long as nothing changes from `willTransitionToTraitCollection` to `viewWillTransitionToSize` (which it shouldn’t) the traits will not be re-propagated anyhow.

Also make sure to use the `ASEnvironmentTraitCollectionMakeDefault` method when creating new envTraitCollection so the struct isn’t filled with junk.
2016-08-22 10:06:53 -07:00
ricky
39da5d2cb0 [ASTraitCollection] propagate window container size via ASTraitCollection in iOS7 (#2019) 2016-08-05 10:34:13 -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
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
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
90d5c97d0f Fixes iOS 7 and iOS 8 wrong size in viewWillAppear: while a a rotation is happening 2016-07-19 16:24:47 -07:00
Adlai Holler
cc8e0049c5 Merge pull request #1921 from facebook/AHRangeModeUpdatingIssues
[ASRangeController] Fix Major Range Mode Updating Issues
2016-07-15 10:22:36 -07:00
Michael Schneider
cd46791f9d Move check for iOS 9 from an early return to an earlier check to prevent objc_msgSend 2016-07-14 14:50:54 -07:00
Michael Schneider
6e8772a68d Fix sizing of root node in ASViewController for modal presentation and root view controller 2016-07-14 14:48:05 -07:00
Adlai Holler
787fd8b90b [ASViewController] Defer range update conformance check until the actual range update 2016-07-14 11:32:50 -07:00
Adlai Holler
3591f7a7c1 [ASViewController] Allow VC to conform to range updating protocol, log message if impossible to update 2016-07-14 10:56:52 -07:00
appleguy
3b2af7eb6d [Build] Remove Unused Imports across all of AsyncDisplayKit. This uses a feature of AppCode. (#1875)
Details on the tool are here: https://www.jetbrains.com/help/idea/2016.1/optimizing-imports.html
2016-07-09 17:20:59 -07:00
ricky
fe61c3e3ab [ASEnvironmentTraitCollection] Fixed bug where containerSize wasn't being saved
Summary:
The old assignment of `self.node.environmentTraitCollection.containerSize = windowSize;` doesn't because the struct creates a copy and then assigns `windowSize` to that copy.

Also realized that we need to create a new `ASEnvironmentTraitCollection` in `willTransitionToTraitCollection:withTransitionCoordinator`:. If we only update in `viewWillTransitionToSize:` we will only update the `containerSize` value in `self.environmentTraitCollection` as we don't have the new trait collection yet.

Differential Revision: https://phabricator.pinadmin.com/D101807
2016-07-08 15:00:50 -07:00
Michael Schneider
33e093b1f6 Check if a superview is present before calculating the legacy constrained size 2016-07-08 13:20:18 -07:00
Michael Schneider
057c48482a Fix Modal presented ASViewController don't rotate on iOS 8.3 2016-07-08 13:10:41 -07:00
ricky
7314a18ab4 rename containerWindowSize to containerSize 2016-07-07 10:55:18 -07:00
ricky
3512cf47aa assert we are on the main thread before accessing view. 2016-07-07 10:21:40 -07:00
ricky
637c4f3a9f [ASTraitCollection] Remove traitCollectionContext from ASTraitCollection; add containerWindowSize
Passing around a pointer was leading to crashes as the ASVC was the sole owner of the context. There are cases where the VC would dealloc while its subnodes were laying out. This could lead to the subnodes accessing a garbage pointer.
2016-07-07 09:23:37 -07:00
Hannah Troisi
c857e809f4 Clean up header comments (for consistent Facebook licensing info) (#1741)
[Licensing] Clean up header comments (for consistent Facebook licensing info)
2016-06-11 23:31:39 -07:00
ricky
01dbc86778 First pass of comments
* make variable naming reflect ASEnvironmentTraitCollection vs ASTraitCollection
* move trait propagation to cell allocation instead of via a nested block
* move trait propagation when setting a displaynode's supernode instead of when adding a subnode
* fixed misspelling of "colection"
2016-06-03 09:59:24 -07:00
ricky
501fed16aa nil out displayContext when we get a new one
Summary: Don't set the new one in the subnodes yet as this will cause ASEnvironmentTraitCollectionIsEqualToASEnvironmentTraitCollection to return NO if only the displayContext changed.

Reviewers: garrett, levi, rmalik

Reviewed By: garrett, levi, rmalik

Subscribers: rmalik

Differential Revision: https://phabricator.pinadmin.com/D94320
2016-06-02 10:33:32 -07:00
ricky
59a26ee111 [ASTraitCollection] Bug fixing/LayoutSpec propagation
* Fixed bug in `ASEnvironmentMergeObjectAndState`
* New ASLayoutSpec methods for `setChild`/`setChildren`/`setChild:forIdentifier:` have been added to take in a trait collection.
* Added `setChild:`-like methods for ASLayoutSpecs take a traitCollection
* Fixed instances where nodes in a data controller were not getting their trait collections
* propagate traitCollection in ASDisplayNode on insertSubnode or addSubnode
2016-05-23 16:37:40 -07:00
Garrett Moon
8d4959bd76 Revert "ASViewController.m -> ASViewController.mm upstream"
This reverts commit b34e8d78de20ea11b2b07a24df3b12d2936d1a5e.

In attempting to rebase my visibility patch, I overwrote all of Ricky's
changes to ASViewController. This puts them back in.
2016-05-16 15:03:15 -07:00
Garrett Moon
4c78fb3846 Add setVisibilityDepth setter. 2016-05-12 13:42:05 -07:00
Garrett Moon
e296cad8ee Add support for visibility depth
Summary:
This adds support for the concept of visibility depth.

Visibility essentially defines the number of user actions it would
take a user to have a view controller visible. Knowing a view controllers
visibility depth allows view controllers to take action such as clearing
out memory that can be restored at a later date.

This patch also add two new view controller subclasses which adopt
the ASManagesChildVisibilityDepth protocol. Any view controller
that has child view controllers can adopt this protocol to indicate
to the child what they're visibility is. For example, ASNavigationController
will return a visibility depth of it's own visibilityDepth + 1 for
a view controller that would be revealed by tapping the back button.

Move common implementations to macros

Turn off visibility logging

Differential Revision: https://phabricator.pinadmin.com/D90395
2016-05-12 13:42:05 -07:00
Garrett Moon
b7b8ad54fd Move common implementations to macros 2016-05-12 13:42:05 -07:00
Garrett Moon
af7a2f09d7 Add support for visibility depth
This adds support for the concept of visibility depth.

Visibility essentially defines the number of user actions it would
take a user to have a view controller visible. Knowing a view controllers
visibility depth allows view controllers to take action such as clearing
out memory that can be restored at a later date.

This patch also add two new view controller subclasses which adopt
the ASManagesChildVisibilityDepth protocol. Any view controller
that has child view controllers can adopt this protocol to indicate
to the child what they're visibility is. For example, ASNavigationController
will return a visibility depth of it's own visibilityDepth + 1 for
a view controller that would be revealed by tapping the back button.
2016-05-12 13:42:05 -07:00
Garrett Moon
b34e8d78de ASViewController.m -> ASViewController.mm upstream 2016-05-12 13:40:32 -07:00
rcancro
cfa9dcda56 typo and comment 2016-05-11 14:08:06 -07:00
rcancro
4b54144f55 Levi's comments 2016-05-11 10:21:11 -07:00
rcancro
9d622c7eac changed DisplayTraits to TraitCollection 2016-05-10 14:45:03 -07:00
rcancro
f828d079fa added nsobject based ASDisplayTraits class 2016-05-10 14:44:43 -07:00
rcancro
b4a6f87ca6 addressed some comments 2016-05-10 14:44:32 -07:00
rcancro
8bb4eba080 Initial attempt at implementing Display Traits
Initial attempt to get display traits working with ASEnvironment.

To get proper ASDisplayTraits support, you must use an ASViewController. The ASViewController implements UITraitCollection-related methods (`traitCollectionDidChange:`, `willTransitionToTraitCollection:withTransitionCoordinator:`, viewWillTransitionToSize:withTransitionCoordinator`) to update the internal ASDisplayTraits and propagate them to subnodes.

ASTableNode and ASCollectionNode don't actually have their cells as subnodes, so a little bit of trickery is involved (on `setEnvironment:` the table/collection node gets its data controllers completedNodes and propagates the new traits. see `ASDisplayTraitsCollectionTableSetEnvironmentState`). The data controller also passes the current display traits when creating new cells.

ASViewController also supports the ability to return a custom set of display traits. So if you have a modal dialog that should always be told it is in a compact size class, you can set the override block before displaying the VC.

A new example, called Display Traits, has been added. It shows how display traits can be used in a ASViewController with a normal ASDisplayNode as its root, as well as in ASViewControllers hosting table nodes and collection nodes. There is also an example of overriding the default display traits of a VC.

Please provide feedback!
2016-05-10 14:44:22 -07:00