FlatList Dynamic Height Sizing

aprofromindia picture aprofromindia · Sep 5, 2017 · Viewed 15.1k times · Source

I have an AutoComplete Box which gives me a list of autocomplete items. I display the items in FlatList, I also have a border around the FlatList. My code is given below: -

render(){
return (
  <View>
    <TextInput
       clearButtonMode="while-editing"
       onChangeText={this.onChangeText}
       value={this.state.searchText}
       onSubmitEditing={this.onTextSubmitted}
       placeholder="Find..." />
       {this.state.data.length > 0 &&
        <FlatList
           style={styles.list}
           keyboardShouldPersistTaps="handled"
           data={this.state.data}
           ItemSeparatorComponent={this.renderSeparator}
           keyExtractor={item => item.properties.id}
           renderItem={this.renderItem} />});
}

const styles = StyleSheet.create({
list: {
    borderWidth: 16,
    borderColor: colors.searchBorder,
  },
});

How can I increase/decrease the size of the FlatList with the number of list items, (I think the border is the reason behind this error).

Sample Image

Answer

Julian K picture Julian K · Mar 10, 2018

Add flexGrow: 0 to your list style.