-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding new styling props to FlatList/VirtualizedList for ListHeaderCo…
…mponent and ListFooterComponent Summary: We ran into a problem trying to style the optional prop `ListHeaderComponent` in the `FlatList` library component. Essentially we wanted to make `ListHeaderComponent` a flex item that filled all of the empty space in the list if there was any. Unfortunately the `ListHeaderComponent` is later wrapped in a `View` that blocked our styling. The `View` component was necessary as it added styling to handle inverting the `FlatList`. Similarly `ListFooterComponent` was handled the same way. We came up the simple solution of adding two new optional props, `ListHeaderComponentStyle` and `ListFooterComponentStyle`, that are of type `ViewStyleProp` that allow users to pass in styling for `ListHeaderComponent` and `ListFooterComponent`. With this change we were able to do something like the following to get the header component to fill all empty space in the `FlatList`. ``` <FlatList ... contentContainerStyle={{flexGrow: 1}} ListHeaderComponent={<View style={{flex: 1}} />} ListHeaderComponentStyle={{flexGrow: 1}} ... /> ``` This solution will give users a lot more freedom when working with headers and footers. Reviewed By: sahrens Differential Revision: D8777038 fbshipit-source-id: f34116ce68548ea70223e639d0f84a099327f6b3
- Loading branch information
1 parent
8ee60e9
commit a2675ce
Showing
5 changed files
with
30 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a2675ce
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think better names for this prop would be
ListHeaderComponentContainerStyle
andListFooterComponentContainerStyle
(notice the addedContainer
). Because we're stylling the contaienr view, and not the actual component. We should probably also document this in the docs, as we document theScrollView
container, as that has major repercussions on styling/layout.a2675ce
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my react native version is 0.54.0,but i want use this api,how can i do it?
i add these code in my project, but is not work in ios,android is fine,plz help