Fix setMeasureFunction during cloning
Reviewed By: achen1 Differential Revision: D7753602 fbshipit-source-id: 284ec13b4cd784dfc61eeb0205f5779847854aac
This commit is contained in:
parent
c6b96c0df7
commit
409dbd2057
|
@ -7,6 +7,7 @@
|
|||
|
||||
package com.facebook.react.views.progressbar;
|
||||
|
||||
import com.facebook.react.uimanager.ReactShadowNodeImpl;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
@ -41,7 +42,7 @@ public class ProgressBarShadowNode extends LayoutShadowNode implements YogaMeasu
|
|||
mHeight = new SparseIntArray();
|
||||
mWidth = new SparseIntArray();
|
||||
mMeasured = new HashSet<>();
|
||||
setMeasureFunction(this);
|
||||
initMeasureFunction();
|
||||
}
|
||||
|
||||
public ProgressBarShadowNode(ProgressBarShadowNode node) {
|
||||
|
@ -49,11 +50,28 @@ public class ProgressBarShadowNode extends LayoutShadowNode implements YogaMeasu
|
|||
mWidth = node.mWidth.clone();
|
||||
mHeight = node.mHeight.clone();
|
||||
mMeasured = new HashSet<>(node.mMeasured);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReactShadowNodeImpl mutableCopyWithNewChildren() {
|
||||
ProgressBarShadowNode node = (ProgressBarShadowNode) super.mutableCopyWithNewChildren();
|
||||
node.initMeasureFunction();
|
||||
return node;
|
||||
}
|
||||
|
||||
private void initMeasureFunction() {
|
||||
setMeasureFunction(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ProgressBarShadowNode copy() {
|
||||
public ReactShadowNodeImpl mutableCopy() {
|
||||
ProgressBarShadowNode node = (ProgressBarShadowNode) super.mutableCopy();
|
||||
node.initMeasureFunction();
|
||||
return node;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProgressBarShadowNode copy() {
|
||||
return new ProgressBarShadowNode(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import android.widget.SeekBar;
|
|||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.common.MapBuilder;
|
||||
import com.facebook.react.uimanager.LayoutShadowNode;
|
||||
import com.facebook.react.uimanager.ReactShadowNodeImpl;
|
||||
import com.facebook.react.uimanager.SimpleViewManager;
|
||||
import com.facebook.react.uimanager.ThemedReactContext;
|
||||
import com.facebook.react.uimanager.UIManagerModule;
|
||||
|
@ -63,6 +64,20 @@ public class ReactSliderManager extends SimpleViewManager<ReactSlider> {
|
|||
setMeasureFunction(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReactShadowNodeImpl mutableCopy() {
|
||||
ReactSliderShadowNode reactShadowNode = (ReactSliderShadowNode) super.mutableCopy();
|
||||
reactShadowNode.initMeasureFunction();
|
||||
return reactShadowNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReactShadowNodeImpl mutableCopyWithNewChildren() {
|
||||
ReactSliderShadowNode reactShadowNode = (ReactSliderShadowNode) super.mutableCopyWithNewChildren();
|
||||
reactShadowNode.initMeasureFunction();
|
||||
return reactShadowNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReactSliderShadowNode copy() {
|
||||
return new ReactSliderShadowNode(this);
|
||||
|
|
|
@ -13,6 +13,7 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
|
||||
import com.facebook.react.uimanager.ReactShadowNodeImpl;
|
||||
import com.facebook.yoga.YogaMeasureMode;
|
||||
import com.facebook.yoga.YogaMeasureFunction;
|
||||
import com.facebook.yoga.YogaNode;
|
||||
|
@ -48,13 +49,26 @@ public class ReactSwitchManager extends SimpleViewManager<ReactSwitch> {
|
|||
mWidth = node.mWidth;
|
||||
mHeight = node.mHeight;
|
||||
mMeasured = node.mMeasured;
|
||||
initMeasureFunction();
|
||||
}
|
||||
|
||||
private void initMeasureFunction() {
|
||||
setMeasureFunction(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReactShadowNodeImpl mutableCopy() {
|
||||
ReactSwitchShadowNode reactShadowNode = (ReactSwitchShadowNode) super.mutableCopy();
|
||||
reactShadowNode.initMeasureFunction();
|
||||
return reactShadowNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReactShadowNodeImpl mutableCopyWithNewChildren() {
|
||||
ReactSwitchShadowNode reactShadowNode = (ReactSwitchShadowNode) super.mutableCopyWithNewChildren();
|
||||
reactShadowNode.initMeasureFunction();
|
||||
return reactShadowNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReactSwitchShadowNode copy() {
|
||||
return new ReactSwitchShadowNode(this);
|
||||
|
|
|
@ -46,7 +46,7 @@ public class ReactTextInputShadowNode extends ReactBaseTextShadowNode
|
|||
mTextBreakStrategy = (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) ?
|
||||
0 : Layout.BREAK_STRATEGY_SIMPLE;
|
||||
|
||||
setMeasureFunction(this);
|
||||
initMeasureFunction();
|
||||
}
|
||||
|
||||
private ReactTextInputShadowNode(ReactTextInputShadowNode node) {
|
||||
|
@ -64,7 +64,7 @@ public class ReactTextInputShadowNode extends ReactBaseTextShadowNode
|
|||
@Override
|
||||
public ReactTextInputShadowNode mutableCopy() {
|
||||
ReactTextInputShadowNode node = (ReactTextInputShadowNode) super.mutableCopy();
|
||||
node.setMeasureFunction(this);
|
||||
node.initMeasureFunction();
|
||||
ThemedReactContext themedContext = getThemedContext();
|
||||
if (themedContext != null) {
|
||||
node.setThemedContext(themedContext);
|
||||
|
@ -72,10 +72,14 @@ public class ReactTextInputShadowNode extends ReactBaseTextShadowNode
|
|||
return node;
|
||||
}
|
||||
|
||||
private void initMeasureFunction() {
|
||||
setMeasureFunction(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReactTextInputShadowNode mutableCopyWithNewChildren() {
|
||||
ReactTextInputShadowNode node = (ReactTextInputShadowNode) super.mutableCopyWithNewChildren();
|
||||
node.setMeasureFunction(this);
|
||||
node.initMeasureFunction();
|
||||
ThemedReactContext themedContext = getThemedContext();
|
||||
if (themedContext != null) {
|
||||
node.setThemedContext(themedContext);
|
||||
|
|
|
@ -34,6 +34,7 @@ rn_robolectric_test(
|
|||
react_native_target("java/com/facebook/react/uimanager:uimanager"),
|
||||
react_native_target("java/com/facebook/react/views/text:text"),
|
||||
react_native_target("java/com/facebook/react/views/view:view"),
|
||||
react_native_target("java/com/facebook/react/views/progressbar:progressbar"),
|
||||
react_native_tests_target("java/com/facebook/react/bridge:testhelpers"),
|
||||
],
|
||||
)
|
||||
|
|
|
@ -2,41 +2,29 @@
|
|||
package com.facebook.react.fabric;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.facebook.react.ReactRootView;
|
||||
import com.facebook.react.bridge.CatalystInstance;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactTestHelper;
|
||||
import com.facebook.react.bridge.ReadableNativeMap;
|
||||
import com.facebook.react.common.ClearableSynchronizedPool;
|
||||
import com.facebook.react.fabric.FabricUIManager;
|
||||
import com.facebook.react.uimanager.ReactShadowNode;
|
||||
import com.facebook.react.uimanager.ReactShadowNodeImpl;
|
||||
import com.facebook.react.uimanager.Spacing;
|
||||
import com.facebook.react.uimanager.ThemedReactContext;
|
||||
import com.facebook.react.uimanager.ViewManager;
|
||||
import com.facebook.react.uimanager.ViewManagerRegistry;
|
||||
import com.facebook.react.views.progressbar.ProgressBarShadowNode;
|
||||
import com.facebook.react.views.text.ReactRawTextManager;
|
||||
import com.facebook.react.views.text.ReactRawTextShadowNode;
|
||||
import com.facebook.react.views.text.ReactTextViewManager;
|
||||
import com.facebook.react.views.view.ReactViewManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.fest.assertions.data.Offset;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
|
@ -52,11 +40,10 @@ public class FabricUIManagerTest {
|
|||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mNextReactTag = 2;
|
||||
mThemedReactContext = mock(ThemedReactContext.class);
|
||||
CatalystInstance catalystInstance = ReactTestHelper.createMockCatalystInstance();
|
||||
ReactApplicationContext reactContext =
|
||||
new ReactApplicationContext(RuntimeEnvironment.application);
|
||||
reactContext.initializeWithInstance(catalystInstance);
|
||||
ReactApplicationContext reactContext = new ReactApplicationContext(RuntimeEnvironment.application);
|
||||
reactContext.initializeWithInstance(ReactTestHelper.createMockCatalystInstance());
|
||||
mThemedReactContext = new ThemedReactContext(reactContext, reactContext);
|
||||
|
||||
List<ViewManager> viewManagers =
|
||||
Arrays.<ViewManager>asList(
|
||||
new ReactViewManager(), new ReactTextViewManager(), new ReactRawTextManager());
|
||||
|
@ -143,6 +130,14 @@ public class FabricUIManagerTest {
|
|||
assertThat(clonedNode).isNotEqualTo(node);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLayoutProgressBarAfterClonning() {
|
||||
ProgressBarShadowNode node = new ProgressBarShadowNode();
|
||||
node.setThemedContext(mThemedReactContext);
|
||||
ProgressBarShadowNode clone = (ProgressBarShadowNode) node.mutableCopy();
|
||||
clone.calculateLayout();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneNodeWithNewChildren() {
|
||||
ReactShadowNode node = createViewNode();
|
||||
|
|
Loading…
Reference in New Issue