mirror of
https://github.com/status-im/react-native.git
synced 2025-01-17 21:11:45 +00:00
0fc5a91889
Summary: In order to dispatch event, `EventHandlers` must also know react tag. So we have to store it inside. We plan to illuminate this requirement (and `tag` from `EventHandlers`) eventually. Reviewed By: fkgozali Differential Revision: D8211685 fbshipit-source-id: 2064c0f4a7869cbf4d2c92d0349f4ee3998cb8f5
59 lines
1.4 KiB
C++
59 lines
1.4 KiB
C++
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
*
|
|
* 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 <memory>
|
|
|
|
#include <folly/dynamic.h>
|
|
#include <fabric/core/EventDispatcher.h>
|
|
#include <fabric/core/EventPrimitives.h>
|
|
#include <fabric/core/ReactPrimitives.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
class EventHandlers;
|
|
|
|
using SharedEventHandlers = std::shared_ptr<const EventHandlers>;
|
|
|
|
|
|
|
|
/*
|
|
* Base class for all particular typed event handlers.
|
|
* Stores `InstanceHandle` identifying a particular component and the pointer
|
|
* to `EventDispatcher` which is responsible for delivering the event.
|
|
*
|
|
* TODO: Reconsider naming of all event-related things.
|
|
*/
|
|
class EventHandlers {
|
|
|
|
public:
|
|
virtual ~EventHandlers() = default;
|
|
EventHandlers(const InstanceHandle &instanceHandle, const Tag &tag, const SharedEventDispatcher &eventDispatcher);
|
|
|
|
protected:
|
|
|
|
/*
|
|
* Initates an event delivery process.
|
|
* Is used by particular subclasses only.
|
|
*/
|
|
void dispatchEvent(
|
|
const std::string &type,
|
|
const folly::dynamic &payload = folly::dynamic::object(),
|
|
const EventPriority &priority = EventPriority::AsynchronousBatched
|
|
) const;
|
|
|
|
private:
|
|
|
|
InstanceHandle instanceHandle_;
|
|
Tag tag_;
|
|
std::weak_ptr<const EventDispatcher> eventDispatcher_;
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|