133 Commits

Author SHA1 Message Date
Huy Nguyen
3761d8b0c3 ASVideoNode should play when its player is ready and if it is expected to play (#2876)
- When a video node is first visible, it's player is called to play if auto play flag is on. However, the player might not be ready by that time, especially when the video is loaded on a slow network. The player just continues loading its asset.
- When the player is ready, we should check if it is expected to be playing and if true, try to play again.
2017-01-09 12:02:00 -08:00
Huy Nguyen
99c5021be7 Remove duplicated _delegate ivar in ASVideoNode (#2844) 2017-01-01 18:42:41 -08:00
Huy Nguyen
f7a0ac9760 [ASThread][ASDisplayNode] Detect and avoid deadlocks caused by upward lock gathering in didEnter/Exit states (#2764)
* Implement mutex ownership and use it to check potential upward lock gathering

* Don't hold instance lock and call willEnterHierarchy/didExitHierarchy of ASDisplayNode
- This can cause deadlocks (e.g #2605) if subsequent methods, that are implemented by developers, walk up the node tree.
- This is a way to keep the optimizations introduced in 9e87813 while making sure the locking situation is a bit safer.

* More lock ownership assertions in ASDisplayNode

* Document main thread contract  of -clearContents

* ASNetworkImageNode shoud not call setNeedsPreload while holding instance lock
- This helps to avoid potentially deadlocks caused if the node (esp in case it's a subclass of ASNetworkImageNode) walks up the tree in didEnterPreloadState, for example to build logging context.

* ASVideoNode should not call setNeedsPreload while holding instance lock
- This helps to avoid potentially deadlocks caused if the node (esp. if it's a subclass of ASVideoNode) walks up the tree in didEnterPreloadState, for example to build logging context.

* Don't hold instance lock for the entire insert subnode operation
- The recursive lock should not be held throughout `_insertSubnode:atSubnodeIndex:sublayerIndex:andRemoveSubnode:`. The method instead should manage the lock itself and acquire it as shortly as possible. The reason is that this method calls many methods outside the scope of `self`. `[subnode __setSupernode:self]` is especially troublesome because it causes the subnode to migrate to new hierarchy and interface states, which triggers `didEnter/Exit(.*)State` methods. These methods are meant to be overriden by subclasses. Thus they might walk up the node tree and potentially cause deadlocks, or they perform expensive tasks and cause the lock to be held for too long.
- Other methods that call this method should release the lock before doing so.

* Lock getter and setter of `synchronous` flag

* Address comment in ASVideoNode

* Add main thread assertions to methods that change asset and assetURL of ASVideoNode

* Explain CHECK_LOCKING_SAFETY flag

* More thread and locking assertions in ASVideNode
- It's not safe to call `-[subnode __setSupernode:self]` while holding instance lock of soon-to-be supernode (e.g `self`).
- It's also not safe to call `[subnode __setSupernode:nil]` while holding the instance lock of the old supernode (e.g `self`).
- did(Enter|Exit)(.*)State methods are always called on main. Add main thread assertions to indicate that.

* Minor change in explanation of CHECK_LOCKING_SAFETY flag
2016-12-19 12:11:26 -08:00
appleguy
eeb977e145 [ASDisplayNode] Ensure all subclasses are using base class __instanceLock__ and not re-defining their own. (#2754)
* [ASDisplayNode] Ensure all subclasses are using base class __instanceLock__ and not re-defining their own.

This also moves the @package definition of the instance variable to +FrameworkPrivate instead of Internal.h,
because Internal.h should ideally not be used outside of the ASDisplayNode file setup.  This has greatly reduced
the number of imports of Internal.h.

* [ASDisplayNode] Add ASDisplayNode+FrameworkSubclasses.h to share __instanceLock__ definition.
2016-12-12 19:42:41 -08:00
Michael Schneider
cacc366706 Some video node improvements 2016-12-06 06:55:47 -08:00
Michael Schneider
ef84e99673 Tremendously make the implementation easier 2016-12-05 20:15:23 -08:00
Michael Schneider
9fefd4a5b0 Cleanup ASVideoNode a bit 2016-12-05 16:43:46 -08:00
Michael Schneider
9adb6554fc Add assertion against externally setting .image in specific ASImageNode subclasses 2016-12-05 16:43:46 -08:00
Garrett Moon
ba2268ac99 2611 rename fetch data (#2689)
* Replace fetch data with preload terminology
- Deprecate `-fetchData` and `-clearFetchedData` in favor of `-preload` and `-clearPreloadedData`
- Move `-setNeedsPreload`, `-recursivelyPreload` and `-recursivelyClearPreloadedData` to ASDisplayNode+FrameworkPrivate.h
- Update internal implementation, comments and tests

* Folllow up on #2642:
- Remove -preload and -clearPreloadedData in favor of -didEnterPreloadState and -didExitPreloadState.
- -didEnterPreloadState and -didExitPreloadState call the deprecated -fetchData and -clearFetchedData methods if they are overriden.

* Missed one in a test

* Get rid of behavior change for now.

* Revert more behavior changes, fix tests.

* Don't need these anymore.
2016-12-01 13:41:22 -08:00
Scott Goodson
72585e4262 Revert "Prevent premature placeholder image clearing when setting the video asset at a later point in time."
See test failure in https://github.com/facebook/AsyncDisplayKit/pull/2626

This reverts commit 4ad8361eeaef1f0bce8fab3c89b6cd28fd043999.
2016-11-19 21:59:14 -08:00
David Robles
4ad8361eea Prevent premature placeholder image clearing when setting the video asset at a later point in time. 2016-11-17 10:35:26 -08:00
Michael Schneider
d649f2524f Remove legacy ASVideoNode flags 2016-11-14 09:21:38 -08:00
gazreese
3cdbc63e31 [ASVideoNode] Addition of reset method to return to initial state (#2119)
* [ASVideoNode] Addition of reset method to allow video node to return to initial state of placeholder and play button

* Implemented pull request review comments for code style
2016-11-10 16:35:43 -08:00
Hannah Troisi
902bb0999d remove miscellaneous true values (#2391)
[Code Cleanup] Replace `true` values with `YES`
2016-10-15 18:28:46 -07:00
Michael Schneider
d6e5e27c39 [Layout] Add helper properties for setting sizes via CGSize and ASRelativeSize (#2324)
* Remove set layout style size helper

* Update API to set and get a CGSize / ASRelativeSize from an ASLayoutElementStyle

- Expose ASRelativeSize type
- Add new helper properties to set a size / relative size to ASLayoutElementStyle
- Don't expose the size in ASLayoutElementStyle anymore and move into ASLayoutElementStylePrivate

* Update examples

* Update comments for size helpers
2016-10-04 12:35:45 -04:00
Garrett Moon
5205ef6840 [API] Remove old deprecated methods. (#2312)
* Remove old deprecated methods. Will restore ones that were removed recently based on PR.

* Update example to use non-deprecated method.

* Don't remove locking / unlocking, insets or willDisplayNode deprecated methods yet.
2016-10-03 14:57:01 -04:00
Michael Schneider
f574f2c54e [Layout] Further deprecation steps for preferredFrameSize (#2255)
* Deprecate preferredFrameSize

- Remove all support for preferredFrameSize in ASDK
- preferredFrameSize setter calls through and sets the width and height of the node
- preferredFrameSize getter tries to return a CGSize based on the width and height properties otherwise if this is not possible it throws

* Address comments

* Return CGSizeZero for preferredFrameSize unless width and height are ASDimensionUnitPoints

* Better comment for preferredFrameSize and remove lock in calculateSizeThatFits:
2016-09-27 16:07:36 -04:00
Michael Schneider
75dca556e6 [Layout] Add style property to ASLayoutable (#2261)
* Add style property to ASLayoutable

* Add styles property to further layout specs

* Adjust some examples

* Add `loadStyle` to create the style object in a ASLayoutable

* Revert "Add `loadStyle` to create the style object in a ASLayoutable"

This reverts commit 2b7240f2c7dc993e38cadf290cfdf08482dd70c7.

* Revert "Adjust some examples"

This reverts commit 3254ae0a321e75db3ecfa80adee9d96bde93a33d.

* Revert "Add styles property to further layout specs"

This reverts commit c779dcb876ead27122c1af1300146a6ad36912cb.

* Rename ASLayoutableStyleDeclaration to ASLayoutableStyle

* Add styleClass class property for extensibility support of the ASLayoutable style object

* flexShrink should not be YES by default
2016-09-22 16:00:52 -07:00
gazreese
025af5d594 [ASVideoNode] Maintain playback position between visibility changes (#2120)
* [ASVideoNode] Maintain playback position between visibility changes

* [ASVideoNode] Code style changes and moved the pause to be before caching the current playback time.
2016-09-13 20:44:26 -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
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
Maximilian Szengel
43370fe6ff Expose AVPlayerLayer on ASVideoNode (#2028)
The playerLayer is needed for picture in picture support on the iPad (AVPictureInPictureController).
2016-08-13 17:28:19 -07:00
Flo
39cb188b9e [ASVideoNode] Improve playerStatus behaviour and image generation (#2024)
* [ASVideoNode] Use the videoComposition when generating images.

* [ASVideoNode] Improve playerState behaviour.

* [ASVideoNode] Use KVO on _player.rate to determine the playerState.
2016-08-12 12:06:02 -07:00
David Rodrigues
70574243f7 Prevent API misuse at compile time (#2035)
Using Objective-C attributes, in this case `unavailable`, we can hide
unsupported APIs at compile time instead of detecting and warn about it
at runtime with a set of asserts.
2016-08-04 19:00:46 -07:00
Levi McCallum
0c70bca2bd [ASVideoNode] Fix conditional that prevented local asset loading (#1962)
* Fix conditional that prevented local asset loading

* Allow setting new asset to clear previously set URL
2016-07-21 10:39:31 -07:00
Max Gu
1d4620edce Adding documentation for assetURL in ASVideoNode, and adding a mutex lock for assetURL setter (#1961)
* Adding comment in ASVideoNode.h for the assetURL property

* Adding a mutexlock in setAssetURL in ASVideoNode
2016-07-20 18:40:49 -07:00
Max Gu
6bd287086c Addressing Adlai's comment 2016-07-20 17:33:34 -07:00
Max Gu
b8ad8d6cc0 Combine 2 if statements into 1 2016-07-20 17:09:23 -07:00
Max Gu
76303f3799 Setting the internal asset to the player item's asest 2016-07-20 17:03:57 -07:00
Max Gu
b04aa2e2bc Removing some unused method 2016-07-20 16:07:17 -07:00
Max Gu
f6eaa43315 Adding the new ASVideoNode API that allows for video player item construction with URL 2016-07-20 16:01:14 -07:00
Max Gu
44a80672cb Adding track to the requestedKeys to be loaded asynchronously so that it doesn't block the main thread 2016-07-19 20:25:32 -07:00
Max Gu
a4555869de Re-enabling HLS video constructed from URL
Apple claims in the AVFoundationProgramming Guide that HLS videos can be constructed only through URL, but later with iOS 4.3 release notes it claimed to bring updates to how the HLS videos should be initialized, which works with asset too. I’ve tested with both, and it looks like initializing with asset is buggy.
2016-07-19 15:57:22 -07:00
appleguy
74bf376b2f [ASDisplayNode] Rename _propertyLock to __instanceLock__ to avoid subclass naming collisions. (#1941) 2016-07-16 15:32:13 -07:00
Flo
2e65339f33 [ASVideoNode, ASVideoPlayerNode] Add video composition and audio mix capabilities (#1800)
* [ASVideoNode] Add delegate method called when the currentItem is set.

* [ASVideoNode] Add videoComposition and audioMix properties to the ASVideoNode.

* [ASVideoPlayerNode] Add new initialiser with videoComposition and audioMix, and forward new delegate method.

* [ASVideoPlayerNode] Forward missing ASVideoNodeDelegate methods.
2016-07-10 11:32:21 -07:00
Hannah Troisi
f39c2ce7e3 [ASTextNode, ASImageNode, ASVideoNode] Use ASDisplayNode base class lock for subclass property synchronization (#1877)
* [ASTextNode, ASVideoNode] Use ASDisplayNode base class lock for subclass property synchronization

* fix headers to match master

* address @appleguy, @maicki comments

* import header

* Swap lock in ASNetworkImageNode as well

* remove invalid comment

* more cleanup of locks
2016-07-09 22:08:34 -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
Scott Goodson
f0ff9c108d Merge branch 'master' of git://github.com/kielgillard/AsyncDisplayKit into kielgillard-master 2016-07-09 15:44:31 -07:00
Kiel Gillard
6a15ab6130 * Tidy the header imports, forward declaring classes and protocols where appropriate to avoid import cycles and using the framework/system header notation for imports occuring in .h files.
* Perhaps controversially, decomposing ASRangeControllerUpdateRangeProtocol+Beta.h such that the categories on various classes are defined in the classes themselves since that's where the implementation of those categories is provided.
* Updating unit tests and import other headers the tests took for granted. The tests could probably import the umbrella header and not have to worry about this.
* Updating the "Life without Cocoapods" sample to build and run dependent on ASDK as a static library.
* Added a "Life With Frameworks" sample app to build and run dependent on ASDK as a framework, proving the framework targets work.
2016-07-07 15:12:19 +10:00
Gareth Reese
b9b002354a [ASVideoNode] Only seek to beginning when auto repeating 2016-07-05 13:27:53 +01:00
Adlai Holler
f4ccb93969 Merge pull request #1788 from gazreese/ASVideoNode-overwrittenplaceholder
[ASVideoNode] issue #1782 Placeholder images are replaced by blanks during loading
2016-07-02 08:30:38 -07:00
Gareth Reese
1d356242fd [ASVideoNode] Ensure that observer methods don't observer all other ASVideoNode objects 2016-06-28 15:41:26 +01:00
Gareth Reese
9349abb737 Merge branch 'master' of https://github.com/facebook/AsyncDisplayKit into ASVideoNode-overwrittenplaceholder 2016-06-24 11:39:12 +01:00
Gareth Reese
3fee0810d5 [ASVideoNode] Ensure that both ASVideoNode and ASNetworkImageNode delegate methods are called for ASVideoNode observers 2016-06-21 11:36:54 +01:00
Gareth Reese
062bcf3631 [ASVideoNode] issue #1782 Placeholder images are replaced by a blank placeholder. Now checks the .URL property of the parent class as well as the .image to ensure that new placeholders aren't generated. 2016-06-21 07:51:58 +01: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
appleguy
a7128cd213 Merge pull request #1605 from lappp9/override-callback-for-display-range
[ASDisplayNode] Added callbacks for entering and exiting fetch data and display ranges
2016-06-11 22:21:20 -07:00
Eric Jensen
001d3ea624 Use a strong reference to the current asset in order to prevent setting a placeholder image if the asset is set to nil while the placeholder image is generating 2016-06-08 12:37:32 -07:00
Luke Parham
fc5467b110 fixed typo and added backwards compatibility for 'visibilityDidChange' 2016-06-06 02:02:23 -05:00
Luke Parham
e510120031 changed '-visibilityDidChange:' to '-visiblieStateDidChange:' to match the others 2016-06-06 00:56:21 -05:00