mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
1953f6f02e
Summary: With the `MapBuffer`-based props calculated from C++ props, there's no need to keep `rawProps` around for Android views. This change makes sure that the `rawProps` field is only initialized under the feature flag that is responsible for enabling `MapBuffer` for prop diffing, potentially decreasing memory footprint and speeding up node initialization as JS props don't have to be converted to `folly::dynamic` anymore. For layout animations, props rely on C++ values, so there's no need to update `rawProps` values either. Changelog: [Internal][Android] - Do not init `rawProps` when mapbuffer serialization is used for ViewProps. Reviewed By: mdvacca Differential Revision: D33793044 fbshipit-source-id: 35873b10d3ca8b152b25344ef2c27aff9641846f
114 lines
3.4 KiB
C++
114 lines
3.4 KiB
C++
/*
|
|
* 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 "ViewShadowNode.h"
|
|
#include <react/config/ReactNativeConfig.h>
|
|
#include <react/renderer/components/view/primitives.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
char const ViewComponentName[] = "View";
|
|
|
|
static inline bool keepRawValuesInViewProps(PropsParserContext const &context) {
|
|
static bool shouldUseRawProps = true;
|
|
|
|
#ifdef ANDROID
|
|
static bool initialized = false;
|
|
|
|
if (!initialized) {
|
|
auto config =
|
|
context.contextContainer.find<std::shared_ptr<const ReactNativeConfig>>(
|
|
"ReactNativeConfig");
|
|
if (config.has_value()) {
|
|
initialized = true;
|
|
shouldUseRawProps = !config.value()->getBool(
|
|
"react_native_new_architecture:use_mapbuffer_for_viewprops");
|
|
}
|
|
}
|
|
#endif
|
|
|
|
return shouldUseRawProps;
|
|
}
|
|
|
|
ViewShadowNodeProps::ViewShadowNodeProps(
|
|
PropsParserContext const &context,
|
|
ViewShadowNodeProps const &sourceProps,
|
|
RawProps const &rawProps)
|
|
: ViewProps(
|
|
context,
|
|
sourceProps,
|
|
rawProps,
|
|
keepRawValuesInViewProps(context)){};
|
|
|
|
ViewShadowNode::ViewShadowNode(
|
|
ShadowNodeFragment const &fragment,
|
|
ShadowNodeFamily::Shared const &family,
|
|
ShadowNodeTraits traits)
|
|
: ConcreteViewShadowNode(fragment, family, traits) {
|
|
initialize();
|
|
}
|
|
|
|
ViewShadowNode::ViewShadowNode(
|
|
ShadowNode const &sourceShadowNode,
|
|
ShadowNodeFragment const &fragment)
|
|
: ConcreteViewShadowNode(sourceShadowNode, fragment) {
|
|
initialize();
|
|
}
|
|
|
|
void ViewShadowNode::initialize() noexcept {
|
|
auto &viewProps = static_cast<ViewProps const &>(*props_);
|
|
|
|
bool formsStackingContext = !viewProps.collapsable ||
|
|
viewProps.pointerEvents == PointerEventsMode::None ||
|
|
!viewProps.nativeId.empty() || viewProps.accessible ||
|
|
viewProps.opacity != 1.0 || viewProps.transform != Transform{} ||
|
|
(viewProps.zIndex.has_value() &&
|
|
viewProps.yogaStyle.positionType() != YGPositionTypeStatic) ||
|
|
viewProps.yogaStyle.display() == YGDisplayNone ||
|
|
viewProps.getClipsContentToBounds() ||
|
|
isColorMeaningful(viewProps.shadowColor) ||
|
|
viewProps.accessibilityElementsHidden ||
|
|
viewProps.accessibilityViewIsModal ||
|
|
viewProps.importantForAccessibility != ImportantForAccessibility::Auto ||
|
|
viewProps.removeClippedSubviews;
|
|
|
|
#ifdef ANDROID
|
|
formsStackingContext = formsStackingContext || viewProps.elevation != 0;
|
|
#endif
|
|
|
|
bool formsView = formsStackingContext ||
|
|
isColorMeaningful(viewProps.backgroundColor) ||
|
|
isColorMeaningful(viewProps.foregroundColor) ||
|
|
viewProps.events.bits.any() ||
|
|
!(viewProps.yogaStyle.border() == YGStyle::Edges{}) ||
|
|
!viewProps.testId.empty();
|
|
|
|
#ifdef ANDROID
|
|
formsView = formsView || viewProps.nativeBackground.has_value() ||
|
|
viewProps.nativeForeground.has_value() || viewProps.focusable ||
|
|
viewProps.hasTVPreferredFocus ||
|
|
viewProps.needsOffscreenAlphaCompositing ||
|
|
viewProps.renderToHardwareTextureAndroid;
|
|
#endif
|
|
|
|
if (formsView) {
|
|
traits_.set(ShadowNodeTraits::Trait::FormsView);
|
|
} else {
|
|
traits_.unset(ShadowNodeTraits::Trait::FormsView);
|
|
}
|
|
|
|
if (formsStackingContext) {
|
|
traits_.set(ShadowNodeTraits::Trait::FormsStackingContext);
|
|
} else {
|
|
traits_.unset(ShadowNodeTraits::Trait::FormsStackingContext);
|
|
}
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|