Skip to content

Commit

Permalink
Wrap measureLayoutRelativeToContainingList in try-catch to mitigate c…
Browse files Browse the repository at this point in the history
…rash

Summary: This function sometimes causes an "Unable to find node on an unmounted component" crash during pagination for reasons that still need to be investigated; in the meanwhile, wrap this in a try-catch block to mitigate the crash.

Reviewed By: sahrens

Differential Revision: D12829971

fbshipit-source-id: bc9fe5b9b8c03430ff890bfbb27c39aa270c9eb7
  • Loading branch information
Wen-Chien Chen authored and facebook-github-bot committed Oct 31, 2018
1 parent 811a99c commit 5803772
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions Libraries/Lists/VirtualizedList.js
Expand Up @@ -1112,28 +1112,40 @@ class VirtualizedList extends React.PureComponent<Props, State> {
}; };


measureLayoutRelativeToContainingList(): void { measureLayoutRelativeToContainingList(): void {
UIManager.measureLayout( // TODO (T35574538): findNodeHandle sometimes crashes with "Unable to find
ReactNative.findNodeHandle(this), // node on an unmounted component" during scrolling
ReactNative.findNodeHandle( try {
this.context.virtualizedList.getOutermostParentListRef(), UIManager.measureLayout(
), ReactNative.findNodeHandle(this),
error => { ReactNative.findNodeHandle(
console.warn( this.context.virtualizedList.getOutermostParentListRef(),
"VirtualizedList: Encountered an error while measuring a list's" + ),
' offset from its containing VirtualizedList.', error => {
); console.warn(
}, "VirtualizedList: Encountered an error while measuring a list's" +
(x, y, width, height) => { ' offset from its containing VirtualizedList.',
this._offsetFromParentVirtualizedList = this._selectOffset({x, y}); );
this._scrollMetrics.contentLength = this._selectLength({width, height}); },

(x, y, width, height) => {
const scrollMetrics = this._convertParentScrollMetrics( this._offsetFromParentVirtualizedList = this._selectOffset({x, y});
this.context.virtualizedList.getScrollMetrics(), this._scrollMetrics.contentLength = this._selectLength({
); width,
this._scrollMetrics.visibleLength = scrollMetrics.visibleLength; height,
this._scrollMetrics.offset = scrollMetrics.offset; });
},
); const scrollMetrics = this._convertParentScrollMetrics(
this.context.virtualizedList.getScrollMetrics(),
);
this._scrollMetrics.visibleLength = scrollMetrics.visibleLength;
this._scrollMetrics.offset = scrollMetrics.offset;
},
);
} catch (error) {
console.warn(
'measureLayoutRelativeToContainingList threw an error',
error.stack,
);
}
} }


_onLayout = (e: Object) => { _onLayout = (e: Object) => {
Expand Down

0 comments on commit 5803772

Please sign in to comment.