Skip to content
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

Merged
merged 7 commits into from
Feb 20, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Filter out css props without style flattening
  • Loading branch information
MatiPl01 committed Feb 20, 2025
commit b026b32080ec2903d3f04c9e6ad73550c8c1d8c3
48 changes: 37 additions & 11 deletions packages/react-native-reanimated/src/css/component/utils.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,42 @@
'use strict';
import type { StyleProp } from 'react-native';
import { StyleSheet } from 'react-native';
import type {
Falsy,
RecursiveArray,
RegisteredStyle,
StyleProp,
} from 'react-native';

import type { AnyRecord, CSSStyle, PlainStyle } from '../types';
import type { AnyRecord, CSSStyle } from '../types';
import { isCSSStyleProp } from '../utils/guards';

export function filterNonCSSStyleProps(props: StyleProp<CSSStyle>): PlainStyle {
const flattened = StyleSheet.flatten(props);
return Object.entries(flattened).reduce<AnyRecord>((acc, [key, value]) => {
if (!isCSSStyleProp(key)) {
acc[key] = value;
}
return acc;
}, {});
type BaseStyle = CSSStyle | Falsy | RegisteredStyle<CSSStyle>;
type StyleProps = BaseStyle | RecursiveArray<BaseStyle> | readonly BaseStyle[];

function filterNonCSSStylePropsRecursive(
props: StyleProps
): StyleProp<CSSStyle> {
if (Array.isArray(props)) {
return props.map(filterNonCSSStylePropsRecursive);
}

if (!props) {
return props;
}

if (typeof props === 'object') {
return Object.entries(props).reduce<AnyRecord>((acc, [key, value]) => {
if (!isCSSStyleProp(key)) {
acc[key] = value;
}
return acc;
}, {});
}

return props;
}

export function filterNonCSSStyleProps(
props: StyleProp<CSSStyle>
): StyleProp<CSSStyle> {
return filterNonCSSStylePropsRecursive(props);
}