ImageState.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 <folly/dynamic.h>
  9. #include <react/imagemanager/ImageRequest.h>
  10. #include <react/imagemanager/primitives.h>
  11. namespace facebook {
  12. namespace react {
  13. /*
  14. * State for <Image> component.
  15. */
  16. class ImageState final {
  17. public:
  18. ImageState(ImageSource const &imageSource, ImageRequest imageRequest)
  19. : imageSource_(imageSource),
  20. imageRequest_(
  21. std::make_shared<ImageRequest>(std::move(imageRequest))){};
  22. /*
  23. * Returns stored ImageSource object.
  24. */
  25. ImageSource getImageSource() const;
  26. /*
  27. * Exposes for reading stored `ImageRequest` object.
  28. * `ImageRequest` object cannot be copied or moved from `ImageLocalData`.
  29. */
  30. ImageRequest const &getImageRequest() const;
  31. #ifdef ANDROID
  32. ImageState(ImageState const &previousState, folly::dynamic data){};
  33. /*
  34. * Empty implementation for Android because it doesn't use this class.
  35. */
  36. folly::dynamic getDynamic() const {
  37. return {};
  38. };
  39. #endif
  40. private:
  41. ImageSource imageSource_;
  42. std::shared_ptr<ImageRequest> imageRequest_;
  43. };
  44. } // namespace react
  45. } // namespace facebook