-
Notifications
You must be signed in to change notification settings - Fork 430
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
Bugfix ensure reference to getStableId is updated #348
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,11 +152,14 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends | |
|
||
constructor(props: P, context?: any) { | ||
super(props, context); | ||
this._virtualRenderer = new VirtualRenderer(this._renderStackWhenReady, (offset) => { | ||
this._pendingScrollToOffset = offset; | ||
}, (index) => { | ||
return this.props.dataProvider.getStableId(index); | ||
}, !props.disableRecycling); | ||
this._virtualRenderer = new VirtualRenderer( | ||
this._renderStackWhenReady, | ||
(offset) => { | ||
this._pendingScrollToOffset = offset; | ||
}, | ||
this.props.dataProvider.getStableId, | ||
!props.disableRecycling, | ||
); | ||
|
||
this.state = { | ||
renderStack: {}, | ||
|
@@ -367,9 +370,19 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends | |
this._params.itemCount = newProps.dataProvider.getSize(); | ||
this._virtualRenderer.setParamsAndDimensions(this._params, this._layout); | ||
this._virtualRenderer.setLayoutProvider(newProps.layoutProvider); | ||
if (newProps.dataProvider.hasStableIds() && this.props.dataProvider !== newProps.dataProvider && newProps.dataProvider.requiresDataChangeHandling()) { | ||
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. I created a small snippet to verify that this change is necessary. On this line 370, new DataProvider((a, b) => a !== b)
.cloneWithRows([1, 2])
.cloneWithRows([1, 2, 3])
.requiresDataChangeHandling() // returns false or new DataProvider((a, b) => a !== b)
.cloneWithRows([])
.cloneWithRows([1, 2, 3])
.requiresDataChangeHandling() // returns false (where result of first clone is the initial data provider and second is the next data provider) In both instances, This potentially means another patch is required inside I could have misunderstood the purpose of 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.
|
||
|
||
const hasStableIds = newProps.dataProvider.hasStableIds(); | ||
const isNewDataProvider = this.props.dataProvider !== newProps.dataProvider; | ||
const requiresDataChangeHandling = newProps.dataProvider.requiresDataChangeHandling(); | ||
if (hasStableIds && isNewDataProvider && requiresDataChangeHandling) { | ||
this._virtualRenderer.handleDataSetChange(newProps.dataProvider, this.props.optimizeForInsertDeleteAnimations); | ||
} | ||
|
||
if (hasStableIds && isNewDataProvider) { | ||
// Future calls to get stable IDs must use the function provided by the new data provider. | ||
this._virtualRenderer.setStableIdProvider(newProps.dataProvider.getStableId); | ||
} | ||
|
||
if (forceFullRender || this.props.layoutProvider !== newProps.layoutProvider || this.props.isHorizontal !== newProps.isHorizontal) { | ||
//TODO:Talha use old layout manager | ||
this._virtualRenderer.setLayoutManager(newProps.layoutProvider.newLayoutManager(this._layout, newProps.isHorizontal)); | ||
|
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.
This doesn't seem to do what you expect. This inline function seems to be permanently bound to the first dataProvider.
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 another way to look at this is stableId inside virtualRenderer is updated regardless if the inline method permanently bound it or not, therefore the inline method has no effect. I agree this change is 👍
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 the problem here is the fact that look up will happen in old dataProvider till react lifecycle is completed. Only post that this.props will point to the new one.