Skip to content

Commit

Permalink
Refactor MobileConfig Access for "react_fabric: treat_auto_as_undefin…
Browse files Browse the repository at this point in the history
…ed" (#37208)

Summary: Pull Request resolved: #37208

Reviewed By: javache

Differential Revision: D45434603

fbshipit-source-id: 9081ea11c87a05e0d8ff95e55d8aa8bcd52b4c39
  • Loading branch information
NickGerleman authored and facebook-github-bot committed May 7, 2023
1 parent bde38d5 commit e1876af
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <folly/Conv.h>
#include <folly/dynamic.h>
#include <glog/logging.h>
#include <react/config/ReactNativeConfig.h>
#include <react/debug/react_native_expect.h>
#include <react/renderer/components/view/primitives.h>
#include <react/renderer/core/LayoutMetrics.h>
Expand Down Expand Up @@ -408,19 +407,14 @@ inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
YGStyle::ValueRepr &result) {
// For bug compatibility, pass "auto" as YGValueUndefined
static bool treatAutoAsUndefined =
context.contextContainer
.at<std::shared_ptr<ReactNativeConfig const>>("ReactNativeConfig")
->getBool("react_fabric:treat_auto_as_undefined");

if (value.hasType<Float>()) {
result = yogaStyleValueFromFloat((Float)value);
return;
} else if (value.hasType<std::string>()) {
const auto stringValue = (std::string)value;
if (stringValue == "auto") {
result = treatAutoAsUndefined ? YGValueUndefined : YGValueAuto;
result = context.treatAutoAsYGValueUndefined() ? YGValueUndefined
: YGValueAuto;
return;
} else {
if (stringValue.back() == '%') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ target_link_libraries(react_render_core
folly_runtime
glog
jsi
react_config
react_debug
react_render_debug
react_render_graphics
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include "PropsParserContext.h"

#include <react/config/ReactNativeConfig.h>

namespace facebook::react {

bool PropsParserContext::treatAutoAsYGValueUndefined() const {
if (treatAutoAsYGValueUndefined_ == std::nullopt) {
auto config = contextContainer.at<std::shared_ptr<const ReactNativeConfig>>(
"ReactNativeConfig");
treatAutoAsYGValueUndefined_ = config
? config->getBool("react_fabric:treat_auto_as_undefined")
: false;
}

return *treatAutoAsYGValueUndefined_;
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#pragma once

#include <optional>

#include <react/renderer/core/ReactPrimitives.h>
#include <react/utils/ContextContainer.h>

Expand All @@ -16,12 +18,23 @@ namespace facebook::react {
// It should be used as infrequently as possible - most props can and should
// be parsed without any context.
struct PropsParserContext {
PropsParserContext(
SurfaceId const surfaceId,
ContextContainer const &contextContainer)
: surfaceId(surfaceId), contextContainer(contextContainer) {}

// Non-copyable
PropsParserContext(const PropsParserContext &) = delete;
PropsParserContext &operator=(const PropsParserContext &) = delete;

SurfaceId const surfaceId;
ContextContainer const &contextContainer;

// Temporary feature flags
bool treatAutoAsYGValueUndefined() const;

private:
mutable std::optional<bool> treatAutoAsYGValueUndefined_;
};

} // namespace facebook::react

0 comments on commit e1876af

Please sign in to comment.