2018-05-22 22:48:19 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SchedulerEventDispatcher.h"
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
2018-06-01 16:36:25 +00:00
|
|
|
// TODO(T29874519): Get rid of "top" prefix once and for all.
|
|
|
|
/*
|
|
|
|
* Capitalizes the first letter of the event type and adds "top" prefix
|
|
|
|
* (e.g. "layout" becames "topLayout").
|
|
|
|
*/
|
|
|
|
static std::string normalizeEventType(const std::string &type) {
|
|
|
|
std::string prefixedType = type;
|
|
|
|
prefixedType[0] = toupper(prefixedType[0]);
|
|
|
|
prefixedType.insert(0, "top");
|
|
|
|
return prefixedType;
|
|
|
|
}
|
|
|
|
|
2018-06-15 17:56:40 +00:00
|
|
|
void SchedulerEventDispatcher::setUIManager(std::shared_ptr<const FabricUIManager> uiManager) const {
|
2018-06-01 16:36:25 +00:00
|
|
|
uiManager_ = uiManager;
|
|
|
|
}
|
|
|
|
|
2018-05-22 22:48:19 +00:00
|
|
|
void SchedulerEventDispatcher::dispatchEvent(
|
2018-06-01 16:36:25 +00:00
|
|
|
const EventTarget &eventTarget,
|
|
|
|
const std::string &type,
|
2018-05-22 22:48:19 +00:00
|
|
|
const folly::dynamic &payload,
|
|
|
|
const EventPriority &priority
|
|
|
|
) const {
|
2018-06-21 21:14:59 +00:00
|
|
|
if (!uiManager_) {
|
|
|
|
return;
|
|
|
|
}
|
2018-06-15 17:56:38 +00:00
|
|
|
// TODO: Schedule the event based on priority.
|
2018-06-29 22:30:30 +00:00
|
|
|
uiManager_->dispatchEventToTarget(eventTarget, normalizeEventType(type), payload);
|
2018-05-22 22:48:19 +00:00
|
|
|
}
|
|
|
|
|
2018-06-21 21:14:59 +00:00
|
|
|
void SchedulerEventDispatcher::releaseEventTarget(const EventTarget &eventTarget) const {
|
|
|
|
if (!uiManager_) {
|
|
|
|
return;
|
|
|
|
}
|
2018-06-29 22:30:30 +00:00
|
|
|
// TODO(shergin): This needs to move to the destructor of EventEmitter. For now we'll leak.
|
|
|
|
// uiManager_->releaseEventTarget(eventTarget);
|
2018-06-21 21:14:59 +00:00
|
|
|
}
|
|
|
|
|
2018-05-22 22:48:19 +00:00
|
|
|
} // namespace react
|
|
|
|
} // namespace facebook
|