Skip to content

Commit 279f1be

Browse files
authored
Fix issue with GridView lastItemOverlayColor error when undefined (#1900)
* Fix issue with GridView lastItemOverlayColor error when undefined * Update code snippet of GridView
1 parent df21605 commit 279f1be

File tree

4 files changed

+7
-23
lines changed

4 files changed

+7
-23
lines changed

demo/src/screens/componentScreens/GridViewScreen.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import _ from 'lodash';
2-
import {View, Text, Image, Colors, Constants, Avatar, GridView, Shadows, Card} from 'react-native-ui-lib';
2+
import {View, Text, Image, Colors, Constants, Avatar, GridView, Card} from 'react-native-ui-lib';
33
import React, {Component} from 'react';
44
import {Alert, ScrollView} from 'react-native';
55
import conversations from '../../data/conversations';
@@ -153,7 +153,7 @@ class GridViewScreen extends Component {
153153
items={contacts}
154154
// viewWidth={300}
155155
numColumns={6}
156-
lastItemOverlayColor={Colors.primary}
156+
lastItemOverlayColor={Colors.rgba(Colors.primary, 0.6)}
157157
lastItemLabel={7}
158158
/>
159159

@@ -163,7 +163,7 @@ class GridViewScreen extends Component {
163163
<GridView
164164
items={products}
165165
numColumns={4}
166-
lastItemOverlayColor={Colors.primary}
166+
lastItemOverlayColor={Colors.rgba(Colors.primary, 0.6)}
167167
lastItemLabel={42}
168168
keepItemSize
169169
/>

generatedTypes/src/components/gridView/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ declare class GridView extends UIComponent<GridViewProps, GridViewState> {
7373
getGridContainerWidth(): number;
7474
calcNumberOfColumns(): number;
7575
calcItemSize(): number;
76-
getThemeColor(placeColor: string): any;
7776
renderLastItemOverlay(): JSX.Element | undefined;
7877
renderItem: (item: GridListItemProps, index: number) => JSX.Element;
7978
render(): JSX.Element;

src/components/gridView/gridView.api.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
" items={[{title: 'item 1', onPress: () => console.log('item 1 pressed')}, {title: 'item 2', onPress: () => console.log('item 2 pressed')}, ]$1}",
3131
" numColumns={2$2}",
3232
" lastItemLabel={'+'$3}",
33+
" lastItemOverlayColor={'Colors.rgba(Colors.blue30)'$4}",
3334
"/>"
3435
]
3536
}

src/components/gridView/index.tsx

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import _ from 'lodash';
22
import React from 'react';
33
import {StyleSheet} from 'react-native';
4-
import {Colors, Spacings} from 'style';
4+
import {Spacings} from 'style';
55
// TODO: we should use asBaseComponent here instead of using UIComponent directly
66
import UIComponent from '../../commons/UIComponent';
77
import View from '../view';
@@ -145,19 +145,8 @@ class GridView extends UIComponent<GridViewProps, GridViewState> {
145145
return (containerWidth - itemSpacing * (numColumns - 1)) / numColumns;
146146
}
147147

148-
getThemeColor(placeColor: string) {
149-
if (_.toLower(placeColor) === _.toLower(Colors.white)) {
150-
return Colors.black;
151-
} else if (Colors.isDark(placeColor)) {
152-
return placeColor;
153-
} else {
154-
return Colors.getColorTint(placeColor, 30);
155-
}
156-
}
157-
158148
renderLastItemOverlay() {
159-
const {lastItemLabel, items} = this.props;
160-
const overlayColor = this.getThemeColor(this.props.lastItemOverlayColor ?? '');
149+
const {lastItemLabel, items, lastItemOverlayColor} = this.props;
161150
const formattedLabel = formatLastItemLabel(lastItemLabel, {shouldAddPlus: true});
162151

163152
if (!lastItemLabel) {
@@ -166,12 +155,7 @@ class GridView extends UIComponent<GridViewProps, GridViewState> {
166155

167156
const imageBorderRadius = _.flow(_.first, item => _.get(item, 'imageProps.borderRadius'))(items);
168157
return (
169-
<View
170-
style={[
171-
styles.overlayContainer,
172-
{backgroundColor: Colors.rgba(overlayColor, 0.6), borderRadius: imageBorderRadius}
173-
]}
174-
>
158+
<View style={[styles.overlayContainer, {backgroundColor: lastItemOverlayColor, borderRadius: imageBorderRadius}]}>
175159
<Text mainBold white>
176160
{formattedLabel}
177161
</Text>

0 commit comments

Comments
 (0)