Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public interface ReactRootViewEventListener {
private @Nullable String mInitialUITemplate;
private @Nullable CustomGlobalLayoutListener mCustomGlobalLayoutListener;
private @Nullable ReactRootViewEventListener mRootViewEventListener;
private int mRootViewTag;
private int mRootViewTag =
0; /* This should be View.NO_ID, but for legacy reasons we haven't migrated yet */
private boolean mIsAttachedToInstance;
private boolean mShouldLogContentAppeared;
private @Nullable JSTouchDispatcher mJSTouchDispatcher;
Expand Down Expand Up @@ -451,6 +452,14 @@ private void updateRootLayoutSpecs(
FLog.w(TAG, "Unable to update root layout specs for uninitialized ReactInstanceManager");
return;
}
// In Fabric we cannot call `updateRootLayoutSpecs` until a SurfaceId has been set.
// Sometimes,
if (getUIManagerType() == FABRIC && !isRootViewTagSet()) {
ReactMarker.logMarker(ReactMarkerConstants.ROOT_VIEW_UPDATE_LAYOUT_SPECS_END);
FLog.e(TAG, "Unable to update root layout specs for ReactRootView: no rootViewTag set yet");
return;
}

final ReactContext reactApplicationContext = mReactInstanceManager.getCurrentReactContext();

if (reactApplicationContext != null) {
Expand Down Expand Up @@ -572,7 +581,7 @@ public String getJSModuleName() {
public void setAppProperties(@Nullable Bundle appProperties) {
UiThreadUtil.assertOnUiThread();
mAppProperties = appProperties;
if (getRootViewTag() != 0) {
if (isRootViewTagSet()) {
runApplication();
}
}
Expand Down Expand Up @@ -667,6 +676,10 @@ public int getRootViewTag() {
return mRootViewTag;
}

private boolean isRootViewTagSet() {
return mRootViewTag != 0 && mRootViewTag != NO_ID;
}

public void setRootViewTag(int rootViewTag) {
mRootViewTag = rootViewTag;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -869,11 +869,20 @@ public void updateRootLayoutSpecs(
final int offsetY) {

if (ENABLE_FABRIC_LOGS) {
FLog.d(TAG, "Updating Root Layout Specs");
FLog.d(TAG, "Updating Root Layout Specs for [%d]", surfaceId);
}

SurfaceMountingManager surfaceMountingManager = mMountingManager.getSurfaceManager(surfaceId);

// TODO T83615646: make this a hard-crash in the future.
if (surfaceMountingManager == null) {
ReactSoftException.logSoftException(
TAG,
new IllegalViewOperationException(
"Cannot updateRootLayoutSpecs on surfaceId that does not exist: " + surfaceId));
return;
}

SurfaceMountingManager surfaceMountingManager =
mMountingManager.getSurfaceManagerEnforced(surfaceId, "updateRootLayoutSpecs");
ThemedReactContext reactContext = surfaceMountingManager.getContext();
boolean isRTL = false;
boolean doLeftAndRightSwapInRTL = false;
Expand Down
10 changes: 7 additions & 3 deletions ReactCommon/react/renderer/mounting/ShadowTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,22 +222,26 @@ ShadowTree::ShadowTree(
SurfaceId surfaceId,
LayoutConstraints const &layoutConstraints,
LayoutContext const &layoutContext,
RootComponentDescriptor const &rootComponentDescriptor,
ShadowTreeDelegate const &delegate,
std::weak_ptr<MountingOverrideDelegate const> mountingOverrideDelegate)
: surfaceId_(surfaceId), delegate_(delegate) {
const auto noopEventEmitter = std::make_shared<const ViewEventEmitter>(
nullptr, -1, std::shared_ptr<const EventDispatcher>());

static auto globalRootComponentDescriptor =
std::make_unique<RootComponentDescriptor const>(
ComponentDescriptorParameters{
EventDispatcher::Shared{}, nullptr, nullptr});

const auto props = std::make_shared<const RootProps>(
*RootShadowNode::defaultSharedProps(), layoutConstraints, layoutContext);

auto const fragment =
ShadowNodeFamilyFragment{surfaceId, surfaceId, noopEventEmitter};
auto family = rootComponentDescriptor.createFamily(fragment, nullptr);
auto family = globalRootComponentDescriptor->createFamily(fragment, nullptr);

auto rootShadowNode = std::static_pointer_cast<const RootShadowNode>(
rootComponentDescriptor.createShadowNode(
globalRootComponentDescriptor->createShadowNode(
ShadowNodeFragment{
/* .props = */ props,
},
Expand Down
1 change: 0 additions & 1 deletion ReactCommon/react/renderer/mounting/ShadowTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class ShadowTree final {
SurfaceId surfaceId,
LayoutConstraints const &layoutConstraints,
LayoutContext const &layoutContext,
RootComponentDescriptor const &rootComponentDescriptor,
ShadowTreeDelegate const &delegate,
std::weak_ptr<MountingOverrideDelegate const> mountingOverrideDelegate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <gtest/gtest.h>

#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
#include <react/renderer/components/root/RootComponentDescriptor.h>
#include <react/renderer/components/view/ViewComponentDescriptor.h>
#include <react/renderer/element/ComponentBuilder.h>
#include <react/renderer/element/Element.h>
Expand Down Expand Up @@ -95,14 +94,10 @@ TEST(StateReconciliationTest, testStateReconciliation) {
auto &family = shadowNodeAB->getFamily();
auto state1 = shadowNodeAB->getState();
auto shadowTreeDelegate = DummyShadowTreeDelegate{};
auto eventDispatcher = EventDispatcher::Shared{};
auto rootComponentDescriptor =
ComponentDescriptorParameters{eventDispatcher, nullptr, nullptr};
ShadowTree shadowTree{
SurfaceId{11},
LayoutConstraints{},
LayoutContext{},
rootComponentDescriptor,
shadowTreeDelegate,
{}};

Expand Down
4 changes: 0 additions & 4 deletions ReactCommon/react/renderer/scheduler/Scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ Scheduler::Scheduler(
componentDescriptorRegistry_ = schedulerToolbox.componentRegistryFactory(
eventDispatcher, schedulerToolbox.contextContainer);

rootComponentDescriptor_ = std::make_unique<const RootComponentDescriptor>(
ComponentDescriptorParameters{eventDispatcher, nullptr, nullptr});

uiManager->setBackgroundExecutor(schedulerToolbox.backgroundExecutor);
uiManager->setDelegate(this);
uiManager->setComponentDescriptorRegistry(componentDescriptorRegistry_);
Expand Down Expand Up @@ -188,7 +185,6 @@ void Scheduler::startSurface(
surfaceId,
layoutConstraints,
layoutContext,
*rootComponentDescriptor_,
*uiManager_,
mountingOverrideDelegate);

Expand Down
1 change: 0 additions & 1 deletion ReactCommon/react/renderer/scheduler/Scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ class Scheduler final : public UIManagerDelegate {
private:
SchedulerDelegate *delegate_;
SharedComponentDescriptorRegistry componentDescriptorRegistry_;
std::unique_ptr<const RootComponentDescriptor> rootComponentDescriptor_;
RuntimeExecutor runtimeExecutor_;
std::shared_ptr<UIManager> uiManager_;
std::shared_ptr<const ReactNativeConfig> reactNativeConfig_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.io.File;
import org.apache.log4j.Logger;
import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
Expand All @@ -25,8 +24,6 @@
*/
public class CodegenPlugin implements Plugin<Project> {

Logger logger = Logger.getLogger(getClass());

public void apply(final Project project) {
final CodegenPluginExtension extension =
project.getExtensions().create("react", CodegenPluginExtension.class, project);
Expand All @@ -49,8 +46,6 @@ public void apply(final Project project) {
s -> {
generatedSrcDir.delete();
generatedSrcDir.mkdirs();
logger.warn(
"[Gradle] Codegen command on execution: " + ((Exec) s).getCommandLine());
});

task.getInputs()
Expand All @@ -65,13 +60,15 @@ public void apply(final Project project) {
ImmutableList.of("**/*.js"))));
task.getOutputs().file(generatedSchemaFile);

task.executable("yarn")
.args(ImmutableList.copyOf(extension.nodeExecutableAndArgs))
.args(extension.codegenGenerateSchemaCLI().getAbsolutePath())
.args(generatedSchemaFile.getAbsolutePath())
.args(extension.jsRootDir.getAbsolutePath());

logger.warn("[Gradle] Codegen command on configure: " + task.getCommandLine());
ImmutableList<String> execCommands =
new ImmutableList.Builder<String>()
.add("yarn")
.addAll(ImmutableList.copyOf(extension.nodeExecutableAndArgs))
.add(extension.codegenGenerateSchemaCLI().getAbsolutePath())
.add(generatedSchemaFile.getAbsolutePath())
.add(extension.jsRootDir.getAbsolutePath())
.build();
task.commandLine(execCommands);
});

// 3. Task: generate Java code from schema.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ function filterJSFile(file) {
);
}

console.log('[JS] Codegen args: ' + process.argv.join(' '));
const allFiles = [];
fileList.forEach(file => {
if (fs.lstatSync(file).isDirectory()) {
Expand Down