Commit Graph

24 Commits

Author SHA1 Message Date
Pieter De Baets dd48509185 Unbreak LAYOUT_ANIMATION_VERBOSE_LOGGING
Summary:
Noticed this logging was broken when enabling the flag.

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D38616851

fbshipit-source-id: acf0ab75918b389586cb713c2edf5a6bf83ee7a2
2022-08-24 05:09:12 -07:00
Graham Mendick e24ce708ab Migrate needsCustomLayoutForChildren check to the new architecture (#34254)
Summary:
Fixes https://github.com/facebook/react-native/issues/34120

The new React Native architecture doesn't check `needsCustomLayoutForChildren` so it wrongly positions native views on Android. In https://github.com/facebook/react-native/issues/34120 there are videos comparing the positioning of a native action view in the old and the new architecture.

This PR passes the parent tag to the `updateLayout` method of the `SurfaceMountingManager`. The `SurfaceMountingManager` calls `needsCustomLayoutForChildren` on the parent view manager (copied the code from the `NativeViewHierarchyManager` in the old architecture).

**NOTE** - I wasn't sure where to get the parent shadow view from so I've put in my best guesses where I could and left it as `{}` otherwise.

## Changelog

[Android] [Fixed] - Migrate `needsCustomLayoutForChildren` check to the new architecture

Pull Request resolved: https://github.com/facebook/react-native/pull/34254

Test Plan:
I checked the fix in the repro from https://github.com/facebook/react-native/issues/34165. Here is a video of the action view closing using the native button that is now visible in the new architecture.

https://user-images.githubusercontent.com/1761227/180607896-35bf477f-4552-4b8a-8e09-9e8c49122c0c.mov

Reviewed By: cipolleschi

Differential Revision: D38153924

Pulled By: javache

fbshipit-source-id: e2c77fa70d725a33ce73fe4a615f6d884312580c
2022-07-28 09:57:36 -07:00
Andres Suarez 8bd3edec88 Update copyright headers from Facebook to Meta
Reviewed By: aaronabramov

Differential Revision: D33367752

fbshipit-source-id: 4ce94d184485e5ee0a62cf67ad2d3ba16e285c8f
2021-12-30 15:11:21 -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
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 668ce510bd Avoid copy in LayoutAnimationDriver
Summary:
changelog: [internal]

Avoid unnecessary copy of `ShadowViewMutation` and `ShadowView`.

Reviewed By: RSNara

Differential Revision: D30756214

fbshipit-source-id: 39c44dd60582e6c111986df482613212e25739d7
2021-09-09 11:57:24 -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 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 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 61d59fff23 Add additional debug logging in LayoutAnimationDriver
Summary:
Log final when synthetic final mutations are generated at the end of an animation.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D27407768

fbshipit-source-id: 0e9aface54bcca73dfa5ea263a8474db7c47c078
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 b3930f935f Convert most Fabric Cxx code to use react_native_assert instead of assert
Summary:
See react_native_assert.{h,cpp}. Because of the BUCK+Android issue where NDEBUG is always defined, we use react_native_assert instead of assert to enable xplat asserts in debug/dev mode.

This migrates most of the codebase, but probably not 100%. The goal is to increase assertion coverage on Android, not to get to 100% (yet).

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D26562866

fbshipit-source-id: a7bf2055b973e1d3650ed8d68a6d02d556604af9
2021-02-19 20:52:52 -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
Andres Suarez 0f4f917663 Apply clang-format update fixes
Reviewed By: igorsugak

Differential Revision: D25861683

fbshipit-source-id: 616afca13ae64c76421053ce49286035e0687e36
2021-01-09 22:11:00 -08:00
Joshua Gross e8770d7bb2 Code quality: Refactor ShadowViewMutation::UpdateMutation to remove index, parentShadowView parameters
Summary:
The `index` parameter for UpdateMutation is optional, and is normally just -1. It's not useful, so remove it. `parentShadowView` is also not relevant and is not used; in some existing use-cases the actual parent view of the updated view is available, and in some contexts the parent view is not set.

The function now will always set the index to -1 for UpdateMutations, and `{}` for ParentShadowView.

This should have no impact on iOS or Android, as this parameter is not used. It could theoretically have an impact on lifetimes of objects retained (now not retained) by not passing parentShadowView into the mutation. For example, any shared props or state associated with the parent will not be retained in the Update mutation now.

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D25342943

fbshipit-source-id: 0ddbef76a6e2eefc2629c9729f721d8674d7737e
2020-12-07 13:37:10 -08:00
Joshua Gross f9a4cafa20 LayoutAnimations: Remove unnecessary optionals in config
Summary:
These configs are never actually empty, so they shouldn't be optionals.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D25129254

fbshipit-source-id: 626119fefad0440732541c680286ebbbfab6aeba
2020-11-20 17:30:11 -08:00
Joshua Gross 5bd5fcdd38 LayoutAnimations: ensure that all mutations retain the correct "old" node
Summary:
The current implementation of LayoutAnimations assumed that the "previous/old" ShadowView passed into the diff mutation didn't matter except for purposes of diffing.

As it turns out, iOS components could possibly use the "old" version of props, state, etc - so we should try to keep track of the current value in the tree as much as possible.

This diff accomplishes that by keeping track of the "previous" view, which the AnimationDriver will update over time. This also allows us to simplify logic around conflicting animations.

I'm also adding a few additional asserts to assist in debugging.

This doesn't totally eliminate all asserts hit on iOS, yet, but it does reduce the number of times the asserts are hit in StubViewTree.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D25048644

fbshipit-source-id: d00aeece5af04624d8193063be453c7ce4a6e565
2020-11-19 14:53:23 -08:00
Samuel Susla eaab64764e Do not remove oldChildShadowView from mutation
Summary:
Changelog: [internal]

This diff reverts some changes in D23886519 (https://github.com/facebook/react-native/commit/9f00752a97db3fe0b03cb412c5357eeebc3e2b16), I was not able to repro the issues that D23886519 (https://github.com/facebook/react-native/commit/9f00752a97db3fe0b03cb412c5357eeebc3e2b16) is fixing.
`oldChildShadowView` must be defined for update mutation.

Reviewed By: JoshuaGross

Differential Revision: D25088008

fbshipit-source-id: 956d0cc536e35376ce0e1cc09f7c5b66cb89fc77
2020-11-19 11:57:55 -08:00
Joshua Gross 61c1d60356 LayoutAnimations: generate final mutation instruction for interrupted animations without a final Mutation already queued up
Summary:
For some interrupted animations we will execute a "final" mutation associated with the animation, if it exists. For example, "UPDATE" animations always have a final Update animation associated with them.
Some, however, do not. For example: INSERT animations do not have a final mutation associated by default. In these cases (before this diff) if the animation from opacity 0 to 1 was interrupted, the View will
appear "stuck" at some intermediate opacity. To mitigate that, we generate a synthetic "final" mutation at 100% progress through the animation if it is interrupted.

Changelog: [Internal]

Reviewed By: fred2028

Differential Revision: D24691151

fbshipit-source-id: d9730b8a3493a5eeac4de325e7e0a7a64f73c8a0
2020-11-03 09:08:19 -08:00
Joshua Gross 9f00752a97 LayoutAnimations: force props to update when executing "final" mutations
Summary:
When an animation is completed or a conflicting animation is detected, force props, state, layout, etc to update.

Currently, when a final animation mutation is queued, some attributes can be updated but not others, causing unexpected visual glitches at least on Android.

Some of these are arguably component bugs, but it's easier to just flush all attributes by tricking the platforms into updating all attributes. This will also prevent us from having to track down more of these bugs, potentially.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D23886519

fbshipit-source-id: 8e5081bbe3b7843c16c0f283fa07fdec0e211aa8
2020-09-24 11:59:31 -07:00
Joshua Gross 0599742db8 LayoutAnimations: at the end of every animation, issue an update mutation
Summary:
LayoutAnimations: at the end of every animation, issue an update mutation - this is so that the props data on the Mounting layer/StubViewTree layer is pointer-identical to the props data on the ShadowTree.

This unblocks iOS debug mode crashes.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D23753606

fbshipit-source-id: 407e0c2746a65e6d3ee29c1cce891cd7c1013593
2020-09-17 12:29:29 -07:00
Joshua Gross 6a3c866b6a LayoutAnimations: work on making index adjustment more robust to flattening/unflattening and many reorders
Summary:
My goal in this diff is to make LayoutAnimations more stable, and more resilient to challenging situations. Namely, LayoutAnimations already works fine with:

1) Reorders
2) Flattening/unflattening
3) Deletion and recreation of the same hierarchy
4) Updates conflicting with an existing animation

However, what if /all/ of those things are combined? Handling update conflicts with multiple ongoing animations, repeatedly flattening/unflattening the same layer of hierarchy and reordering both parents and children, etc .

This diff does not make LayoutAnimations perfect, but it does make LayoutAnimations much more resilient to situations it was not able to handle before.

My primary method of testing was to use two Playground examples: one just repeatedly queues up mutations (some animated, some not) that create, update, and delete in the same hierarchy layer. The second, more complex one, mutates between random view hierarchies that involve a lot of flattening and unflattening as well as reordering, over a depth of 5. It also exercises animations over TextInlineViews, which is more challenging.

LayoutAnimations works best with the new "Flattening Differ" for now, because the Flattening Differ produces a much smaller, nearly minimal set of instructions in cases of flattening-unflattening. I would like that to not be a hard requirement for using LayoutAnimations, but it's a good starting-point for now.

As part of this work, I also developed a lot of debugging and logging mechanisms that are handy for detecting inconsistencies and debugging crashes. Some are included in this diff behind `#define` statements that are disabled by default, and the rest will be published separately and likely cannot be landed permanently, as they're more invasive changes that are only helpful in debugging.

# Followups:

- Automate testing: write a suite of C++ tests that mutates between random diffs and guarantees that all mutations in a StubViewTree are sensible
- Construct a set of minimal repros that catalogues all remaining crashes and inconsistency issues (these seem to be extremely marginal cases and are very hard to repro - so I think it's fine to run this in prod for now, but I will follow-up as soon as I'm back to catalogue and fix all remaining issues)
- This diff focuses on *not crashing*, but it is still possible to construct a sequence of complex mutations that results in (for example) views having some opacity between 0 and 1 if animations are interrupted repeatedly. Although this is easy enough to prevent in product code - the types of scenarios I'm running in tests are very unlikely to ever happen in production - it would be nice to be *sure* that LayoutAnimations will always converge to a sensible View hierarchy with up-to-date props.
- In general, the index adjustment logic is complicated. I don't know if there's a great way around it, so I need to at least catalogue and test all edge-cases as mentioned above.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D23382975

fbshipit-source-id: f379d9aa2a4b9c33fa2ba8fa07870c9e31fad5e7
2020-08-27 19:37:06 -07:00
Joshua Gross e3302eeeab LayoutAnimations: call onSuccess, onFailure callbacks
Summary:
Hook up onSuccess and onFailure callbacks to LayoutAnimations.

Note that in non-Fabric RN, onSuccess is not known to work in Android. I could not find any uses of onFailure and it's not documented, so for now, it is only called if the setup of the animation fails.

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D22889352

fbshipit-source-id: 4306debb350388dd2b7a2cbfe295eb99723988e2
2020-08-02 16:37:03 -07:00
David Vacca 3093010ea5 move fabric to ReactCommon/react/renderer
Summary:
This diff moves fabric C++ code from ReactCommon/fabric to ReactCommon/react/renderer
As part of this diff I also refactored components, codegen and callsites on CatalystApp, FB4A and venice

Script: P137350694

changelog: [internal] internal refactor

Reviewed By: fkgozali

Differential Revision: D22852139

fbshipit-source-id: f85310ba858b6afd81abfd9cbe6d70b28eca7415
2020-07-31 13:34:29 -07:00