mirror of
https://github.com/status-im/react-native.git
synced 2025-01-17 04:50:59 +00:00
2ca4770011
Summary: Calling the event emitters on the main thread seems to be problematic, so let's dispatch it via the JS thread. This requires some changes to make "eventTarget" single-use because otherwise the binding would need to synchronize the actual JS call with the act of releasing the target. Reviewed By: shergin Differential Revision: D8375291 fbshipit-source-id: bd2b42731176ae209f4a19c232309c163fb1c01b
45 lines
1.3 KiB
C++
45 lines
1.3 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.
|
|
*/
|
|
|
|
#include "SchedulerEventDispatcher.h"
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
// 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;
|
|
}
|
|
|
|
void SchedulerEventDispatcher::setUIManager(std::shared_ptr<const FabricUIManager> uiManager) {
|
|
uiManager_ = uiManager;
|
|
}
|
|
|
|
EventTarget SchedulerEventDispatcher::createEventTarget(const InstanceHandle &instanceHandle) const {
|
|
return uiManager_->createEventTarget(instanceHandle);
|
|
}
|
|
|
|
void SchedulerEventDispatcher::dispatchEvent(
|
|
const EventTarget &eventTarget,
|
|
const std::string &type,
|
|
const folly::dynamic &payload,
|
|
const EventPriority &priority
|
|
) const {
|
|
// TODO: Schedule the event based on priority.
|
|
uiManager_->dispatchEvent(eventTarget, normalizeEventType(type), payload);
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|