Are there any flow types definition for react-native styles?

前端 未结 2 1041
慢半拍i
慢半拍i 2021-02-19 22:37

I\'m making a react native component and using Flow to define the property types like this:

type Props = {
    text: string,
    textStyle: object
}
相关标签:
2条回答
  • 2021-02-19 23:06

    Update

    StyleObj is no longer part of StyleSheetTypes.

    Now import:

    {LayoutStyle, TransformStyle, ShadowStyle, ViewStyle, TextStyle, ImageStyle, DangerouslyImpreciseStyle} from 'react-native/Libraries/StyleSheet/StyleSheetTypes';

    In your case, you should:

    import { TextStyle } from 'react-native/Libraries/StyleSheet/StyleSheetTypes';

    0 讨论(0)
  • 2021-02-19 23:19

    Update 3:

    Current best practice is:

    import type {
       ViewStyleProp,
       TextStyleProp,
       ImageStyleProp,
    } from 'react-native/Libraries/StyleSheet/StyleSheet';
    

    Update 2: The following PR makes things simpler, as of today flowtype styles are as follow.

    type StyleValue = {[key: string]: Object} | number | false | null;
    type StyleProp = StyleValue | Array<StyleValue>; 
    

    Obsolete: The following PR fixes it, can be found from v0.52.0

    It is possible to do the following:

    // @flow
    
    import type { StyleObj } from 'react-native/Libraries/StyleSheet/StyleSheetTypes';
    
    type Props = {
        style?: StyleObj
    };
    

    Following discussion on: https://github.com/flowtype/flow-typed/issues/631#issuecomment-282009393

    0 讨论(0)
提交回复
热议问题