Skip to content
Permalink
Browse files

Improve flowtypes (#1429)

* Update types.js

* Remove dummy unused prop

* Usae object types instead of interfaces

* Add default type for generic params

* Update flowtypes to use react node instead of react elem
  • Loading branch information...
amiralies authored and xcarpentier committed Sep 30, 2019
1 parent 52294eb commit 0dd41de27825f034ba34ac56483c4bcdccbab500
@@ -1,21 +1,21 @@
// @flow
import { Component } from 'react'
import * as React from 'react'
import type {
ViewStyleProp,
ImageStyleProp,
TextStyleProp,
} from 'react-native/Libraries/StyleSheet/StyleSheet'

export interface ActionsProps {
export type ActionsProps = $ReadOnly<{|
options?: {
[key: string]: any,
};
optionTintColor?: string;
icon?: () => React$Element<any>;
wrapperStyle?: ViewStyleProp;
iconTextStyle?: TextStyleProp;
containerStyle?: ViewStyleProp;
onPressActionButton?: () => void;
}
},
optionTintColor?: string,
icon?: () => React.Node,
wrapperStyle?: ViewStyleProp,
iconTextStyle?: TextStyleProp,
containerStyle?: ViewStyleProp,
onPressActionButton?: () => void,
|}>

export default class Actions extends Component<ActionsProps> {}
export default class Actions extends React.Component<ActionsProps> {}
@@ -1,29 +1,27 @@
// @flow
import { Component } from 'react'
import * as React from 'react'
import type { IMessage, User, LeftRightStyle } from './types'
import type {
ImageStyleProp,
ViewStyleProp,
} from 'react-native/Libraries/StyleSheet/StyleSheet'

type Props = { name: string, age: number => string }

export interface AvatarProps<TMessage: IMessage> {
currentMessage?: TMessage;
previousMessage?: TMessage;
nextMessage?: TMessage;
position: 'left' | 'right';
renderAvatarOnTop?: boolean;
showAvatarForEveryMessage?: boolean;
imageStyle?: LeftRightStyle<ImageStyleProp>;
containerStyle?: LeftRightStyle<ViewStyleProp>;
export type AvatarProps<TMessage: IMessage = IMessage> = $ReadOnly<{|
currentMessage?: TMessage,
previousMessage?: TMessage,
nextMessage?: TMessage,
position: 'left' | 'right',
renderAvatarOnTop?: boolean,
showAvatarForEveryMessage?: boolean,
imageStyle?: LeftRightStyle<ImageStyleProp>,
containerStyle?: LeftRightStyle<ViewStyleProp>,
renderAvatar?: (
$Diff<AvatarProps<TMessage>, {| renderAvatar: * |}>,
) => React$Element<any>;
onPressAvatar?: User => void;
onLongPressAvatar?: User => void;
}
) => React.Node,
onPressAvatar?: User => void,
onLongPressAvatar?: User => void,
|}>

export default class Avatar<TMessage: IMessage> extends Component<
AvatarProps<TMessage>,
> {}
export default class Avatar<
TMessage: IMessage = IMessage,
> extends React.Component<AvatarProps<TMessage>> {}
@@ -1,5 +1,5 @@
// @flow
import { Component } from 'react'
import * as React from 'react'
import type { QuickRepliesProps } from './QuickReplies'
import type { MessageImageProps } from './MessageImage'
import type { MessageVideoProps } from './MessageVideo'
@@ -11,61 +11,57 @@ import type {
ViewStyleProp,
} from 'react-native/Libraries/StyleSheet/StyleSheet'

export type RenderMessageImageProps<TMessage: IMessage> = $Diff<
export type RenderMessageImageProps<TMessage: IMessage = IMessage> = $Diff<
BubbleProps<TMessage>,
{| containerStyle: *, wrapperStyle: * |},
> &
MessageImageProps<TMessage>

export type RenderMessageVideoProps<TMessage: IMessage> = $Diff<
export type RenderMessageVideoProps<TMessage: IMessage = IMessage> = $Diff<
BubbleProps<TMessage>,
{| containerStyle: *, wrapperStyle: * |},
> &
MessageVideoProps<TMessage>

export type RenderMessageTextProps<TMessage: IMessage> = $Diff<
export type RenderMessageTextProps<TMessage: IMessage = IMessage> = $Diff<
BubbleProps<TMessage>,
{| containerStyle: *, wrapperStyle: * |},
> &
MessageTextProps<TMessage>

export interface BubbleProps<TMessage: IMessage> {
user?: User;
touchableProps?: Object;
renderUsernameOnMessage?: boolean;
isCustomViewBottom?: boolean;
inverted?: boolean;
position: 'left' | 'right';
currentMessage?: TMessage;
nextMessage?: TMessage;
previousMessage?: TMessage;
optionTitles?: string;
containerStyle?: LeftRightStyle<ViewStyleProp>;
wrapperStyle?: LeftRightStyle<ViewStyleProp>;
textStyle?: LeftRightStyle<TextStyleProp>;
bottomContainerStyle?: LeftRightStyle<ViewStyleProp>;
tickStyle?: TextStyleProp;
containerToNextStyle?: LeftRightStyle<ViewStyleProp>;
containerToPreviousStyle?: LeftRightStyle<ViewStyleProp>;
usernameStyle?: LeftRightStyle<TextStyleProp>;
quickReplyStyle?: ViewStyleProp;
onLongPress?: (context?: any, message?: any) => void;
onQuickReply?: (Array<Reply>) => void;
renderMessageImage?: (
RenderMessageImageProps<TMessage>,
) => React$Element<any>;
renderMessageVideo?: (
RenderMessageVideoProps<TMessage>,
) => React$Element<any>;
renderMessageText?: (RenderMessageTextProps<TMessage>) => React$Element<any>;
renderCustomView?: (BubbleProps<TMessage>) => React$Element<any>;
renderTime?: (TimeProps: TMessage) => React$Element<any>;
renderTicks?: TMessage => React$Element<any>;
renderUsername?: () => React$Element<any>;
renderQuickReplySend?: () => React$Element<any>;
renderQuickReplies?: QuickRepliesProps => React$Element<any>;
}
export type BubbleProps<TMessage: IMessage = IMessage> = $ReadOnly<{|
user?: User,
touchableProps?: Object,
renderUsernameOnMessage?: boolean,
isCustomViewBottom?: boolean,
inverted?: boolean,
position: 'left' | 'right',
currentMessage?: TMessage,
nextMessage?: TMessage,
previousMessage?: TMessage,
optionTitles?: string,
containerStyle?: LeftRightStyle<ViewStyleProp>,
wrapperStyle?: LeftRightStyle<ViewStyleProp>,
textStyle?: LeftRightStyle<TextStyleProp>,
bottomContainerStyle?: LeftRightStyle<ViewStyleProp>,
tickStyle?: TextStyleProp,
containerToNextStyle?: LeftRightStyle<ViewStyleProp>,
containerToPreviousStyle?: LeftRightStyle<ViewStyleProp>,
usernameStyle?: LeftRightStyle<TextStyleProp>,
quickReplyStyle?: ViewStyleProp,
onLongPress?: (context?: any, message?: any) => void,
onQuickReply?: (Array<Reply>) => void,
renderMessageImage?: (RenderMessageImageProps<TMessage>) => React.Node,
renderMessageVideo?: (RenderMessageVideoProps<TMessage>) => React.Node,
renderMessageText?: (RenderMessageTextProps<TMessage>) => React.Node,
renderCustomView?: (BubbleProps<TMessage>) => React.Node,
renderTime?: (TimeProps: TMessage) => React.Node,
renderTicks?: TMessage => React.Node,
renderUsername?: () => React.Node,
renderQuickReplySend?: () => React.Node,
renderQuickReplies?: QuickRepliesProps => React.Node,
|}>

export default class Bubble<TMessage: IMessage> extends Component<
BubbleProps<TMessage>,
> {}
export default class Bubble<
TMessage: IMessage = IMessage,
> extends React.Component<BubbleProps<TMessage>> {}
@@ -4,21 +4,21 @@ import * as React from 'react'

type TextInputProps = $Shape<React.ElementProps<typeof TextInput>>

export interface ComposerProps {
composerHeight?: number;
text?: string;
placeholder?: string;
placeholderTextColor?: string;
textInputProps?: TextInputProps;
textInputStyle?: $PropertyType<TextInputProps, 'style'>;
textInputAutoFocus?: boolean;
keyboardAppearance?: $PropertyType<TextInputProps, 'keyboardAppearance'>;
multiline?: boolean;
onTextChanged?: string => void;
export type ComposerProps = $ReadOnly<{|
composerHeight?: number,
text?: string,
placeholder?: string,
placeholderTextColor?: string,
textInputProps?: TextInputProps,
textInputStyle?: $PropertyType<TextInputProps, 'style'>,
textInputAutoFocus?: boolean,
keyboardAppearance?: $PropertyType<TextInputProps, 'keyboardAppearance'>,
multiline?: boolean,
onTextChanged?: string => void,
onInputSizeChanged?: ({|
width: number,
height: number,
|}) => void;
}
|}) => void,
|}>

export default class Composer extends React.Component<ComposerProps> {}
@@ -7,17 +7,17 @@ import type {
TextStyleProp,
} from 'react-native/Libraries/StyleSheet/StyleSheet'

export interface DayProps<TMessage: IMessage> {
currentMessage?: TMessage;
nextMessage?: TMessage;
previousMessage?: TMessage;
containerStyle?: ViewStyleProp;
wrapperStyle?: ViewStyleProp;
textStyle?: TextStyleProp;
dateFormat?: string;
inverted?: boolean;
}
export type DayProps<TMessage: IMessage = IMessage> = $ReadOnly<{|
currentMessage?: TMessage,
nextMessage?: TMessage,
previousMessage?: TMessage,
containerStyle?: ViewStyleProp,
wrapperStyle?: ViewStyleProp,
textStyle?: TextStyleProp,
dateFormat?: string,
inverted?: boolean,
|}>

export default class Day<TMessage: IMessage> extends PureComponent<
export default class Day<TMessage: IMessage = IMessage> extends PureComponent<
DayProps<TMessage>,
> {}
@@ -6,12 +6,12 @@ import type {
TextStyleProp,
} from 'react-native/Libraries/StyleSheet/StyleSheet'

export interface GiftedAvatarProps {
user?: User;
avatarStyle?: ImageStyleProp;
textStyle?: TextStyleProp;
onPress: any => void;
onLongPress: any => void;
}
export type GiftedAvatarProps = $ReadOnly<{|
user?: User,
avatarStyle?: ImageStyleProp,
textStyle?: TextStyleProp,
onPress: any => void,
onLongPress: any => void,
|}>

export default class GiftedAvatar extends Component<GiftedAvatarProps> {}

0 comments on commit 0dd41de

Please sign in to comment.
You can’t perform that action at this time.