Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native FlatList last item visibility issue

I am fetching products list and then displaying using a FlatList, my list contains 5 items and as you can see FlatList row height is variable because of varying description text. So the issue is my last item card is not completely visible maybe this is some kind of flat list issue or layout issue. Any help would be highly appreciated

 renderProducts() {         if (this.props.loading === true) {             return (                 <View style={Styles.spinnerStyle}>                     <ActivityIndicator size='large' />                 </View>             );         }          return (                 <FlatList                     data={this.props.myProducts}                     keyExtractor={(item) => item.id}                     renderItem={({ item }) => (                         <Card                              title={item.title}                              image={{                                  uri: item.image !== null ? item.image.src :'../resImage.jpg'                              }}                         >                             <Text style={{ marginBottom: 10 }}>                                 {item.body_html}                             </Text>                             <Button                                 icon={{ name: 'code' }}                                 backgroundColor='#03A9F4'                                 fontFamily='Lato'                                 buttonStyle={{ borderRadius: 0, marginLeft: 0, marginRight: 0, marginBottom: 0 }}                                 title='VIEW NOW'                              />                       </Card>                       )}                 />         );     }          render() {         return (             <View>                 <View style={Styles.viewStyle}>                     <Text style    {Styles.textStyle}>ProductsList</Text>                 </View>                     {                          this.renderProducts()                      }             </View>         );     } 
like image 216
Muhammad Talha Avatar asked Sep 13 '17 11:09

Muhammad Talha


People also ask

How can I see the last item in FlatList?

You can use FlatList's ListFooterComponent prop to render some JSX or a component at the end of the list. If you need to know that you are at the end of the list within renderItem , you can check the index in the metadata provided to renderItem against the length of data . Thanks for the detailed answer.

What is keyExtractor in FlatList?

keyExtractor ​ (item: object, index: number) => string; Used to extract a unique key for a given item at the specified index. Key is used for caching and as the react key to track item re-ordering. The default extractor checks item. key , then item.id , and then falls back to using the index, like React does.

How do you refresh a FlatList in React Native?

To implement pull to refresh FlatList with React Native, we can set the refreshing and onRefresh props. to set the refreshing prop to isFetching , which is true when we're getting data for the FlatList . And we set onRefresh to the onRefresh which sets refreshing to true and then set it back to false after 2 seconds.

What is onEndReachedThreshold?

In 2020, onEndReachedThreshold represents the number of screen lengths you should be from the bottom before it fires the event. I use onEndReachedThreshold={2} to fire onEndReached when I'm two full screen lengths away. Follow this answer to receive notifications.


2 Answers

Set bottom padding to the <FlatList> content container:

<FlatList     contentContainerStyle={{ paddingBottom: 20 }} /> 
like image 136
krish Avatar answered Sep 19 '22 00:09

krish


Add {flex: 1} to the View tag housing the Flatlist component.

In my case,

const App = () => {   return (     <Provider store={createStore(reducers)}>     <View style={{ flex: 1 }}>       <Header headerText={'My App'} />       <ScreenTabs /> // this is my content with FlatList      </View>     </Provider>   ); };  export default App; 
like image 40
Ashish Avatar answered Sep 20 '22 00:09

Ashish