Files
react-native/ReactCommon/react/renderer/core/EventDispatcher.h
T
Samuel Susla 2669118fc8 Make event coalescing more aggressive
Summary:
Changelog: [internal]

Previous implementation of coalescing would only look at the last element in `eventQueue_` and if it was the same type and target, it would coalesce the two together. This was problem when user would scroll in UIScrollView, this triggers onTouchMove and onScroll events at high rates and prevents coalescing of them.

This changes changes the behaviour to search the `eventQueue_` backwards for an event of the same type and target. If one if found, it is moved into its place. If even of another type is found before for the same target, the event is pushed back onto the queue.

Reviewed By: JoshuaGross

Differential Revision: D24992941

fbshipit-source-id: fc1eae4ecd100af6202346674778b0634ed7a15b
2020-11-17 04:21:01 -08:00

72 lines
2.1 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 <array>
#include <memory>
#include <react/renderer/core/BatchedEventQueue.h>
#include <react/renderer/core/EventBeat.h>
#include <react/renderer/core/EventPipe.h>
#include <react/renderer/core/EventPriority.h>
#include <react/renderer/core/StatePipe.h>
#include <react/renderer/core/StateUpdate.h>
#include <react/renderer/core/UnbatchedEventQueue.h>
namespace facebook {
namespace react {
class 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(
EventPipe const &eventPipe,
StatePipe const &statePipe,
EventBeat::Factory const &synchonousEventBeatFactory,
EventBeat::Factory const &asynchonousEventBeatFactory,
EventBeat::SharedOwnerBox const &ownerBox,
bool enableV2EventCoalescing);
/*
* Dispatches a raw event with given priority using event-delivery pipe.
*/
void dispatchEvent(RawEvent const &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 const &rawEvent) const;
/*
* Dispatches a state update with given priority.
*/
void dispatchStateUpdate(StateUpdate &&stateUpdate, EventPriority priority)
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_;
};
} // namespace react
} // namespace facebook