-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Crashes during CSS transitions of complex properties #6966
base: main
Are you sure you want to change the base?
Conversation
b247abf
to
a37bff4
Compare
const size_t valuesCount = newStyleValue.isObject() | ||
? newStyleValue.asObject(rt).asArray(rt).size(rt) | ||
: oldStyleValue.asObject(rt).asArray(rt).size(rt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was incorrect as it assumed that both arrays have always the same length. The quite new RN prop boxShadow
allows passing any number of shadow objects, so we need to make it possible to interpolate between arrays with different number of elements.
std::unordered_set<std::string> propertyNamesSet; | ||
const jsi::Object *objects[] = {&oldStyleObject, &newStyleObject}; | ||
for (const auto *styleObject : objects) { | ||
const auto propertyNames = styleObject->getPropertyNames(rt); | ||
for (size_t i = 0; i < propertyNames.size(rt); ++i) { | ||
propertyNamesSet.insert( | ||
propertyNames.getValueAtIndex(rt, i).asString(rt).utf8(rt)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new implementation ensures that all props are taken into account. It is a similar change to the arrays interpolator, where we can now support arrays of different lengths.
If a prop from old object is missing in the new one, it will be animated to the fallback value, similarly if there is a prop in the new object but there was no such a prop in the old one.
I can also see that during the first transition view flickers. I think it is related to a well known |
Summary
There were a few different issues related to
boxShadow
interpolation in CSS transitions (and to other non-primitive props except transforms, where I had a special case handling logic implemented).List of changes
getChangedProps
- it handled arrays in the same way as objects, which resulted in creating objects with indexes as keys instead of arrays,getChangedProps
implementation,updateKeyframesFromStyleChange
method implementation used by CSS transitions, which didn't support arrays of different lengths / objects with different keys, where keys of the old object not existing in the new one were ignored,boxShadow
string parsing functionparseBoxShadowString
and added tests to this function to make sure it works as expected,Examples
boxShadow
exampleSource code
Simulator.Screen.Recording.-.iPhone.16.Pro.-.2025-01-31.at.21.18.59.mp4
Simulator.Screen.Recording.-.iPhone.16.Pro.-.2025-01-31.at.21.01.51.mp4
Separate props shadow example
Source code
You can see that in the second example shadow is smoothly animated in both axes, whilst, in the first example, animation is smooth only in y axis. This happens because the
width
property is missing in one ofshadowOffset
values and previous implementation didn't support this case.Simulator.Screen.Recording.-.iPhone.16.Pro.-.2025-01-31.at.21.19.22.mp4
Simulator.Screen.Recording.-.iPhone.16.Pro.-.2025-01-31.at.21.02.29.mp4