From 0bb3252066e23425ba2d2da5b56cc482573f46eb Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 16 Mar 2022 22:56:05 -0300 Subject: [PATCH 1/6] Chore: Migrate containers: List to Typescript --- app/containers/List/ListContainer.tsx | 2 +- app/containers/List/ListHeader.tsx | 23 ++++---- app/containers/List/ListIcon.tsx | 19 ++++--- app/containers/List/ListInfo.tsx | 20 ++++--- app/containers/List/ListItem.tsx | 82 ++++++++++++++------------- app/containers/List/ListSection.tsx | 5 +- app/containers/List/ListSeparator.tsx | 13 +++-- app/dimensions.tsx | 4 +- 8 files changed, 91 insertions(+), 77 deletions(-) diff --git a/app/containers/List/ListContainer.tsx b/app/containers/List/ListContainer.tsx index deb9c8a7109..75647b22e80 100644 --- a/app/containers/List/ListContainer.tsx +++ b/app/containers/List/ListContainer.tsx @@ -11,7 +11,7 @@ const styles = StyleSheet.create({ }); interface IListContainer { - children: React.ReactNode; + children: React.ReactElement | React.ReactElement[] | null; testID?: string; } const ListContainer = React.memo(({ children, ...props }: IListContainer) => ( diff --git a/app/containers/List/ListHeader.tsx b/app/containers/List/ListHeader.tsx index 9a0b977315d..469d4cec66a 100644 --- a/app/containers/List/ListHeader.tsx +++ b/app/containers/List/ListHeader.tsx @@ -4,7 +4,7 @@ import { StyleSheet, Text, View } from 'react-native'; import sharedStyles from '../../views/Styles'; import { themes } from '../../constants/colors'; import I18n from '../../i18n'; -import { withTheme } from '../../theme'; +import { useTheme } from '../../theme'; import { PADDING_HORIZONTAL } from './constants'; const styles = StyleSheet.create({ @@ -20,18 +20,21 @@ const styles = StyleSheet.create({ interface IListHeader { title: string; - theme?: string; translateTitle?: boolean; } -const ListHeader = React.memo(({ title, theme, translateTitle = true }: IListHeader) => ( - - - {translateTitle ? I18n.t(title) : title} - - -)); +const ListHeader = React.memo(({ title, translateTitle = true }: IListHeader) => { + const { theme } = useTheme(); + + return ( + + + {translateTitle ? I18n.t(title) : title} + + + ); +}); ListHeader.displayName = 'List.Header'; -export default withTheme(ListHeader); +export default ListHeader; diff --git a/app/containers/List/ListIcon.tsx b/app/containers/List/ListIcon.tsx index 71e4fbdf235..c134b169036 100644 --- a/app/containers/List/ListIcon.tsx +++ b/app/containers/List/ListIcon.tsx @@ -3,11 +3,10 @@ import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native'; import { themes } from '../../constants/colors'; import { CustomIcon } from '../../lib/Icons'; -import { withTheme } from '../../theme'; +import { useTheme } from '../../theme'; import { ICON_SIZE } from './constants'; interface IListIcon { - theme?: string; name: string; color?: string; style?: StyleProp; @@ -21,12 +20,16 @@ const styles = StyleSheet.create({ } }); -const ListIcon = React.memo(({ theme, name, color, style, testID }: IListIcon) => ( - - - -)); +const ListIcon = React.memo(({ name, color, style, testID }: IListIcon) => { + const { theme } = useTheme(); + + return ( + + + + ); +}); ListIcon.displayName = 'List.Icon'; -export default withTheme(ListIcon); +export default ListIcon; diff --git a/app/containers/List/ListInfo.tsx b/app/containers/List/ListInfo.tsx index 2bfe68e324d..baac47ccc8a 100644 --- a/app/containers/List/ListInfo.tsx +++ b/app/containers/List/ListInfo.tsx @@ -3,7 +3,7 @@ import { StyleSheet, Text, View } from 'react-native'; import sharedStyles from '../../views/Styles'; import { themes } from '../../constants/colors'; -import { withTheme } from '../../theme'; +import { useTheme } from '../../theme'; import { PADDING_HORIZONTAL } from './constants'; import I18n from '../../i18n'; @@ -18,18 +18,20 @@ const styles = StyleSheet.create({ } }); -interface IListHeader { +interface IListInfo { info: string; - theme?: string; translateInfo?: boolean; } -const ListInfo = React.memo(({ info, theme, translateInfo = true }: IListHeader) => ( - - {translateInfo ? I18n.t(info) : info} - -)); +const ListInfo = React.memo(({ info, translateInfo = true }: IListInfo) => { + const { theme } = useTheme(); + return ( + + {translateInfo ? I18n.t(info) : info} + + ); +}); ListInfo.displayName = 'List.Info'; -export default withTheme(ListInfo); +export default ListInfo; diff --git a/app/containers/List/ListItem.tsx b/app/containers/List/ListItem.tsx index 79b3dcbf73b..2df3cf9ab9f 100644 --- a/app/containers/List/ListItem.tsx +++ b/app/containers/List/ListItem.tsx @@ -4,11 +4,11 @@ import { I18nManager, StyleSheet, Text, View } from 'react-native'; import Touch from '../../utils/touch'; import { themes } from '../../constants/colors'; import sharedStyles from '../../views/Styles'; -import { withTheme } from '../../theme'; +import { useTheme } from '../../theme'; import I18n from '../../i18n'; import { Icon } from '.'; import { BASE_HEIGHT, ICON_SIZE, PADDING_HORIZONTAL } from './constants'; -import { withDimensions } from '../../dimensions'; +import { useDimensions } from '../../dimensions'; import { CustomIcon } from '../../lib/Icons'; const styles = StyleSheet.create({ @@ -59,13 +59,12 @@ interface IListItemContent { left?: () => JSX.Element | null; right?: () => JSX.Element | null; disabled?: boolean; + theme: string; testID?: string; - theme?: string; color?: string; translateTitle?: boolean; translateSubtitle?: boolean; showActionIndicator?: boolean; - fontScale?: number; alert?: boolean; } @@ -78,78 +77,83 @@ const Content = React.memo( left, right, color, - theme, - fontScale, alert, translateTitle = true, translateSubtitle = true, - showActionIndicator = false - }: IListItemContent) => ( - - {left ? {left()} : null} - - - - {translateTitle ? I18n.t(title) : title} - - {alert ? ( - + showActionIndicator = false, + theme + }: IListItemContent) => { + const { fontScale } = useDimensions(); + + return ( + + {left ? {left()} : null} + + + + {translateTitle ? I18n.t(title) : title} + + {alert ? ( + + ) : null} + + {subtitle ? ( + + {translateSubtitle ? I18n.t(subtitle) : subtitle} + ) : null} - {subtitle ? ( - - {translateSubtitle ? I18n.t(subtitle) : subtitle} - + {right || showActionIndicator ? ( + + {right ? right() : null} + {showActionIndicator ? : null} + ) : null} - {right || showActionIndicator ? ( - - {right ? right() : null} - {showActionIndicator ? : null} - - ) : null} - - ) + ); + } ); interface IListButtonPress { - onPress?: Function; + onPress: Function; } interface IListItemButton extends IListButtonPress { title?: string; disabled?: boolean; - theme?: string; + theme: string; backgroundColor?: string; underlayColor?: string; } const Button = React.memo(({ onPress, backgroundColor, underlayColor, ...props }: IListItemButton) => ( onPress!(props.title)} - style={{ backgroundColor: backgroundColor || themes[props.theme!].backgroundColor }} + onPress={() => onPress(props.title)} + style={{ backgroundColor: backgroundColor || themes[props.theme].backgroundColor }} underlayColor={underlayColor} enabled={!props.disabled} - theme={props.theme!}> + theme={props.theme}> )); -interface IListItem extends IListItemContent, IListItemButton { +interface IListItem extends Omit, Omit { backgroundColor?: string; } const ListItem = React.memo(({ ...props }: IListItem) => { + const { theme } = useTheme(); + if (props.onPress) { - return