Skip to content

Commit 2e94e82

Browse files
refactor: heap-allocate clipPath via unique_ptr
1 parent bd838e1 commit 2e94e82

4 files changed

Lines changed: 26 additions & 11 deletions

File tree

packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,9 +1375,9 @@ - (void)invalidateLayer
13751375
self.currentContainerView.layer.mask = nil;
13761376

13771377
// Handle clip-path property
1378-
if (_props->clipPath.has_value()) {
1378+
if (_props->clipPath != nullptr) {
13791379
if (auto yogaStylableProps = std::static_pointer_cast<const YogaStylableProps>(_props)) {
1380-
CALayer *maskLayer = [RCTClipPathUtils createClipPathLayer:_props->clipPath.value()
1380+
CALayer *maskLayer = [RCTClipPathUtils createClipPathLayer:*_props->clipPath
13811381
layoutMetrics:_layoutMetrics
13821382
yogaStylableProps:*yogaStylableProps.get()
13831383
bounds:layer.bounds

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,19 @@ BaseViewProps::BaseViewProps(
323323
"removeClippedSubviews",
324324
sourceProps.removeClippedSubviews,
325325
false)),
326-
clipPath(convertRawProp(
327-
context,
328-
rawProps,
329-
"clipPath",
330-
sourceProps.clipPath,
331-
{})) {}
326+
clipPath([&]() -> std::unique_ptr<ClipPath> {
327+
auto optionalClipPath = convertRawProp(
328+
context,
329+
rawProps,
330+
"clipPath",
331+
sourceProps.clipPath
332+
? std::make_optional(*sourceProps.clipPath)
333+
: std::nullopt,
334+
std::nullopt);
335+
return optionalClipPath
336+
? std::make_unique<ClipPath>(std::move(*optionalClipPath))
337+
: nullptr;
338+
}()) {}
332339

333340
#define VIEW_EVENT_CASE(eventType) \
334341
case CONSTEXPR_RAW_PROPS_KEY_HASH("on" #eventType): { \
@@ -391,7 +398,14 @@ void BaseViewProps::setProp(
391398
RAW_SET_PROP_SWITCH_CASE_BASIC(filter);
392399
RAW_SET_PROP_SWITCH_CASE_BASIC(boxShadow);
393400
RAW_SET_PROP_SWITCH_CASE_BASIC(mixBlendMode);
394-
RAW_SET_PROP_SWITCH_CASE_BASIC(clipPath);
401+
case CONSTEXPR_RAW_PROPS_KEY_HASH("clipPath"): {
402+
std::optional<ClipPath> parsedClipPath;
403+
fromRawValue(context, value, parsedClipPath);
404+
clipPath = parsedClipPath
405+
? std::make_unique<ClipPath>(std::move(*parsedClipPath))
406+
: nullptr;
407+
return;
408+
}
395409
// events field
396410
VIEW_EVENT_CASE(PointerEnter);
397411
VIEW_EVENT_CASE(PointerEnterCapture);

packages/react-native/ReactCommon/react/renderer/components/view/BaseViewProps.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <react/renderer/graphics/Isolation.h>
2828
#include <react/renderer/graphics/Transform.h>
2929

30+
#include <memory>
3031
#include <optional>
3132

3233
namespace facebook::react {
@@ -112,7 +113,7 @@ class BaseViewProps : public YogaStylableProps, public AccessibilityProps {
112113

113114
bool removeClippedSubviews{false};
114115

115-
std::optional<ClipPath> clipPath{};
116+
std::unique_ptr<ClipPath> clipPath{};
116117

117118
#pragma mark - Convenience Methods
118119

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void ViewShadowNode::initialize() noexcept {
5959
viewProps.mixBlendMode != BlendMode::Normal ||
6060
viewProps.isolation == Isolation::Isolate ||
6161
HostPlatformViewTraitsInitializer::formsStackingContext(viewProps) ||
62-
!viewProps.accessibilityOrder.empty() || viewProps.clipPath.has_value();
62+
!viewProps.accessibilityOrder.empty() || viewProps.clipPath != nullptr;
6363

6464
bool formsView = formsStackingContext ||
6565
isColorMeaningful(viewProps.backgroundColor) || hasBorder() ||

0 commit comments

Comments
 (0)