Skip to content

Commit df08b74

Browse files
authored
Fix/grid list item theme support (#3059)
* Remove unnecessary default values to allow theme to work * try using nvm 20 * Revert nvm to use 16 * Remove comments
1 parent 56c6f86 commit df08b74

File tree

1 file changed

+19
-45
lines changed

1 file changed

+19
-45
lines changed

src/components/gridListItem/index.tsx

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import React, {Component} from 'react';
33
import {StyleProp, StyleSheet, ViewStyle} from 'react-native';
44
import memoize from 'memoize-one';
55
import * as Modifiers from '../../commons/modifiers';
6-
import {Colors, Spacings, Typography} from 'style';
6+
import {Spacings} from 'style';
77
import View, {ViewProps} from '../view';
88
import TouchableOpacity, {TouchableOpacityProps} from '../touchableOpacity';
9-
import Text from '../text';
9+
import Text, {type TextProps} from '../text';
1010
import Image, {ImageProps} from '../image';
1111

1212
export enum HorizontalAlignment {
@@ -115,15 +115,6 @@ export interface GridListItemProps {
115115
children?: React.ReactElement | React.ReactElement[];
116116
}
117117

118-
interface RenderContentType {
119-
text?: string | React.ReactElement;
120-
typography?: string;
121-
color?: string;
122-
numberOfLines?: number;
123-
style?: StyleProp<ViewStyle>;
124-
testID?: string;
125-
}
126-
127118
/**
128119
* @description: A single grid view/list item component
129120
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/GridViewScreen.tsx
@@ -165,23 +156,12 @@ class GridListItem extends Component<GridListItemProps> {
165156
}
166157
});
167158

168-
renderContent({text, typography, color, numberOfLines = 1, style, testID}: RenderContentType) {
159+
renderContent(text: string | React.ReactElement | undefined, textProps: Partial<TextProps>) {
169160
const {alignToStart, horizontalAlignment} = this.props;
170161
const textAlign = alignToStart ? 'left' : horizontalAlignment;
171162
if (text) {
172163
return (
173-
<Text
174-
testID={testID}
175-
// @ts-ignore
176-
style={[
177-
style,
178-
//@ts-ignore
179-
Typography[typography],
180-
color && {color},
181-
{textAlign}
182-
]}
183-
numberOfLines={numberOfLines}
184-
>
164+
<Text {...textProps} style={[textProps.style, {textAlign}]}>
185165
{text}
186166
</Text>
187167
);
@@ -199,18 +179,18 @@ class GridListItem extends Component<GridListItemProps> {
199179
renderCustomItem,
200180
children,
201181
title,
202-
titleTypography,
203-
titleColor = Colors.$textDefault,
182+
titleTypography = 'bodySmallBold',
183+
titleColor,
204184
titleLines,
205185
overlayText,
206186
overlayTextContainerStyle,
207187
subtitle,
208-
subtitleTypography,
209-
subtitleColor = Colors.$textDefault,
188+
subtitleTypography = 'subtext',
189+
subtitleColor,
210190
subtitleLines,
211191
description,
212-
descriptionTypography,
213-
descriptionColor = Colors.$textDefault,
192+
descriptionTypography = 'subtext',
193+
descriptionColor,
214194
descriptionLines,
215195
onPress,
216196
renderOverlay
@@ -237,26 +217,23 @@ class GridListItem extends Component<GridListItemProps> {
237217
{!_.isNil(renderCustomItem) && <View style={{width}}>{renderCustomItem()}</View>}
238218
{renderOverlay && <View style={[styles.overlay, itemSize]}>{renderOverlay()}</View>}
239219
<TextContainer {...textContainerStyle}>
240-
{this.renderContent({
220+
{this.renderContent(title, {
241221
testID: `${testID}.title`,
242-
text: title,
243-
typography: titleTypography,
222+
[titleTypography]: true,
244223
color: titleColor,
245224
numberOfLines: titleLines,
246225
style: styles.title
247226
})}
248-
{this.renderContent({
227+
{this.renderContent(subtitle, {
249228
testID: `${testID}.subtitle`,
250-
text: subtitle,
251-
typography: subtitleTypography,
229+
[subtitleTypography]: true,
252230
color: subtitleColor,
253231
numberOfLines: subtitleLines,
254232
style: styles.subtitle
255233
})}
256-
{this.renderContent({
234+
{this.renderContent(description, {
257235
testID: `${testID}.description`,
258-
text: description,
259-
typography: descriptionTypography,
236+
[descriptionTypography]: true,
260237
color: descriptionColor,
261238
numberOfLines: descriptionLines,
262239
style: styles.description
@@ -274,16 +251,13 @@ const styles = StyleSheet.create({
274251
},
275252
title: {
276253
marginTop: Spacings.s1,
277-
textAlign: 'center',
278-
...Typography.bodySmallBold
254+
textAlign: 'center'
279255
},
280256
subtitle: {
281-
textAlign: 'center',
282-
...Typography.subtext
257+
textAlign: 'center'
283258
},
284259
description: {
285-
textAlign: 'center',
286-
...Typography.subtext
260+
textAlign: 'center'
287261
},
288262
overlay: {
289263
position: 'absolute',

0 commit comments

Comments
 (0)