Skip to content

Commit 73fd450

Browse files
committed
feat(android): add NeedsComputedBoxModel trait for clipPath handling
1 parent 962c1ef commit 73fd450

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <react/featureflags/ReactNativeFeatureFlags.h>
1717
#include <react/jni/ReadableNativeMap.h>
1818
#include <react/renderer/components/scrollview/ScrollViewProps.h>
19-
#include <react/renderer/components/view/BaseViewProps.h>
2019
#include <react/renderer/components/view/conversions.h>
2120
#include <react/renderer/core/DynamicPropsUtilities.h>
2221
#include <react/renderer/core/conversions.h>
@@ -65,9 +64,8 @@ void FabricMountingManager::setComputedBoxModelRegistry(
6564

6665
namespace {
6766

68-
inline bool hasClipPath(const ShadowView& shadowView) {
69-
auto props = std::dynamic_pointer_cast<const BaseViewProps>(shadowView.props);
70-
return props && props->clipPath.has_value();
67+
inline bool needsComputedBoxModel(const ShadowView& shadowView) {
68+
return shadowView.traits.check(ShadowNodeTraits::Trait::NeedsComputedBoxModel);
7169
}
7270

7371
#ifdef REACT_NATIVE_DEBUG
@@ -718,14 +716,14 @@ void FabricMountingManager::executeMount(
718716
}
719717

720718
// Store BoxModel data (margin and padding) only if layout
721-
// information has changed and clipPath prop is present. This
722-
// information is needed for proper calculation of the clipPath
719+
// information has changed and NeedsComputedBoxModel trait is set.
720+
// This information is needed for proper calculation of the clipPath
723721
// geometry box.
724-
auto oldHasClipPath = hasClipPath(oldChildShadowView);
725-
auto newHasClipPath = hasClipPath(newChildShadowView);
722+
auto oldNeedsComputedBoxModel = needsComputedBoxModel(oldChildShadowView);
723+
auto newNeedsComputedBoxModel = needsComputedBoxModel(newChildShadowView);
726724

727725
if (computedBoxModelRegistry_) {
728-
if (newHasClipPath &&
726+
if (newNeedsComputedBoxModel &&
729727
(oldChildShadowView.layoutMetrics.marginInsets !=
730728
newChildShadowView.layoutMetrics.marginInsets ||
731729
oldChildShadowView.layoutMetrics.paddingInsets !=
@@ -735,7 +733,7 @@ void FabricMountingManager::executeMount(
735733
newChildShadowView.tag,
736734
newChildShadowView.layoutMetrics.marginInsets,
737735
newChildShadowView.layoutMetrics.paddingInsets);
738-
} else if (oldHasClipPath && !newHasClipPath) {
736+
} else if (oldNeedsComputedBoxModel && !newNeedsComputedBoxModel) {
739737
computedBoxModelRegistry_->remove(
740738
surfaceId, newChildShadowView.tag);
741739
}
@@ -828,7 +826,7 @@ void FabricMountingManager::executeMount(
828826
// information has changed and clipPath prop is present. This
829827
// information is needed for proper calculation of the clipPath
830828
// geometry box.
831-
if (hasClipPath(newChildShadowView)) {
829+
if (needsComputedBoxModel(newChildShadowView)) {
832830
if (computedBoxModelRegistry_) {
833831
computedBoxModelRegistry_->store(
834832
surfaceId,

packages/react-native/ReactCommon/react/renderer/components/view/ViewShadowNode.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ void ViewShadowNode::initialize() noexcept {
9090
} else {
9191
traits_.unset(ShadowNodeTraits::Trait::ChildrenFormStackingContext);
9292
}
93+
94+
if (viewProps.clipPath.has_value()) {
95+
traits_.set(ShadowNodeTraits::Trait::NeedsComputedBoxModel);
96+
} else {
97+
traits_.unset(ShadowNodeTraits::Trait::NeedsComputedBoxModel);
98+
}
9399
}
94100

95101
} // namespace facebook::react

packages/react-native/ReactCommon/react/renderer/core/ShadowNodeTraits.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ class ShadowNodeTraits {
9191
// **Deprecated**: This trait is deprecated and will be removed in a future
9292
// version of React Native.
9393
DirtyYogaNode = 1 << 14,
94+
95+
// Indicates that the `ShadowNode` needs to store computed box model
96+
// information (margin and padding) for proper calculation of the clipPath
97+
// geometry box.
98+
NeedsComputedBoxModel = 1 << 15,
9499
};
95100

96101
/*

0 commit comments

Comments
 (0)