Pass fabric flag from native to JS

Reviewed By: mdvacca

Differential Revision: D7373722

fbshipit-source-id: 3cd051f38677900693f3da797effa11f9161df37
This commit is contained in:
Andrew Chen (Eng) 2018-03-23 09:03:45 -07:00 committed by Facebook Github Bot
parent 046d4cee8b
commit cbb7c7c193
8 changed files with 31 additions and 98 deletions

View File

@ -1,24 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule TestFabricView
* @flow
* @format
*/
'use strict';
/**
* This is a switch on the correct View to use for Fabric testing purposes
*/
let TestFabricView;
const FabricTestModule = require('NativeModules').FabricTestModule;
if (FabricTestModule && FabricTestModule.IS_FABRIC_ENABLED) {
TestFabricView = require('FabricView');
} else {
TestFabricView = require('View');
}
module.exports = TestFabricView;

View File

@ -0,0 +1,25 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule requireFabricView
* @flow
* @format
*/
'use strict';
/**
* This is a switch on the correct view to use for Fabric
*/
module.exports = (name: string, fabric: boolean) => {
switch (name) {
case 'View':
return fabric ? require('FabricView') : require('View');
case 'Text':
return fabric ? require('FabricText') : require('Text');
default:
throw new Error(name + ' is not supported by Fabric yet');
}
};

View File

@ -35,7 +35,6 @@ export type AppConfig = {
component?: ComponentProvider,
run?: Function,
section?: boolean,
fabric?: boolean,
};
export type Runnable = {
component?: ComponentProvider,
@ -85,7 +84,6 @@ const AppRegistry = {
appConfig.appKey,
appConfig.component,
appConfig.section,
appConfig.fabric,
);
}
});
@ -100,13 +98,12 @@ const AppRegistry = {
appKey: string,
componentProvider: ComponentProvider,
section?: boolean,
fabric?: boolean,
): string {
runnables[appKey] = {
componentProvider,
run: appParameters => {
let renderFunc = renderApplication;
if (fabric) {
if (appParameters.fabric) {
invariant(
fabricRendererProvider != null,
'A Fabric renderer provider must be set to render Fabric components',

View File

@ -34,7 +34,7 @@ function renderFabricSurface<Props: Object>(
fabric={true}
rootTag={rootTag}
WrapperComponent={WrapperComponent}>
<RootComponent {...initialProps} rootTag={rootTag} />
<RootComponent {...initialProps} rootTag={rootTag} fabric={true} />
</AppContainer>
);

View File

@ -1,24 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule TestFabricText
* @flow
* @format
*/
'use strict';
/**
* This is a switch on the correct Text to use for Fabric testing purposes
*/
let TestFabricText;
const FabricTestModule = require('NativeModules').FabricTestModule;
if (FabricTestModule && FabricTestModule.IS_FABRIC_ENABLED) {
TestFabricText = require('FabricText');
} else {
TestFabricText = require('Text');
}
module.exports = TestFabricText;

View File

@ -13,7 +13,6 @@ import android.view.View;
import android.view.ViewGroup;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.testing.fabric.FabricTestModule;
import com.facebook.react.testing.idledetection.IdleWaiter;
/**
@ -116,11 +115,7 @@ public abstract class ReactInstrumentationTest extends
* Override this method to provide extra native modules to be loaded before the app starts
*/
protected ReactInstanceSpecForTest createReactInstanceSpecForTest() {
ReactInstanceSpecForTest instanceSpec = new ReactInstanceSpecForTest();
if (isFabricTest()) {
instanceSpec.addNativeModule(new FabricTestModule(isFabricTest()));
}
return instanceSpec;
return new ReactInstanceSpecForTest();
}
/**

View File

@ -1,39 +0,0 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.testing.fabric;
import com.facebook.react.common.MapBuilder;
import java.util.Map;
import javax.annotation.Nullable;
import com.facebook.react.bridge.BaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
/**
* Module to indicate if a test is using Fabric
*/
public final class FabricTestModule extends BaseJavaModule {
private final boolean mIsFabricEnabled;
public FabricTestModule(boolean isFabricEnabled) {
mIsFabricEnabled = isFabricEnabled;
}
@Override
public String getName() {
return "FabricTestModule";
}
@Override
public Map<String, Object> getConstants() {
return MapBuilder.<String, Object>of("IS_FABRIC_ENABLED", mIsFabricEnabled);
}
}

View File

@ -490,6 +490,9 @@ public class ReactRootView extends SizeMonitoringFrameLayout
if (appProperties != null) {
appParams.putMap("initialProps", Arguments.fromBundle(appProperties));
}
if (isFabric()) {
appParams.putBoolean("fabric", true);
}
mShouldLogContentAppeared = true;