react-native/ReactCommon/fabric/components/image/ImageComponentDescriptor.h
Spencer Ahrens 34ea65e3d9 tighter ContextContainer semantics
Summary:
shergin mentioned that he'd like to move away from RTTI a bit and use explicit key strings for context container instances rather than relying on the `typeid`, so this does this.

We also fatal with a useful error message if we get a collision, rather than failing silently.

Reviewed By: shergin

Differential Revision: D13384308

fbshipit-source-id: 0b06d7555b082be89e8f130c23e94be99749a7a3
2018-12-21 18:00:36 -08:00

52 lines
1.5 KiB
C++

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <react/components/image/ImageShadowNode.h>
#include <react/core/ConcreteComponentDescriptor.h>
#include <react/imagemanager/ImageManager.h>
#include <react/uimanager/ContextContainer.h>
namespace facebook {
namespace react {
/*
* Descriptor for <Image> component.
*/
class ImageComponentDescriptor final
: public ConcreteComponentDescriptor<ImageShadowNode> {
public:
ImageComponentDescriptor(
SharedEventDispatcher eventDispatcher,
const SharedContextContainer &contextContainer)
: ConcreteComponentDescriptor(eventDispatcher),
imageManager_(
contextContainer
? contextContainer->getInstance<SharedImageManager>(
"ImageManager")
: nullptr) {}
void adopt(UnsharedShadowNode shadowNode) const override {
ConcreteComponentDescriptor::adopt(shadowNode);
assert(std::dynamic_pointer_cast<ImageShadowNode>(shadowNode));
auto imageShadowNode =
std::static_pointer_cast<ImageShadowNode>(shadowNode);
// `ImageShadowNode` uses `ImageManager` to initiate image loading and
// communicate the loading state and results to mounting layer.
imageShadowNode->setImageManager(imageManager_);
}
private:
const SharedImageManager imageManager_;
};
} // namespace react
} // namespace facebook