mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-06 07:06:11 +00:00
Changed `requireNativeComponent` to `codegenNativeComponent` so that upcoming changes (Static View Configs, Bridgeless Mode and idk what more) in `react-native` are available in the library. Also, types and native components are now taken directly from `fabric` folder to make sure the values passed to the native components are the ones defined in props. It should work on all supported versions since `codegenNativeComponent` function exists from RN v. 0.61.0. Suggested by @RSNara and @cipolleschi Reason for [`5394bbb` (#1847)](5394bbbced): - on `Paper`, `Animated` uses `setNativeProps` method when we set `useNativeDriver` to `false`, and does not rerender the component. Therefore, new transform lands only in `SvgView` and is parsed in `RCTViewManager.m` . - on `Fabric`, the same code makes the components rerender. Due to this, information about new transform is passed to the `SvgView` child: `G` , making it apply translations from the transform in its `updateProps` method. - other than `Animated` use-case, on both archs, if we just passed `transform` prop to `Svg` component, it would end up in double transformations now as well. All of those changes are due to https://github.com/software-mansion/react-native-svg/pull/1895, which added proper parsing of RN style `transform` prop (array of transformations objects) therefore making `G` properly handle `transform` prop passed from `Svg`. Reason for [`19bcb24` (#1847)](19bcb2464b): Same as https://github.com/software-mansion/react-native-screens/pull/1624
64 lines
1.5 KiB
C++
64 lines
1.5 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 <cstdlib>
|
|
#include <limits>
|
|
|
|
#include <react/renderer/core/LayoutContext.h>
|
|
|
|
#include "RNSVGImageShadowNode.h"
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
const char RNSVGImageComponentName[] = "RNSVGImage";
|
|
|
|
void RNSVGImageShadowNode::setImageManager(
|
|
const SharedImageManager &imageManager) {
|
|
ensureUnsealed();
|
|
imageManager_ = imageManager;
|
|
}
|
|
|
|
ImageSource RNSVGImageShadowNode::getImageSource() const {
|
|
auto source = getConcreteProps().src;
|
|
|
|
auto layoutMetrics = getLayoutMetrics();
|
|
auto size = layoutMetrics.getContentFrame().size;
|
|
auto scale = layoutMetrics.pointScaleFactor;
|
|
source.size = size;
|
|
source.scale = scale;
|
|
return source;
|
|
}
|
|
|
|
void RNSVGImageShadowNode::updateStateIfNeeded() {
|
|
ensureUnsealed();
|
|
|
|
auto imageSource = getImageSource();
|
|
auto const ¤tState = getStateData();
|
|
bool hasSameImageSource = currentState.getImageSource() == imageSource;
|
|
|
|
if (hasSameImageSource) {
|
|
return;
|
|
}
|
|
|
|
auto state = RNSVGImageState{
|
|
imageSource,
|
|
imageManager_->requestImage(imageSource, getSurfaceId()),
|
|
};
|
|
setStateData(std::move(state));
|
|
}
|
|
|
|
#pragma mark - LayoutableShadowNode
|
|
|
|
void RNSVGImageShadowNode::layout(LayoutContext layoutContext) {
|
|
updateStateIfNeeded();
|
|
ConcreteViewShadowNode::layout(layoutContext);
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|