Skip to content

Commit d1b2ddc

Browse files
sammy-SCmeta-codesync[bot]
authored andcommitted
Fix const-correctness for EventEmitter (facebook#55714)
Summary: Pull Request resolved: facebook#55714 Changelog: [Internal] Remove incorrect const qualifier from EventEmitter setter methods (setEnabled, setShadowNodeFamily). This is part of a larger effort to fix const-correctness throughout the React Native Fabric codebase. Reviewed By: NickGerleman Differential Revision: D90765891 fbshipit-source-id: f36e3ec0f934ddacd76a203d1d8265481db9e6e0
1 parent 8475dcc commit d1b2ddc

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
179179

180180
ShadowNodeFamily::Shared createFamily(const ShadowNodeFamilyFragment &fragment) const override
181181
{
182-
auto eventEmitter = std::make_shared<const ConcreteEventEmitter>(
182+
auto eventEmitter = std::make_shared<ConcreteEventEmitter>(
183183
std::make_shared<EventTarget>(fragment.instanceHandle, fragment.surfaceId), eventDispatcher_);
184184
auto family = std::make_shared<ShadowNodeFamily>(fragment, eventEmitter, eventDispatcher_, *this);
185185
eventEmitter->setShadowNodeFamily(family);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void EventEmitter::dispatchUniqueEvent(
125125
RawEvent::Category::Continuous));
126126
}
127127

128-
void EventEmitter::setEnabled(bool enabled) const {
128+
void EventEmitter::setEnabled(bool enabled) {
129129
enableCounter_ += enabled ? 1 : -1;
130130

131131
bool shouldBeEnabled = enableCounter_ > 0;
@@ -149,7 +149,7 @@ void EventEmitter::setEnabled(bool enabled) const {
149149
}
150150

151151
void EventEmitter::setShadowNodeFamily(
152-
std::weak_ptr<const ShadowNodeFamily> shadowNodeFamily) const {
152+
std::weak_ptr<const ShadowNodeFamily> shadowNodeFamily) {
153153
shadowNodeFamily_ = std::move(shadowNodeFamily);
154154
}
155155

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace facebook::react {
2121

2222
class EventEmitter;
2323

24-
using SharedEventEmitter = std::shared_ptr<const EventEmitter>;
24+
using SharedEventEmitter = std::shared_ptr<EventEmitter>;
2525

2626
/*
2727
* Base class for all particular typed event handlers.
@@ -31,7 +31,7 @@ using SharedEventEmitter = std::shared_ptr<const EventEmitter>;
3131
*/
3232
class EventEmitter {
3333
public:
34-
using Shared = std::shared_ptr<const EventEmitter>;
34+
using Shared = std::shared_ptr<EventEmitter>;
3535

3636
static std::string normalizeEventType(std::string type);
3737

@@ -53,12 +53,12 @@ class EventEmitter {
5353
* a number of `disable` calls to release the event target.
5454
* `DispatchMutex` must be acquired before calling.
5555
*/
56-
void setEnabled(bool enabled) const;
56+
void setEnabled(bool enabled);
5757

5858
/*
5959
* Sets a weak reference to the cooresponding ShadowNodeFamily
6060
*/
61-
void setShadowNodeFamily(std::weak_ptr<const ShadowNodeFamily> shadowNodeFamily) const;
61+
void setShadowNodeFamily(std::weak_ptr<const ShadowNodeFamily> shadowNodeFamily);
6262

6363
const SharedEventTarget &getEventTarget() const;
6464

@@ -106,12 +106,12 @@ class EventEmitter {
106106
private:
107107
friend class UIManagerBinding;
108108

109-
mutable SharedEventTarget eventTarget_;
110-
mutable std::weak_ptr<const ShadowNodeFamily> shadowNodeFamily_;
109+
SharedEventTarget eventTarget_;
110+
std::weak_ptr<const ShadowNodeFamily> shadowNodeFamily_;
111111

112112
EventDispatcher::Weak eventDispatcher_;
113-
mutable int enableCounter_{0};
114-
mutable bool isEnabled_{false};
113+
int enableCounter_{0};
114+
bool isEnabled_{false};
115115
};
116116

117117
} // namespace facebook::react

packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTAttributedTextUtils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ BOOL RCTIsAttributedStringEffectivelySame(
5252
NSDictionary<NSAttributedStringKey, id> *insensitiveAttributes,
5353
const facebook::react::TextAttributes &baseTextAttributes);
5454

55-
static inline NSData *RCTWrapEventEmitter(const facebook::react::SharedEventEmitter &eventEmitter)
55+
static inline NSData *RCTWrapEventEmitter(const std::shared_ptr<const facebook::react::EventEmitter> &eventEmitter)
5656
{
5757
auto eventEmitterPtr = new std::weak_ptr<const facebook::react::EventEmitter>(eventEmitter);
5858
return [[NSData alloc] initWithBytesNoCopy:eventEmitterPtr
5959
length:sizeof(eventEmitterPtr)
6060
deallocator:^(void *ptrToDelete, NSUInteger) {
61-
delete (std::weak_ptr<facebook::react::EventEmitter> *)ptrToDelete;
61+
delete (std::weak_ptr<const facebook::react::EventEmitter> *)ptrToDelete;
6262
}];
6363
}
6464

65-
static inline facebook::react::SharedEventEmitter RCTUnwrapEventEmitter(NSData *data)
65+
static inline std::shared_ptr<const facebook::react::EventEmitter> RCTUnwrapEventEmitter(NSData *data)
6666
{
6767
if (data.length == 0) {
6868
return nullptr;

packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ using RCTTextLayoutFragmentEnumerationBlock =
4747
(facebook::react::ParagraphAttributes)paragraphAttributes
4848
size:(CGSize)size;
4949

50-
- (facebook::react::SharedEventEmitter)
50+
- (std::shared_ptr<const facebook::react::EventEmitter>)
5151
getEventEmitterWithAttributeString:(facebook::react::AttributedString)attributedString
5252
paragraphAttributes:(facebook::react::ParagraphAttributes)paragraphAttributes
5353
frame:(CGRect)frame

packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,10 @@ - (NSTextStorage *)_textStorageAndLayoutManagerWithAttributesString:(NSAttribute
251251
return textStorage;
252252
}
253253

254-
- (SharedEventEmitter)getEventEmitterWithAttributeString:(AttributedString)attributedString
255-
paragraphAttributes:(ParagraphAttributes)paragraphAttributes
256-
frame:(CGRect)frame
257-
atPoint:(CGPoint)point
254+
- (std::shared_ptr<const EventEmitter>)getEventEmitterWithAttributeString:(AttributedString)attributedString
255+
paragraphAttributes:(ParagraphAttributes)paragraphAttributes
256+
frame:(CGRect)frame
257+
atPoint:(CGPoint)point
258258
{
259259
NSTextStorage *textStorage = [self
260260
_textStorageAndLayoutManagerWithAttributesString:[self _nsAttributedStringFromAttributedString:attributedString]

0 commit comments

Comments
 (0)