Pass fabric flag from native to JS
Reviewed By: mdvacca Differential Revision: D7373722 fbshipit-source-id: 3cd051f38677900693f3da797effa11f9161df37
This commit is contained in:
parent
046d4cee8b
commit
cbb7c7c193
|
@ -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;
|
|
|
@ -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');
|
||||||
|
}
|
||||||
|
};
|
|
@ -35,7 +35,6 @@ export type AppConfig = {
|
||||||
component?: ComponentProvider,
|
component?: ComponentProvider,
|
||||||
run?: Function,
|
run?: Function,
|
||||||
section?: boolean,
|
section?: boolean,
|
||||||
fabric?: boolean,
|
|
||||||
};
|
};
|
||||||
export type Runnable = {
|
export type Runnable = {
|
||||||
component?: ComponentProvider,
|
component?: ComponentProvider,
|
||||||
|
@ -85,7 +84,6 @@ const AppRegistry = {
|
||||||
appConfig.appKey,
|
appConfig.appKey,
|
||||||
appConfig.component,
|
appConfig.component,
|
||||||
appConfig.section,
|
appConfig.section,
|
||||||
appConfig.fabric,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -100,13 +98,12 @@ const AppRegistry = {
|
||||||
appKey: string,
|
appKey: string,
|
||||||
componentProvider: ComponentProvider,
|
componentProvider: ComponentProvider,
|
||||||
section?: boolean,
|
section?: boolean,
|
||||||
fabric?: boolean,
|
|
||||||
): string {
|
): string {
|
||||||
runnables[appKey] = {
|
runnables[appKey] = {
|
||||||
componentProvider,
|
componentProvider,
|
||||||
run: appParameters => {
|
run: appParameters => {
|
||||||
let renderFunc = renderApplication;
|
let renderFunc = renderApplication;
|
||||||
if (fabric) {
|
if (appParameters.fabric) {
|
||||||
invariant(
|
invariant(
|
||||||
fabricRendererProvider != null,
|
fabricRendererProvider != null,
|
||||||
'A Fabric renderer provider must be set to render Fabric components',
|
'A Fabric renderer provider must be set to render Fabric components',
|
||||||
|
|
|
@ -34,7 +34,7 @@ function renderFabricSurface<Props: Object>(
|
||||||
fabric={true}
|
fabric={true}
|
||||||
rootTag={rootTag}
|
rootTag={rootTag}
|
||||||
WrapperComponent={WrapperComponent}>
|
WrapperComponent={WrapperComponent}>
|
||||||
<RootComponent {...initialProps} rootTag={rootTag} />
|
<RootComponent {...initialProps} rootTag={rootTag} fabric={true} />
|
||||||
</AppContainer>
|
</AppContainer>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -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;
|
|
|
@ -13,7 +13,6 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import com.facebook.react.bridge.JavaScriptModule;
|
import com.facebook.react.bridge.JavaScriptModule;
|
||||||
import com.facebook.react.bridge.ReactContext;
|
import com.facebook.react.bridge.ReactContext;
|
||||||
import com.facebook.react.testing.fabric.FabricTestModule;
|
|
||||||
import com.facebook.react.testing.idledetection.IdleWaiter;
|
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
|
* Override this method to provide extra native modules to be loaded before the app starts
|
||||||
*/
|
*/
|
||||||
protected ReactInstanceSpecForTest createReactInstanceSpecForTest() {
|
protected ReactInstanceSpecForTest createReactInstanceSpecForTest() {
|
||||||
ReactInstanceSpecForTest instanceSpec = new ReactInstanceSpecForTest();
|
return new ReactInstanceSpecForTest();
|
||||||
if (isFabricTest()) {
|
|
||||||
instanceSpec.addNativeModule(new FabricTestModule(isFabricTest()));
|
|
||||||
}
|
|
||||||
return instanceSpec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -490,6 +490,9 @@ public class ReactRootView extends SizeMonitoringFrameLayout
|
||||||
if (appProperties != null) {
|
if (appProperties != null) {
|
||||||
appParams.putMap("initialProps", Arguments.fromBundle(appProperties));
|
appParams.putMap("initialProps", Arguments.fromBundle(appProperties));
|
||||||
}
|
}
|
||||||
|
if (isFabric()) {
|
||||||
|
appParams.putBoolean("fabric", true);
|
||||||
|
}
|
||||||
|
|
||||||
mShouldLogContentAppeared = true;
|
mShouldLogContentAppeared = true;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue