Skip to content
Open
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 @@ -57,7 +57,7 @@ - (instancetype)initWithSurfacePresenter:(RCTSurfacePresenter *)surfacePresenter
if (self = [super init]) {
_surfacePresenter = surfacePresenter;

_surfaceHandler = SurfaceHandler{RCTStringFromNSString(moduleName), getNextRootViewTag()};
_surfaceHandler.emplace(RCTStringFromNSString(moduleName), getNextRootViewTag());
_surfaceHandler->setProps(convertIdToFollyDynamic(initialProperties));

[_surfacePresenter registerSurface:self];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,34 +166,39 @@ void FabricUIManagerBinding::startSurface(
return;
}

auto layoutContext = LayoutContext{};
layoutContext.pointScaleFactor = pointScaleFactor_;
SurfaceHandler* surfaceHandler = nullptr;
{
std::unique_lock lock(surfaceHandlerRegistryMutex_);
auto [it, _] = surfaceHandlerRegistry_.try_emplace(
surfaceId,
std::in_place_index<0>,
moduleName->toStdString(),
surfaceId);
surfaceHandler = &std::get<SurfaceHandler>(it->second);
}

auto surfaceHandler = SurfaceHandler{moduleName->toStdString(), surfaceId};
surfaceHandler.setContextContainer(scheduler->getContextContainer());
surfaceHandler->setContextContainer(scheduler->getContextContainer());
if (initialProps != nullptr) {
surfaceHandler.setProps(initialProps->consume());
surfaceHandler->setProps(initialProps->consume());
}
surfaceHandler.constraintLayout({}, layoutContext);

scheduler->registerSurface(surfaceHandler);
auto layoutContext = LayoutContext{};
layoutContext.pointScaleFactor = pointScaleFactor_;
surfaceHandler->constraintLayout({}, layoutContext);

scheduler->registerSurface(*surfaceHandler);

auto mountingManager = getMountingManager("startSurface");
if (mountingManager != nullptr) {
mountingManager->onSurfaceStart(surfaceId);
}

surfaceHandler.start();
surfaceHandler->start();

if (ReactNativeFeatureFlags::enableLayoutAnimationsOnAndroid()) {
surfaceHandler.getMountingCoordinator()->setMountingOverrideDelegate(
surfaceHandler->getMountingCoordinator()->setMountingOverrideDelegate(
animationDriver_);
}

{
std::unique_lock lock(surfaceHandlerRegistryMutex_);
surfaceHandlerRegistry_.emplace(surfaceId, std::move(surfaceHandler));
}
}

jint FabricUIManagerBinding::findNextFocusableElement(
Expand Down Expand Up @@ -338,31 +343,36 @@ void FabricUIManagerBinding::startSurfaceWithConstraints(
constraints.layoutDirection =
isRTL != 0 ? LayoutDirection::RightToLeft : LayoutDirection::LeftToRight;

auto surfaceHandler = SurfaceHandler{moduleName->toStdString(), surfaceId};
surfaceHandler.setContextContainer(scheduler->getContextContainer());
SurfaceHandler* surfaceHandler = nullptr;
{
std::unique_lock lock(surfaceHandlerRegistryMutex_);
auto [it, _] = surfaceHandlerRegistry_.try_emplace(
surfaceId,
std::in_place_index<0>,
moduleName->toStdString(),
surfaceId);
surfaceHandler = &std::get<SurfaceHandler>(it->second);
}

surfaceHandler->setContextContainer(scheduler->getContextContainer());
if (initialProps != nullptr) {
surfaceHandler.setProps(initialProps->consume());
surfaceHandler->setProps(initialProps->consume());
}
surfaceHandler.constraintLayout(constraints, context);
surfaceHandler->constraintLayout(constraints, context);

scheduler->registerSurface(surfaceHandler);
scheduler->registerSurface(*surfaceHandler);

auto mountingManager = getMountingManager("startSurfaceWithConstraints");
if (mountingManager != nullptr) {
mountingManager->onSurfaceStart(surfaceId);
}

surfaceHandler.start();
surfaceHandler->start();

if (ReactNativeFeatureFlags::enableLayoutAnimationsOnAndroid()) {
surfaceHandler.getMountingCoordinator()->setMountingOverrideDelegate(
surfaceHandler->getMountingCoordinator()->setMountingOverrideDelegate(
animationDriver_);
}

{
std::unique_lock lock(surfaceHandlerRegistryMutex_);
surfaceHandlerRegistry_.emplace(surfaceId, std::move(surfaceHandler));
}
}

// Used by non-bridgeless+Fabric
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,6 @@ SurfaceHandler::SurfaceHandler(
parameters_.surfaceId = surfaceId;
}

SurfaceHandler::SurfaceHandler(SurfaceHandler&& other) noexcept {
operator=(std::move(other));
}

SurfaceHandler& SurfaceHandler::operator=(SurfaceHandler&& other) noexcept {
std::unique_lock lock1(linkMutex_, std::defer_lock);
std::unique_lock lock2(parametersMutex_, std::defer_lock);
std::unique_lock lock3(other.linkMutex_, std::defer_lock);
std::unique_lock lock4(other.parametersMutex_, std::defer_lock);
std::lock(lock1, lock2, lock3, lock4);

link_ = other.link_;
parameters_ = other.parameters_;

other.link_ = Link{};
other.parameters_ = Parameters{};
other.parameters_.contextContainer = parameters_.contextContainer;
return *this;
}

#pragma mark - Surface Life-Cycle Management

void SurfaceHandler::setContextContainer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ class SurfaceHandler {
virtual ~SurfaceHandler() noexcept;

/*
* Movable-only.
* Not moveable or copyable
*/
SurfaceHandler(SurfaceHandler&& other) noexcept;
SurfaceHandler(SurfaceHandler&& other) noexcept = delete;
SurfaceHandler(const SurfaceHandler& SurfaceHandler) noexcept = delete;
SurfaceHandler& operator=(SurfaceHandler&& other) noexcept;
SurfaceHandler& operator=(SurfaceHandler&& other) noexcept = delete;
SurfaceHandler& operator=(const SurfaceHandler& other) noexcept = delete;

#pragma mark - Surface Life-Cycle Management
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ void SurfaceManager::startSurface(
const LayoutContext& layoutContext) noexcept {
{
std::unique_lock lock(mutex_);
auto surfaceHandler = SurfaceHandler{moduleName, surfaceId};
surfaceHandler.setContextContainer(scheduler_.getContextContainer());
registry_.emplace(surfaceId, std::move(surfaceHandler));
auto [it, _] = registry_.try_emplace(surfaceId, moduleName, surfaceId);
it->second.setContextContainer(scheduler_.getContextContainer());
}

visit(surfaceId, [&](const SurfaceHandler& surfaceHandler) {
Expand Down
Loading