Skip to content

Commit 77cb2ba

Browse files
sammy-SCmeta-codesync[bot]
authored andcommitted
Fix const-correctness for EventTarget (#55681)
Summary: Pull Request resolved: #55681 Changelog: [Internal] Remove incorrect const qualifier from setter/modifier methods in EventTarget. This is part of a larger effort to fix const-correctness throughout the React Native Fabric codebase. Reviewed By: javache Differential Revision: D90763776 fbshipit-source-id: 06ba88ea3082f792e1b38660ad67a3f6ce7b0845
1 parent 017bf1a commit 77cb2ba

File tree

8 files changed

+18
-20
lines changed

8 files changed

+18
-20
lines changed

packages/react-native/ReactCommon/react/renderer/core/EventPipe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace facebook::react {
2020

2121
using EventPipe = std::function<void(
2222
jsi::Runtime &runtime,
23-
const EventTarget *eventTarget,
23+
EventTarget *eventTarget,
2424
const std::string &type,
2525
ReactEventPriority priority,
2626
const EventPayload &payload)>;

packages/react-native/ReactCommon/react/renderer/core/EventTarget.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ EventTarget::EventTarget(
2020
surfaceId_(surfaceId),
2121
strongInstanceHandle_(jsi::Value::null()) {}
2222

23-
void EventTarget::setEnabled(bool enabled) const {
23+
void EventTarget::setEnabled(bool enabled) {
2424
enabled_ = enabled;
2525
}
2626

27-
void EventTarget::retain(jsi::Runtime& runtime) const {
27+
void EventTarget::retain(jsi::Runtime& runtime) {
2828
if (!enabled_) {
2929
return;
3030
}
@@ -46,7 +46,7 @@ void EventTarget::retain(jsi::Runtime& runtime) const {
4646
// react_native_assert(!strongInstanceHandle_.isUndefined());
4747
}
4848

49-
void EventTarget::release(jsi::Runtime& /*runtime*/) const {
49+
void EventTarget::release(jsi::Runtime& /*runtime*/) {
5050
// The method does not use `jsi::Runtime` reference.
5151
// It takes it only to ensure thread-safety (if the caller has the reference,
5252
// we are on a proper thread).

packages/react-native/ReactCommon/react/renderer/core/EventTarget.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ class EventTarget {
4040
* Sets the `enabled` flag that allows creating a strong instance handle from
4141
* a weak one.
4242
*/
43-
void setEnabled(bool enabled) const;
43+
void setEnabled(bool enabled);
4444

4545
/*
4646
* Retains an instance handler by creating a strong reference to it.
4747
* If the EventTarget is disabled, does nothing.
4848
*/
49-
void retain(jsi::Runtime &runtime) const;
49+
void retain(jsi::Runtime &runtime);
5050

5151
/*
5252
* Releases the instance handler by nulling a strong reference to it.
5353
*/
54-
void release(jsi::Runtime &runtime) const;
54+
void release(jsi::Runtime &runtime);
5555

5656
/*
5757
* Creates and returns the `instanceHandle`.
@@ -69,11 +69,11 @@ class EventTarget {
6969
private:
7070
const InstanceHandle::Shared instanceHandle_;
7171
const SurfaceId surfaceId_;
72-
mutable bool enabled_{false}; // Protected by `EventEmitter::DispatchMutex()`.
73-
mutable jsi::Value strongInstanceHandle_; // Protected by `jsi::Runtime &`.
74-
mutable size_t retainCount_{0}; // Protected by `jsi::Runtime &`.
72+
bool enabled_{false}; // Protected by `EventEmitter::DispatchMutex()`.
73+
jsi::Value strongInstanceHandle_; // Protected by `jsi::Runtime &`.
74+
size_t retainCount_{0}; // Protected by `jsi::Runtime &`.
7575
};
7676

77-
using SharedEventTarget = std::shared_ptr<const EventTarget>;
77+
using SharedEventTarget = std::shared_ptr<EventTarget>;
7878

7979
} // namespace facebook::react

packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Scheduler::Scheduler(
8585

8686
auto eventPipe = [uiManager](
8787
jsi::Runtime& runtime,
88-
const EventTarget* eventTarget,
88+
EventTarget* eventTarget,
8989
const std::string& type,
9090
ReactEventPriority priority,
9191
const EventPayload& payload) {

packages/react-native/ReactCommon/react/renderer/uimanager/PointerEventsProcessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace facebook::react {
1515
std::shared_ptr<const ShadowNode>
1616
PointerEventsProcessor::getShadowNodeFromEventTarget(
1717
jsi::Runtime& runtime,
18-
const EventTarget* target) {
18+
EventTarget* target) {
1919
if (target != nullptr) {
2020
target->retain(runtime);
2121
auto instanceHandle = target->getInstanceHandle(runtime);

packages/react-native/ReactCommon/react/renderer/uimanager/PointerEventsProcessor.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ using PointerHoverTrackerRegistry = std::unordered_map<PointerIdentifier, Pointe
4747

4848
class PointerEventsProcessor final {
4949
public:
50-
static std::shared_ptr<const ShadowNode> getShadowNodeFromEventTarget(
51-
jsi::Runtime &runtime,
52-
const EventTarget *target);
50+
static std::shared_ptr<const ShadowNode> getShadowNodeFromEventTarget(jsi::Runtime &runtime, EventTarget *target);
5351

5452
void interceptPointerEvent(
5553
const std::shared_ptr<const ShadowNode> &target,

packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ UIManagerBinding::~UIManagerBinding() {
6262

6363
void UIManagerBinding::dispatchEvent(
6464
jsi::Runtime& runtime,
65-
const EventTarget* eventTarget,
65+
EventTarget* eventTarget,
6666
const std::string& type,
6767
ReactEventPriority priority,
6868
const EventPayload& eventPayload) const {
@@ -101,7 +101,7 @@ void UIManagerBinding::dispatchEvent(
101101

102102
void UIManagerBinding::dispatchEventToJS(
103103
jsi::Runtime& runtime,
104-
const EventTarget* eventTarget,
104+
EventTarget* eventTarget,
105105
const std::string& type,
106106
ReactEventPriority priority,
107107
const EventPayload& eventPayload) const {

packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class UIManagerBinding : public jsi::HostObject {
4444
*/
4545
void dispatchEvent(
4646
jsi::Runtime &runtime,
47-
const EventTarget *eventTarget,
47+
EventTarget *eventTarget,
4848
const std::string &type,
4949
ReactEventPriority priority,
5050
const EventPayload &payload) const;
@@ -73,7 +73,7 @@ class UIManagerBinding : public jsi::HostObject {
7373
*/
7474
void dispatchEventToJS(
7575
jsi::Runtime &runtime,
76-
const EventTarget *eventTarget,
76+
EventTarget *eventTarget,
7777
const std::string &type,
7878
ReactEventPriority priority,
7979
const EventPayload &payload) const;

0 commit comments

Comments
 (0)