Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flexDirection: 'row' is not working in FlatList

I'm trying to get below output but flexDirection: 'row' is not working properly. Please can anyone explain me how to get below output. Any help is appreciated.

**Required output: ** enter image description here

My output: enter image description here

My code is:

_renderItem(rowData) {
    return(
       <View style={{flex: 1, flexDirection: 'row', flexWrap: 'wrap'}}>
           <View style={{margin: 2, width: '24%', backgroundColor: '#fff', borderWidth: 1, borderColor: '#aaa'}}>
                <TouchableOpacity activeOpacity={0.9} style={{height: 190}}>
                    <Image source={{uri: rowData.item.images[0].src}} style={{height: '100%', width: '100%'}}/>
                </TouchableOpacity>
                <View style={{padding: 5}}>
                    <TouchableOpacity activeOpacity={0.9} style={{flexDirection: 'row', justifyContent: 'space-between'}}>
                        <View>
                            <CapitalizedText style={{color: '#666', fontSize: 14}}>{rowData.item.title}</CapitalizedText>
                            <Text style={{fontSize: 15, color: '#666', justifyContent: 'center', alignItems: 'center'}}>{'₹' + rowData.item.variants[0].price}</Text>
                        </View>
                        <Icon size={24} color="#aaa" name="turned-in-not" />
                    </TouchableOpacity>
                    <CapitalizedText style={{fontSize: 14, color: '#bbb'}}>Printed Top</CapitalizedText>
                </View>
            </View>
         </View>
    );
}
render() {
   return(
       <View>
          {
             this.state.product_detail.length <= 0 ?
                <ActivityIndicator color = '#bc2b78' size = "large" style={{alignItems: 'center', justifyContent: 'center'}} />
          :
                <FlatList
                    keyExtractor = {( item, index ) => index }
                    data = { this.state.product_detail }
                    renderItem = {(rowData) => this._renderItem(rowData)}
                    ListFooterComponent = { this._render_Footer }
                />
          }
        </View>
);}

Thank you.

like image 589
Riddhi Avatar asked May 05 '18 07:05

Riddhi


2 Answers

Please see this one if is work for you https://snack.expo.io/SywBhpMgW

like image 107
Priya Avatar answered Oct 03 '22 07:10

Priya


Use numColumns property in flatList to align text items of flatList in a row like

let numColumns=5;
<FlatList numColumns={numColumns}/>
like image 37
Ambesh Tiwari Avatar answered Oct 03 '22 06:10

Ambesh Tiwari