Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ - (instancetype)initWithBundleURLBlock:(RCTBundleURLBlock)bundleURLBlock
@end

@interface RCTRootViewFactory () <RCTCxxBridgeDelegate> {
facebook::react::ContextContainer::Shared _contextContainer;
std::shared_ptr<const facebook::react::ContextContainer> _contextContainer;
std::shared_ptr<facebook::react::RuntimeScheduler> _runtimeScheduler;
}
@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, weak) id<RCTMountingManagerDelegate> delegate;
@property (nonatomic, strong) RCTComponentViewRegistry *componentViewRegistry;

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

/**
* Designates the view as a rendering viewport of a React Native surface.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ @implementation RCTMountingManager {
RCTMountingTransactionObserverCoordinator _observerCoordinator;
BOOL _transactionInFlight;
BOOL _followUpTransactionRequired;
ContextContainer::Shared _contextContainer;
std::shared_ptr<const ContextContainer> _contextContainer;
}

- (instancetype)init
Expand All @@ -155,7 +155,7 @@ - (instancetype)init
return self;
}

- (void)setContextContainer:(ContextContainer::Shared)contextContainer
- (void)setContextContainer:(std::shared_ptr<const ContextContainer>)contextContainer
{
_contextContainer = contextContainer;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native/React/Fabric/RCTSurfacePresenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
@interface RCTSurfacePresenter : NSObject

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

@property (nonatomic) facebook::react::ContextContainer::Shared contextContainer;
@property (nonatomic) std::shared_ptr<const facebook::react::ContextContainer> contextContainer;
@property (nonatomic) facebook::react::RuntimeExecutor runtimeExecutor;

/*
Expand Down
20 changes: 11 additions & 9 deletions packages/react-native/React/Fabric/RCTSurfacePresenter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ @implementation RCTSurfacePresenter {
std::mutex _schedulerAccessMutex;
std::mutex _schedulerLifeCycleMutex;
RCTScheduler *_Nullable _scheduler; // Thread-safe. Pointer is protected by `_schedulerAccessMutex`.
ContextContainer::Shared _contextContainer; // Protected by `_schedulerLifeCycleMutex`.
std::shared_ptr<const ContextContainer> _contextContainer; // Protected by `_schedulerLifeCycleMutex`.
RuntimeExecutor _runtimeExecutor; // Protected by `_schedulerLifeCycleMutex`.
std::optional<RuntimeExecutor> _bridgelessBindingsExecutor; // Only used for installing bindings.

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

- (instancetype)initWithContextContainer:(ContextContainer::Shared)contextContainer
- (instancetype)initWithContextContainer:(std::shared_ptr<const ContextContainer>)contextContainer
runtimeExecutor:(RuntimeExecutor)runtimeExecutor
bridgelessBindingsExecutor:(std::optional<RuntimeExecutor>)bridgelessBindingsExecutor
{
Expand Down Expand Up @@ -96,7 +96,7 @@ - (RCTScheduler *_Nullable)scheduler
return _scheduler;
}

- (ContextContainer::Shared)contextContainer
- (std::shared_ptr<const ContextContainer>)contextContainer
{
std::lock_guard<std::mutex> lock(_schedulerLifeCycleMutex);
return _contextContainer;
Expand Down Expand Up @@ -231,12 +231,14 @@ - (BOOL)resume

- (RCTScheduler *)_createScheduler
{
auto componentRegistryFactory =
[factory = wrapManagedObject(_mountingManager.componentViewRegistry.componentViewFactory)](
const EventDispatcher::Weak &eventDispatcher, const ContextContainer::Shared &contextContainer) {
return [(RCTComponentViewFactory *)unwrapManagedObject(factory)
createComponentDescriptorRegistryWithParameters:{eventDispatcher, contextContainer}];
};
auto componentRegistryFactory = [factory =
wrapManagedObject(_mountingManager.componentViewRegistry.componentViewFactory)](
const EventDispatcher::Weak &eventDispatcher,
const std::shared_ptr<const ContextContainer> &contextContainer) {
return [(RCTComponentViewFactory *)unwrapManagedObject(factory)
createComponentDescriptorRegistryWithParameters:{.eventDispatcher = eventDispatcher,
.contextContainer = contextContainer}];
};

auto runtimeExecutor = _runtimeExecutor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ facebook::react::RuntimeExecutor RCTRuntimeExecutorFromBridge(RCTBridge *bridge)
@interface RCTSurfacePresenterBridgeAdapter : NSObject

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

/*
* Returns a stored instance of Surface Presenter which is managed by a bridge.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ @interface RCTBridge ()
- (void)invokeAsync:(std::function<void()> &&)func;
@end

static ContextContainer::Shared RCTContextContainerFromBridge(RCTBridge *bridge)
static std::shared_ptr<const ContextContainer> RCTContextContainerFromBridge(RCTBridge *bridge)
{
auto contextContainer = std::make_shared<const ContextContainer>();

Expand Down Expand Up @@ -85,7 +85,8 @@ @implementation RCTSurfacePresenterBridgeAdapter {
__weak RCTBridge *_batchedBridge;
}

- (instancetype)initWithBridge:(RCTBridge *)bridge contextContainer:(ContextContainer::Shared)contextContainer
- (instancetype)initWithBridge:(RCTBridge *)bridge
contextContainer:(std::shared_ptr<const ContextContainer>)contextContainer
{
if (self = [super init]) {
contextContainer->update(*RCTContextContainerFromBridge(bridge));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ void FabricUIManagerBinding::installFabricUIManager(
mountingManager_ =
std::make_shared<FabricMountingManager>(globalJavaUiManager);

ContextContainer::Shared contextContainer =
std::shared_ptr<const ContextContainer> contextContainer =
std::make_shared<ContextContainer>();

auto runtimeExecutor = runtimeExecutorHolder->cthis()->get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ void DefaultComponentsRegistry::setRegistryRunction(
ComponentFactory* delegate) {
delegate
->buildRegistryFunction = [](const EventDispatcher::Weak& eventDispatcher,
const ContextContainer::Shared&
const std::shared_ptr<
const ContextContainer>&
contextContainer) {
ComponentDescriptorParameters params{
.eventDispatcher = eventDispatcher,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class LayoutAnimationDriver : public LayoutAnimationKeyFrameManager {
public:
LayoutAnimationDriver(
RuntimeExecutor runtimeExecutor,
ContextContainer::Shared& contextContainer,
std::shared_ptr<const ContextContainer>& contextContainer,
LayoutAnimationStatusDelegate* delegate)
: LayoutAnimationKeyFrameManager(
runtimeExecutor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ interpolateFloats(Float coefficient, Float oldValue, Float newValue) {

LayoutAnimationKeyFrameManager::LayoutAnimationKeyFrameManager(
RuntimeExecutor runtimeExecutor,
ContextContainer::Shared& contextContainer,
std::shared_ptr<const ContextContainer>& contextContainer,
LayoutAnimationStatusDelegate* delegate)
: runtimeExecutor_(std::move(runtimeExecutor)),
contextContainer_(contextContainer),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class LayoutAnimationKeyFrameManager : public UIManagerAnimationDelegate,
public:
LayoutAnimationKeyFrameManager(
RuntimeExecutor runtimeExecutor,
ContextContainer::Shared& contextContainer,
std::shared_ptr<const ContextContainer>& contextContainer,
LayoutAnimationStatusDelegate* delegate);

#pragma mark - UIManagerAnimationDelegate methods
Expand Down Expand Up @@ -137,7 +137,7 @@ class LayoutAnimationKeyFrameManager : public UIManagerAnimationDelegate,

private:
RuntimeExecutor runtimeExecutor_;
ContextContainer::Shared contextContainer_;
std::shared_ptr<const ContextContainer> contextContainer_;

mutable std::mutex layoutAnimationStatusDelegateMutex_;
mutable LayoutAnimationStatusDelegate* layoutAnimationStatusDelegate_{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace facebook::react {
using ComponentRegistryFactory =
std::function<SharedComponentDescriptorRegistry(
const EventDispatcher::Weak& eventDispatcher,
const ContextContainer::Shared& contextContainer)>;
const std::shared_ptr<const ContextContainer>& contextContainer)>;

ComponentRegistryFactory getDefaultComponentRegistryFactory();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace facebook::react {
ComponentDescriptorRegistry::ComponentDescriptorRegistry(
ComponentDescriptorParameters parameters,
const ComponentDescriptorProviderRegistry& providerRegistry,
ContextContainer::Shared contextContainer)
std::shared_ptr<const ContextContainer> contextContainer)
: parameters_(std::move(parameters)),
providerRegistry_(providerRegistry),
contextContainer_(std::move(contextContainer)) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ComponentDescriptorRegistry {
ComponentDescriptorRegistry(
ComponentDescriptorParameters parameters,
const ComponentDescriptorProviderRegistry& providerRegistry,
ContextContainer::Shared contextContainer);
std::shared_ptr<const ContextContainer> contextContainer);

/*
* This is broken. Please do not use.
Expand Down Expand Up @@ -81,7 +81,7 @@ class ComponentDescriptorRegistry {
ComponentDescriptor::Shared _fallbackComponentDescriptor;
ComponentDescriptorParameters parameters_{};
const ComponentDescriptorProviderRegistry& providerRegistry_;
ContextContainer::Shared contextContainer_;
std::shared_ptr<const ContextContainer> contextContainer_;
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static Class getViewManagerClass(const std::string &componentName, RCTBridge *br
}

static const std::shared_ptr<void> constructCoordinator(
const ContextContainer::Shared &contextContainer,
const std::shared_ptr<const ContextContainer> &contextContainer,
const ComponentDescriptor::Flavor &flavor)
{
auto optionalBridge = contextContainer->find<std::shared_ptr<void>>("Bridge");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace facebook::react {
class AndroidProgressBarMeasurementsManager {
public:
AndroidProgressBarMeasurementsManager(
const ContextContainer::Shared& contextContainer)
const std::shared_ptr<const ContextContainer>& contextContainer)
: contextContainer_(contextContainer) {}

Size measure(
Expand All @@ -26,7 +26,7 @@ class AndroidProgressBarMeasurementsManager {
LayoutConstraints layoutConstraints) const;

private:
const ContextContainer::Shared contextContainer_;
const std::shared_ptr<const ContextContainer> contextContainer_;
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ namespace facebook::react {
class AndroidSwitchMeasurementsManager {
public:
AndroidSwitchMeasurementsManager(
const ContextContainer::Shared& contextContainer)
const std::shared_ptr<const ContextContainer>& contextContainer)
: contextContainer_(contextContainer) {}

Size measure(SurfaceId surfaceId, LayoutConstraints layoutConstraints) const;

private:
const ContextContainer::Shared contextContainer_;
const std::shared_ptr<const ContextContainer> contextContainer_;
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class ComponentDescriptor {
class ComponentDescriptorParameters {
public:
EventDispatcher::Weak eventDispatcher;
ContextContainer::Shared contextContainer;
std::shared_ptr<const ContextContainer> contextContainer;
ComponentDescriptor::Flavor flavor;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ std::shared_ptr<ShadowNode> ShadowNode::clone(
}
}

ContextContainer::Shared ShadowNode::getContextContainer() const {
std::shared_ptr<const ContextContainer> ShadowNode::getContextContainer()
const {
return family_->componentDescriptor_.getContextContainer();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class ShadowNode : public Sealable,
/*
* Returns the `ContextContainer` used by this ShadowNode.
*/
ContextContainer::Shared getContextContainer() const;
std::shared_ptr<const ContextContainer> getContextContainer() const;

/*
* Returns a state associated with the particular node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace facebook::react {

inline ComponentBuilder simpleComponentBuilder(
ContextContainer::Shared contextContainer = nullptr) {
std::shared_ptr<const ContextContainer> contextContainer = nullptr) {
ComponentDescriptorProviderRegistry componentDescriptorProviderRegistry{};
auto eventDispatcher = EventDispatcher::Shared{};
auto componentDescriptorRegistry =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using SharedImageManager = std::shared_ptr<ImageManager>;
*/
class ImageManager {
public:
ImageManager(const ContextContainer::Shared& contextContainer);
ImageManager(const std::shared_ptr<const ContextContainer>& contextContainer);
virtual ~ImageManager();

virtual ImageRequest requestImage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace facebook::react {

class ImageFetcher {
public:
ImageFetcher(ContextContainer::Shared contextContainer)
ImageFetcher(std::shared_ptr<const ContextContainer> contextContainer)
: contextContainer_(std::move(contextContainer)) {}

ImageRequest requestImage(
Expand All @@ -31,6 +31,6 @@ class ImageFetcher {
Tag tag) const;

private:
ContextContainer::Shared contextContainer_;
std::shared_ptr<const ContextContainer> contextContainer_;
};
} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

namespace facebook::react {

ImageManager::ImageManager(const ContextContainer::Shared& contextContainer)
ImageManager::ImageManager(
const std::shared_ptr<const ContextContainer>& contextContainer)
: self_(new ImageFetcher(contextContainer)) {}

ImageManager::~ImageManager() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace facebook::react {

ImageManager::ImageManager(
const ContextContainer::Shared& /*contextContainer*/) {
const std::shared_ptr<const ContextContainer>& /*contextContainer*/) {
// Silence unused-private-field warning.
(void)self_;
// Not implemented.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace facebook::react {

ImageManager::ImageManager(const ContextContainer::Shared &contextContainer)
ImageManager::ImageManager(const std::shared_ptr<const ContextContainer> &contextContainer)
{
id<RCTImageLoaderWithAttributionProtocol> imageLoader =
(id<RCTImageLoaderWithAttributionProtocol>)unwrapManagedObject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ void Scheduler::reportMount(SurfaceId surfaceId) const {
uiManager_->reportMount(surfaceId);
}

ContextContainer::Shared Scheduler::getContextContainer() const {
std::shared_ptr<const ContextContainer> Scheduler::getContextContainer() const {
return contextContainer_;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Scheduler final : public UIManagerDelegate {
void uiManagerDidStartSurface(const ShadowTree& shadowTree) override;

#pragma mark - ContextContainer
ContextContainer::Shared getContextContainer() const;
std::shared_ptr<const ContextContainer> getContextContainer() const;

#pragma mark - UIManager
std::shared_ptr<UIManager> getUIManager() const;
Expand Down Expand Up @@ -148,7 +148,7 @@ class Scheduler final : public UIManagerDelegate {
* Hold onto ContextContainer. See SchedulerToolbox.
* Must not be nullptr.
*/
ContextContainer::Shared contextContainer_;
std::shared_ptr<const ContextContainer> contextContainer_;

RuntimeScheduler* runtimeScheduler_{nullptr};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct SchedulerToolbox final {
* Represents general purpose DI container for product components/needs.
* Must not be `nullptr`.
*/
ContextContainer::Shared contextContainer;
std::shared_ptr<const ContextContainer> contextContainer;

/*
* Represents externally managed, lazily available collection of components.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ SurfaceHandler& SurfaceHandler::operator=(SurfaceHandler&& other) noexcept {
#pragma mark - Surface Life-Cycle Management

void SurfaceHandler::setContextContainer(
ContextContainer::Shared contextContainer) const noexcept {
std::shared_ptr<const ContextContainer> contextContainer) const noexcept {
parameters_.contextContainer = std::move(contextContainer);
}

Expand Down
Loading
Loading