15

Following this question on fixed footer with a ScrollView, I'm trying to implement a fixed footer on the screen with a FlatList. I have tried to use the answer provided by putting the flat list inside a view, but then none of the items are rendered. Does any one know how to implement a fixed footer with a flat list as the other main element of component?

avriis
  • 1,581
  • 4
  • 17
  • 31

6 Answers6

27

Using this flex solution I managed to do it with a couple of nested Views:

<View style={{flex: 1}}>
  <View style={{flex: 0.9}}>
    <FlatList/>
  </View>
  <View style={{flex: 0.1}}/>
</View>
Tom
  • 1,636
  • 2
  • 13
  • 21
avriis
  • 1,581
  • 4
  • 17
  • 31
6

It is similar to the answer above, but I think this also works.

<View style={{flex: 1}}>
  <View style={{flex: 1}}>
    <FlatList/>
  </View>
  <View />
</View>
박제영
  • 101
  • 1
  • 4
4

FlatList comes with footer support in the form of ListFooterComponent

Try adding something like this to your flatlist

ListFooterComponent={() => <Text>Footer content</Text>}

Hope this helps!

tjkind
  • 161
  • 1
  • 1
  • 7
  • 11
    Thanks for the answer. As far as I understand the docs at https://facebook.github.io/react-native/docs/flatlist.html#listfootercomponent, this is to specify something that is rendered at the bottom of _all_ the items and not at the bottom of the screen... – avriis Mar 14 '18 at 13:32
  • 1
    `ListFooterComponent` only renders once but it doesn't have a *sticky* option. – Michel Floyd Oct 08 '21 at 21:04
3

To complete the solution of Tom and avoid a gap/space at the bottom of the screen.

Use an integer for flex value

<View style={{flex: 1}}>
  <View style={{flex: 1}}>
    <FlatList/>
  </View>
  <View style={{flex: 0}}/>
</View>
Laurent
  • 662
  • 2
  • 10
  • 13
1

This also worked for me to keep the button at the bottom while allowing FlatList to work properly:

<View style={{
  display: 'flex',
}}>
  <View style={{flex: 1}}>
    <FlatList
      data={data}
      renderItem={() => <Item/>}
    />
  </View>
  <View style={{ marginTop: 'auto'}}>
    <Btn/>
  </View>
</View>

marginTop: auto will push the button to the bottom of the screen.

Augusto Franzoia
  • 570
  • 3
  • 13
0

The selected answer does work, but you can also have the flatlist grow and let footer take up the space it needs:

<View style={{flex: 1}}>
  <View style={{flex: 1, flexGrow: 1}}>
    <FlatList/>
  </View>
  <Button>Anything here</Button>
</View>

Snack demo here

Example

Nicolai Lissau
  • 7,298
  • 5
  • 43
  • 57