Skip to content

Commit 8c21421

Browse files
fix flow: resolve conditional style values in flattenStyle output
The conditional-value widening on style props leaked into flattenStyle's return type, breaking ~15 consumers that expect concrete values (splitLayoutProps, Image, Touchable, etc.). Widen flattenStyle's input bound to accept conditionals and strip them from its output so a flattened style presents its resolved type.
1 parent 6b3d98e commit 8c21421

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

packages/react-native/Libraries/StyleSheet/StyleSheetTypes.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,8 +1106,13 @@ export type ____DangerouslyImpreciseStyleProp_Internal = StyleProp<
11061106
>,
11071107
>;
11081108

1109-
export type ____DangerouslyImpreciseAnimatedStyleProp_Internal =
1110-
WithAnimatedValue<StyleProp<Partial<____DangerouslyImpreciseStyle_Internal>>>;
1109+
export type ____DangerouslyImpreciseAnimatedStyleProp_Internal = WithAnimatedValue<
1110+
StyleProp<
1111+
____WithConditionalValues_Internal<
1112+
Partial<____DangerouslyImpreciseStyle_Internal>,
1113+
>,
1114+
>,
1115+
>;
11111116

11121117
export type ____ViewStyleProp_Internal = StyleProp<
11131118
____WithConditionalValues_Internal<Readonly<Partial<____ViewStyle_Internal>>>,
@@ -1133,6 +1138,15 @@ type ____WithConditionalValues_Internal<out T> = {
11331138
[K in keyof T]: T[K] | ____ConditionalStyleValue_Internal<T[K]>,
11341139
};
11351140

1141+
// Inverse of `____WithConditionalValues_Internal`: narrows each property back
1142+
// to its base type. Conditional values are resolved natively, so a *flattened*
1143+
// style presents its resolved (base) type to JS consumers.
1144+
type ____ResolveConditionalValue_Internal<V> =
1145+
V extends ____ConditionalStyleValue_Internal<infer U> ? U : V;
1146+
type ____ResolveConditionalValues_Internal<out T> = {
1147+
[K in keyof T]: ____ResolveConditionalValue_Internal<T[K]>,
1148+
};
1149+
11361150
export type ____Styles_Internal = {
11371151
// $FlowFixMe[incompatible-exact]
11381152
// $FlowFixMe[incompatible-type]
@@ -1164,4 +1178,6 @@ export type ____FlattenStyleProp_Internal<
11641178
> =
11651179
____FlattenStyleProp_Helper<TStyleProp> extends empty // $FlowFixMe[unclear-type]
11661180
? any
1167-
: ____FlattenStyleProp_Helper<TStyleProp>;
1181+
: ____ResolveConditionalValues_Internal<
1182+
____FlattenStyleProp_Helper<TStyleProp>,
1183+
>;

0 commit comments

Comments
 (0)