mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-03 22:48:25 +08:00
Make FlatUIImplementation.measure() work with virtual views (shadow nodes that don't map to a View)
Summary: UIImplementation.measure() can only measure shadow nodes that map to native Views. As a result of this, every time we tried to measure a shadow node that doesn't map to a View, we trigger callback with no data (to indicate an error). To fix this issue, walk up until we find a node that maps to a View, then measure that View and adjust for the bounds of a virtual child. Reviewed By: ahmedre Differential Revision: D2800960
This commit is contained in:
committed by
Ahmed El-Helw
parent
b321ea98d3
commit
05544f6bca
@@ -16,6 +16,8 @@ import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.uimanager.CatalystStylesDiffMap;
|
||||
@@ -151,6 +153,43 @@ public class FlatUIImplementation extends UIImplementation {
|
||||
addChildren(parentNode, addChildTags, addAtIndices);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void measure(int reactTag, Callback callback) {
|
||||
FlatShadowNode node = (FlatShadowNode) resolveShadowNode(reactTag);
|
||||
if (node.mountsToView()) {
|
||||
super.measure(reactTag, callback);
|
||||
return;
|
||||
}
|
||||
|
||||
float width = node.getLayoutWidth();
|
||||
float height = node.getLayoutHeight();
|
||||
|
||||
float xInParent = node.getLayoutX();
|
||||
float yInParent = node.getLayoutY();
|
||||
|
||||
while (true) {
|
||||
node = Assertions.assumeNotNull((FlatShadowNode) node.getParent());
|
||||
if (node.mountsToView()) {
|
||||
break;
|
||||
}
|
||||
|
||||
xInParent += node.getLayoutX();
|
||||
yInParent += node.getLayoutY();
|
||||
}
|
||||
|
||||
float parentWidth = node.getLayoutWidth();
|
||||
float parentHeight = node.getLayoutHeight();
|
||||
|
||||
FlatUIViewOperationQueue operationsQueue = mStateBuilder.getOperationsQueue();
|
||||
operationsQueue.enqueueMeasureVirtualView(
|
||||
node.getReactTag(),
|
||||
xInParent / parentWidth,
|
||||
yInParent / parentHeight,
|
||||
width / parentWidth,
|
||||
height / parentHeight,
|
||||
callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all children defined by moveFrom and removeFrom from a given parent,
|
||||
* preparing elements in moveFrom to be re-added at proper index.
|
||||
|
||||
Reference in New Issue
Block a user