mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Refactor the way UIManagerModule uses measure specs
Summary: Instead of using measure specs to set certain yoga properties on the root node (like max width, auto width, specific width), use yoga's calculateLayout(width, height) instead. The measure specs will be stored in the shadow node. This allows us to remove duplicated code that processes the measure specs and allows us to remove other logic like the enableLayoutCalculation() method. This diff also removes MeasureSpecProvider. MeasureSpecProvider was originally introduced to pass previously measured view measure specs to the initial creation of the root shadow node, but it turns out that this is unnecessary. We can update the root layout specs from the root view instead. Reviewed By: mdvacca Differential Revision: D9729744 fbshipit-source-id: 79b0b27ca879758f5dc3fc7cc8a0d38856a6cc79
This commit is contained in:
committed by
Facebook Github Bot
parent
9cb93abc47
commit
e758435167
@@ -48,7 +48,6 @@ import com.facebook.react.uimanager.PixelUtil;
|
||||
import com.facebook.react.uimanager.RootView;
|
||||
import com.facebook.react.uimanager.UIManagerHelper;
|
||||
import com.facebook.react.uimanager.UIManagerModule;
|
||||
import com.facebook.react.uimanager.common.MeasureSpecProvider;
|
||||
import com.facebook.react.uimanager.common.UIManagerType;
|
||||
import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
import com.facebook.systrace.Systrace;
|
||||
@@ -66,7 +65,7 @@ import javax.annotation.Nullable;
|
||||
* subsequent touch events related to that gesture (in case when JS code wants to handle that
|
||||
* gesture).
|
||||
*/
|
||||
public class ReactRootView extends FrameLayout implements RootView, MeasureSpecProvider {
|
||||
public class ReactRootView extends FrameLayout implements RootView {
|
||||
|
||||
/**
|
||||
* Listener interface for react root view events
|
||||
@@ -156,9 +155,7 @@ public class ReactRootView extends FrameLayout implements RootView, MeasureSpecP
|
||||
// Check if we were waiting for onMeasure to attach the root view.
|
||||
if (mReactInstanceManager != null && !mIsAttachedToInstance) {
|
||||
attachToReactInstanceManager();
|
||||
enableLayoutCalculation();
|
||||
} else {
|
||||
enableLayoutCalculation();
|
||||
updateRootLayoutSpecs(mWidthMeasureSpec, mHeightMeasureSpec);
|
||||
}
|
||||
|
||||
@@ -167,22 +164,6 @@ public class ReactRootView extends FrameLayout implements RootView, MeasureSpecP
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidthMeasureSpec() {
|
||||
if (!mWasMeasured && getLayoutParams() != null && getLayoutParams().width > 0) {
|
||||
return MeasureSpec.makeMeasureSpec(getLayoutParams().width, MeasureSpec.EXACTLY);
|
||||
}
|
||||
return mWidthMeasureSpec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeightMeasureSpec() {
|
||||
if (!mWasMeasured && getLayoutParams() != null && getLayoutParams().height > 0) {
|
||||
return MeasureSpec.makeMeasureSpec(getLayoutParams().height, MeasureSpec.EXACTLY);
|
||||
}
|
||||
return mHeightMeasureSpec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChildStartedNativeGesture(MotionEvent androidEvent) {
|
||||
if (mReactInstanceManager == null || !mIsAttachedToInstance ||
|
||||
@@ -389,23 +370,6 @@ public class ReactRootView extends FrameLayout implements RootView, MeasureSpecP
|
||||
}
|
||||
}
|
||||
|
||||
private void enableLayoutCalculation() {
|
||||
if (mReactInstanceManager == null) {
|
||||
FLog.w(
|
||||
ReactConstants.TAG,
|
||||
"Unable to enable layout calculation for uninitialized ReactInstanceManager");
|
||||
return;
|
||||
}
|
||||
final ReactContext reactApplicationContext = mReactInstanceManager.getCurrentReactContext();
|
||||
if (reactApplicationContext != null) {
|
||||
reactApplicationContext
|
||||
.getCatalystInstance()
|
||||
.getNativeModule(UIManagerModule.class)
|
||||
.getUIImplementation()
|
||||
.enableLayoutCalculationForRootNode(getRootViewTag());
|
||||
}
|
||||
}
|
||||
|
||||
private void updateRootLayoutSpecs(final int widthMeasureSpec, final int heightMeasureSpec) {
|
||||
if (mReactInstanceManager == null) {
|
||||
FLog.w(
|
||||
@@ -487,6 +451,9 @@ public class ReactRootView extends FrameLayout implements RootView, MeasureSpecP
|
||||
return;
|
||||
}
|
||||
|
||||
if (mWasMeasured) {
|
||||
updateRootLayoutSpecs(mWidthMeasureSpec, mHeightMeasureSpec);
|
||||
}
|
||||
CatalystInstance catalystInstance = reactContext.getCatalystInstance();
|
||||
|
||||
WritableNativeMap appParams = new WritableNativeMap();
|
||||
|
||||
Reference in New Issue
Block a user