react-native/Libraries/Lists/__tests__/SectionList-test.js

103 lines
3.5 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
jest.disableAutomock();
const React = require('React');
const ReactTestRenderer = require('react-test-renderer');
const SectionList = require('SectionList');
describe('SectionList', () => {
it('renders empty list', () => {
const component = ReactTestRenderer.create(
<SectionList
sections={[]}
Many improvements Summary: These got smashed together with some weird rebase snafu. They are pretty intertwined anyway so the value of separate commits is minimal (e.g. separate commits would not revert cleanly anyway). == [lists] better fill rate logging (previously D4907958) After looking through some production data, I think this will address all the issues we're seeing. Now: - Header/Footer getting no longer counted as blank. - Avoid floating point for Scuba. - Compare actual time of blankness, not just samples. - Include both "any" vs. "mostly" blank (similar to 1 and 4 frame drops). - Include events where there is no blankness so we have a baseline. - Remove events with too few samples **Test Plan: ** A bunch of scrolling in FlatListExample T17384966 == [Lists] Update SectionSeparatorItem docs (previously D4909526) Forgot to update the language here when we modified the behavior with the introduction of separator highlighting support. ** Test Plan: ** nope. == [Lists] Add renderSectionFooter prop to SectionList (previously D4923353) Handy for things like "see more" links and such. The logic here is to render the footer last, *after* the bottom section separator. This is to preserve the highlighting behavior of the section separator by keeping it adjacent to the items. **Test Plan: ** Added to snapshot test and example: {F66635525} {F66635526} == [SectionList] Add a bunch more info for rendering items and separators (previously D4923663) This extra info can be helpful for rending more complex patterns. **Test Plan: ** Made snapshot test more comprehensive and inspected the output. == [Lists] reduce render churn (previously D4924639) I don't think the velocity based leadFactor is helping and might actually be hurting because it causes a lot of churn in the items we render. Instead, this diff introduces fillPreference which biases the window expansion in the direction of scroll, but doesn't actually affect the final bounds of the window at all, so items that are already rendered are more likely to stay rendered. **Test Plan: ** Played around in debug mode and watched the overlay - seems better. Also tests all pass. T16621861 == [Lists] Add initialScrollIndex prop Makes it easy to load a VirtualizedList at a location in the middle of the content without wasting time rendering initial rows that aren't relevant, for example when opening an infinite calendar view to "today". **Test Plan: ** With debug overlay, set `initialScrollIndex={52}` prop in `FlatListExample` and and see it immediately render a full screen of items with item 52 aligned at the top of the screen. Note no initial items are mounted per debug overlay. Scroll around a bunch and everything else seems to work as normal. No SectionList impl since `getItemLayout` isn't easy to use there. T17091314 Reviewed By: bvaughn Differential Revision: D4907958 fbshipit-source-id: 8b9f1f542f9b240f1e317f3fd7e31c9376e8670e
2017-04-25 21:44:00 +00:00
renderItem={({item}) => <item v={item.key} />}
/>
);
expect(component).toMatchSnapshot();
});
it('rendering empty section headers is fine', () => {
const component = ReactTestRenderer.create(
<SectionList
sections={[{key: 's1', data: [{key: 'i1'}, {key: 'i2'}]}]}
Many improvements Summary: These got smashed together with some weird rebase snafu. They are pretty intertwined anyway so the value of separate commits is minimal (e.g. separate commits would not revert cleanly anyway). == [lists] better fill rate logging (previously D4907958) After looking through some production data, I think this will address all the issues we're seeing. Now: - Header/Footer getting no longer counted as blank. - Avoid floating point for Scuba. - Compare actual time of blankness, not just samples. - Include both "any" vs. "mostly" blank (similar to 1 and 4 frame drops). - Include events where there is no blankness so we have a baseline. - Remove events with too few samples **Test Plan: ** A bunch of scrolling in FlatListExample T17384966 == [Lists] Update SectionSeparatorItem docs (previously D4909526) Forgot to update the language here when we modified the behavior with the introduction of separator highlighting support. ** Test Plan: ** nope. == [Lists] Add renderSectionFooter prop to SectionList (previously D4923353) Handy for things like "see more" links and such. The logic here is to render the footer last, *after* the bottom section separator. This is to preserve the highlighting behavior of the section separator by keeping it adjacent to the items. **Test Plan: ** Added to snapshot test and example: {F66635525} {F66635526} == [SectionList] Add a bunch more info for rendering items and separators (previously D4923663) This extra info can be helpful for rending more complex patterns. **Test Plan: ** Made snapshot test more comprehensive and inspected the output. == [Lists] reduce render churn (previously D4924639) I don't think the velocity based leadFactor is helping and might actually be hurting because it causes a lot of churn in the items we render. Instead, this diff introduces fillPreference which biases the window expansion in the direction of scroll, but doesn't actually affect the final bounds of the window at all, so items that are already rendered are more likely to stay rendered. **Test Plan: ** Played around in debug mode and watched the overlay - seems better. Also tests all pass. T16621861 == [Lists] Add initialScrollIndex prop Makes it easy to load a VirtualizedList at a location in the middle of the content without wasting time rendering initial rows that aren't relevant, for example when opening an infinite calendar view to "today". **Test Plan: ** With debug overlay, set `initialScrollIndex={52}` prop in `FlatListExample` and and see it immediately render a full screen of items with item 52 aligned at the top of the screen. Note no initial items are mounted per debug overlay. Scroll around a bunch and everything else seems to work as normal. No SectionList impl since `getItemLayout` isn't easy to use there. T17091314 Reviewed By: bvaughn Differential Revision: D4907958 fbshipit-source-id: 8b9f1f542f9b240f1e317f3fd7e31c9376e8670e
2017-04-25 21:44:00 +00:00
renderItem={({item}) => <item v={item.key} />}
renderSectionHeader={() => null}
/>
);
expect(component).toMatchSnapshot();
});
it('renders all the bells and whistles', () => {
const component = ReactTestRenderer.create(
<SectionList
Render section footer in <SectionList> sections with no data Summary: Fixes https://github.com/facebook/react-native/issues/13784 The section footer was only rendered with the last item of the section. However, that meant in sections where no items were rendered, no section footer would be rendered. This patch makes sure that when there are no items the section footer is rendered with the section header in addition to adding tests asserting the existance of section footers in empty lists. One potential point of contention is whether or not a section separator (as defined by the `SectionSeparatorComponent` prop to `<SectionList>`) should be rendered in an empty list. I did not include a section separator for empty lists, but let me know if you think one should be included. See the test plan below for an image of an empty section rendered without a section separator. I was also running into a lint error, `no-alert`, in `SectionListExample.js` around line 135 that blocked me from publishing. This error looks to be triggered when the `alert()` global function is called, so to fix the error I added an import for the `Alert` module and called the `alert()` function on that module. To help debug the `scrollToLocation()` behavior that was modified as a part of this PR I added three buttons (can be seen in the test plan image) which scroll to arbitrary points in the list. Reviewed By: sahrens Differential Revision: D5084095 fbshipit-source-id: 4c98bebc1c3f1ceaa5a634fa144685d83d1072df
2017-05-25 17:18:48 +00:00
initialNumToRender={Infinity}
Many improvements Summary: These got smashed together with some weird rebase snafu. They are pretty intertwined anyway so the value of separate commits is minimal (e.g. separate commits would not revert cleanly anyway). == [lists] better fill rate logging (previously D4907958) After looking through some production data, I think this will address all the issues we're seeing. Now: - Header/Footer getting no longer counted as blank. - Avoid floating point for Scuba. - Compare actual time of blankness, not just samples. - Include both "any" vs. "mostly" blank (similar to 1 and 4 frame drops). - Include events where there is no blankness so we have a baseline. - Remove events with too few samples **Test Plan: ** A bunch of scrolling in FlatListExample T17384966 == [Lists] Update SectionSeparatorItem docs (previously D4909526) Forgot to update the language here when we modified the behavior with the introduction of separator highlighting support. ** Test Plan: ** nope. == [Lists] Add renderSectionFooter prop to SectionList (previously D4923353) Handy for things like "see more" links and such. The logic here is to render the footer last, *after* the bottom section separator. This is to preserve the highlighting behavior of the section separator by keeping it adjacent to the items. **Test Plan: ** Added to snapshot test and example: {F66635525} {F66635526} == [SectionList] Add a bunch more info for rendering items and separators (previously D4923663) This extra info can be helpful for rending more complex patterns. **Test Plan: ** Made snapshot test more comprehensive and inspected the output. == [Lists] reduce render churn (previously D4924639) I don't think the velocity based leadFactor is helping and might actually be hurting because it causes a lot of churn in the items we render. Instead, this diff introduces fillPreference which biases the window expansion in the direction of scroll, but doesn't actually affect the final bounds of the window at all, so items that are already rendered are more likely to stay rendered. **Test Plan: ** Played around in debug mode and watched the overlay - seems better. Also tests all pass. T16621861 == [Lists] Add initialScrollIndex prop Makes it easy to load a VirtualizedList at a location in the middle of the content without wasting time rendering initial rows that aren't relevant, for example when opening an infinite calendar view to "today". **Test Plan: ** With debug overlay, set `initialScrollIndex={52}` prop in `FlatListExample` and and see it immediately render a full screen of items with item 52 aligned at the top of the screen. Note no initial items are mounted per debug overlay. Scroll around a bunch and everything else seems to work as normal. No SectionList impl since `getItemLayout` isn't easy to use there. T17091314 Reviewed By: bvaughn Differential Revision: D4907958 fbshipit-source-id: 8b9f1f542f9b240f1e317f3fd7e31c9376e8670e
2017-04-25 21:44:00 +00:00
ItemSeparatorComponent={(props) => <defaultItemSeparator v={propStr(props)} />}
Add ListEmptyComponent prop Summary: Hey there :) Please let me know if the name `ListEmptyComponent` should be changed. I also thought about `ListNoItemsComponent`. Or maybe `ListPlaceholderComponent`? - [x] Explain the **motivation** for making this change. - [x] Provide a **test plan** demonstrating that the code is solid. - [x] Match the **code formatting** of the rest of the codebase. - [x] Target the `master` branch, NOT a "stable" branch. In a FlatList, I wanted to show some placeholder when my data is empty (while keeping eventual Header/Footer/RefreshControl). A way around this issue would be to do something like adding a `ListHeaderComponent` that checks if the list is empty, like so: ```js ListHeaderComponent={() => (!data.length ? <Text style={styles.noDataText}>No data found</Text> : null)} ``` But I felt it was not easily readable as soon as you have an actual header. This PR adds a `ListEmptyComponent` that is rendered when the list is empty. I added tests for VirtualizedList, FlatList and SectionList and ran `yarn test -- -u`. I then checked that the snapshots changed like I wanted. I also tested this against one of my project, though I had to manually add my changes because the project is on RN 0.43. Here are the docs screenshots: - [VirtualizedList](https://cloud.githubusercontent.com/assets/82368/25566000/0ebf2b82-2dd2-11e7-8b80-d8c505f1f2d6.png) - [FlatList](https://cloud.githubusercontent.com/assets/82368/25566005/2842ab42-2dd2-11e7-81b4-32c74c2b4fc3.png) - [SectionList](https://cloud.githubusercontent.com/assets/82368/25566010/368aec1e-2dd2-11e7-9425-3bb5e5803513.png) Thanks for your work! Closes https://github.com/facebook/react-native/pull/13718 Differential Revision: D4993711 Pulled By: sahrens fbshipit-source-id: 055b40f709067071e40308bdf5a37cedaa223dc5
2017-05-04 07:08:14 +00:00
ListEmptyComponent={(props) => <empty v={propStr(props)} />}
Many improvements Summary: These got smashed together with some weird rebase snafu. They are pretty intertwined anyway so the value of separate commits is minimal (e.g. separate commits would not revert cleanly anyway). == [lists] better fill rate logging (previously D4907958) After looking through some production data, I think this will address all the issues we're seeing. Now: - Header/Footer getting no longer counted as blank. - Avoid floating point for Scuba. - Compare actual time of blankness, not just samples. - Include both "any" vs. "mostly" blank (similar to 1 and 4 frame drops). - Include events where there is no blankness so we have a baseline. - Remove events with too few samples **Test Plan: ** A bunch of scrolling in FlatListExample T17384966 == [Lists] Update SectionSeparatorItem docs (previously D4909526) Forgot to update the language here when we modified the behavior with the introduction of separator highlighting support. ** Test Plan: ** nope. == [Lists] Add renderSectionFooter prop to SectionList (previously D4923353) Handy for things like "see more" links and such. The logic here is to render the footer last, *after* the bottom section separator. This is to preserve the highlighting behavior of the section separator by keeping it adjacent to the items. **Test Plan: ** Added to snapshot test and example: {F66635525} {F66635526} == [SectionList] Add a bunch more info for rendering items and separators (previously D4923663) This extra info can be helpful for rending more complex patterns. **Test Plan: ** Made snapshot test more comprehensive and inspected the output. == [Lists] reduce render churn (previously D4924639) I don't think the velocity based leadFactor is helping and might actually be hurting because it causes a lot of churn in the items we render. Instead, this diff introduces fillPreference which biases the window expansion in the direction of scroll, but doesn't actually affect the final bounds of the window at all, so items that are already rendered are more likely to stay rendered. **Test Plan: ** Played around in debug mode and watched the overlay - seems better. Also tests all pass. T16621861 == [Lists] Add initialScrollIndex prop Makes it easy to load a VirtualizedList at a location in the middle of the content without wasting time rendering initial rows that aren't relevant, for example when opening an infinite calendar view to "today". **Test Plan: ** With debug overlay, set `initialScrollIndex={52}` prop in `FlatListExample` and and see it immediately render a full screen of items with item 52 aligned at the top of the screen. Note no initial items are mounted per debug overlay. Scroll around a bunch and everything else seems to work as normal. No SectionList impl since `getItemLayout` isn't easy to use there. T17091314 Reviewed By: bvaughn Differential Revision: D4907958 fbshipit-source-id: 8b9f1f542f9b240f1e317f3fd7e31c9376e8670e
2017-04-25 21:44:00 +00:00
ListFooterComponent={(props) => <footer v={propStr(props)} />}
ListHeaderComponent={(props) => <header v={propStr(props)} />}
SectionSeparatorComponent={(props) => <sectionSeparator v={propStr(props)} />}
sections={[
{
Many improvements Summary: These got smashed together with some weird rebase snafu. They are pretty intertwined anyway so the value of separate commits is minimal (e.g. separate commits would not revert cleanly anyway). == [lists] better fill rate logging (previously D4907958) After looking through some production data, I think this will address all the issues we're seeing. Now: - Header/Footer getting no longer counted as blank. - Avoid floating point for Scuba. - Compare actual time of blankness, not just samples. - Include both "any" vs. "mostly" blank (similar to 1 and 4 frame drops). - Include events where there is no blankness so we have a baseline. - Remove events with too few samples **Test Plan: ** A bunch of scrolling in FlatListExample T17384966 == [Lists] Update SectionSeparatorItem docs (previously D4909526) Forgot to update the language here when we modified the behavior with the introduction of separator highlighting support. ** Test Plan: ** nope. == [Lists] Add renderSectionFooter prop to SectionList (previously D4923353) Handy for things like "see more" links and such. The logic here is to render the footer last, *after* the bottom section separator. This is to preserve the highlighting behavior of the section separator by keeping it adjacent to the items. **Test Plan: ** Added to snapshot test and example: {F66635525} {F66635526} == [SectionList] Add a bunch more info for rendering items and separators (previously D4923663) This extra info can be helpful for rending more complex patterns. **Test Plan: ** Made snapshot test more comprehensive and inspected the output. == [Lists] reduce render churn (previously D4924639) I don't think the velocity based leadFactor is helping and might actually be hurting because it causes a lot of churn in the items we render. Instead, this diff introduces fillPreference which biases the window expansion in the direction of scroll, but doesn't actually affect the final bounds of the window at all, so items that are already rendered are more likely to stay rendered. **Test Plan: ** Played around in debug mode and watched the overlay - seems better. Also tests all pass. T16621861 == [Lists] Add initialScrollIndex prop Makes it easy to load a VirtualizedList at a location in the middle of the content without wasting time rendering initial rows that aren't relevant, for example when opening an infinite calendar view to "today". **Test Plan: ** With debug overlay, set `initialScrollIndex={52}` prop in `FlatListExample` and and see it immediately render a full screen of items with item 52 aligned at the top of the screen. Note no initial items are mounted per debug overlay. Scroll around a bunch and everything else seems to work as normal. No SectionList impl since `getItemLayout` isn't easy to use there. T17091314 Reviewed By: bvaughn Differential Revision: D4907958 fbshipit-source-id: 8b9f1f542f9b240f1e317f3fd7e31c9376e8670e
2017-04-25 21:44:00 +00:00
renderItem: (props) => <itemForSection1 v={propStr(props)} />,
key: 's1',
keyExtractor: (item, index) => item.id,
Many improvements Summary: These got smashed together with some weird rebase snafu. They are pretty intertwined anyway so the value of separate commits is minimal (e.g. separate commits would not revert cleanly anyway). == [lists] better fill rate logging (previously D4907958) After looking through some production data, I think this will address all the issues we're seeing. Now: - Header/Footer getting no longer counted as blank. - Avoid floating point for Scuba. - Compare actual time of blankness, not just samples. - Include both "any" vs. "mostly" blank (similar to 1 and 4 frame drops). - Include events where there is no blankness so we have a baseline. - Remove events with too few samples **Test Plan: ** A bunch of scrolling in FlatListExample T17384966 == [Lists] Update SectionSeparatorItem docs (previously D4909526) Forgot to update the language here when we modified the behavior with the introduction of separator highlighting support. ** Test Plan: ** nope. == [Lists] Add renderSectionFooter prop to SectionList (previously D4923353) Handy for things like "see more" links and such. The logic here is to render the footer last, *after* the bottom section separator. This is to preserve the highlighting behavior of the section separator by keeping it adjacent to the items. **Test Plan: ** Added to snapshot test and example: {F66635525} {F66635526} == [SectionList] Add a bunch more info for rendering items and separators (previously D4923663) This extra info can be helpful for rending more complex patterns. **Test Plan: ** Made snapshot test more comprehensive and inspected the output. == [Lists] reduce render churn (previously D4924639) I don't think the velocity based leadFactor is helping and might actually be hurting because it causes a lot of churn in the items we render. Instead, this diff introduces fillPreference which biases the window expansion in the direction of scroll, but doesn't actually affect the final bounds of the window at all, so items that are already rendered are more likely to stay rendered. **Test Plan: ** Played around in debug mode and watched the overlay - seems better. Also tests all pass. T16621861 == [Lists] Add initialScrollIndex prop Makes it easy to load a VirtualizedList at a location in the middle of the content without wasting time rendering initial rows that aren't relevant, for example when opening an infinite calendar view to "today". **Test Plan: ** With debug overlay, set `initialScrollIndex={52}` prop in `FlatListExample` and and see it immediately render a full screen of items with item 52 aligned at the top of the screen. Note no initial items are mounted per debug overlay. Scroll around a bunch and everything else seems to work as normal. No SectionList impl since `getItemLayout` isn't easy to use there. T17091314 Reviewed By: bvaughn Differential Revision: D4907958 fbshipit-source-id: 8b9f1f542f9b240f1e317f3fd7e31c9376e8670e
2017-04-25 21:44:00 +00:00
ItemSeparatorComponent: (props) => <itemSeparatorForSection1 v={propStr(props)} />,
data: [{id: 'i1s1'}, {id: 'i2s1'}],
},
{
Many improvements Summary: These got smashed together with some weird rebase snafu. They are pretty intertwined anyway so the value of separate commits is minimal (e.g. separate commits would not revert cleanly anyway). == [lists] better fill rate logging (previously D4907958) After looking through some production data, I think this will address all the issues we're seeing. Now: - Header/Footer getting no longer counted as blank. - Avoid floating point for Scuba. - Compare actual time of blankness, not just samples. - Include both "any" vs. "mostly" blank (similar to 1 and 4 frame drops). - Include events where there is no blankness so we have a baseline. - Remove events with too few samples **Test Plan: ** A bunch of scrolling in FlatListExample T17384966 == [Lists] Update SectionSeparatorItem docs (previously D4909526) Forgot to update the language here when we modified the behavior with the introduction of separator highlighting support. ** Test Plan: ** nope. == [Lists] Add renderSectionFooter prop to SectionList (previously D4923353) Handy for things like "see more" links and such. The logic here is to render the footer last, *after* the bottom section separator. This is to preserve the highlighting behavior of the section separator by keeping it adjacent to the items. **Test Plan: ** Added to snapshot test and example: {F66635525} {F66635526} == [SectionList] Add a bunch more info for rendering items and separators (previously D4923663) This extra info can be helpful for rending more complex patterns. **Test Plan: ** Made snapshot test more comprehensive and inspected the output. == [Lists] reduce render churn (previously D4924639) I don't think the velocity based leadFactor is helping and might actually be hurting because it causes a lot of churn in the items we render. Instead, this diff introduces fillPreference which biases the window expansion in the direction of scroll, but doesn't actually affect the final bounds of the window at all, so items that are already rendered are more likely to stay rendered. **Test Plan: ** Played around in debug mode and watched the overlay - seems better. Also tests all pass. T16621861 == [Lists] Add initialScrollIndex prop Makes it easy to load a VirtualizedList at a location in the middle of the content without wasting time rendering initial rows that aren't relevant, for example when opening an infinite calendar view to "today". **Test Plan: ** With debug overlay, set `initialScrollIndex={52}` prop in `FlatListExample` and and see it immediately render a full screen of items with item 52 aligned at the top of the screen. Note no initial items are mounted per debug overlay. Scroll around a bunch and everything else seems to work as normal. No SectionList impl since `getItemLayout` isn't easy to use there. T17091314 Reviewed By: bvaughn Differential Revision: D4907958 fbshipit-source-id: 8b9f1f542f9b240f1e317f3fd7e31c9376e8670e
2017-04-25 21:44:00 +00:00
key: 's2',
data: [{key: 'i1s2'}, {key: 'i2s2'}],
},
Many improvements Summary: These got smashed together with some weird rebase snafu. They are pretty intertwined anyway so the value of separate commits is minimal (e.g. separate commits would not revert cleanly anyway). == [lists] better fill rate logging (previously D4907958) After looking through some production data, I think this will address all the issues we're seeing. Now: - Header/Footer getting no longer counted as blank. - Avoid floating point for Scuba. - Compare actual time of blankness, not just samples. - Include both "any" vs. "mostly" blank (similar to 1 and 4 frame drops). - Include events where there is no blankness so we have a baseline. - Remove events with too few samples **Test Plan: ** A bunch of scrolling in FlatListExample T17384966 == [Lists] Update SectionSeparatorItem docs (previously D4909526) Forgot to update the language here when we modified the behavior with the introduction of separator highlighting support. ** Test Plan: ** nope. == [Lists] Add renderSectionFooter prop to SectionList (previously D4923353) Handy for things like "see more" links and such. The logic here is to render the footer last, *after* the bottom section separator. This is to preserve the highlighting behavior of the section separator by keeping it adjacent to the items. **Test Plan: ** Added to snapshot test and example: {F66635525} {F66635526} == [SectionList] Add a bunch more info for rendering items and separators (previously D4923663) This extra info can be helpful for rending more complex patterns. **Test Plan: ** Made snapshot test more comprehensive and inspected the output. == [Lists] reduce render churn (previously D4924639) I don't think the velocity based leadFactor is helping and might actually be hurting because it causes a lot of churn in the items we render. Instead, this diff introduces fillPreference which biases the window expansion in the direction of scroll, but doesn't actually affect the final bounds of the window at all, so items that are already rendered are more likely to stay rendered. **Test Plan: ** Played around in debug mode and watched the overlay - seems better. Also tests all pass. T16621861 == [Lists] Add initialScrollIndex prop Makes it easy to load a VirtualizedList at a location in the middle of the content without wasting time rendering initial rows that aren't relevant, for example when opening an infinite calendar view to "today". **Test Plan: ** With debug overlay, set `initialScrollIndex={52}` prop in `FlatListExample` and and see it immediately render a full screen of items with item 52 aligned at the top of the screen. Note no initial items are mounted per debug overlay. Scroll around a bunch and everything else seems to work as normal. No SectionList impl since `getItemLayout` isn't easy to use there. T17091314 Reviewed By: bvaughn Differential Revision: D4907958 fbshipit-source-id: 8b9f1f542f9b240f1e317f3fd7e31c9376e8670e
2017-04-25 21:44:00 +00:00
{
key: 's3',
data: [{key: 'i1s3'}, {key: 'i2s3'}],
},
]}
refreshing={false}
onRefresh={jest.fn()}
Many improvements Summary: These got smashed together with some weird rebase snafu. They are pretty intertwined anyway so the value of separate commits is minimal (e.g. separate commits would not revert cleanly anyway). == [lists] better fill rate logging (previously D4907958) After looking through some production data, I think this will address all the issues we're seeing. Now: - Header/Footer getting no longer counted as blank. - Avoid floating point for Scuba. - Compare actual time of blankness, not just samples. - Include both "any" vs. "mostly" blank (similar to 1 and 4 frame drops). - Include events where there is no blankness so we have a baseline. - Remove events with too few samples **Test Plan: ** A bunch of scrolling in FlatListExample T17384966 == [Lists] Update SectionSeparatorItem docs (previously D4909526) Forgot to update the language here when we modified the behavior with the introduction of separator highlighting support. ** Test Plan: ** nope. == [Lists] Add renderSectionFooter prop to SectionList (previously D4923353) Handy for things like "see more" links and such. The logic here is to render the footer last, *after* the bottom section separator. This is to preserve the highlighting behavior of the section separator by keeping it adjacent to the items. **Test Plan: ** Added to snapshot test and example: {F66635525} {F66635526} == [SectionList] Add a bunch more info for rendering items and separators (previously D4923663) This extra info can be helpful for rending more complex patterns. **Test Plan: ** Made snapshot test more comprehensive and inspected the output. == [Lists] reduce render churn (previously D4924639) I don't think the velocity based leadFactor is helping and might actually be hurting because it causes a lot of churn in the items we render. Instead, this diff introduces fillPreference which biases the window expansion in the direction of scroll, but doesn't actually affect the final bounds of the window at all, so items that are already rendered are more likely to stay rendered. **Test Plan: ** Played around in debug mode and watched the overlay - seems better. Also tests all pass. T16621861 == [Lists] Add initialScrollIndex prop Makes it easy to load a VirtualizedList at a location in the middle of the content without wasting time rendering initial rows that aren't relevant, for example when opening an infinite calendar view to "today". **Test Plan: ** With debug overlay, set `initialScrollIndex={52}` prop in `FlatListExample` and and see it immediately render a full screen of items with item 52 aligned at the top of the screen. Note no initial items are mounted per debug overlay. Scroll around a bunch and everything else seems to work as normal. No SectionList impl since `getItemLayout` isn't easy to use there. T17091314 Reviewed By: bvaughn Differential Revision: D4907958 fbshipit-source-id: 8b9f1f542f9b240f1e317f3fd7e31c9376e8670e
2017-04-25 21:44:00 +00:00
renderItem={(props) => <defaultItem v={propStr(props)} />}
renderSectionHeader={(props) => <sectionHeader v={propStr(props)} />}
renderSectionFooter={(props) => <sectionFooter v={propStr(props)} />}
/>
);
expect(component).toMatchSnapshot();
});
Render section footer in <SectionList> sections with no data Summary: Fixes https://github.com/facebook/react-native/issues/13784 The section footer was only rendered with the last item of the section. However, that meant in sections where no items were rendered, no section footer would be rendered. This patch makes sure that when there are no items the section footer is rendered with the section header in addition to adding tests asserting the existance of section footers in empty lists. One potential point of contention is whether or not a section separator (as defined by the `SectionSeparatorComponent` prop to `<SectionList>`) should be rendered in an empty list. I did not include a section separator for empty lists, but let me know if you think one should be included. See the test plan below for an image of an empty section rendered without a section separator. I was also running into a lint error, `no-alert`, in `SectionListExample.js` around line 135 that blocked me from publishing. This error looks to be triggered when the `alert()` global function is called, so to fix the error I added an import for the `Alert` module and called the `alert()` function on that module. To help debug the `scrollToLocation()` behavior that was modified as a part of this PR I added three buttons (can be seen in the test plan image) which scroll to arbitrary points in the list. Reviewed By: sahrens Differential Revision: D5084095 fbshipit-source-id: 4c98bebc1c3f1ceaa5a634fa144685d83d1072df
2017-05-25 17:18:48 +00:00
it('renders a footer when there is no data', () => {
const component = ReactTestRenderer.create(
<SectionList
sections={[{key: 's1', data: []}]}
renderItem={({item}) => <item v={item.key} />}
renderSectionHeader={(props) => <sectionHeader v={propStr(props)} />}
renderSectionFooter={(props) => <sectionFooter v={propStr(props)} />}
/>
);
expect(component).toMatchSnapshot();
});
it('renders a footer when there is no data and no header', () => {
const component = ReactTestRenderer.create(
<SectionList
sections={[{key: 's1', data: []}]}
renderItem={({item}) => <item v={item.key} />}
renderSectionFooter={(props) => <sectionFooter v={propStr(props)} />}
/>
);
expect(component).toMatchSnapshot();
});
});
Many improvements Summary: These got smashed together with some weird rebase snafu. They are pretty intertwined anyway so the value of separate commits is minimal (e.g. separate commits would not revert cleanly anyway). == [lists] better fill rate logging (previously D4907958) After looking through some production data, I think this will address all the issues we're seeing. Now: - Header/Footer getting no longer counted as blank. - Avoid floating point for Scuba. - Compare actual time of blankness, not just samples. - Include both "any" vs. "mostly" blank (similar to 1 and 4 frame drops). - Include events where there is no blankness so we have a baseline. - Remove events with too few samples **Test Plan: ** A bunch of scrolling in FlatListExample T17384966 == [Lists] Update SectionSeparatorItem docs (previously D4909526) Forgot to update the language here when we modified the behavior with the introduction of separator highlighting support. ** Test Plan: ** nope. == [Lists] Add renderSectionFooter prop to SectionList (previously D4923353) Handy for things like "see more" links and such. The logic here is to render the footer last, *after* the bottom section separator. This is to preserve the highlighting behavior of the section separator by keeping it adjacent to the items. **Test Plan: ** Added to snapshot test and example: {F66635525} {F66635526} == [SectionList] Add a bunch more info for rendering items and separators (previously D4923663) This extra info can be helpful for rending more complex patterns. **Test Plan: ** Made snapshot test more comprehensive and inspected the output. == [Lists] reduce render churn (previously D4924639) I don't think the velocity based leadFactor is helping and might actually be hurting because it causes a lot of churn in the items we render. Instead, this diff introduces fillPreference which biases the window expansion in the direction of scroll, but doesn't actually affect the final bounds of the window at all, so items that are already rendered are more likely to stay rendered. **Test Plan: ** Played around in debug mode and watched the overlay - seems better. Also tests all pass. T16621861 == [Lists] Add initialScrollIndex prop Makes it easy to load a VirtualizedList at a location in the middle of the content without wasting time rendering initial rows that aren't relevant, for example when opening an infinite calendar view to "today". **Test Plan: ** With debug overlay, set `initialScrollIndex={52}` prop in `FlatListExample` and and see it immediately render a full screen of items with item 52 aligned at the top of the screen. Note no initial items are mounted per debug overlay. Scroll around a bunch and everything else seems to work as normal. No SectionList impl since `getItemLayout` isn't easy to use there. T17091314 Reviewed By: bvaughn Differential Revision: D4907958 fbshipit-source-id: 8b9f1f542f9b240f1e317f3fd7e31c9376e8670e
2017-04-25 21:44:00 +00:00
function propStr(props) {
return Object.keys(props).map(k => {
const propObj = props[k] || {};
return `${k}:${propObj.key || propObj.id || props[k]}`;
}).join(',');
}