Files
react-native/packages/rn-tester/NativeComponentWithState/ios/RNTNativeComponentWithStateCustomComponentDescriptor.h
T
Riccardo Cipolleschi 1a9cceb20b Add sample component with state in RNTester (#34909)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/34909

This Diff introduces a Sample component in RNTester which uses the NativeState to load some images.
It is an example on how to use CustomNativeState

In this first diff, I focused on the iOS side of things. The next diff will make this work with Android.

## Changelog
[iOS][Added] - Introduce sample component which work with the native state.

Reviewed By: cortinico

Differential Revision: D39884926

fbshipit-source-id: 9323d751fd06a1bb8ff93af836d97010c2095833
2022-10-10 02:51:06 -07:00

46 lines
1.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 <react/renderer/core/ConcreteComponentDescriptor.h>
#include "RNTNativeComponentWithStateCustomShadowNode.h"
namespace facebook {
namespace react {
/*
* Descriptor for <RNTNativeComponentWithStateCustomComponentDescriptor>
* component.
*/
class RNTNativeComponentWithStateCustomComponentDescriptor final
: public ConcreteComponentDescriptor<
RNTNativeComponentWithStateCustomShadowNode> {
public:
RNTNativeComponentWithStateCustomComponentDescriptor(
ComponentDescriptorParameters const &parameters)
: ConcreteComponentDescriptor(parameters),
imageManager_(std::make_shared<ImageManager>(contextContainer_)) {}
void adopt(ShadowNode::Unshared const &shadowNode) const override {
ConcreteComponentDescriptor::adopt(shadowNode);
auto compShadowNode =
std::static_pointer_cast<RNTNativeComponentWithStateCustomShadowNode>(
shadowNode);
// `RNTNativeComponentWithStateCustomShadowNode` uses `ImageManager` to
// initiate image loading and communicate the loading state
// and results to mounting layer.
compShadowNode->setImageManager(imageManager_);
}
private:
const SharedImageManager imageManager_;
};
} // namespace react
} // namespace facebook