Skip to content

Commit

Permalink
[skip ci] Allow creating empty surfaces without using AppRegistry ini…
Browse files Browse the repository at this point in the history
…tialization paths (facebook#48262)

Summary:

Changelog: [internal]

At the moment, we can't start surfaces in Fabric without calling `AppRegistry.runApplication`.

This is completely unnecessary in cases like Fantom, where the creation of the surface is done manually from JS and we render to it immediately after (so we don't need to call into JS again to run AppRegistry).

Reviewed By: javache

Differential Revision: D67199971
  • Loading branch information
rubennorte authored and facebook-github-bot committed Dec 16, 2024
1 parent 2fee130 commit 8e314d2
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ SurfaceHandler::SurfaceHandler(
parameters_.surfaceId = surfaceId;
}

SurfaceHandler::SurfaceHandler(SurfaceId surfaceId) noexcept {
parameters_.surfaceId = surfaceId;
}

SurfaceHandler::SurfaceHandler(SurfaceHandler&& other) noexcept {
operator=(std::move(other));
}
Expand Down Expand Up @@ -81,11 +85,15 @@ void SurfaceHandler::start() const noexcept {

link_.shadowTree = shadowTree.get();

link_.uiManager->startSurface(
std::move(shadowTree),
parameters.moduleName,
parameters.props,
parameters_.displayMode);
if (!parameters.moduleName.empty()) {
link_.uiManager->startSurface(
std::move(shadowTree),
parameters.moduleName,
parameters.props,
parameters_.displayMode);
} else {
link_.uiManager->startEmptySurface(std::move(shadowTree));
}

link_.status = Status::Running;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ class SurfaceHandler {
* Can be constructed anytime with a `moduleName` and a `surfaceId`.
*/
SurfaceHandler(const std::string& moduleName, SurfaceId surfaceId) noexcept;

/*
* Can be constructed anytime with a `surfaceId`.
* As the module name is not passed, the surface will have to be rendered
* manually by the caller (AppRegistry will not be called).
*/
SurfaceHandler(SurfaceId surfaceId) noexcept;

virtual ~SurfaceHandler() noexcept;

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ void SurfaceManager::startSurface(
});
}

void SurfaceManager::startEmptySurface(
SurfaceId surfaceId,
const LayoutConstraints& layoutConstraints,
const LayoutContext& layoutContext) const noexcept {
startSurface(surfaceId, "", {}, layoutConstraints, layoutContext);
}

void SurfaceManager::stopSurface(SurfaceId surfaceId) const noexcept {
visit(surfaceId, [&](const SurfaceHandler& surfaceHandler) {
surfaceHandler.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class SurfaceManager final {
const LayoutConstraints& layoutConstraints = {},
const LayoutContext& layoutContext = {}) const noexcept;

void startEmptySurface(
SurfaceId surfaceId,
const LayoutConstraints& layoutConstraints = {},
const LayoutContext& layoutContext = {}) const noexcept;

void stopSurface(SurfaceId surfaceId) const noexcept;

Size measureSurface(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ void UIManager::startSurface(
});
}

void UIManager::startEmptySurface(ShadowTree::Unique&& shadowTree) const {
SystraceSection s("UIManager::startEmptySurface");
shadowTreeRegistry_.add(std::move(shadowTree));
}

void UIManager::setSurfaceProps(
SurfaceId surfaceId,
const std::string& moduleName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class UIManager final : public ShadowTreeDelegate {
const folly::dynamic& props,
DisplayMode displayMode) const;

void startEmptySurface(ShadowTree::Unique&& shadowTree) const;

void setSurfaceProps(
SurfaceId surfaceId,
const std::string& moduleName,
Expand Down

0 comments on commit 8e314d2

Please sign in to comment.