-
-
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: CSS transition shorthand property behavior in react-native-web #7019
base: @matipl01/css-keyframes-registry
Are you sure you want to change the base?
fix: CSS transition shorthand property behavior in react-native-web #7019
Conversation
4758801
to
61992a0
Compare
8a31475
to
1d01d03
Compare
) => `Invalid transition property "${JSON.stringify(transitionProperty)}"`, | ||
}; | ||
|
||
function getExpandedConfigProperties( | ||
config: CSSTransitionProperties | ||
): ExpandedConfigProperties { | ||
const configEntries = Object.entries(config); | ||
const shorthandIndex = config.transition |
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.
I moved this removal of transition properties listed before the transition
shorthand property to the filterCSSAndStyleProperties
because it simplifies the logic and removing invalid properties as soon as possible seems to be a better solution for me.
return splitByComma(value).reduce<ExpandedCSSTransitionConfigProperties>( | ||
(acc, part) => { | ||
const result = parseSingleTransitionShorthand(part); | ||
acc.transitionProperty.push(result.transitionProperty ?? 'all'); | ||
acc.transitionDuration.push( | ||
result.transitionDuration ? String(result.transitionDuration) : '0s' | ||
); | ||
acc.transitionTimingFunction.push( | ||
result.transitionTimingFunction ?? 'ease' | ||
); | ||
acc.transitionDelay.push( | ||
result.transitionDelay ? String(result.transitionDelay) : '0s' | ||
); | ||
acc.transitionBehavior.push(result.transitionBehavior ?? 'normal'); | ||
return acc; | ||
}, | ||
createEmptyTransitionConfig() | ||
); |
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.
I decided to parse the transition shorthand on web as well in order to:
- Ensure that behavior is always the same as in the mobile implementation
- Because
parseSingleTransitionShorthand
already validates a correctness of the transition property shorthand
61992a0
to
2db4ac2
Compare
39a007a
to
eb04501
Compare
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.
I haven't tested it, but I didn't find anything controversial in these changes, so I can approve it 👍
Summary
This PR fixes CSS transition properties being overridden by
react-native-web
. It happened because we didn't filter out CSS props from the style object passed to the component in therender()
method of theAnimatedComponent
.I also made a few other changes to ensure that the transition shorthand is validated on web as well and preprocessed in a similar way to the native implementation.
Example Recordings
In the previous implementation, the
transitionTimingFunction
prop specified before thetransition
property shorthand was overriding thetransition
prop easing. Web also shown an error in the console that shorthand props shouldn't be mixed with longhand ones. We don't want this error to show up and want to support usage of both at the same time.Web
Screen.Recording.2025-02-13.at.14.28.49.mp4
Screen.Recording.2025-02-13.at.14.24.37.mp4
iOS
This recording is just for comparison to see that the behavior on web is also correct (the same as on the recording below) after changes implemented in this PR
Simulator.Screen.Recording.-.iPhone.16.Pro.-.2025-02-13.at.14.25.02.mp4
Source code