Skip to content

Commit 178c30d

Browse files
sammy-SCmeta-codesync[bot]
authored andcommitted
Fix const-correctness for ShadowNodeFamily (#55783)
Summary: Pull Request resolved: #55783 Changelog: [Internal] remove unnecessary const from ShadowNodeFamily. This allows us to get rid of a few mutable keywords. Reviewed By: christophpurrer Differential Revision: D90763777 fbshipit-source-id: 036c87ad504331507acb86b8e556d884c0a5d815
1 parent e5d720d commit 178c30d

7 files changed

Lines changed: 25 additions & 25 deletions

File tree

packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ void FabricUIManagerBinding::schedulerDidRequestPreliminaryViewAllocation(
740740
// to be destroyed if the ShadowNode is destroyed but it was never mounted
741741
// on the screen.
742742
if (shadowNode.getTraits().check(ShadowNodeTraits::Trait::FormsView)) {
743-
shadowNode.getFamily().onUnmountedFamilyDestroyed(
743+
shadowNode.getFamilyShared()->onUnmountedFamilyDestroyed(
744744
[weakMountingManager =
745745
std::weak_ptr(mountingManager)](const ShadowNodeFamily& family) {
746746
if (auto mountingManager = weakMountingManager.lock()) {

packages/react-native/ReactCommon/react/renderer/animated/AnimatedModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class AnimatedModule : public NativeAnimatedModuleCxxSpec<AnimatedModule>, publi
8989

9090
struct ConnectAnimatedNodeToShadowNodeFamilyOp {
9191
Tag nodeTag{};
92-
std::shared_ptr<const ShadowNodeFamily> shadowNodeFamily{};
92+
std::shared_ptr<ShadowNodeFamily> shadowNodeFamily{};
9393
};
9494

9595
struct DisconnectAnimatedNodeFromViewOp {

packages/react-native/ReactCommon/react/renderer/animated/NativeAnimatedNodesManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ void NativeAnimatedNodesManager::connectAnimatedNodeToView(
236236

237237
void NativeAnimatedNodesManager::connectAnimatedNodeToShadowNodeFamily(
238238
Tag propsNodeTag,
239-
std::shared_ptr<const ShadowNodeFamily> family) noexcept {
239+
std::shared_ptr<ShadowNodeFamily> family) noexcept {
240240
react_native_assert(propsNodeTag);
241241
auto node = getAnimatedNode<PropsAnimatedNode>(propsNodeTag);
242242
if (node != nullptr && family != nullptr) {

packages/react-native/ReactCommon/react/renderer/animated/NativeAnimatedNodesManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class NativeAnimatedNodesManager {
101101

102102
void connectAnimatedNodeToView(Tag propsNodeTag, Tag viewTag) noexcept;
103103

104-
void connectAnimatedNodeToShadowNodeFamily(Tag propsNodeTag, std::shared_ptr<const ShadowNodeFamily> family) noexcept;
104+
void connectAnimatedNodeToShadowNodeFamily(Tag propsNodeTag, std::shared_ptr<ShadowNodeFamily> family) noexcept;
105105

106106
void disconnectAnimatedNodes(Tag parentTag, Tag childTag) noexcept;
107107

packages/react-native/ReactCommon/react/renderer/components/root/RootShadowNode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ RootShadowNode::Unshared RootShadowNode::clone(
5959

6060
void RootShadowNode::setInstanceHandle(
6161
InstanceHandle::Shared instanceHandle) const {
62-
getFamily().setInstanceHandle(instanceHandle);
62+
getFamilyShared()->setInstanceHandle(instanceHandle);
6363
}
6464

6565
} // namespace facebook::react

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ShadowNodeFamily::ShadowNodeFamily(
3333
componentHandle_(componentDescriptor.getComponentHandle()),
3434
componentName_(componentDescriptor.getComponentName()) {}
3535

36-
void ShadowNodeFamily::setParent(const ShadowNodeFamily::Shared& parent) const {
36+
void ShadowNodeFamily::setParent(const ShadowNodeFamily::Shared& parent) {
3737
react_native_assert(parent_.lock() == nullptr || parent_.lock() == parent);
3838
if (hasParent_) {
3939
return;
@@ -59,7 +59,7 @@ ComponentName ShadowNodeFamily::getComponentName() const {
5959
return componentName_;
6060
}
6161

62-
void ShadowNodeFamily::setMounted() const {
62+
void ShadowNodeFamily::setMounted() {
6363
hasBeenMounted_ = true;
6464
}
6565

@@ -68,7 +68,7 @@ const ComponentDescriptor& ShadowNodeFamily::getComponentDescriptor() const {
6868
}
6969

7070
void ShadowNodeFamily::onUnmountedFamilyDestroyed(
71-
std::function<void(const ShadowNodeFamily& family)> callback) const {
71+
std::function<void(const ShadowNodeFamily& family)> callback) {
7272
onUnmountedFamilyDestroyedCallback_ = std::move(callback);
7373
}
7474

@@ -89,7 +89,7 @@ InstanceHandle::Shared ShadowNodeFamily::getInstanceHandle() const {
8989
}
9090

9191
void ShadowNodeFamily::setInstanceHandle(
92-
InstanceHandle::Shared& instanceHandle) const {
92+
InstanceHandle::Shared& instanceHandle) {
9393
instanceHandle_ = instanceHandle;
9494
}
9595

@@ -144,7 +144,7 @@ State::Shared ShadowNodeFamily::getMostRecentState() const {
144144
return mostRecentState_;
145145
}
146146

147-
void ShadowNodeFamily::setMostRecentState(const State::Shared& state) const {
147+
void ShadowNodeFamily::setMostRecentState(const State::Shared& state) {
148148
std::unique_lock lock(mutex_);
149149

150150
/*
@@ -175,7 +175,7 @@ std::shared_ptr<const State> ShadowNodeFamily::getMostRecentStateIfObsolete(
175175

176176
void ShadowNodeFamily::dispatchRawState(
177177
StateUpdate&& stateUpdate,
178-
EventQueue::UpdateMode updateMode) const {
178+
EventQueue::UpdateMode updateMode) {
179179
auto eventDispatcher = eventDispatcher_.lock();
180180
if (!eventDispatcher) {
181181
return;

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ struct ShadowNodeFamilyFragment {
4141
*/
4242
class ShadowNodeFamily final : public jsi::NativeState {
4343
public:
44-
using Shared = std::shared_ptr<const ShadowNodeFamily>;
45-
using Weak = std::weak_ptr<const ShadowNodeFamily>;
44+
using Shared = std::shared_ptr<ShadowNodeFamily>;
45+
using Weak = std::weak_ptr<ShadowNodeFamily>;
4646

4747
using AncestorList =
4848
std::vector<std::pair<std::reference_wrapper<const ShadowNode> /* parentNode */, int /* childIndex */>>;
@@ -58,7 +58,7 @@ class ShadowNodeFamily final : public jsi::NativeState {
5858
* This is not technically thread-safe, but practically it mutates the object
5959
* only once (and the model enforces that this first call is not concurrent).
6060
*/
61-
void setParent(const ShadowNodeFamily::Shared &parent) const;
61+
void setParent(const ShadowNodeFamily::Shared &parent);
6262

6363
/*
6464
* Returns a handle (or name) associated with the component.
@@ -90,23 +90,23 @@ class ShadowNodeFamily final : public jsi::NativeState {
9090
* @param callback will be executed when an unmounted instance of
9191
* ShadowNodeFamily is destroyed.
9292
*/
93-
void onUnmountedFamilyDestroyed(std::function<void(const ShadowNodeFamily &family)> callback) const;
93+
void onUnmountedFamilyDestroyed(std::function<void(const ShadowNodeFamily &family)> callback);
9494

9595
/*
9696
* Sets and gets the most recent state.
9797
*/
9898
std::shared_ptr<const State> getMostRecentState() const;
99-
void setMostRecentState(const std::shared_ptr<const State> &state) const;
99+
void setMostRecentState(const std::shared_ptr<const State> &state);
100100

101101
/**
102102
* Mark this ShadowNodeFamily as mounted.
103103
*/
104-
void setMounted() const;
104+
void setMounted();
105105

106106
/*
107107
* Dispatches a state update with given priority.
108108
*/
109-
void dispatchRawState(StateUpdate &&stateUpdate, EventQueue::UpdateMode updateMode) const;
109+
void dispatchRawState(StateUpdate &&stateUpdate, EventQueue::UpdateMode updateMode);
110110

111111
/*
112112
* Holds currently applied native props. `nullptr` if setNativeProps API is
@@ -122,7 +122,7 @@ class ShadowNodeFamily final : public jsi::NativeState {
122122

123123
jsi::Value getInstanceHandle(jsi::Runtime &runtime) const;
124124
InstanceHandle::Shared getInstanceHandle() const;
125-
void setInstanceHandle(InstanceHandle::Shared &instanceHandle) const;
125+
void setInstanceHandle(InstanceHandle::Shared &instanceHandle);
126126

127127
/**
128128
* Override destructor to call onUnmountedFamilyDestroyedCallback() for
@@ -142,10 +142,10 @@ class ShadowNodeFamily final : public jsi::NativeState {
142142
std::shared_ptr<const State> getMostRecentStateIfObsolete(const State &state) const;
143143

144144
EventDispatcher::Weak eventDispatcher_;
145-
mutable std::shared_ptr<const State> mostRecentState_;
145+
std::shared_ptr<const State> mostRecentState_;
146146
mutable std::shared_mutex mutex_;
147147

148-
mutable std::function<void(ShadowNodeFamily &family)> onUnmountedFamilyDestroyedCallback_ = nullptr;
148+
std::function<void(ShadowNodeFamily &family)> onUnmountedFamilyDestroyedCallback_ = nullptr;
149149

150150
/*
151151
* Deprecated.
@@ -160,7 +160,7 @@ class ShadowNodeFamily final : public jsi::NativeState {
160160
/*
161161
* Weak reference to the React instance handle
162162
*/
163-
mutable InstanceHandle::Shared instanceHandle_;
163+
InstanceHandle::Shared instanceHandle_;
164164

165165
/*
166166
* `EventEmitter` associated with all nodes of the family.
@@ -184,18 +184,18 @@ class ShadowNodeFamily final : public jsi::NativeState {
184184
/*
185185
* Points to a family of all parent nodes of all nodes of the family.
186186
*/
187-
mutable ShadowNodeFamily::Weak parent_{};
187+
ShadowNodeFamily::Weak parent_{};
188188

189189
/*
190190
* Represents a case where `parent_` is `nullptr`.
191191
* For optimization purposes only.
192192
*/
193-
mutable bool hasParent_{false};
193+
bool hasParent_{false};
194194

195195
/*
196196
* Determines if the ShadowNodeFamily was ever mounted on the screen.
197197
*/
198-
mutable bool hasBeenMounted_{false};
198+
bool hasBeenMounted_{false};
199199
};
200200

201201
} // namespace facebook::react

0 commit comments

Comments
 (0)