[react-native] fixes StyleSheet.flatten use caused by StyleSheet.compose definition (#41408)

This commit is contained in:
Valentin Tolochko
2020-01-06 12:23:40 +02:00
committed by Eloy Durán
parent 1b29bd026a
commit 32f58bbeea
2 changed files with 8 additions and 3 deletions

View File

@@ -1963,10 +1963,10 @@ export interface ViewPropsAndroid {
}
type Falsy = undefined | null | false;
interface RecursiveArray<T> extends Array<T | RecursiveArray<T>> {}
interface RecursiveArray<T> extends Array<T | ReadonlyArray<T> | RecursiveArray<T>> {}
/** Keep a brand of 'T' so that calls to `StyleSheet.flatten` can take `RegisteredStyle<T>` and return `T`. */
type RegisteredStyle<T> = number & { __registeredStyleBrand: T };
export type StyleProp<T> = T | RegisteredStyle<T> | ReadonlyArray<T> | RecursiveArray<T | RegisteredStyle<T> | Falsy> | Falsy;
export type StyleProp<T> = T | RegisteredStyle<T> | RecursiveArray<T | RegisteredStyle<T> | Falsy> | Falsy;
/**
* @see https://facebook.github.io/react-native/docs/accessibility.html#accessibility-properties
@@ -5136,7 +5136,7 @@ export namespace StyleSheet {
* an array, saving allocations and maintaining reference equality for
* PureComponent checks.
*/
export function compose<T>(style1: StyleProp<T>, style2: StyleProp<T>): StyleProp<T>;
export function compose<T>(style1: StyleProp<T> | Array<StyleProp<T>>, style2: StyleProp<T> | Array<StyleProp<T>>): StyleProp<T>;
/**
* WARNING: EXPERIMENTAL. Breaking changes will probably happen a lot and will

View File

@@ -187,6 +187,11 @@ const textProperty = StyleSheet.flatten(textStyle).fontSize;
const imageProperty = StyleSheet.flatten(imageStyle).resizeMode;
const fontVariantProperty = StyleSheet.flatten(fontVariantStyle).fontVariant;
// correct use of the StyleSheet.flatten
const styleArray: StyleProp<ViewStyle>[] = [];
const flattenStyle = StyleSheet.flatten(styleArray);
const { top } = flattenStyle;
const s = StyleSheet.create({
shouldWork: {
fontWeight: "900", // if we comment this line, errors gone