273 Commits
Author SHA1 Message Date
Andy Finnell e696302586 Add default image provider (#2127)
* Add default image provider

## Summary

Right now image nodes hardcode logic to use either PINRemoteImage or the basic image downloader. Additionally, Texture is missing annotations for nullability and sendable for several of the image blocks and types.

Introduce ASDefaultImageDownloader as a singleton. It takes blocks to return the default image downloader and image cache. Update both image nodes to use this. By default ASDefaultImageDownloader uses the same logic the image nodes used to, so change in behavior.

## Test plan

Run the Kittens example and verify it works.

* Appears we need Xcode 16.4

* And need at least 18.5
2025-10-22 12:36:55 -04:00
ricky 2d7bf71e7c [_ASDisplayLayer] Add protection around setting a layer’s position and transform (#2116)
There is built in protection around setting invalid bounds for `_ASDisplayLayer`. Let’s extend this to also include protecting against setting an invalid position and an invalid transform.
2024-09-04 08:44:57 -07:00
Andy Finnell e9bd484149 Update to Xcode 15 (#2107)
* Update to Xcode 15

## Summary

We want to make Texture build with recent tools like Xcode 15. Part of this is bumping the minimum supported OS to iOS 14.

I only removed the dead code (i.e. code gated on versions older than iOS 14). There are still some warnings about outdated APIs in use, but they are non-trivial changes to fix.

## Test plan

Run all the examples. Run all the unit tests and make them pass.

* Use Xcode 15.3 so we have 17.4 simulators

* Fixing an asset catalog compiler error when building against iPhone SE

* Fix a couple of file extensions for assets

A couple of PNGs were marked as JPGs
2024-05-21 13:04:39 -04:00
Carlos Compean 923901a1ce Fix build errors and a crash in xcode 15 (#2093)
* Fix build errors and a crash in xcode 15

* early return if 0 or negative dimensions found
2023-09-11 10:43:37 -07:00
Mussa Charles fea847be55 Increase default diskCache byte limit from 20 to 50MB(PINCache default) (#2002) 2022-08-18 09:27:58 -07:00
David Ha 053688bfb2 Xcode 13 ASLoadFrameworkInitializer dead lock fix on running unit test (#2032)
* replace destructor for after main execute

* separate ASLoadFrameworkInitializer between constructor and destructor

* AS_EXTERN -> ASDK_EXTERN

* initialSetNeedsDisplayCount should be called once on iOS 15

* Loaded node of contentsScale must be 2.0 on layer backed

* initialSetNeedsDisplayCount must called once
2021-12-03 09:32:05 -08:00
Sylvain Defresne 39ea9fe2f2 Remove trailing semicolons between method parameters and body (#1973)
Having a semi-colon between a method parameters list and a method
body is not not correct and is usually caused by a copy and paste
error while creating the method definition from its declaration.

Fixes the following compilation warnings when building with
-Wsemicolon-before-method-body (which is part of -Wextra):

  ASPINRemoteImageDownloader.mm:230:85: error: semicolon before method body is ignored [-Werror,-Wsemicolon-before-method-body]
  - (id <ASImageContainerProtocol>)synchronouslyFetchedCachedImageWithURL:(NSURL *)URL;
                                                                                      ^
  ASPINRemoteImageDownloader.mm:275:76: error: semicolon before method body is ignored [-Werror,-Wsemicolon-before-method-body]
                           completion:(ASImageDownloaderCompletion)completion;
                                                                             ^
  2 errors generated.

Fixes applied to both code, examples and samples in documentation.
2021-03-26 11:07:31 -07:00
Christos Gkekas 17d4d13463 Exposes a new option in ASImageDownloaderProtocol to retry image downloads (#1948)
* Exposes a new option in ASImageDownloaderProtocol to retry image downloads

At the moment the ASBasicImageDownloader does not automatically retry image downloads if the remote
host is unreachable. On the contrary the ASPINRemoteImageDownloader automatically retries. Retrying is
something that ultimately clients need to be able to control, for example to fail fast to an alternative image
rather than keep retrying for more than one minute while not displaying any image. This change exposes
a new option in the ASImageDownloaderProtocol to retry image downloads. It also uses this new option
in both ASNetworkImageNode and also ASMultiplexImageNode, setting it to YES to preserve the current
behaviour.

* Fixes a failing test in ASMultiplexImageNodeTests

* Fixes ScreenNode.m

ScreenNode.m is implementing ASImageDownloaderProtocol and needs to
be fixed to reflect changes in the latter.
2021-02-19 08:23:01 -08:00
Zev Eisenberg 9e8de03845 Fix WKWebView Accessibility (#1955)
* Return nil instead of empty array when no accessibility elements are found. Fixes #1954.

* Use nullability annotations to fix static analyzer warnings.

* Add UI test target.

* Add UI test to make sure web view stays accessible.

* Revert "Add UI test to make sure web view stays accessible."

This reverts commit 00253f49a0af329602b0d9709b58bc92dcd90147.

* Revert "Add UI test target."

This reverts commit 288b5e0f564ef3ba3fb5568baa832bc03124cdc9.

* Add unit test to make sure accessibility elements are correct when a WKWebView is wrapped in an ASDisplayNode.
2021-02-03 13:24:39 -08:00
Ben Dolman efdd8acd99 Fix hit point when ASCollectionNode inverted set to true (#1781)
* Account for possible inverted transform during hit test

When ASCollectionNode has the `inverted` flag set, a transform gets
set on the cell node. We need to make sure that we account for that
when dealing in the view coordinates.

* Store self.node and self.node.view in local variables for better readability.

* Add a test for hit testing in an inverted ASCollectionNode
2020-10-06 09:36:43 -07:00
Huy Nguyen 2758ff18d9 More on ASDataController's main-thread-only mode (#1915)
Follow up on #1911: it's not enough to execute step 3 on the main thread because -_allocateNodesFromElements: uses ASDispatchApply to offload the work to other threads. So this diff adds a flag to tell that method to do everything serially on the calling thread.
2020-09-18 10:08:21 -07:00
Huy Nguyen 32679feb84 Add an experiment that makes ASDataController to do everything on main thread (#1911)
* Add an experiment that makes ASDataController to do everything on main thread

Under this experiment, ASDataController will allocate and layout all nodes on the main thread. This helps to avoid deadlocks that would otherwise occur if some of the node allocations or layouts caused ASDataController's background queue to block on main thread. As a bonus, this experiment also helps to measure how much performance wins we get from doing the work off main.

* Remove ASSERT_ON_EDITING_QUEUE
2020-09-17 18:04:17 -07:00
Greg Bolsinga 45c0f19ae1 Do not expose tgmath.h to all clients of Texture (#1900)
* Do not expose tgmath.h to all clients of Texture

- tgmath.h #undef the `log` macro for mathematical reasons. Code that may also use a log name (such as CocoaLumberjack) will get confused by this when they try to use `NS_SWIFT_NAME` with `log` as part of the name.
- `ABS` from NSObjCRuntime.h is what is typically used for abs on `CGFloat`.
- Note: removing tgmath.h from the Texture umbrella header may expose clients that implicitly depended upon it being imported. Sources may have to be updated after this to `#import <tgmath.h>` explicitly.
2020-08-21 14:22:34 -07:00
ricky f56a4dd1dd [Accessibility] Ship ASExperimentalDoNotCacheAccessibilityElements (#1888)
We did not notice any effect on performance of the Pinterest app by not caching `accessibilityElements` in `_ASDisplayView`. By not caching the elements, we can be sure that the elements will be correct even when nodes change visibility state. There will be a performance impact when voice over is enabled, but providing the correct elements for the current state of a view is more important than performance in this case.

https://github.com/TextureGroup/Texture/issues/1853
2020-07-23 15:21:07 -07:00
Garrett Moon c5f69f0b01 Renames AS_EXTERN and ASViewController (#1876)
* Renames AS_EXTERN and ASViewController

To ASDK_EXTERN and ASDKViewController.
This is to avoid conflicting with AuthenticationServices in
Xcode 12

* Fix up examples and docs

* Add bit about updating ASViewController rename
2020-06-29 12:49:59 -07:00
Garrett Moon dbb06bf58f Fix all the warnings and re-enable on CI (#1872) 2020-06-25 11:54:00 -07:00
ricky e16fdd67e1 [ASDisplayNode] Implement accessibilityElementsHidden (#1859)
Most of this code comes from an old PR that @fruitcoder put up https://github.com/TextureGroup/Texture/pull/795 2 years ago.

When creating our array of accessibilityElements, we need to respect the value of `accessibilityElementsHidden`. If the value of this property changes, we need to invalidate the cached accessibility elements (unless we are in the experiment that doesn’t cache `accessibilityElements`).

I created a simple test app and made sure this matched UIKit’s implementation. I also added a test case that changes the value of `accessibilityElementsHidden` and makes sure the proper accessibilityElements are returned.
2020-06-03 16:16:43 -07:00
ricky 08bd6f6e3b [ASDisplayNode] Implement accessibilityViewIsModal (#1858)
* [ASDisplayNode] Implement accessibilityViewIsModal

A PR to add support for `accessibilityViewIsModal` in `CollectAccessibilityElements`.

If in a list of subnodes more than 1 subnode has `accessibilityViewIsModal` marked as `YES`, then the node with the highest index in `subnodes` will be the one that is considered modal. This behavior matches UIKit.

If the value of `accessibilityViewIsModal` changes, we need to clear all the cached `accessibilityElements` from that view up. I added this in ASDisplayNode’s `setAccessibilityViewIsModal` method. Note that if we ship `ASExperimentalDoNotCacheAccessibilityElements` then we can remove the invalidation step.

Finally, I changed all the tests to ask the view for accessibilityElements, not the node. This is a better representation of what will really happen when UIKit asks a node’s view for its accessibility elements. It also allowed me to test that clearing the accessibilityElements was working.

* add some experiment checks

* fix tests and address jon’s comment

* Fix tests

* remove debug code
2020-06-01 12:58:44 -07:00
Greg Bolsinga a6f9ceec71 Ship ASExperimentalUnfairLock experiment (#1841)
- Followup to #1742
- At Pinterest this shipped with D516974 in late 02/2020
- As discussed in #858 this is iOS10 or later, so the runtime `gMutex_unfair` check is still necessary for Texture.
2020-05-26 20:56:28 -07:00
Greg Bolsinga 44c68a3fef Update Texture Xcode project to 11.4 and fix resulting warnings - 4 (#1838)
* Update Texture Xcode project to 11.4 and fix resulting warnings - 4

* Some tests require testing deprecated functionality
2020-05-26 13:55:16 -07:00
vovasty 74fd8f3d33 deprecate ASGraphicsCreateImageWithTraitCollectionAndOptions (#1836) 2020-05-22 20:15:09 -07:00
+22 38852e16cd [Accessibility] Do not exclude elements outside the window’s rect that are subviews of UIScrollView (#1821)
* [Accessibility] Do not exclude elements outside the window’s rect that are subviews of UIScrollView

Previously I put up a diff to exclude accessibility elements that were outside of the current window rect. However, I didn’t take the case of scrollViews (including table and collection views) into consideration. By ignoring cells outside of the window, the scroll view would not advance to additional elements in the scrollView but off screen.

I did some side-by-side testing with UIKit and it appears that no elements are excluded that are in a scroll view, even if the element’s rect is outside of the scroll view’s visible rect. In order to match this behavior, I added a recursive superview check to see if an element that is off screen has a scrollView as a parent. If so, we do not exclude it:

```    if (!CGRectIntersectsRect(view.window.frame, nodeInWindowCoords) && !recusivelyCheckSuperviewsForScrollView(view)) {
        continue;
    }```

* fix some spacings

* force a build

* build bump again

* Removes unnecessary `-tearDown` code. (#1822)

* Update Texture.podspec (#1773)

3.0.0

* support cancelation in ASGraphicsCreateImage (#1814)

* support cancelation in ASGraphicsCreateImage

* updated comment

* [IGListKit] Extended IGListKit support for displaying delegates (#1011)

* Extended IGListKit support for node deselect, highlight and unhighlight

* Proposal of renaming willDisplayItemWithNode and didEndDisplayingItemWithNode to be similiar to UICollectionView

* Extended support for IGListDisplayDelegate

* Updated changelog with displaying delegates change

* Removed extra deprecation supression flag

* Reverted ASCollectionNode changes and implemented displaing delegate with indexPathForNode:

* Sending a real UICollectionViewCell to the delegate if not nil

* Added safety check for nil indexPaths

* Discard any CHANGELOG changes for fix Danger error

* Add an experimental flag to use native dispatch_apply (#1345)

* Add an experimental flag to use native dispatch_apply instead of our core count * 2 approach. This has shown performance wins in some profiling.

* Add in other places

* Don't return non-animated GIFs for animation (update to latest PINRemoteImage beta) (#940)

* Don't return non-animated GIFs for animation

* Update to latest PINRemoteImage beta

* Fix typos  (#1348)

* Update containers-overview.md

* Update subclassing.md

* Update node-overview.md

ASImageNode, ASNetworkImageNode and ASMultiplexImageNode are in place of UIImageView, not UIImage.

* Revert "Have node and controller share lock (#1227)" (#1347)

This reverts commit 2baa9438d7.

* Don't compile out ASExperimentalTextNode if ASTextNode is compiled out (#1353)

* 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

* Update layout-transition-api.md (#1357)

* Optimize ASTwoDimensionalArrayUtils (#1351)

* Optimize ASTwoDimensionalArrayUtils

These methods are called on the main thread during range controller updates (i.e. every frame) and so they should be as fast as possible.

* Rename

* Use vector instead of stack array to handle really big cases (e.g. photos)

* If we check for batching before content size is available we'll always fetch (#1355)

* 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.

* Resolve root constrained size before informing delegate to resolve infinite layout loop. (#1359)

* Add `setNeedsLayout` to yoga tree changes. (#1361)

* Make ASCollectionElement Public (#1303)

* Update AsyncDisplayKit.h

* Update project.pbxproj

* 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

* _ASCollectionViewCell - The point isn't converted before to send to node, impossible to touch button into the node hierarchy (#1362)

* Revert node call, useless, the node has a ASDisplayView, and this view forward on the node in first.

* Use convertPoint to convert the given point in hittest & pointInside methods.
Keep the standard usage if the node didn't rasterized a view.

* Removed isNodeLoaded, finally it's useless in this case
In these methods, we are on the mainThread, we can create the view if the view is not created.

* Optimize ASCATransactionQueue (#1350)

* Optimize ASCATransactionQueue. This queue is very busy, and it runs on the main thread so it's important for it to be fast.

Avoid waking up the run loop for every single node.
Avoid a ton of NSPointerArray overhead that we don't need.
Avoid retain/release traffic on the singleton by using an inline function. I confirmed that in release mode, the static __strong is correctly inlined and no ARC traffic is incurred.

* Comment

* Unlock right

* Remove magic number

* Cleanup Yoga Categories (#1364)

* Add forwarding of UIAccessibilityAction methods (#1344)

* Add forwarding of UIAccessibilityAction methods

* Use OCMock for testing UIAccessibilityAction method forwarding

* Don't add extraneous truncation token during kCTLineTruncationMiddle. (#1297)

* Don't add extraneous truncation token during kCTLineTruncationMiddle

* Expand these comments a little.

* Update the FAQ to throw less shade. (#1379)

* Update the FAQ to throw less shade.

Both of these technologies have their place, no point in being assholes.

* Update faq.md

* [Updated Snapshots] Don't add extraneous truncation token during kCTLineTruncationMiddle (#1375)

* Don't add extraneous truncation token during kCTLineTruncationMiddle

* Expand these comments a little.

* Update snapshot tests with beautiful correct behavior

* Launches switching ASNetworkImageNode callbacks to global queue. (#1369)

* Launches switching ASNetworkImageNode callbacks to global queue.

* Good catch configuration tests!

* Make ASTextNode2 more forgiving when searching for links (#1374)

* Make ASTextNode2 more forgiving when searching for links by searching a 44x44 square around the touch

* Trailing whitespace

* Safely handle end-of-line

* Experiment with different strategies for image downloader priority (#1349)

Right now when an image node enters preload state, we kick off an image request with the default priority. Then when it enters display state, we change the priority to "imminent" which is mapped to the default priority as well. This means that requests from preload and display nodes have the same priority and are put to the same pool. The right behavior would be that preload requests should have a lower priority from the beginning.

Another problem is that, due to the execution order of -didEnter(Preload|Display|Visible)State calls, a node may kick off a low priority request when it enters preload state even though it knows that it's also visible. By the time -didEnterVisibleState is called, the low priority request may have already been consumed and the download/data task won't pick up the new higher priority, or some work needs to be done to move it to another queue. A better behavior would be to always use the current interface state to determine the priority. This means that visible nodes will kick off high priority requests as soon as -didEnterPreloadState is called.

The last (and smaller) issue is that a node marks its request as preload/low priority as soon as it exits visible state. I'd argue that this is too agressive. It may be reasonble for nodes in the trailing direction. Even so, we already handle this case by (almost always) have smaller trailing buffers. So this diff makes sure that nodes that exited visible state will have imminent/default priority if they remain in the display range.

All of these new behaviors are wrapped in an experiment and will be tested carefully before being rolled out.

* Add imports

* Fix build failure

* Encapsulate common logics into methods

* Address comments

* Whoops, someone forgot an else! (#1385)

Luckily it seems this didn't cause huge memory bloat because there's
a check below that keeps the display flag from being set in low memory
conditions when the node is off the screen.

* Catch invalid sizes during yoga layout (#1376)

* Correct View vs. Layer here (tho it doesn't make any difference) (#1378)

Older FBSnapshot versions, however, don't use VerifyViewOrLayer

* Expose initial constrained size before layout in case anyone is interested later during the layout on the same thread. (#1377)

Optionally, clients are expected to clean it up after usage to avoid accessing outdated data.

* Assert for context creation failure during displayBlock. (#1373)

Nothing good can possibly happen if we continue without one.

* Fix an issue where state change notifications can be sent mulitple times. (#1372)

Before the change: both - (void)setShouldInvertStrongReference:(BOOL)shouldInvertStrongReference and - (void)setNode:(ASDisplayNode *)node will call through [self setupReferencesWithNode:node]; which call the [node addInterfaceStateDelegate:self];

* Add Yoga support to ASButtonNode (#1381)

* Add Yoga support to ASButtonNode

* Drop unowned ASLayoutElementStyle parameter

* Fix access of Yoga properties

* Move ASButtonNode Yoga logic to Category

* Update header

* Fix CTLineRef leaks (#1386)

Found by Clang Static Analyzer:

~/Texture/Source/ASTextNode2.mm:663:39: warning: Potential leak of an object stored into 'truncationTokenLine'
      CTLineRef truncationTokenLine = CTLineCreateWithAttributedString((CFAttributedStringRef)_truncationAttributedText);
                                      ^
~/Texture/Source/ASTextNode2.mm:666:49: warning: Potential leak of an object stored into 'additionalTruncationTokenLine'
      CTLineRef additionalTruncationTokenLine = CTLineCreateWithAttributedString((CFAttributedStringRef)_additionalTruncationMessage);
                                                ^
2 warnings generated.

* Correct attributes lookup for supplementary elements. (#1318)

* Need some more locks for working with calculated yoga layouts (#1388)

* Adds support for using UIGraphicsImageRenderer in ASTextNode. (#1384)

* Adds support for using UIGraphicsImageRenderer in ASTextNode.

In many cases this reduces the backing store of text nodes by 1/2.

* Guard for UIGraphicsRenderer availability.

* Comma

* Add UIDataSourceModelAssociation to ASTableView and ASCollectionView (#1354)

* Add UIDataSourceModelAssociation protocol conformance to ASTableView and ASCollectionView.

* Implementing review feedback from @Adlai-Holler

* 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

* Clean up a clang analyzer cast error (#1387)

~/Texture/Source/Private/ASMutableElementMap.mm:32:24: warning: Conversion from value of type 'NSMutableArray<NSMutableArray *> *' to incompatible type 'ASMutableCollectionElementTwoDimensionalArray *'
    _sectionsOfItems = (id)ASTwoDimensionalArrayDeepMutableCopy(items);
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

* Update for 9.4.1 CI (#1392)

* Remove experimental features (exp_skip_a11y_wait && exp_new_default_cell_layout_mode) (#1383)

* Remove experimental features

* prevent blocking main thread

* remove small content all together as none is the default

* Update ASExperimentalFeatures.h

* Make experiment checks faster (#1393)

* Make experiment checks use dispatch_once when not debugging, clean up singleton

* One more

* Pull out the variable

* Make shared CA transaction queue variable extern so it's actually shared (#1397)

* Fix header typo (#1402)

* Context is a pretty general name that will cause conflicts with subclasses (#1399)

* Suppress documentation warnings when using external libraries (#1401)

Fixes 1400

* Add layer-action support to nodes (#1396)

* Add layer-action support to nodes, unify hierarchy notifications on it

* Better pending state

* Fix bool

* Skip extra copy

* Never run default actions

* Continue the search

* Avoid an unnecessary lock & unlock pair in ASMainSerialQueue (#1409)

* Add clang-format for a common source code format (#1365)

* Add clang-format

* Update format to be as close as our current style

* Fix GIF Caching (#1405)

* Add support for reverse direction to yoga layouts (#1413)

* Add support for reverse direction to yoga layouts

* #ifdef YOGA yoga-specific additions

* oops

* Only set ASLayoutElementStyle delegate if Yoga is enabled (#1417)

* Fix bug in ASRangeController that causes some cell nodes of a collection view which is about to becomes invisible to load their backing view/layer and render (#1418)

* Fix a bug with Yoga nodes whose position change and don't update. (#1408)

* Follow up on the ASRangeController fix in #1418 (#1419)

The changes in #1418 is a bit too aggressive when it comes to nodes that are in display range. It forces those nodes to not preload.

Also update the changes to avoid diluting the experiment data by triggering too broadly (i.e avoid triggering when the old and new implementations yield the same result leading to no behavior change).

* Dev docs for threading in Texture (#1319)

* Getting started on adding threading by example

* writing writing writing

* more info

* More threading

* More more more

* Threading

* self lock

* Some language fixes

* Update docs/_docs/development/threading.md

Co-Authored-By: mikezucc <mikezuccarino@gmail.com>

* fix image references

* Removed locked jekyll version (#1322)

* showcase.md updated (#1421)

* Experiment with disabling ASViewController background dealloc (#1420)

* [Experiment] Dont forget about these collection view background deallocs (#1424)

* Dont forget about these collection view background deallocs

* Also Table view for completeness

* Fix retain cycle with transaction operations (#1429)

Add unit tests that help find cycles. `-testWeakWithSingleOperation` fails without the code fix applied.

* Replace +load initializers with __attribute__((constructor)) functions (#1425)

* Replace +load initializers with __attribute__((constructor)) functions

* Updating the documentation for textureDidInitialize, per @nguyenhuy

* Fix dealloc on bg (#1410)

* fix SIMULATE_WEB_RESPONSE not imported #449

* Fix to make rangeMode update in right time

* remove uncessary assert

* Fix collection cell editing bug for iOS 9 & 10

* Revert "Fix collection cell editing bug for iOS 9 & 10"

This reverts commit 06e18a1059.

* Fix dealloc long gesture in background

* Add support for clipping only specific corners, add unit tests (#1415)

* Add support for clipping only specific corners, add unit tests

* Remove some cleanup to make the diff smaller

* Fix

* [ASImageNode]fix incorrect backing size calculation (#1189)

* fix backing size for image node which content mode is scaleAspectFit

* chore: update comments and naming

* add change log

* Update CHANGELOG.md

* Update CHANGELOG.md

Co-Authored-By: junjielu <348649634@qq.com>

* add unit test for backing size calculation

* correct license

* Have image nodes draw into opaque contexts automatically if possible (#1432)

* Have image nodes draw into opaque contexts if the image is opaque and it fills the context

* Call backingSize once

* Fix typo in batch-fetching-api.md (#1437)

* [ASDisplayNode] Stop infinite layout in _u_measureNodeWithBoundsIfNecessary (#1434)

We came across an infinite layout loop in `_u_measureNodeWithBoundsIfNecessary`. After requesting a layout from above, the sizes between pending and caluclated layout still do not match. We continue to prefer to use the pending layout and ask for another layout loop from above. We can’t seem to break out of this loop. The solution (thanks to Huy for the guidance) was to nil out the pending layout we get from requesting the layout from above.

I was only able to reproduce this when working with a node in a `UINavigationBarItem’s` `titleView`. I think that UIKit must be doing something sneaky with setting the frame on the view. While I was not able to create a unit test to catch this issue (I tried for a long time, and can post what I’ve come up with to see if anyone has any suggestions), I was able to create a pretty simple example project that shows the behavior:
https://github.com/rcancro/TextureLayoutLoopExample

* Add a verbose log for locking operations. Has no effect in production (#1436)

* Add a verbose log for locking operations. Has no effect in production

* Need check

* Wrap transaction operation retain cycle fix in an experiment (#1438)

* Wrap transaction operation retain cycle fix in an experiment

This is a follow on to #1429.

* fix typo in experiment name. fix copyright in tests file.

* Fix scroll node in yoga (#1435)

* fix SIMULATE_WEB_RESPONSE not imported #449

* Fix to make rangeMode update in right time

* remove uncessary assert

* Fix collection cell editing bug for iOS 9 & 10

* Revert "Fix collection cell editing bug for iOS 9 & 10"

This reverts commit 06e18a1059.

* Fix child not fit to full scroll node's bounds when flex_grow = 1.0 is used on child

* Fix the stub for layerActionForKey: to let CA continue the search (#1441)

* Fix the stub for layerActionForKey: to let CA continue the search

* Kick CI

* Revert "Have image nodes draw into opaque contexts automatically if possible (#1432)" (#1443)

This reverts commit 28522ce977.

* Use instance lock for ASPrimitiveTraitCollection (#1442)

* Use instance lock for ASPrimitiveTraitCollection

* Remove the atomic

* Simplify ASTraitCollection propagation in ASViewController (#1447)

* Use AS::Mutex in ASCollectionElement (#1445)

* [ASTextNode] Maintain isAccessibilityElement setting on text nodes when updating text (#1326)

* Add didEnterHierarchy/didExitHierarchy to ASNodeController. (#1444)

* Fix wrongly formatted RELEASE link (#1453)

* Only create activities during debug (#1456)

* [#1451] Add support for UIAccessibilityCustomAction (#1452)

This PR adds support for UIAccessibilityCustomAction propagation through ASPendingState so that it can be picked up by VoiceOver.

* Shut down graphics contexts experiment (#1458)

* Shut down graphics contexts experiment

* Remove dead import

* Remove gone class

* Remove lock of ASTextNodeRendererKey (#1454)

* Remove lock of ASTextNodeRendererKey

* Remove class check for isEqual

* Add const specifier to function parameter

* Fixes typo

* Fixes typo

* Disable ASAssertLocked and ASAssertUnlocked (#1412)

* Try to remove global lock when initialising TextKit components (#1455)

* Try to remove global lock when initialising TextKit components

* Adding experiment flag to dis/enable lock of textkit component

* Adding tests

* code clean

fix typo

Make remove lock optional

Keep locks

code clean

* Make ASCollectionNode's pan gesture customizable (#1457)

* changes done

* complete set of uigesturedeleagte methods

* Remove iOS 8 support from logging code. (#1462)

* Drop support for Xcode 8 and fix some compiler warnings (#1463)

* Remove ASEventLog (#1460)

* Remove ASEventLog. We'll focus on ASLog for the future, possibly making it triggerable on a per-node basis

* See ya!

* Hello semicolon

* Remove refs to gone tree methods

* Fix

* Remove irrelevant change, kick CI

* Clean up

* Cover the other background dealloc surfaces (#1464)

* Passthrough pagingEnabled for ASCollectionNode / ASTableNode (#1466)

* Passthrough pagingEnabled for ASCollectionNode and ASTableNode

* Add tvOS handling

* Fix open context bug introduced in #1458 (#1468)

* Make sure all ASDisplayNode properties have backing ivars for consistency. (#1475)

* Make sure all ASDisplayNodes have backing ivars for consistency.

Found this by enabling #pragma clang diagnostic error "-Wobjc-missing-property-synthesis" for ASDisplayNode. One property is unused, saving 8 bytes of heap space per instance on 64-bit builds. Implement setter/getters for these properties, and add appropriate locking. add the warning as error to the build for this file.

* Ensure ASControlMode properties lock before accessing their ivars (#1476)

Enable `#pragma clang diagnostic error "-Wobjc-missing-property-synthesis"` for this file.

* Add a new "global drawing" experiment to use UIGraphicsRenderer (#1469)

* Add a new "global drawing" experiment to use UIGraphicsRenderer everywhere, when available

* Fix logic

* Use preferredFormat

* Cut version 2.8.1 (#1491)

* Clean up documentation issues around periods (#1490)

There were so unnecessary `'` around periods for some reason. Just deleting those because they are distracting.

* Minor update in change log #changelog (#1492)

* Ship ASExperimentalFixRangeController (#1486)

* Shrink _ASCollectionPendingState from 144 to 128 bytes, a 12.5% reduction (#1485)

* Shrink _ASCollectionPendingState from 144 to 128 bytes, a 12.5% reduction

These objects accumulate in the heap, so reducing their size will allow more to accumulate before memory warnings.

Group the `BOOL`s into a struct. Shrink the various stored `enum`s to fit the size of their contents. Move the ivars around so that the smaller `enum` are near eachother and the bitfield struct.

* address review comments. move enums out. add comment. rename struct to _flags

* fix a missing rename

* Shrink _ASPendingState from 824 to 808 bytes, reduction of ~2% (#1483)

* Shrink _ASPendingState from 824 to 808 bytes, reduction of ~2%

These objects accumulate in the heap, so reducing their size will allow more to accumulate before memory warnings.

Shrink ASPendingState BOOLs. Use unsigned int for these bitfields for clarity. Separate from `_flags` as that struct is compared to `0` for testing. The `_boolFlags` struct is just storing other `BOOL`s.

* rename struct fields as suggested in garret's review.

* Shrink ASDisplayNode from 1072 to 968 bytes, reduction of 10.74% (#1484)

* Shrink ASDisplayNode from 1088 to 976 bytes, reduction of 11.48%

These objects accumulate in the heap, so reducing their size will allow more to accumulate before memory warnings.

Group the `BOOL`s into a struct. Shrink the various stored `enum`s to fit the size of their contents. Move the ivars around so that the smaller `enum` are near eachother and the bitfield struct.

* Forgot to bit-field-ify placeholderEnable; new small size is 968, old size is 1072 (measured consistentlyl on iPhoneSE simulator). 10.74% reduction.

* Shrink Button Node (#1494)

Button: 1312 to 1288 bytes, running on iPhone SE simulator. 1.9% reduction.

Shrink the enums it stores, and place them next to each other (along with a BOOL) to reduce instance size.

* Shrink TextNode(2) (#1495)

Running in iPhone SE Simulator:
- ASTextNode: 1360 to 1352 bytes .6% reduction
- ASTextNode2: 1360 to 1304 bytes 4.3% redction

Shrink stored enum sizes. Group BOOLs near these smaller enums. Override -usingExperiment to return constant instead of never set, but allocated ivar.

* Shrink Pager and Scroll Node (#1496)

Running on iPhone SE Simulator:
ASPagerNode 1240 to 1232 bytes .7% reduction
ASScrollNode 1104 to 1096 bytes .7% reduction

- make ASScrollNode smaller by shrinking ASScrollDirection, which requires a change to ASRangeController
- shrink ASPagerNode by declaring the BOOL next to the struct

* Shrink ASImageNode by .6% and ASNetworkImageNode by 2.2% (#1487)

* Shrink ASImageNode by .6% and ASNetworkImageNode by 2.2%

ASImageNode goes from 1384 to 1376. ASNetworkImageNode goes from 1496 to 1464.

These objects accumulate in the heap, so reducing their size will allow more to accumulate before memory warnings.

Group the `BOOL`s into a struct. Shrink the various stored `enum`s to fit the size of their contents. Move the ivars around so that the smaller `enum` are near eachother and the bitfield struct.

* add comments as requested in garrett's review.

* access ivar directly since already locked as suggested in review.

* Remove unused declaration, missed in #1460 (#1497)

* Keep the atomics - does not affect memory work (#1498)

Revert "Ensure ASControlMode properties lock before accessing their ivars (#1476)"
This reverts commit ce1e1956f4.

Revert "Make sure all ASDisplayNode properties have backing ivars for consistency. (#1475)"
This reverts commit d6061f4390.
- Except the unused property `interfaceStateSuspended` is still removed (this is a memory saver).

* Shrink ASCellNode by 8 bytes (#1499)

Group the BOOLs together, since there are only 4 (and there are no other auto-generated ivars that are < 64 bits) this is sufficient and keeps the properties `atomic`.

* Shrink ASEditableTextNode by 16 bytes (#1500)

Just shuffle some BOOLs around and explicitly declare an ivar so it is grouped with the others.

* ASSignpost: Add support for the os_signpost API, fixes (#1501)

* ASSignpost: Add support for the os_signpost API

- Removes support for colored intervals. These weren't really useful and they aren't part of the signpost api.
- Fixes an issue with range controller interval logging.
- Adds an interval for interface orientation changes.

* Rename

* Support Xcode 9

* Commentary

* Shrink ASLayout (#1503)

- Shrink the enum. Save 8 bytes. There are 1000s of these in the heap after running Pinterest for 10 minutes.

* Cleanup whitespace #trivial (#1507)

(It's easier to deal with these as silly oneoffs IMO than to
have them conflated with real work)

* Shrink LayoutSpec classes (#1502)

- Resize enums to make `ASStackLayoutSpec` 40 bytes smaller. This applies to the subclasses too.

Co-authored-by: Adlai Holler <adlai@icloud.com>
Co-authored-by: Garrett Moon <garrett@pinterest.com>
Co-authored-by: dirtmelon <272485887@qq.com>
Co-authored-by: Michael Schneider <maicki@users.noreply.github.com>
Co-authored-by: Kevin <kevin@wode.com>
Co-authored-by: dirtmelon <0xffdirtmelon@gmail.com>
Co-authored-by: Jonathan Downing <jd@jonathandowning.uk>
Co-authored-by: Xavier Deloge <Idefix60@users.noreply.github.com>
Co-authored-by: Eric Scheers <smeis@users.noreply.github.com>
Co-authored-by: Huy Nguyen <allforone1511@gmail.com>
Co-authored-by: Greg Bolsinga <bolsinga@mac.com>
Co-authored-by: Jacob Farkas <farktronix@users.noreply.github.com>
Co-authored-by: ernestmama <43187788+ernestmama@users.noreply.github.com>
Co-authored-by: Andrew Yates <contact@andydev.co.uk>
Co-authored-by: Tim Norman <tim@normsoft.com>
Co-authored-by: Michael Zuccarino <mikezuccarino@gmail.com>
Co-authored-by: Dmitry Gridnev <dmitr.gridnev@gmail.com>
Co-authored-by: Max Wang <max.wang.cs@gmail.com>
Co-authored-by: Ballad <348649634@qq.com>
Co-authored-by: ricky <rickycancro@gmail.com>
Co-authored-by: Patrick Balestra <me@patrickbalestra.com>
Co-authored-by: Harry Shamansky <harry.shamansky@gmail.com>
Co-authored-by: Wu Zhong <zhongwuzw@qq.com>
Co-authored-by: Oskar Zhang <i@oskarzhang.me>
Co-authored-by: Adlai Holler <adlai@google.com>
Co-authored-by: Greg Bolsinga <gbolsinga@pinterest.com>
Co-authored-by: Huy Nguyen <huy@pinterest.com>
Co-authored-by: Andrew Monshizadeh <amonshiz+github@gmail.com>

* use iOS 13.4.1 and default Xcode 11.4.1 for CI (#1831)

Co-authored-by: dmaclach <dmaclach@gmail.com>
Co-authored-by: Jeffrey Macko <mackoj@users.noreply.github.com>
Co-authored-by: vovasty <vlad@aramzamzam.net>
Co-authored-by: Heberti Almeida <hebertialmeida@gmail.com>
Co-authored-by: Adlai Holler <adlai@icloud.com>
Co-authored-by: Garrett Moon <garrett@pinterest.com>
Co-authored-by: dirtmelon <272485887@qq.com>
Co-authored-by: Michael Schneider <maicki@users.noreply.github.com>
Co-authored-by: Kevin <kevin@wode.com>
Co-authored-by: dirtmelon <0xffdirtmelon@gmail.com>
Co-authored-by: Jonathan Downing <jd@jonathandowning.uk>
Co-authored-by: Xavier Deloge <Idefix60@users.noreply.github.com>
Co-authored-by: Eric Scheers <smeis@users.noreply.github.com>
Co-authored-by: Huy Nguyen <allforone1511@gmail.com>
Co-authored-by: Greg Bolsinga <bolsinga@mac.com>
Co-authored-by: Jacob Farkas <farktronix@users.noreply.github.com>
Co-authored-by: ernestmama <43187788+ernestmama@users.noreply.github.com>
Co-authored-by: Andrew Yates <contact@andydev.co.uk>
Co-authored-by: Tim Norman <tim@normsoft.com>
Co-authored-by: Michael Zuccarino <mikezuccarino@gmail.com>
Co-authored-by: Dmitry Gridnev <dmitr.gridnev@gmail.com>
Co-authored-by: Max Wang <max.wang.cs@gmail.com>
Co-authored-by: Ballad <348649634@qq.com>
Co-authored-by: Patrick Balestra <me@patrickbalestra.com>
Co-authored-by: Harry Shamansky <harry.shamansky@gmail.com>
Co-authored-by: Wu Zhong <zhongwuzw@qq.com>
Co-authored-by: Oskar Zhang <i@oskarzhang.me>
Co-authored-by: Adlai Holler <adlai@google.com>
Co-authored-by: Greg Bolsinga <gbolsinga@pinterest.com>
Co-authored-by: Huy Nguyen <huy@pinterest.com>
Co-authored-by: Andrew Monshizadeh <amonshiz+github@gmail.com>
2020-05-21 18:54:58 -07:00
vovasty 416568584d support cancelation in ASGraphicsCreateImage (#1814)
* support cancelation in ASGraphicsCreateImage

* updated comment
2020-05-20 10:48:01 -07:00
ricky d085cd6349 [ASDisplayViewAccessibility] A few accessibility improvements (#1812)
* [ASDisplayViewAccessibility] A few accessibility improvements

This diff includes a few improvements for accessibility in Texture.

* When determining a node’s accessibility elements, ignore any elements that are hidden, transparent, or out of the window. This matches UIKit’s behavior.
* When sorting the accessible elements and their origins are equal, give precedence to elements with shorter accessibility frames, followed by elements with narrower widths.
* Allow the ability to customize the comparator block that sorts the accessibility elements
* Create an experiment to stop caching accessibilityElements in `_ASDisplayView`. If we cache elements, we will require users to clear the cache (by calling `setAccessibilityElements` to get the side effect of clearing the cache) when nodes change their hidden state or opacity. This seems like a lot to request of the user. We will put this in an experiment so we can see the perf implication is both when using voice over and when not using voice over.

A few other notes:
* I got rid of the `ASAccessibilityElementPositioning` protocol in favor of passing `NSObjects` to the sort comparator. `NSObject` implements the informal `UIAccessibilityProtocol` and therefore has an `accessibilityFrame` property.
* I removed `static` from the `SortAccessibilityElements()` method definition. This allows me to declare it as `extern` in test it via unit tests.
2020-05-06 11:10:35 -07:00
ricky 508bd2b49a [ASDisplayNode] Allow explicit setting of accessibilityElements (#1807)
* [ASDisplayNode] Allow explicit setting of accessibilityElements

Since `NSObject` conforms to the informal accessibility protocol, `ASDisplayNode` has an inherited property for `accessibilityElements`. However, setting this property has no effect since `ASDisplayNode` overrides the `accessibilityElements` getter. Added a small change to the getter to check if the `accessibilityElements` property on `ASDisplayNode` has been explicitly set, and if so return that.

I also added a comment around  `_ASDisplayView`’s `setAccessibilityElements:` method to clear up some (of my own) confusion.

* comment tweak

* Fix flakey test
2020-04-24 12:35:13 -07:00
Oliver Fox 7798440bcf Prevent crashing during non critical logging at rotation (#1770) 2020-02-10 16:30:27 -08:00
Huy Nguyen 8becd09b4e Omit UIUserInterfaceLevel from tvOS build (#1757)
- UIUserInterfaceLevel was added to ASTraitCollection in #1568. However, it's unavailable on tvOS and thus broke our podspec linting CI job. Fix by only include it if the build target is iOS.
2020-01-03 10:06:37 -08:00
Hanton Yang 69ae7ddf79 Simplify push_back GroupNotify (#1736) 2020-01-02 11:45:34 -08:00
Andrew Yates 005e2d5aa9 First pass at supporting new traits (#1568) 2020-01-02 10:37:42 -08:00
Hanton Yang 6a2fdb2606 Use queue in ASMainSerialQueue (#1738)
For removing the first element, time complexity of `NSMutableArray` is O(n) while `queue` is O(1), which is more efficient.
2019-12-28 00:02:26 -08:00
Adlai Holler d688ce3d20 Improve recursive unfair lock: (#1742)
- Use relaxed memory since we don't need acquire/release. This'll make it faster.
- Add a couple assertions and organize the code better.
- In contested case, just lock instead of tryLock-fail-lock.
- In recursive case, do not tryLock. Just notice it's recursive and be done.
- In uncontested case, just lock instead of tryLock.

PRESUBMIT=passed
BUG=137413265
R=maicki
CC=maxwang,rexhu,wiseoldduck,yt-elements-eng+cl
REQUIRED_REVIEW=1
DELTA=50 (14 added, 13 deleted, 23 changed)
DELTA_BY_EXTENSION=h=1,mm=36
OCL=278419008


P4 change: 278454084
2019-12-10 13:51:14 -08:00
darrengyles 744bb3ecd3 Fix for images retrieved from the memory cache being reported a… (#1722)
* Fix for incorrectly reporting images retrieved from the memory cache as disk (i.e. asynchronous) cache hits.
2019-11-07 10:25:04 -08:00
vovasty 18fa714c3f deprecate ASGraphicsCreateImageWithOptions (#1704) 2019-10-16 13:20:39 -07:00
Hanton Yang 4c9000c0db Remove build warnings (#1681) 2019-10-10 11:21:29 -07:00
vovasty e5eba118a3 introduction of ASGraphicsCreateImageWithTraitCollectionAndOptions (#1675)
* initial `ASGraphicsCreateImageWithTraitCollectionAndOptions`

* comments
2019-09-16 14:14:53 -07:00
Hanton Yang 712efc434f Fix _ASAsyncTransaction initialization method (#1656)
- Invoke the superclass (super) initializer
2019-09-15 23:33:29 -07:00
Hanton Yang c99bcb02f8 Use CAEdgeAntialiasingMask instead of unsigned int (#1667) 2019-09-11 10:38:06 -07:00
Rahul Malik 6464153489 Cleanup from recent changes (#1647)
- Fix availability warnings for usage of userInterfaceLevel
- Deprecate `asyncTraitCollectionDidChange` in favor of the new method
- Remove old compiler warning flag added for Xcode 9 building
- Access `textColorFollowsTintColor` with a locked scope
2019-08-28 12:24:03 -07:00
Rahul Malik caa0d8de54 Fix issue where UIGraphicsRendererFormat is mutated (#1645)
* Fix issue where UIGraphicsRendererFormat is mutated

As part of https://github.com/TextureGroup/Texture/pull/1629, we use the
preferred or default UIGraphicsRendererFormat. This was pointing to a
static variable which content scale was mutated across several graphic
render passes and lead to pixelated views.

* Update reference images with iOS 10.3
2019-08-27 13:51:38 -07:00
Hanton Yang 762c8e8bff Keep using unowned macro (#1626) 2019-08-22 17:02:50 -07:00
Jessie Alvarez ccee5666dd Allow full color tinting on grayscale template images. (#1629)
* Allow full color tinting on grayscale template images.

* Signing a commit with the correct email address.

* Add snapshot test for a grayscale image with ASExperimentalDrawingGlobal enabled.
2019-08-22 12:53:49 -07:00
Huy Nguyen b721a911c8 Remove _ASDisplayLayer's delegateDidChangeBounds flag (#1618)
We rely on the delegate setter to be called to set the flag. However, recent change on iOS 13 causes the setter to not be called at all and thus we had to put up a workaround (https://github.com/TextureGroup/Texture/pull/1609). While the workaround works, the perf benefit of that the flag provides doesn't warranty the extra complexity IMO. So I think we should just remove everything.
2019-08-15 10:01:36 -07:00
Hanton Yang ad1ed9f6b6 Remove unused headers (#1615)
* Improve compilation time by reducing unnecessary compilation dependencies
* More clean code
2019-08-15 05:42:26 -07:00
Rahul Malik 4ebd38c316 Update ASPendingState type for backgroundColor to UIColor
Given that UIColor is now a dynamic provider we can no longer rely on the fact that there is a 1:1 mapping between UIColor <-> CGColorRef.

I've updated the UIViewBridge and ASPendingState accordingly to use UIColor and translate to CGColorRef only when interacting with layers. This should preserve any dynamic capabilities we might need in the future when trying to re-render layer backed nodes.
2019-07-20 18:53:37 -07:00
Hanton b7d64a0917 Fix the build warning in ASRangeController.mm (#1575) 2019-07-11 12:14:14 -07:00
Huy Nguyen 6e46d9bcd5 [ASDataController] Add an experiment that avoids flushing editing queue before starting the data pipeline pipeline (#1564)
* [ASDataController] Avoid flushing editing queue before starting data controller pipeline

Step 1 of the pipeline is on main thread and needs pendingMap which was updated by the end of step 1 of the run. And step 1 operates on data source index space. So it should be ok to start it ASAP -- without waiting for any running work on the background editing queue.

One potential race condition after this change is that it's possible for main thread to query the data source (step 1) while the editing queue consumes the last change set (step 3). However, as long as the client's each nodeBlock and the node's layout code capture/reference an individual model object (as opposed to the whole data set) -- which is what clients are supposed to do anyways, then everything should be fine.

The benefit of this diff is that the pipeline will be able to accept many more change sets within a short time window, for example when clients submit a burst of separate small updates.

I tested this diff against our test suite several times and smoke tested it in our code base without any issues.

* Wrap in an experiment

* Enable experiment in tests

* Minor change
2019-06-30 21:08:06 -07:00
Huy Nguyen e274e5dac5 Remove ivar of ASCellNode.owningNode (#1559) 2019-06-25 10:58:43 -07:00
Huy Nguyen ba1e0acb1e Restore call pattern where UIView methods drive __enterHierarchy and __exitHierarchy for view-backed nodes (#1561)
After #1396, some view-backed nodes in our app stop responding to tap events. I tracked it down to [this change](https://github.com/TextureGroup/Texture/pull/1396/files#diff-7fbc7d84a259cbfbee7546a5310dddcfR162) which suggests that the order of execution matters.

This diff attempts to fix the issue by restoring the previous call order where `__enterHierarchy` and `__exitHierarchy` are driven by `_ASDisplayView`'s `-willMoveToWindow:` and `-didMoveToWindow` if the node is view-backed. Layer-backed nodes will still call `__enterHierarchy`/`__exitHierarchy` when they get `kCAOnOrderIn`/`kCAOnOrderOut`.

This maintains the layer-action support introduced in #1396.
2019-06-25 10:58:13 -07:00
Greg Bolsinga c67acab290 Remove ASExperimentalTransactionOperationRetainCycle (#1547)
* Remove ASExperimentalTransactionOperationRetainCycle
2019-06-13 15:42:24 -07:00
Michael Schneider 19fb1240ad Fix multiple issues around accessibility handlinig (#1537)
* Improve Accessibility Implementation

- Fixes calculations for accessibilityFrame of ASAccessibilityCustomAction and ASAccessibilityElement
- Fix crash for accessibility elements within layer backed nodes
- Fix accessibility action label updating after other actions change the accessibility label of the corresponding node

* Address comments
2019-06-05 13:51:25 -07:00