ImageShadowNode.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #pragma once
  8. #include <react/components/image/ImageEventEmitter.h>
  9. #include <react/components/image/ImageProps.h>
  10. #include <react/components/image/ImageState.h>
  11. #include <react/components/view/ConcreteViewShadowNode.h>
  12. #include <react/imagemanager/ImageManager.h>
  13. #include <react/imagemanager/primitives.h>
  14. namespace facebook {
  15. namespace react {
  16. extern const char ImageComponentName[];
  17. /*
  18. * `ShadowNode` for <Image> component.
  19. */
  20. class ImageShadowNode final : public ConcreteViewShadowNode<
  21. ImageComponentName,
  22. ImageProps,
  23. ImageEventEmitter,
  24. ImageState> {
  25. public:
  26. using ConcreteViewShadowNode::ConcreteViewShadowNode;
  27. /*
  28. * Associates a shared `ImageManager` with the node.
  29. */
  30. void setImageManager(const SharedImageManager &imageManager);
  31. static ImageState initialStateData(
  32. ShadowNodeFragment const &fragment,
  33. SurfaceId const surfaceId,
  34. ComponentDescriptor const &componentDescriptor) {
  35. auto imageSource = ImageSource{ImageSource::Type::Invalid};
  36. return {imageSource, {imageSource, nullptr}};
  37. }
  38. #pragma mark - LayoutableShadowNode
  39. void layout(LayoutContext layoutContext) override;
  40. private:
  41. ImageSource getImageSource() const;
  42. SharedImageManager imageManager_;
  43. void updateStateIfNeeded();
  44. };
  45. } // namespace react
  46. } // namespace facebook