mostly working on Android + OTA

Summary:
It works great on iOS, and mostly works on Android, and is now OTA'able as part of the screen config! Haven't done template view yet. One remaining issue:

Layout is borked on Android. I'm guessing the issue has to do with the timing of setting the constraints in `updateRootLayoutSpecs` and calling `mBinding.startSurface` which actually builds the shadow tree. If I try to call `updateRootLayoutSpecs` earlier, it just crashes immediately. Here's the layout it spits out, which clearly has -440 for the x of 420006, which is the RCTText component, causing it to get cut off on the left of the screen:
```
updateLayoutMountItem for reactTag: 420006 x: -440, y: -13, width: 931, height: 78
updateLayoutMountItem for reactTag: 420010 x: 26, y: 79, width: 0, height: 1651
updateLayoutMountItem for reactTag: 420012 x: 0, y: 26, width: 0, height: 158
updateLayoutMountItem for reactTag: 420016 x: 0, y: 210, width: 454, height: 454
updateLayoutMountItem for reactTag: 420018 x: 454, y: 210, width: 455, height: 454
updateLayoutMountItem for reactTag: 420022 x: 0, y: 690, width: 454, height: 454
updateLayoutMountItem for reactTag: 420024 x: 454, y: 690, width: 455, height: 454
updateLayoutMountItem for reactTag: 420028 x: 0, y: 1171, width: 454, height: 454
updateLayoutMountItem for reactTag: 420030 x: 454, y: 1171, width: 455, height: 454
updateLayoutMountItem for reactTag: 420032 x: 0, y: 1651, width: 0, height: 0
```

Reviewed By: mdvacca

Differential Revision: D12813192

fbshipit-source-id: 450d646af4883ff25184141721351da67b091b7c
This commit is contained in:
Spencer Ahrens authored and Facebook Github Bot committed 2018-11-05 15:43:55 -08:00
1 parent aab01608ba
commit 7b5277bb75
10 files changed
+115 -52

No files matched your search

@@ -7,8 +7,6 @@
#include "ReactBytecodeInterpreter.h"
#include <glog/logging.h>
#include <fabric/components/view/ViewComponentDescriptor.h>
#include <fabric/components/view/ViewProps.h>
#include <fabric/components/view/ViewShadowNode.h>
@@ -18,10 +16,13 @@
#include <fabric/debug/DebugStringConvertible.h>
#include <fabric/debug/DebugStringConvertibleItem.h>
#include <folly/json.h>
#include <glog/logging.h>
namespace facebook {
namespace react {
bool constexpr DEBUG_FLY = false;
struct RBCContext {
const Tag rootTag;
const std::vector<SharedShadowNode> &nodes;
@@ -40,6 +41,7 @@ SharedShadowNode ReactBytecodeInterpreter::runCommand(
const NativeModuleRegistry &nativeModuleRegistry) {
const std::string &opcode = command[0].asString();
const int tagOffset = 420000;
// TODO: change to integer codes and a switch statement
if (opcode == "createNode") {
int tag = command[1].asInt();
const auto &type = command[2].asString();
@@ -55,7 +57,7 @@ SharedShadowNode ReactBytecodeInterpreter::runCommand(
}
} else if (opcode == "childSetNode") {
LOG(INFO)
<< "(stop) ReactBytecodeInterpreter inject serialized 'server rendered' view tree";
<< "(stop) UITemplateProcessor inject serialized 'server rendered' view tree";
return nodes[command[1].asInt()];
} else if (opcode == "loadNativeBool") {
int registerNumber = command[1].asInt();
@@ -68,8 +70,7 @@ SharedShadowNode ReactBytecodeInterpreter::runCommand(
if (conditionDynamic.isNull()) {
// TODO: provide original command or command line?
auto err = std::runtime_error(
"register " + command[1].asString() +
" wasn't loaded before access");
"register " + command[1].asString() + " wasn't loaded before access");
throw err;
} else if (conditionDynamic.type() != folly::dynamic::BOOL) {
// TODO: provide original command or command line?
@@ -104,6 +105,7 @@ SharedShadowNode ReactBytecodeInterpreter::buildShadowTree(
const NativeModuleRegistry &nativeModuleRegistry) {
LOG(INFO)
<< "(strt) ReactBytecodeInterpreter inject hardcoded 'server rendered' view tree";
std::string content = jsonStr;
for (const auto &param : params.items()) {
const auto &key = param.first.asString();
@@ -117,17 +119,26 @@ SharedShadowNode ReactBytecodeInterpreter::buildShadowTree(
std::vector<SharedShadowNode> nodes(commands.size() * 2);
std::vector<folly::dynamic> registers(32);
for (const auto &command : commands) {
auto ret = runCommand(
command,
rootTag,
nodes,
registers,
componentDescriptorRegistry,
nativeModuleRegistry);
if (ret != nullptr) {
return ret;
try {
if (DEBUG_FLY) {
LOG(INFO) << "try to run command " << folly::toJson(command);
}
auto ret = runCommand(
command,
rootTag,
nodes,
registers,
componentDescriptorRegistry,
nativeModuleRegistry);
if (ret != nullptr) {
return ret;
}
} catch (const std::exception &e) {
LOG(ERROR) << " >>> Exception <<< running previous command '"
<< folly::toJson(command) << "': '" << e.what() << "'";
}
}
LOG(ERROR) << "react ui template missing childSetNode command :(";
throw std::runtime_error(
"Missing childSetNode command in template content:\n" + content);
return SharedShadowNode{};