mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-06 07:06:11 +00:00
# Summary Implement custom shadow nodes for nearly all `Svg` components. While it's a foundation for numerous upcoming changes, it currently addresses and resolves #2544. ## Test Plan There shouldn't be any noticeable changes, and everything should function as before, except that `onLayout` will now be triggered only once and with the correct dimensions. ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ✅ | | MacOS | ✅ | | Android | ✅ | --------- Co-authored-by: Jakub Piasecki <jakubpiasecki67@gmail.com>
43 lines
1.8 KiB
C++
43 lines
1.8 KiB
C++
#include "RNSVGLayoutableShadowNode.h"
|
|
#include <react/renderer/core/LayoutContext.h>
|
|
|
|
namespace facebook::react {
|
|
|
|
RNSVGLayoutableShadowNode::RNSVGLayoutableShadowNode(
|
|
const ShadowNodeFragment &fragment,
|
|
const ShadowNodeFamily::Shared &family,
|
|
ShadowNodeTraits traits)
|
|
: YogaLayoutableShadowNode(fragment, family, traits) {
|
|
// SVG handles its layout manually on the native side and does not depend on
|
|
// the Yoga layout. Setting the dimensions to 0 eliminates randomly positioned
|
|
// views in the layout inspector when Yoga attempts to interpret SVG
|
|
// properties like width when viewBox scale is set.
|
|
auto style = yogaNode_.style();
|
|
style.setDimension(yoga::Dimension::Width, yoga::value::points(0));
|
|
style.setDimension(yoga::Dimension::Height, yoga::value::points(0));
|
|
yogaNode_.setStyle(style);
|
|
}
|
|
|
|
RNSVGLayoutableShadowNode::RNSVGLayoutableShadowNode(
|
|
const ShadowNode &sourceShadowNode,
|
|
const ShadowNodeFragment &fragment)
|
|
: YogaLayoutableShadowNode(sourceShadowNode, fragment) {
|
|
// SVG handles its layout manually on the native side and does not depend on
|
|
// the Yoga layout. Setting the dimensions to 0 eliminates randomly positioned
|
|
// views in the layout inspector when Yoga attempts to interpret SVG
|
|
// properties like width when viewBox scale is set.
|
|
auto style = yogaNode_.style();
|
|
style.setDimension(yoga::Dimension::Width, yoga::value::points(0));
|
|
style.setDimension(yoga::Dimension::Height, yoga::value::points(0));
|
|
yogaNode_.setStyle(style);
|
|
}
|
|
|
|
void RNSVGLayoutableShadowNode::layout(LayoutContext layoutContext) {
|
|
auto affectedNodes = layoutContext.affectedNodes;
|
|
layoutContext.affectedNodes = nullptr;
|
|
YogaLayoutableShadowNode::layout(layoutContext);
|
|
layoutContext.affectedNodes = affectedNodes;
|
|
}
|
|
|
|
} // namespace facebook::react
|