-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VirtualizedList CellRenderer optimization #21163
Closed
christianbach
wants to merge
10
commits into
facebook:master
from
christianbach:virtuallist-optimize-cellrenderer
Closed
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0518416
Change CellRenderer to PureComponent, move parentProps to ordinary pr…
christianbach fcf3c45
Make eslint happy
christianbach 3ca1f26
Fix issue with SectionList and stickySectionHeadersEnabled. Swaping o…
christianbach 8ed1dac
Change _onLayout to onLayout based on code review
christianbach 90713d9
Fix re-rendering with extraData, add test
christianbach ef347ea
Minor code cleanup
christianbach e8ca49f
Merge branch 'master' into virtuallist-optimize-cellrenderer
christianbach 4c7d7e8
Merge branch 'master' into virtuallist-optimize-cellrenderer
christianbach bf50ba5
Merge branch 'master' into virtuallist-optimize-cellrenderer
christianbach 14d41f2
Fix flow error tests (#1)
azizhk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,4 +218,59 @@ describe('VirtualizedList', () => { | |
}), | ||
); | ||
}); | ||
|
||
it('calls _onCellLayout properly', () => { | ||
const items = [{key: 'i1'}, {key: 'i2'}, {key: 'i3'}]; | ||
const mock = jest.fn(); | ||
const component = ReactTestRenderer.create( | ||
<VirtualizedList | ||
data={items} | ||
renderItem={({item}) => <item value={item.key} />} | ||
getItem={(data, index) => data[index]} | ||
getItemCount={data => data.length} | ||
/>, | ||
); | ||
const virtualList: VirtualizedList = component.getInstance(); | ||
virtualList._onCellLayout = mock; | ||
component.update( | ||
<VirtualizedList | ||
data={[...items, {key: 'i4'}]} | ||
renderItem={({item}) => <item value={item.key} />} | ||
getItem={(data, index) => data[index]} | ||
getItemCount={data => data.length} | ||
/>, | ||
); | ||
const cell = virtualList._cellRefs.i4; | ||
const event = { | ||
nativeEvent: {layout: {x: 0, y: 0, width: 50, height: 50}}, | ||
}; | ||
cell._onLayout(event); | ||
expect(mock).toHaveBeenCalledWith(event, 'i4', 3); | ||
}); | ||
|
||
it('handles extraData correctly', () => { | ||
const mock = jest.fn(); | ||
const data = [{key: 'i0'}, {key: 'i1'}, {key: 'i2'}]; | ||
const getItem = (data, index) => data[index]; | ||
const getItemCount = data => data.length; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no-shadow: 'data' is already declared in the upper scope. |
||
const component = ReactTestRenderer.create( | ||
<VirtualizedList | ||
data={data} | ||
renderItem={mock} | ||
getItem={getItem} | ||
getItemCount={getItemCount} | ||
/>, | ||
); | ||
|
||
component.update( | ||
<VirtualizedList | ||
data={data} | ||
renderItem={mock} | ||
getItem={getItem} | ||
getItemCount={getItemCount} | ||
extraData={{updated: false}} | ||
/>, | ||
); | ||
expect(mock).toHaveBeenCalledTimes(6); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
no-shadow: 'data' is already declared in the upper scope.