react-native: FlatList paddingBottom not working
Is this a bug report?
yes
Have you read the Contributing Guidelines?
yes
Environment
-
react-native -v
: react-native-cli: 2.0.1 react-native: 0.45.1 -
node -v
: v7.10.1 -
npm -v
: 4.2.0 -
yarn --version
: 0.27.5
Then, specify:
-
Target Platform: Android
-
Development Operating System: Ubuntu 16.04Lts
-
Build tools: Expo
Steps to Reproduce
- Create a FlatList component with items
- Add style with
paddingBottom
to FlatList - No padding after that
Expected Behavior
FlatList has empty space after last rendered item
Actual Behavior
FlatList has no space after last item
(Write what happened. Add screenshots!)
List in screenshot is scrolled to bottom
Simple issue, i think it not needs any other information
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 25 (3 by maintainers)
I added
contentContainerStyle={{paddingBottom:xxx}}
prop for extending the contentview. haven’t testet on Flatlist but works on SectionListFor the last item to be visible in FlatList I added this contentInset prop with a bottom value instead for paddingBottom. It worked like a charm.
<FlatList contentInset= {{bottom: 60}} />
It’s a prioritization matter due to the number of open issues. Happy to re-open if someone commits to opening a PR.
I solved this by using
contentInset
fromscrollView
;As I have an inverted list that scrolls to the bottom by default (chat), adding 16 pixels to the bottom weirdly applies it to the top, which is what I wanted as all my items have
marginBottom
applied.I’m having trouble with this issue, after the research I found out that:
ScrollView
component.ListView
,FlatList
,Sections
andVirtualizedList
extendScrollView
they share the same issue.renderFooter
or puttingpaddingBottom
insidecontentContainerStyle
prop. Which gives a similar result likepaddingBottom
fromScrollView
style but actually not the same.Flatlist with card effect:
As you can see, the content container touch the Flatlist container without any spacing. Notice that the scroll indicator show that it hasn’t reached the bottom.
I have a theory about the cause of this bug. The actual scrollable area was determined using
contentContainer
offset + height, ignore any space between the content container and the container outside.Use this <Flatlist ListFooterComponent={ <View style={{ margin: 50 }} /> } />
@hramos What’s the point of closing an issue if it hasn’t been fixed? I don’t see the goal of sweeping bugs under the carpet, other than to frustrate the developers using your product. It just doesn’t make sense from a bug tracking perspective.
Works fine in FlatList too. Thanks a lot!
@hramos the workaround you linked will not work properly for some cases. Eg.
https://snack.expo.io/@riwu/flatlist-bottom-margin
The bottom button will not have the shadow styling on Android:
Wrapping
Button
with aView
and adding margin to theView
will be the correct workaround in this case.I’m personally not affected too much by this bug since I’m aware of it and the workaround, but i feel sorry for the other thousands of developers who would have to waste their time figuring this out because a dev from RN decided that a workaround is a good enough solution to a bug.
Perhaps none of us here knows a good way to fix this bug, but shouldn’t the issue be left opened so that another more enlightened dev might be able to come up with a proper fix?
Then you guy close it again without actually fix the root cause (メ゚皿゚)
Hi there, I am using react native
0.50.4
I have somewhat a similar problem , I have been stuck for couple of days nowThe
<SearchBox />
pushes theFlatListComp
down out the view screen. I can see the scrollbar indicator going down beyond the screen view, so some list items are hidden (the last 2 or 3 items in the list cannot be seen)Try
1 => Add View in FlatList
2 => Define style height for View 3 => Get screen height on Dimensions function from React Native 4 => Adjust height in StyleSheet `
`
For me it works with
{ flexGrow: 1, paddingBottom: 20}
with 0.49.5Hey guys,
Ran into the same problem today and just thought id post a work around for other who encounter it.
For some reason applying top or bottom padding to the flatList component creates this issue where it pushes the inner content down out of view for the amount you specified.
So the easiest way to tackle this is to apply either no padding at all, or only side padding. Use bottom padding/ margin on your inner list items items instead. And then pass an index through to your inner items so you can apply some top margin/padding to your first item.
ie:
renderItem={({ item, index }) => <ListItem Index={index} event={item} />}
This problem of last 2 3 items not visible is maybe due to irregular size of Flatlist, wrap the Flatlist using a view and provide it a flex count to fix its size and now working like charm!
for ex:
<View> <View style={{flex : 3}}> {some other view }} </View> <View style={{flex : 7}}> <Flatlist ... /> </View> // wrapped inside a view </View>
@pqkluan do you have a PR with a fix you’d like us to look at?