import _ from 'lodash';
import {View, Text, Image, Colors, Constants, Avatar, GridView, Card, GridViewProps} from 'react-native-ui-lib';
import React, {Component} from 'react';
import {Alert, ScrollView} from 'react-native';
import conversations from '../../data/conversations';
import products from '../../data/products';
class GridViewScreen extends Component {
state = {
contacts: _.flow(conversations => _.take(conversations, 15),
(contacts: any[]) =>
_.map(contacts, contact => ({
imageProps: {source: {uri: contact.thumbnail}, borderRadius: 999, style: {backgroundColor: Colors.grey60}},
title: _.split(contact.name, ' ')[0],
titleLines: 1,
onPress: () => Alert.alert('My name is ' + contact.name)
})))(conversations),
products: _.flow(products => _.take(products, 8),
(products: any[]) =>
_.map(products, (product, index) => ({
imageProps: {
source: {uri: product.mediaUrl},
borderRadius: 4,
style: {backgroundColor: Colors.grey60, borderWidth: 1, borderColor: Colors.grey50}
},
title: product.name,
titleTypography: 'subtextBold',
onPress: () => Alert.alert('My price is ' + product.formattedPrice),
renderOverlay: () => {
if (index < 7) {
return ;
}
}
})))(products) as GridViewProps['items'],
pairs: _.flow(products => _.take(products, 2),
(products: any[]) =>
_.map(products, product => ({
containerProps: {useNative: true, activeScale: 0.97, activeOpacity: 1},
renderCustomItem: () => {
return (
);
},
title: product.name,
subtitle: (
{product.formattedPrice}
$50
),
description: product.inventory.status,
descriptionLines: 2,
alignToStart: true,
onPress: () => Alert.alert('My price was ' + product.formattedPrice + ', now it is $50')
})))(products) as GridViewProps['items'],
dynamicLayout: _.flow(products => _.take(products, 3),
(products: any[]) =>
_.map(products, product => ({
imageProps: {
source: {
uri: product.mediaUrl
}
},
itemSize: {height: 90},
title: 'Title',
subtitle: 'subtitle',
description: product.name,
descriptionLines: 2,
alignToStart: true,
onPress: () => Alert.alert('Click!')
})))(products),
overlayText: _.flow(products => _.take(products, 2),
(products: any[]) =>
_.map(products, (product, index) => ({
imageProps: {
source: {
uri: product.mediaUrl
},
overlayType: Image.overlayTypes.VERTICAL,
overlayColor: Colors.white
},
itemSize: {height: 240},
overlayText: true,
title: product.name,
subtitle: (
{product.formattedPrice}
{product.formattedPrice}
),
description: '4 items',
descriptionLines: 2,
alignToStart: true,
onPress: () => Alert.alert('My price was ' + product.formattedPrice + ', now it is $50'),
renderOverlay: () => {
if (index === 0) {
return (
{product.formattedPrice}
);
}
}
})))(products) as GridViewProps['items'],
avatars: _.flow(products => _.take(products, 9),
(products: any[]) =>
_.map(products, item => ({
renderCustomItem: () => {
const imageElementElement = item.thumbnail;
return (
);
},
onPress: () => Alert.alert('Your choose is ' + item.name),
title: item.name,
titleLines: 2,
titleTypography: 'bodySmall'
})))(products),
squares: [Colors.red30, Colors.yellow30, Colors.blue30, Colors.violet30, Colors.green30].map(color => ({
renderCustomItem: () =>
})),
orientation: Constants.orientation
};
onLayout = () => {
if (this.state.orientation !== Constants.orientation) {
// Basically just for triggering render - can be any other variable
// (Constants.orientation is already up-to-date and can be used directly)
this.setState({
orientation: Constants.orientation
});
}
};
render() {
const {contacts, dynamicLayout, overlayText, avatars, products, pairs, squares} = this.state;
return (
GridView
Avatars
Thumbnails
Pairs
Dynamic itemSize
(Using maxItemWidth)
OverlayText
Custom content (Avatars)
Custom content (Squares)
);
}
}
export default GridViewScreen;