mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
e51e19ecc1
Summary: Minimal set of changes to intercept events in external modules. Current intended use-case is for Reanimated to handle events for the Animated properties. Changelog: [Added] Add listeners to allow intercepting events in C++ core. Reviewed By: cipolleschi Differential Revision: D35312534 fbshipit-source-id: ec924b57fd0c0dabf7be7b886dbef23bf3170d6c
81 lines
2.4 KiB
C++
81 lines
2.4 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and 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/core/BatchedEventQueue.h>
|
|
#include <react/renderer/core/EventBeat.h>
|
|
#include <react/renderer/core/EventListener.h>
|
|
#include <react/renderer/core/EventPriority.h>
|
|
#include <react/renderer/core/EventQueueProcessor.h>
|
|
#include <react/renderer/core/StateUpdate.h>
|
|
#include <react/renderer/core/UnbatchedEventQueue.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
struct RawEvent;
|
|
|
|
/*
|
|
* Represents event-delivery infrastructure.
|
|
* Particular `EventEmitter` clases use this for sending events.
|
|
*/
|
|
class EventDispatcher {
|
|
public:
|
|
using Shared = std::shared_ptr<EventDispatcher const>;
|
|
using Weak = std::weak_ptr<EventDispatcher const>;
|
|
|
|
EventDispatcher(
|
|
EventQueueProcessor const &eventProcessor,
|
|
EventBeat::Factory const &synchonousEventBeatFactory,
|
|
EventBeat::Factory const &asynchonousEventBeatFactory,
|
|
EventBeat::SharedOwnerBox const &ownerBox);
|
|
|
|
/*
|
|
* Dispatches a raw event with given priority using event-delivery pipe.
|
|
*/
|
|
void dispatchEvent(RawEvent &&rawEvent, EventPriority priority) const;
|
|
|
|
/*
|
|
* Dispatches a raw event with asynchronous batched priority. Before the
|
|
* dispatch we make sure that no other RawEvent of same type and same target
|
|
* is on the queue.
|
|
*/
|
|
void dispatchUniqueEvent(RawEvent &&rawEvent) const;
|
|
|
|
/*
|
|
* Dispatches a state update with given priority.
|
|
*/
|
|
void dispatchStateUpdate(StateUpdate &&stateUpdate, EventPriority priority)
|
|
const;
|
|
|
|
#pragma mark - Event listeners
|
|
/*
|
|
* Adds provided event listener to the event dispatcher.
|
|
*/
|
|
void addListener(const std::shared_ptr<EventListener const> &listener) const;
|
|
|
|
/*
|
|
* Removes provided event listener to the event dispatcher.
|
|
*/
|
|
void removeListener(
|
|
const std::shared_ptr<EventListener const> &listener) const;
|
|
|
|
private:
|
|
EventQueue const &getEventQueue(EventPriority priority) const;
|
|
|
|
std::unique_ptr<UnbatchedEventQueue> synchronousUnbatchedQueue_;
|
|
std::unique_ptr<BatchedEventQueue> synchronousBatchedQueue_;
|
|
std::unique_ptr<UnbatchedEventQueue> asynchronousUnbatchedQueue_;
|
|
std::unique_ptr<BatchedEventQueue> asynchronousBatchedQueue_;
|
|
|
|
mutable EventListenerContainer eventListeners_;
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|