mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Remove SizeMonitoringFrameLayout
Summary: SizeMonitoringFrameLayout was used to set layout contraints on the root shadow node when the native view's size changes. Since then, we introduced ways for the root node to use proper layout contraints using the root view's measure specs, which provides more accurate constraints for the root node, so SizeMonitoringFrameLayout is no longer needed. This ends up making a lot of UIManagerModule's method signatures cleaner Reviewed By: mdvacca Differential Revision: D9565720 fbshipit-source-id: c569cd15991a09987cc01e89612dc9193ad99b45
This commit is contained in:
committed by
Facebook Github Bot
parent
08a6b573f7
commit
c974b5e966
+4
@@ -173,4 +173,8 @@ public class ReactNativeTestRule implements TestRule {
|
||||
public ReactRootView getView() {
|
||||
return mView;
|
||||
}
|
||||
|
||||
public ReactContext getContext() {
|
||||
return mReactInstanceManager.getCurrentReactContext();
|
||||
}
|
||||
}
|
||||
|
||||
+41
@@ -10,17 +10,20 @@ import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import android.app.Instrumentation;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import com.facebook.react.ReactPackage;
|
||||
import com.facebook.react.ReactRootView;
|
||||
import com.facebook.react.bridge.JavaScriptModule;
|
||||
import com.facebook.react.bridge.ModuleSpec;
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.shell.MainReactPackage;
|
||||
import com.facebook.react.testing.StringRecordingModule;
|
||||
import com.facebook.react.testing.rule.ReactNativeTestRule;
|
||||
import com.facebook.react.uimanager.PixelUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.inject.Provider;
|
||||
@@ -32,6 +35,10 @@ import org.junit.runner.RunWith;
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ReactRootViewTest {
|
||||
|
||||
private interface ReactRootViewTestModule extends JavaScriptModule {
|
||||
void setHeight(int height);
|
||||
}
|
||||
|
||||
final StringRecordingModule mRecordingModule = new StringRecordingModule();
|
||||
final ReactPackage mReactPackage = new MainReactPackage() {
|
||||
@Override
|
||||
@@ -85,6 +92,40 @@ public class ReactRootViewTest {
|
||||
assertThat(newWidth).isEqualTo(childView.getWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRootViewWrapContent() {
|
||||
final ReactRootView rootView = mReactNativeRule.getView();
|
||||
|
||||
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
|
||||
instrumentation.runOnMainSync(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
rootView.setLayoutParams(
|
||||
new FrameLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
}
|
||||
});
|
||||
|
||||
instrumentation.waitForIdleSync();
|
||||
mReactNativeRule.waitForIdleSync();
|
||||
|
||||
int newComponentHeight = 500;
|
||||
mReactNativeRule
|
||||
.getContext()
|
||||
.getJSModule(ReactRootViewTestModule.class)
|
||||
.setHeight(newComponentHeight);
|
||||
|
||||
instrumentation.waitForIdleSync();
|
||||
mReactNativeRule.waitForIdleSync();
|
||||
instrumentation.waitForIdleSync();
|
||||
|
||||
// added 0.5 to account for rounding issues
|
||||
assertThat(rootView.getMeasuredHeight())
|
||||
.isEqualTo((int) (PixelUtil.toPixelFromDIP(newComponentHeight) + 0.5));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that removing the root view from hierarchy will trigger subviews removal both on JS and
|
||||
* native side
|
||||
|
||||
Reference in New Issue
Block a user