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 @@ -51,4 +51,20 @@ std::optional<jsi::Object> NativeViewTransition::getViewTransitionInstance(
return result;
}

jsi::Value NativeViewTransition::findPseudoElementShadowNodeByTag(
jsi::Runtime& rt,
double reactTag) {
auto& uiManager = UIManagerBinding::getBinding(rt)->getUIManager();
auto* viewTransitionDelegate = uiManager.getViewTransitionDelegate();
if (viewTransitionDelegate != nullptr) {
auto shadowNode = viewTransitionDelegate->findPseudoElementShadowNodeByTag(
static_cast<Tag>(reactTag));
if (shadowNode) {
return Bridging<std::shared_ptr<const ShadowNode>>::toJs(rt, shadowNode);
}
}

return jsi::Value::null();
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class NativeViewTransition : public NativeViewTransitionCxxSpec<NativeViewTransi

std::optional<jsi::Object>
getViewTransitionInstance(jsi::Runtime &rt, const std::string &name, const std::string &pseudo);

jsi::Value findPseudoElementShadowNodeByTag(jsi::Runtime &rt, double reactTag);
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,8 @@ Scheduler::Scheduler(

// Initialize ViewTransitionModule
if (ReactNativeFeatureFlags::viewTransitionEnabled()) {
viewTransitionModule_ = std::make_unique<ViewTransitionModule>();
viewTransitionModule_->setUIManager(uiManager_.get());
uiManager_->setViewTransitionDelegate(viewTransitionModule_.get());
viewTransitionModule_ = std::make_shared<ViewTransitionModule>();
viewTransitionModule_->initialize(uiManager_.get(), viewTransitionModule_);
}

uiManager->registerMountHook(*eventPerformanceLogger_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class Scheduler final : public UIManagerDelegate {

RuntimeScheduler *runtimeScheduler_{nullptr};

std::unique_ptr<ViewTransitionModule> viewTransitionModule_;
std::shared_ptr<ViewTransitionModule> viewTransitionModule_;

mutable std::shared_mutex onSurfaceStartCallbackMutex_;
OnSurfaceStartCallback onSurfaceStartCallback_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,37 @@ jsi::Value UIManagerBinding::get(
});
}

if (methodName == "createViewTransitionInstance") {
auto paramCount = 2;
return jsi::Function::createFromHostFunction(
runtime,
name,
paramCount,
[uiManager, methodName, paramCount](
jsi::Runtime& runtime,
const jsi::Value& /*thisValue*/,
const jsi::Value* arguments,
size_t count) -> jsi::Value {
validateArgumentCount(runtime, methodName, paramCount, count);

auto transitionName = arguments[0].isString()
? stringFromValue(runtime, arguments[0])
: "";
auto pseudoElementTag = tagFromValue(arguments[1]);

if (!transitionName.empty()) {
auto* viewTransitionDelegate =
uiManager->getViewTransitionDelegate();
if (viewTransitionDelegate != nullptr) {
viewTransitionDelegate->createViewTransitionInstance(
transitionName, pseudoElementTag);
}
}

return jsi::Value::undefined();
});
}

if (methodName == "cancelViewTransitionName") {
auto paramCount = 2;
return jsi::Function::createFromHostFunction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class UIManagerViewTransitionDelegate {
{
}

virtual void createViewTransitionInstance(const std::string & /*name*/, Tag /*pseudoElementTag*/) {}

virtual void cancelViewTransitionName(const ShadowNode &shadowNode, const std::string &name) {}

virtual void restoreViewTransitionName(const ShadowNode &shadowNode) {}
Expand Down Expand Up @@ -55,6 +57,16 @@ class UIManagerViewTransitionDelegate {
{
return std::nullopt;
}

// Similar to UIManager::findShadowNodeByTag, but searches all direct children
// of the root node (where pseudo-element nodes live) rather than just the
// first child. Pseudo-element nodes are appended as additional children of the
// root node, rather than inserted into the main React tree, to avoid
// disrupting the user-created component tree.
virtual std::shared_ptr<const ShadowNode> findPseudoElementShadowNodeByTag(Tag /*tag*/) const
{
return nullptr;
}
};

} // namespace facebook::react
Loading
Loading