mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-01-12 22:50:10 +08:00
Migrate VirtualizedList to use ref.measureLayout
Summary: This diff migrates VirtualizedList to use ref.measureLayout instead of UIManager.measureLayout, this is a pre-req to make measureLayout to work in Fabric Reviewed By: JoshuaGross, TheSavior Differential Revision: D14865762 fbshipit-source-id: 45dd3374813370188c914acfc7e631075508f74a
This commit is contained in:
committed by
Facebook Github Bot
parent
b3a07685f2
commit
5eac8ca9b0
@@ -730,6 +730,10 @@ class ScrollView extends React.Component<Props, State> {
|
||||
return ReactNative.findNodeHandle(this._innerViewRef);
|
||||
}
|
||||
|
||||
getNativeScrollRef(): ?ScrollView {
|
||||
return this._scrollViewRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrolls to a given x, y offset, either immediately or with a smooth animation.
|
||||
*
|
||||
|
||||
@@ -413,6 +413,14 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
||||
}
|
||||
}
|
||||
|
||||
getScrollRef() {
|
||||
if (this._scrollRef && this._scrollRef.getScrollRef) {
|
||||
return this._scrollRef.getScrollRef();
|
||||
} else {
|
||||
return this._scrollRef;
|
||||
}
|
||||
}
|
||||
|
||||
setNativeProps(props: Object) {
|
||||
if (this._scrollRef) {
|
||||
this._scrollRef.setNativeProps(props);
|
||||
@@ -1124,17 +1132,18 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
||||
// TODO (T35574538): findNodeHandle sometimes crashes with "Unable to find
|
||||
// node on an unmounted component" during scrolling
|
||||
try {
|
||||
UIManager.measureLayout(
|
||||
ReactNative.findNodeHandle(this),
|
||||
if (!this._scrollRef) {
|
||||
return;
|
||||
}
|
||||
// We are asuming that getOutermostParentListRef().getScrollRef()
|
||||
// is a non-null reference to a ScrollView
|
||||
this._scrollRef.measureLayout(
|
||||
ReactNative.findNodeHandle(
|
||||
this.context.virtualizedList.getOutermostParentListRef(),
|
||||
this.context.virtualizedList
|
||||
.getOutermostParentListRef()
|
||||
.getScrollRef()
|
||||
.getNativeScrollRef(),
|
||||
),
|
||||
error => {
|
||||
console.warn(
|
||||
"VirtualizedList: Encountered an error while measuring a list's" +
|
||||
' offset from its containing VirtualizedList.',
|
||||
);
|
||||
},
|
||||
(x, y, width, height) => {
|
||||
this._offsetFromParentVirtualizedList = this._selectOffset({x, y});
|
||||
this._scrollMetrics.contentLength = this._selectLength({
|
||||
@@ -1148,6 +1157,12 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
||||
this._scrollMetrics.visibleLength = scrollMetrics.visibleLength;
|
||||
this._scrollMetrics.offset = scrollMetrics.offset;
|
||||
},
|
||||
error => {
|
||||
console.warn(
|
||||
"VirtualizedList: Encountered an error while measuring a list's" +
|
||||
' offset from its containing VirtualizedList.',
|
||||
);
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
|
||||
Reference in New Issue
Block a user