Skip to content

Commit 7b5307d

Browse files
Replace ContextContainer::Shared with std::shared_ptr<const ContextContainer> 2/2 (#52750)
Summary: Pull Request resolved: #52750 Changelog: [Internal] Reviewed By: rshest Differential Revision: D78704833 fbshipit-source-id: 4df0029f6de860c93864e12c479e387f3981f7b5
1 parent 5e1798a commit 7b5307d

43 files changed

Lines changed: 98 additions & 91 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ - (instancetype)initWithBundleURLBlock:(RCTBundleURLBlock)bundleURLBlock
8383
@end
8484

8585
@interface RCTRootViewFactory () <RCTCxxBridgeDelegate> {
86-
facebook::react::ContextContainer::Shared _contextContainer;
86+
std::shared_ptr<const facebook::react::ContextContainer> _contextContainer;
8787
std::shared_ptr<facebook::react::RuntimeScheduler> _runtimeScheduler;
8888
}
8989
@end

packages/react-native/React/Fabric/Mounting/RCTMountingManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
2828
@property (nonatomic, weak) id<RCTMountingManagerDelegate> delegate;
2929
@property (nonatomic, strong) RCTComponentViewRegistry *componentViewRegistry;
3030

31-
- (void)setContextContainer:(facebook::react::ContextContainer::Shared)contextContainer;
31+
- (void)setContextContainer:(std::shared_ptr<const facebook::react::ContextContainer>)contextContainer;
3232

3333
/**
3434
* Designates the view as a rendering viewport of a React Native surface.

packages/react-native/React/Fabric/Mounting/RCTMountingManager.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ @implementation RCTMountingManager {
143143
RCTMountingTransactionObserverCoordinator _observerCoordinator;
144144
BOOL _transactionInFlight;
145145
BOOL _followUpTransactionRequired;
146-
ContextContainer::Shared _contextContainer;
146+
std::shared_ptr<const ContextContainer> _contextContainer;
147147
}
148148

149149
- (instancetype)init
@@ -155,7 +155,7 @@ - (instancetype)init
155155
return self;
156156
}
157157

158-
- (void)setContextContainer:(ContextContainer::Shared)contextContainer
158+
- (void)setContextContainer:(std::shared_ptr<const ContextContainer>)contextContainer
159159
{
160160
_contextContainer = contextContainer;
161161
}

packages/react-native/React/Fabric/RCTSurfacePresenter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ NS_ASSUME_NONNULL_BEGIN
2727
*/
2828
@interface RCTSurfacePresenter : NSObject
2929

30-
- (instancetype)initWithContextContainer:(facebook::react::ContextContainer::Shared)contextContainer
30+
- (instancetype)initWithContextContainer:(std::shared_ptr<const facebook::react::ContextContainer>)contextContainer
3131
runtimeExecutor:(facebook::react::RuntimeExecutor)runtimeExecutor
3232
bridgelessBindingsExecutor:(std::optional<facebook::react::RuntimeExecutor>)bridgelessBindingsExecutor;
3333

34-
@property (nonatomic) facebook::react::ContextContainer::Shared contextContainer;
34+
@property (nonatomic) std::shared_ptr<const facebook::react::ContextContainer> contextContainer;
3535
@property (nonatomic) facebook::react::RuntimeExecutor runtimeExecutor;
3636

3737
/*

packages/react-native/React/Fabric/RCTSurfacePresenter.mm

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ @implementation RCTSurfacePresenter {
5151
std::mutex _schedulerAccessMutex;
5252
std::mutex _schedulerLifeCycleMutex;
5353
RCTScheduler *_Nullable _scheduler; // Thread-safe. Pointer is protected by `_schedulerAccessMutex`.
54-
ContextContainer::Shared _contextContainer; // Protected by `_schedulerLifeCycleMutex`.
54+
std::shared_ptr<const ContextContainer> _contextContainer; // Protected by `_schedulerLifeCycleMutex`.
5555
RuntimeExecutor _runtimeExecutor; // Protected by `_schedulerLifeCycleMutex`.
5656
std::optional<RuntimeExecutor> _bridgelessBindingsExecutor; // Only used for installing bindings.
5757

5858
std::shared_mutex _observerListMutex;
5959
std::vector<__weak id<RCTSurfacePresenterObserver>> _observers; // Protected by `_observerListMutex`.
6060
}
6161

62-
- (instancetype)initWithContextContainer:(ContextContainer::Shared)contextContainer
62+
- (instancetype)initWithContextContainer:(std::shared_ptr<const ContextContainer>)contextContainer
6363
runtimeExecutor:(RuntimeExecutor)runtimeExecutor
6464
bridgelessBindingsExecutor:(std::optional<RuntimeExecutor>)bridgelessBindingsExecutor
6565
{
@@ -96,7 +96,7 @@ - (RCTScheduler *_Nullable)scheduler
9696
return _scheduler;
9797
}
9898

99-
- (ContextContainer::Shared)contextContainer
99+
- (std::shared_ptr<const ContextContainer>)contextContainer
100100
{
101101
std::lock_guard<std::mutex> lock(_schedulerLifeCycleMutex);
102102
return _contextContainer;
@@ -231,12 +231,14 @@ - (BOOL)resume
231231

232232
- (RCTScheduler *)_createScheduler
233233
{
234-
auto componentRegistryFactory =
235-
[factory = wrapManagedObject(_mountingManager.componentViewRegistry.componentViewFactory)](
236-
const EventDispatcher::Weak &eventDispatcher, const ContextContainer::Shared &contextContainer) {
237-
return [(RCTComponentViewFactory *)unwrapManagedObject(factory)
238-
createComponentDescriptorRegistryWithParameters:{eventDispatcher, contextContainer}];
239-
};
234+
auto componentRegistryFactory = [factory =
235+
wrapManagedObject(_mountingManager.componentViewRegistry.componentViewFactory)](
236+
const EventDispatcher::Weak &eventDispatcher,
237+
const std::shared_ptr<const ContextContainer> &contextContainer) {
238+
return [(RCTComponentViewFactory *)unwrapManagedObject(factory)
239+
createComponentDescriptorRegistryWithParameters:{.eventDispatcher = eventDispatcher,
240+
.contextContainer = contextContainer}];
241+
};
240242

241243
auto runtimeExecutor = _runtimeExecutor;
242244

packages/react-native/React/Fabric/RCTSurfacePresenterBridgeAdapter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ facebook::react::RuntimeExecutor RCTRuntimeExecutorFromBridge(RCTBridge *bridge)
2525
@interface RCTSurfacePresenterBridgeAdapter : NSObject
2626

2727
- (instancetype)initWithBridge:(RCTBridge *)bridge
28-
contextContainer:(facebook::react::ContextContainer::Shared)contextContainer;
28+
contextContainer:(std::shared_ptr<const facebook::react::ContextContainer>)contextContainer;
2929

3030
/*
3131
* Returns a stored instance of Surface Presenter which is managed by a bridge.

packages/react-native/React/Fabric/RCTSurfacePresenterBridgeAdapter.mm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ @interface RCTBridge ()
2929
- (void)invokeAsync:(std::function<void()> &&)func;
3030
@end
3131

32-
static ContextContainer::Shared RCTContextContainerFromBridge(RCTBridge *bridge)
32+
static std::shared_ptr<const ContextContainer> RCTContextContainerFromBridge(RCTBridge *bridge)
3333
{
3434
auto contextContainer = std::make_shared<const ContextContainer>();
3535

@@ -85,7 +85,8 @@ @implementation RCTSurfacePresenterBridgeAdapter {
8585
__weak RCTBridge *_batchedBridge;
8686
}
8787

88-
- (instancetype)initWithBridge:(RCTBridge *)bridge contextContainer:(ContextContainer::Shared)contextContainer
88+
- (instancetype)initWithBridge:(RCTBridge *)bridge
89+
contextContainer:(std::shared_ptr<const ContextContainer>)contextContainer
8990
{
9091
if (self = [super init]) {
9192
contextContainer->update(*RCTContextContainerFromBridge(bridge));

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
@@ -516,7 +516,7 @@ void FabricUIManagerBinding::installFabricUIManager(
516516
mountingManager_ =
517517
std::make_shared<FabricMountingManager>(globalJavaUiManager);
518518

519-
ContextContainer::Shared contextContainer =
519+
std::shared_ptr<const ContextContainer> contextContainer =
520520
std::make_shared<ContextContainer>();
521521

522522
auto runtimeExecutor = runtimeExecutorHolder->cthis()->get();

packages/react-native/ReactAndroid/src/main/jni/react/newarchdefaults/DefaultComponentsRegistry.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ void DefaultComponentsRegistry::setRegistryRunction(
2727
ComponentFactory* delegate) {
2828
delegate
2929
->buildRegistryFunction = [](const EventDispatcher::Weak& eventDispatcher,
30-
const ContextContainer::Shared&
30+
const std::shared_ptr<
31+
const ContextContainer>&
3132
contextContainer) {
3233
ComponentDescriptorParameters params{
3334
.eventDispatcher = eventDispatcher,

packages/react-native/ReactCommon/react/renderer/animations/LayoutAnimationDriver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class LayoutAnimationDriver : public LayoutAnimationKeyFrameManager {
1717
public:
1818
LayoutAnimationDriver(
1919
RuntimeExecutor runtimeExecutor,
20-
ContextContainer::Shared& contextContainer,
20+
std::shared_ptr<const ContextContainer>& contextContainer,
2121
LayoutAnimationStatusDelegate* delegate)
2222
: LayoutAnimationKeyFrameManager(
2323
runtimeExecutor,

0 commit comments

Comments
 (0)