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;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventTarget SchedulerEventDispatcher::createEventTarget(const InstanceHandle &instanceHandle) const {
|
2018-06-21 21:14:59 +00:00
|
|
|
assert(uiManager_ && "Attempted to create EventTarget after FabricUIManager dies.");
|
2018-06-01 16:36:25 +00:00
|
|
|
return uiManager_->createEventTarget(instanceHandle);
|
|
|
|
}
|
|
|
|
|
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-01 16:36:25 +00:00
|
|
|
uiManager_->dispatchEvent(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;
|
|
|
|
}
|
|
|
|
uiManager_->releaseEventTarget(eventTarget);
|
|
|
|
}
|
|
|
|
|
2018-05-22 22:48:19 +00:00
|
|
|
} // namespace react
|
|
|
|
} // namespace facebook
|