mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
bfbd841f38
Summary: Changelog: [internal] `moved_`, introduced in D8526571 (https://github.com/facebook/react-native/commit/979ea2094e74ae8da0288fd5038f1f2838bd7763), no longer servers its purpose. Let's remove it. Reviewed By: JoshuaGross Differential Revision: D24475715 fbshipit-source-id: 162d1fc4ed3d4a67885d8f140904dd80763dcaa0
103 lines
2.8 KiB
C++
103 lines
2.8 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/renderer/imagemanager/ImageResponse.h>
|
|
#include <react/renderer/imagemanager/ImageResponseObserver.h>
|
|
#include <react/renderer/imagemanager/ImageResponseObserverCoordinator.h>
|
|
#include <react/renderer/imagemanager/ImageTelemetry.h>
|
|
#include <react/renderer/imagemanager/primitives.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
/*
|
|
* Represents ongoing request for an image resource.
|
|
* The separate object must be constructed for every single separate
|
|
* image request. The object cannot be copied because it would make managing of
|
|
* event listeners hard and inefficient; the object can be moved though.
|
|
* Destroy to cancel the underlying request.
|
|
*/
|
|
class ImageRequest final {
|
|
public:
|
|
/*
|
|
* The default constructor
|
|
*/
|
|
ImageRequest(
|
|
const ImageSource &imageSource,
|
|
std::shared_ptr<const ImageTelemetry> telemetry);
|
|
|
|
/*
|
|
* The move constructor.
|
|
*/
|
|
ImageRequest(ImageRequest &&other) noexcept;
|
|
|
|
/*
|
|
* `ImageRequest` does not support copying by design.
|
|
*/
|
|
ImageRequest(const ImageRequest &other) = delete;
|
|
|
|
~ImageRequest();
|
|
|
|
/**
|
|
* Set cancelation function.
|
|
*/
|
|
void setCancelationFunction(std::function<void(void)> cancelationFunction);
|
|
|
|
/*
|
|
* Returns the Image Source associated with the request.
|
|
*/
|
|
const ImageSource getImageSource() const {
|
|
return imageSource_;
|
|
}
|
|
|
|
/*
|
|
* Returns stored observer coordinator as a shared pointer.
|
|
* Retain this *or* `ImageRequest` to ensure a correct lifetime of the object.
|
|
*/
|
|
const std::shared_ptr<const ImageResponseObserverCoordinator>
|
|
&getSharedObserverCoordinator() const;
|
|
|
|
/*
|
|
* Returns stored observer coordinator as a reference.
|
|
* Use this if a correct lifetime of the object is ensured in some other way
|
|
* (e.g. by retaining an `ImageRequest`).
|
|
*/
|
|
const ImageResponseObserverCoordinator &getObserverCoordinator() const;
|
|
|
|
/*
|
|
* Returns stored image telemetry object as a shared pointer.
|
|
* Retain this *or* `ImageRequest` to ensure a correct lifetime of the object.
|
|
*/
|
|
const std::shared_ptr<const ImageTelemetry> &getSharedTelemetry() const;
|
|
|
|
private:
|
|
/*
|
|
* Image source associated with the request.
|
|
*/
|
|
ImageSource imageSource_;
|
|
|
|
/*
|
|
* Image telemetry associated with the request.
|
|
*/
|
|
std::shared_ptr<const ImageTelemetry> telemetry_{};
|
|
|
|
/*
|
|
* Event coordinator associated with the reqest.
|
|
*/
|
|
std::shared_ptr<const ImageResponseObserverCoordinator> coordinator_{};
|
|
|
|
/*
|
|
* Function we can call to cancel image request (see destructor).
|
|
*/
|
|
std::function<void(void)> cancelRequest_;
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|