Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/40866

This type doesn't do anything, and we can replace it with a `jsi::Function` inside `UIManagerBinding`.

Changelog: [Internal]

Reviewed By: rubennorte

Differential Revision: D50176084

fbshipit-source-id: 1c782f3e4d212f1d956451fd650d3ed5ed8f0d71
This commit is contained in:
Pieter De Baets 2023-10-16 10:28:20 -07:00 коммит произвёл Facebook GitHub Bot
Родитель f308f0273c
Коммит 50522cfbbf
4 изменённых файлов: 9 добавлений и 46 удалений

Просмотреть файл

@ -1,28 +0,0 @@
/*
* 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 <memory>
namespace facebook::react {
/*
* We need this types only to ensure type-safety when we deal with them.
* Conceptually, they are opaque pointers to some types that derived from those
* classes.
*
* `EventHandler` is managed as a `unique_ptr`, so it must have a *virtual*
* destructor to allow proper deallocation having only a pointer
* to the base (`EventHandler`) class.
*/
struct EventHandler {
virtual ~EventHandler() = default;
};
using UniqueEventHandler = std::unique_ptr<const EventHandler>;
} // namespace facebook::react

Просмотреть файл

@ -155,15 +155,14 @@ void UIManagerBinding::dispatchEventToJS(
LOG(WARNING) << "instanceHandle is null, event will be dropped";
}
auto& eventHandlerWrapper =
static_cast<const EventHandlerWrapper&>(*eventHandler_);
currentEventPriority_ = priority;
eventHandlerWrapper.callback.call(
runtime,
{std::move(instanceHandle),
jsi::String::createFromUtf8(runtime, type),
std::move(payload)});
if (eventHandler_) {
eventHandler_->call(
runtime,
std::move(instanceHandle),
jsi::String::createFromUtf8(runtime, type),
std::move(payload));
}
currentEventPriority_ = ReactEventPriority::Default;
}
@ -545,7 +544,7 @@ jsi::Value UIManagerBinding::get(
auto eventHandler =
arguments[0].getObject(runtime).getFunction(runtime);
eventHandler_ =
std::make_unique<EventHandlerWrapper>(std::move(eventHandler));
std::make_unique<jsi::Function>(std::move(eventHandler));
return jsi::Value::undefined();
});
}

Просмотреть файл

@ -84,7 +84,7 @@ class UIManagerBinding : public jsi::HostObject {
const EventPayload& payload) const;
std::shared_ptr<UIManager> uiManager_;
std::unique_ptr<const EventHandler> eventHandler_;
std::unique_ptr<jsi::Function> eventHandler_;
mutable PointerEventsProcessor pointerEventsProcessor_;
mutable ReactEventPriority currentEventPriority_;
};

Просмотреть файл

@ -12,7 +12,6 @@
#include <jsi/jsi.h>
#include <react/debug/react_native_assert.h>
#include <react/renderer/components/text/RawTextShadowNode.h>
#include <react/renderer/core/EventHandler.h>
#include <react/renderer/core/LayoutMetrics.h>
#include <react/renderer/core/ShadowNode.h>
#include <react/renderer/core/TraitCast.h>
@ -23,13 +22,6 @@ namespace facebook::react {
using BackgroundExecutor =
std::function<void(std::function<void()>&& callback)>;
struct EventHandlerWrapper : public EventHandler {
EventHandlerWrapper(jsi::Function eventHandler)
: callback(std::move(eventHandler)) {}
jsi::Function callback;
};
struct ShadowNodeListWrapper : public jsi::NativeState {
ShadowNodeListWrapper(ShadowNode::UnsharedListOfShared shadowNodeList)
: shadowNodeList(std::move(shadowNodeList)) {}