Commit Graph

82 Commits

Author SHA1 Message Date
Kevin Gozali fb39d45ed5 C++ - better => butter
Summary:
Renaming the `better` utilities to `butter`:
- to prevent claims that this library is superior to others - it really depends on use cases
- to indicate ease of use throughout the codebase, easily spread like butter

Changelog: [C++][Changed] Renaming C++ better util to butter, used by Fabric internals

Reviewed By: JoshuaGross

Differential Revision: D33242764

fbshipit-source-id: 26dc95d9597c61ce8e66708e44ed545e0fc5cff5
2021-12-20 22:25:14 -08:00
Samuel Susla 34c4fdb8e2 Remove implicity type conversions from LayoutAnimations
Summary: changelog: [internal]

Reviewed By: philIip

Differential Revision: D33058920

fbshipit-source-id: 6d39e26c369dad409f5141dceae7554fe65daaba
2021-12-15 07:19:51 -08:00
Pieter De Baets 6025611bd0 Use real propsParserContext in LayoutAnimation
Summary: Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D31053819

fbshipit-source-id: 8ec21012500f3bfc7e8aea018b5ca72323da2d9e
2021-09-21 04:24:28 -07:00
Samuel Susla ce6047d816 Pull function calculateAnimationProgress to a separate file
Summary:
changelog: [internal]

Pulling a function from class since it doesn't use any of the ivars.

Reviewed By: RSNara

Differential Revision: D30766917

fbshipit-source-id: 219d9b7d3bc0b110b659d7188f5e3877c7b480ff
2021-09-14 06:21:05 -07:00
Samuel Susla cc3064d394 Use designated initialisers for ShadowViewMutation
Summary:
changelog: [internal]

In this diff, we delete default initialised for ShadowViewMutation to prevent accidentally creating empty ShadowViewMutation.
The other initialiser is made private and all of its uses are migrated to designated initialisers. This makes for safer API.

Reviewed By: RSNara

Differential Revision: D30774900

fbshipit-source-id: d2064bf08409850e75e13ad06558b7980a7f5d8d
2021-09-12 08:56:32 -07:00
Samuel Susla d2cc91bcc3 Add a way to simulate memory access to ImageProps in LayoutAnimations
Summary:
changelog: [internal]

I'm chasing down a crash in LayoutAnimations, it would help me to simulate the memory access which causes the crash to learn where the bad memory is coming from.

Reviewed By: RSNara

Differential Revision: D30776840

fbshipit-source-id: 1e97fac28ba2df37ba3e47ec2c110043c3823e70
2021-09-12 08:56:32 -07:00
Samuel Susla c6e203bdb0 Prevent implicit conversion to boolean
Summary:
changelog: [internal]

This looks like a bug where the author did not intend the conversion to boolean. This means that `onlyMutationIsUpdate` was evaluated to true even if more than 1 animation was in the vector.

Reviewed By: RSNara

Differential Revision: D30767172

fbshipit-source-id: 0ef47b65a5d8ef07d774d9e0b358e5642dc0a9ea
2021-09-12 08:56:32 -07:00
Samuel Susla 1e4f364f87 Remove movesToAnimate var which was never read
Summary:
changelog: [intenal]

The variable is never read, removing it.

Reviewed By: RSNara

Differential Revision: D30767134

fbshipit-source-id: de72740f9dc7ad10d651129404fe4df093e6206d
2021-09-12 08:56:32 -07:00
Samuel Susla 273f631535 Annotate arguments in AnimationKeyFrame ctor
Summary:
changelog: [internal]

Just improvement to readability.

Reviewed By: philIip

Differential Revision: D30767100

fbshipit-source-id: eb5d36712f8096e6becd8db1e9d47128d5754624
2021-09-12 08:56:32 -07:00
Samuel Susla 10ab64888f Annotate arguments when constructing ShadowViewMutation
Summary: changelog: [internal]

Reviewed By: philIip

Differential Revision: D30766786

fbshipit-source-id: f7fac3371d9f018c15c366b0e8a5be1de021a0e7
2021-09-11 01:42:32 -07:00
Samuel Susla 24b961b6f7 Add option to crash the app if component descriptor is missing in LayoutAnimations
Summary:
changelog: [internal]

Add a log behind feature flag to learn more about missing component descriptor.

Component descriptor should never be missing, that's a state of program that is impossible as far as I can tell. This logic was introduced in D22216030 (https://github.com/facebook/react-native/commit/6342e6e3f11219391ac3296d41233735af7e6cad) and I think it is just cover the real cause of crashes in LA on iOS.

Reviewed By: RSNara

Differential Revision: D30765947

fbshipit-source-id: 6843384e02529de2f024c59c61ae21b8682ac371
2021-09-11 00:26:27 -07:00
Samuel Susla 4fe72bdc22 Move comparision functions to separate file
Summary:
changelog: [internal]

Just moving two functions to separate file.

Reviewed By: RSNara

Differential Revision: D30765732

fbshipit-source-id: e85e749c2910f6f38f07e56b23a21fb9f1cbc9b5
2021-09-09 11:57:25 -07:00
Samuel Susla 661b11e815 Use unordered_set instead of vector to keep track of tags
Summary:
changelog: [internal]

Prefer `unordered_set` over `vector`. Makes for nicer APIs and has better performance characteristics.

Reviewed By: RSNara

Differential Revision: D30756215

fbshipit-source-id: d259da07f8f0d5837441dc8ba11c00324aac3fa4
2021-09-09 11:57:25 -07:00
Samuel Susla 84d039aad2 Avoid extra copy and use more expressive APIs
Summary: changelog: [internal]

Reviewed By: RSNara

Differential Revision: D30756211

fbshipit-source-id: 650b3faa55ce1b6f33a452f25b699d854a5cee25
2021-09-09 11:57:25 -07:00
Samuel Susla ba6f21e32d Pull handling of stopped surfaces into separate method
Summary:
changelog: [internal]

Just moves stopped surfaces logic into separate method

Reviewed By: RSNara

Differential Revision: D30756213

fbshipit-source-id: d8eb637e6b9fc77c400dfdefa900ebaa89710825
2021-09-09 11:57:24 -07:00
Samuel Susla f91974156b Pass by ShadowView by reference to copy
Summary:
changelog: [internal]

Pass ShadowView by reference to avoid unnecessary copy.

Reviewed By: RSNara

Differential Revision: D30756212

fbshipit-source-id: 1ac1f5b943c8f278db5bcdb55d76e88de514debb
2021-09-09 11:57:24 -07:00
Samuel Susla a3343dfca3 Move conversion functions to separate file
Summary:
changelog: [internal]

Just move conversion functions to separate file

Reviewed By: philIip

Differential Revision: D30732128

fbshipit-source-id: 092523de949ee0088b1317c887aca91913991647
2021-09-09 11:57:24 -07:00
Samuel Susla ae4068d63c Add option to skip invalidated key frames
Summary:
changelog: [internal]

Maybe invalid keyframe animation shouldn't be queued. This adds a fix behind feature flag to verify if it fixes iOS crashes.

Reviewed By: RSNara

Differential Revision: D30730005

fbshipit-source-id: 8a2bb54c449449a95d14d51a1a78bfaccad61877
2021-09-09 11:57:24 -07:00
Samuel Susla 16a093029e Group private public and protected methods in LayoutAnimationKeyFrameManager
Summary:
changelog: [internal]

Group public, protected and private methods in header and implementation file. Nothing else is changed in this diff.

Reviewed By: RSNara

Differential Revision: D30729103

fbshipit-source-id: 047bfb86794caedddcf6569ffeee224fee811794
2021-09-08 11:53:16 -07:00
Samuel Susla 2c09095567 Remove unused header imports
Summary:
changelog: [internal]

Clean up unused header imports in LayoutAnimations.

Reviewed By: RSNara

Differential Revision: D30728213

fbshipit-source-id: 725da1a7057b058c6564a8d89856d599f9a798a7
2021-09-08 11:53:16 -07:00
Samuel Susla d83c310144 Simplify Layout Animation callback handling
Summary:
changelog: [internal]

There was extra bookkeeping associated with lifetime of `LayoutAnimationCallbackWrapper`. We can just copy it into runtimeExecutor lambda to manage its life cycle and delete `jsi::Function` once it was called.

Reviewed By: RSNara

Differential Revision: D30728210

fbshipit-source-id: 6fc60ee83846cb73648f1c09e5aaf1ed04bd0817
2021-09-08 11:53:16 -07:00
Samuel Susla cb58c84dc0 Use set instead of vector to hold stopped surfaces
Summary:
changelog: [internal]

Use set instead of vector. It makes for nicer API to check if the element exists.

Reviewed By: cortinico

Differential Revision: D30728211

fbshipit-source-id: 7b7cc1e94bb82a44b064e2945a753adbbce5dc2c
2021-09-08 06:46:52 -07:00
Samuel Susla 7dc22116b0 Remove RTTI from LayoutAnimations
Summary:
changelog: [internal]

Remote use of dynamic_cast from LayoutAnimations.

Reviewed By: JoshuaGross, cortinico

Differential Revision: D30602864

fbshipit-source-id: ce23f9b4a8b4e28d17d2297d64d8e460a1e03472
2021-08-28 06:59:22 -07:00
Samuel Susla b7616242aa Remove redundant includes
Summary:
changelog: internal

Removing unused headers. Fewer headers = faster compilation

Reviewed By: p-sun

Differential Revision: D30398600

fbshipit-source-id: a64801e49d283ad1e2d0cb9c9d688445e30bf0ed
2021-08-20 03:02:02 -07:00
Joshua Gross 09b9422516 Pass context through to all prop parser (core changes)
Summary:
Unfortunately, parsing some props requires stateful context - namely, PlatformColor on Android. We explored several different options but they all seemed inferior to the approach of using ContextContainer, and most would require using global state.

By introducing this change everywhere as early as possible, we can avoid later pain. It is likely that some prop, on some platform, will require this mechanism. We'll be ready for it!

Because we can pass a constref of the ContextContainer through to all props and because the context and context data is never retained by prop parsers, perf and memory hit should be ~0.

This diff contains core changes only. Leaf changes to all props structs and conversions files will be in next diff(s).

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D29838789

fbshipit-source-id: f5090e7f02eb6e8fbe0ef4dd201e7d12104a3e3c
2021-07-28 20:18:20 -07:00
Joshua Gross b637b21f09 LayoutAnimations: don't animate root ShadowNode mutations
Summary:
Root nodes doesn't have a ComponentDescriptor that can be looked up via this mechanism, and we probably shouldn't be animating Root nodes anyway (?). This is a debug-only assert but could be causing issues in production.

The fix is simple - just don't animate any changes to a root node.

Changelog: [Internal]

Reviewed By: Nick177

Differential Revision: D28856396

fbshipit-source-id: 43fa0aa723b03b031fee22e0563eb63cc86239b3
2021-06-03 20:30:37 -07:00
Joshua Gross 967eeff86e Add unit tests for Layout Animations
Summary:
Add unit tests for Layout Animations.

This first batch generates a random mutation, then animates it to completion.

I found one issue with UPDATE+REMOVE+INSERT animation consistency. That shouldn't cause any crashes in production, but is a chance to improve consistency of mutations overall - and could in theory point to memory corruption, though it's somewhat unlikely.

I ran with randomized seeds, found issues, fixed them, re-ran to ensure issues were fixed, rinsed and repeated. At the end I was able to run dozens of times (with random seeds) and found nothing.

The next step is to repeatedly generate mutations that conflict with ongoing animations.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D28343750

fbshipit-source-id: c1c60d89a31be3ac05d57482f0af3c482b866abe
2021-05-11 12:11:35 -07:00
Joshua Gross 49b6c60bc0 EZ: fix up LayoutAnimation logs
Summary:
Make these logs more readable/useful and add debug print of ShadowView hashes in one place.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D27585135

fbshipit-source-id: 5f526856d893c32015d8b480522580732fda0cc6
2021-04-08 10:06:48 -07:00
Joshua Gross 184b372720 Comment out debug-only block causing build failures
Summary:
Temporarily disable due to build failures.

This is debug-only and I've never hit these asserts, so this should be safe; though it should be reenabled during active development of LA.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D27505224

fbshipit-source-id: b3d6d2184d8f226d6f82d3fe0ae6303813c8356a
2021-04-01 09:44:29 -07:00
Joshua Gross eb59cc2636 Queue DELETE instructions for virtual nodes
Summary:
To ensure that we're eventually deleting all ShadowViews from the StubViewTree and from the mounting layer, make sure that we always queue conflicts if they're DELETE instructions, including for virtual nodes.

I was able to hit this by running some extremely complex animations. It is extremely unlikely that even a single user is hitting this in prod. Therefore, while this is the right change to make, I don't expect (for example) OOMs to go down at all.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D27492935

fbshipit-source-id: bce332feb15229af271cc6e14b8367ebcb36536b
2021-03-31 21:33:06 -07:00
Joshua Gross e9ff6d8bca Print ShadowView hash when displaying instructions
Summary:
When displaying instructions in debug logs, also print ShadowView hash to make it easier to reconstruct a series of events.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D27492938

fbshipit-source-id: 276a080a4afcfb4aa0aafc215e2ccd56ef849fcf
2021-03-31 21:33:06 -07:00
Joshua Gross f6168d2661 Bail out of createInterpolatedShadowView if generated props are null
Summary:
We have no evidence of this happening, but it matches other bail-out cases that already exist in this function. If we
fail something that would have been an assert in debug mode, bail out so we don't return garbage values in production.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D27449775

fbshipit-source-id: 5b85016c9611484b615debec514d12a984e6b1ff
2021-03-31 21:33:05 -07:00
Joshua Gross 01f7d4f720 Refactor duplicated code into queueFinalMutationsForCompletedKeyFrame
Summary:
This chunk of code is repeated 3x in the codebase with minor variations. Consolidate as `queueFinalMutationsForCompletedKeyFrame`.

Should be no changes in behavior.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D27407766

fbshipit-source-id: 196f0d4c7868007f0d103b024feb4450640a3f62
2021-03-31 21:33:05 -07:00
Joshua Gross 17c3846838 Only run assert-only path in debug mode
Summary:
This probably won't compile outside of debug mode, because variables are unused outside of asserts. Don't do any of this outside of debug mode.

This path is also a pessimisation, we shouldn't need to run it unless we're running in ultra-conservative debug mode.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D27407767

fbshipit-source-id: 71a8d025463c85d65cd2bc193a19953b97669d84
2021-03-31 21:33:05 -07:00
Joshua Gross 92b8075120 Recursively clean up conflicting animations
Summary:
Call getAndEraseConflictingAnimations recursively, to clean up any conflicting animations.

With a specific sequence of mutation instructions, it is possible that an animation on a tree is set up, and the entire tree needs to be cleaned up if a parent is deleted, say.

This can happen especially if rapidly mutating trees in such a way that invokes view flattening and unflattening (which is not recommended, but is certainly possible).

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D27407776

fbshipit-source-id: 5125250f051c58870692f8fdc43ed23da5058a7f
2021-03-31 21:33:04 -07:00
Joshua Gross ae264b995f Update 'viewPrev' as well as 'viewStart' when transitioning from one animation to another
Summary:
When reconstructing a second animation based on a conflict with a first, we want to ensure we set 'viewPrev' of the second animation properly.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D27407777

fbshipit-source-id: 8fcc72c4c5fadaab4287824a944ad21230f2f97d
2021-03-31 21:33:04 -07:00
Joshua Gross 9ea0020054 For certain types of conflicts we do *not* want to generate a final UPDATE mutation
Summary:
In general, when an animation is interrupted or completed, we want to forcibly "flush" an update that will make the StubViewTree/mounting layer consistent with the ShadowTree.

However, in cases where a conflict creates a second animation and stops the first, we simply updated the "viewPrev" of the second animation and smoothly transition to it.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D27407774

fbshipit-source-id: 928363867d8994c9d69c53154a07bda94f954afa
2021-03-31 21:33:04 -07:00
Joshua Gross 22c9b7d520 If a parent node is DELETEd or CREATEd, immediately end animation
Summary:
Detect conflicts not just when a node is updated, but when its parent is DELETEd or CREATEd.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D27407781

fbshipit-source-id: 719d9a8822bf691d9059073a30d8b5ccb50eece1
2021-03-31 21:33:04 -07:00
Joshua Gross f915ca99be EZ refactor
Summary:
pull out tag so it's easier to read

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D27407770

fbshipit-source-id: e7d2a3ce8e4ac55b6446cddc8c39e73a18fa7170
2021-03-31 21:33:04 -07:00
Joshua Gross 706a223dd2 Refactor LA: keyFrames have N "final items" to execute
Summary:
One of the struggles with the LA engine is to make sure that LA doesn't break the StubViewTree. In particular, we have strict requirements that the "oldShadowView" with every mutation matches exactly what is in the shadow tree, so it appears that there is a linear progression of ShadowNodes for every mutation instruction.

This is a struggle to do with the current setup, requires some wacky code, and doesn't work properly. Instead of spreading REMOVE/DELETE (especially) or INSERT/UPDATE instructions across multiple keyframes, we now allow keyframes to have multiple "final" instructions to execute,
which makes it much easier to keep state consistent.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D27407769

fbshipit-source-id: 3a709503dc30be69efc345690cb1920eb9591e9a
2021-03-31 21:33:04 -07:00
Joshua Gross 7ac5d48341 Generalize "isVirtualView" logic to make debug asserts consistent with platform
Summary:
On Android we have the notion of "virtual views", which are defined consistently but the logic is scattered and duplicated throughout the codebase.

The logic exists to mark nodes that exist in the ShadowTree, but not the View tree. We want to CREATE, UPDATE, and DELETE them on the platform, but not INSERT or REMOVE
them. They basically exist as EventEmitter objects.

The only issue with this is (1) duplicated code, which opened the possibility for inconsistent definition (2) StubViewTree did not account for virtualized views, which caused
assert crashes in debug mode for certain LayoutAnimations on Android.

By moving the definition to ShadowViewMutation and accounting for it in StubViewTree, asserts are correct and consistent on all platforms.

This was not caught until recently, because, until recently, no asserts actually ran on Android.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D27001199

fbshipit-source-id: eb29085317037ba8a286d7813bdd57095ad4746f
2021-03-15 13:50:56 -07:00
Joshua Gross 5be2843c1c Use react_native_assert in LayoutAnimations
Summary:
Use react_native_assert in LayoutAnimations to enable asserts to fire on Android.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D26517096

fbshipit-source-id: f000c4848f29c8779170625d357f547f2e9e6365
2021-02-18 14:31:57 -08:00
Joshua Gross fb1833eede Consolidate various debug-only flags into flags.h (#30988)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/30988

We have a bunch of flags scattered throughout the codebase with poor hygiene and commenting. Consolidate.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D26392518

fbshipit-source-id: 2823de123a5009d6b8c358e8a3f451b9fa0e05b7
2021-02-17 18:00:47 -08:00
Joshua Gross e723294630 LayoutAnimations: remove dead code
Summary:
remove dead code; this flag is always defaulted to false, and not used anywhere

Changelog: [Internal]

Reviewed By: sammy-SC, mdvacca

Differential Revision: D26271507

fbshipit-source-id: e2277cc24f164c53f2e8a0aa72456ac400834d70
2021-02-09 22:43:42 -08:00
Joshua Gross 49baf65844 LayoutAnimations: assert -> LA_ASSERT
Summary:
Add LA_ASSERT macro, this just makes debugging easier on Android since these asserts are compiled out for us even in debug.

Changelog: [internal]

Reviewed By: mdvacca

Differential Revision: D26271508

fbshipit-source-id: 9be8c71e273d762a4f31ff1fcc629ce48218b98d
2021-02-09 22:43:42 -08:00
Joshua Gross 76c384ff61 LayoutAnimations: in setup, guard against props being null in prod
Summary:
These asserts don't run in prod; only set starting/final view props if the result props object is non-null.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D26271512

fbshipit-source-id: b495c014a062cf255fd4b5cb8609582f23edcec8
2021-02-09 22:43:42 -08:00
Joshua Gross 2218952d8b LayoutAnimations: when detecting conflicting mutations: crash more in debug, fail elegantly in prod
Summary:
In this case where there's an ongoing UPDATE animation and an INSERT of the same node, make sure the ongoing animation type is what we expect, and that the `newChildShadowView` is valid.

We were already guarding against these, but we should (1) crash more in debug and (2) fail more elegantly in prod when the asserts don't run.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D26271514

fbshipit-source-id: 48e7d37a2493241f16099d9fe5ecb0d247707ca7
2021-02-09 22:43:41 -08:00
Joshua Gross 95cab24a6e LayoutAnimations: assert that tag >0 instead of != 0
Summary:
LayoutAnimations: assert that tag >0 instead of != 0. It's possible that a corrupt tag value would be below zero which is not valid.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D26271515

fbshipit-source-id: a62445ad29d60e5180e62ec4c6d5b08784655808
2021-02-05 00:57:42 -08:00
Joshua Gross 1c2a95d6c6 LayoutAnimations: when setting up animation start/final ShadowViews, ensure props are not null
Summary:
LayoutAnimations: when setting up animation start/final ShadowViews, ensure props are not null

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D26271510

fbshipit-source-id: 8d99ba8272fb63103a8d85bb0e14d02256a6d74d
2021-02-05 00:57:41 -08:00
Joshua Gross cc9a3e27c2 LayoutAnimations: ensure that interpolated props are never null
Summary:
ensure that interpolated props are never null

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D26271516

fbshipit-source-id: d012e530e92dabce1e0a7df8edf670e90367a892
2021-02-05 00:57:41 -08:00