Remove default arguments from ShadowTree::commit and ShadowTree::tryCommit

Summary:
Changelog: [Internal]

Caller needs to explicitly set commit options. This is for readability and making sure caller is aware of what are the options of the commit. This will be important in subsequent diff where we will add another commit option.

Reviewed By: christophpurrer

Differential Revision: D43082837

fbshipit-source-id: 1417205299c19430f902453c2b6d9bb9ca31707d
This commit is contained in:
Samuel Susla 2023-02-08 06:58:33 -08:00 коммит произвёл Facebook GitHub Bot
Родитель 2fbefff178
Коммит 56cb19f419
5 изменённых файлов: 64 добавлений и 52 удалений

Просмотреть файл

@ -427,7 +427,8 @@ void ShadowTree::commitEmptyTree() const {
/* .props = */ ShadowNodeFragment::propsPlaceholder(),
/* .children = */ ShadowNode::emptySharedShadowNodeSharedList(),
});
});
},
{/* default commit options */});
}
void ShadowTree::emitLayoutEvents(

Просмотреть файл

@ -96,14 +96,14 @@ class ShadowTree final {
*/
CommitStatus tryCommit(
const ShadowTreeCommitTransaction &transaction,
const CommitOptions &commitOptions = {false}) const;
const CommitOptions &commitOptions) const;
/*
* Calls `tryCommit` in a loop until it finishes successfully.
*/
CommitStatus commit(
const ShadowTreeCommitTransaction &transaction,
const CommitOptions &commitOptions = {false}) const;
const CommitOptions &commitOptions) const;
/*
* Returns a `ShadowTreeRevision` representing the momentary state of

Просмотреть файл

@ -264,7 +264,8 @@ void Scheduler::renderTemplateToSurface(
std::make_shared<ShadowNode::ListOfShared>(
ShadowNode::ListOfShared{tree}),
});
});
},
{/* default commit options */});
});
} catch (const std::exception &e) {
LOG(ERROR) << " >>>> EXCEPTION <<< rendering uiTemplate in "

Просмотреть файл

@ -9,7 +9,6 @@
#include <react/debug/react_native_assert.h>
#include <react/renderer/debug/SystraceSection.h>
#include <react/renderer/scheduler/Scheduler.h>
#include <react/renderer/uimanager/UIManager.h>
namespace facebook::react {
@ -239,10 +238,12 @@ void SurfaceHandler::constraintLayout(
react_native_assert(
link_.shadowTree && "`link_.shadowTree` must not be null.");
link_.shadowTree->commit([&](RootShadowNode const &oldRootShadowNode) {
return oldRootShadowNode.clone(
propsParserContext, layoutConstraints, layoutContext);
});
link_.shadowTree->commit(
[&](RootShadowNode const &oldRootShadowNode) {
return oldRootShadowNode.clone(
propsParserContext, layoutConstraints, layoutContext);
},
{/* default commit options */});
}
}
@ -286,7 +287,8 @@ void SurfaceHandler::applyDisplayMode(DisplayMode displayMode) const noexcept {
[&](RootShadowNode const & /*oldRootShadowNode*/) {
return std::static_pointer_cast<RootShadowNode>(
revision.rootShadowNode->ShadowNode::clone({}));
});
},
{/* default commit options */});
break;
}
}

Просмотреть файл

@ -309,34 +309,37 @@ void UIManager::updateState(StateUpdate const &stateUpdate) const {
shadowTreeRegistry_.visit(
family->getSurfaceId(), [&](ShadowTree const &shadowTree) {
shadowTree.commit([&](RootShadowNode const &oldRootShadowNode) {
auto isValid = true;
shadowTree.commit(
[&](RootShadowNode const &oldRootShadowNode) {
auto isValid = true;
auto rootNode = oldRootShadowNode.cloneTree(
*family, [&](ShadowNode const &oldShadowNode) {
auto newData =
callback(oldShadowNode.getState()->getDataPointer());
auto rootNode = oldRootShadowNode.cloneTree(
*family, [&](ShadowNode const &oldShadowNode) {
auto newData =
callback(oldShadowNode.getState()->getDataPointer());
if (!newData) {
isValid = false;
// Just return something, we will discard it anyway.
return oldShadowNode.clone({});
}
if (!newData) {
isValid = false;
// Just return something, we will discard it anyway.
return oldShadowNode.clone({});
}
auto newState =
componentDescriptor.createState(*family, newData);
auto newState =
componentDescriptor.createState(*family, newData);
return oldShadowNode.clone({
/* .props = */ ShadowNodeFragment::propsPlaceholder(),
/* .children = */
ShadowNodeFragment::childrenPlaceholder(),
/* .state = */ newState,
});
});
return oldShadowNode.clone({
/* .props = */ ShadowNodeFragment::propsPlaceholder(),
/* .children = */
ShadowNodeFragment::childrenPlaceholder(),
/* .state = */ newState,
});
});
return isValid ? std::static_pointer_cast<RootShadowNode>(rootNode)
: nullptr;
});
return isValid
? std::static_pointer_cast<RootShadowNode>(rootNode)
: nullptr;
},
{/* default commit options */});
});
}
@ -368,23 +371,26 @@ void UIManager::setNativeProps_DEPRECATED(
shadowTreeRegistry_.visit(
family.getSurfaceId(), [&](ShadowTree const &shadowTree) {
shadowTree.commit([&](RootShadowNode const &oldRootShadowNode) {
auto rootNode = oldRootShadowNode.cloneTree(
family, [&](ShadowNode const &oldShadowNode) {
auto &componentDescriptor = componentDescriptorRegistry_->at(
shadowNode->getComponentHandle());
PropsParserContext propsParserContext{
family.getSurfaceId(), *contextContainer_.get()};
auto props = componentDescriptor.cloneProps(
propsParserContext,
getNewestCloneOfShadowNode(*shadowNode)->getProps(),
rawProps);
shadowTree.commit(
[&](RootShadowNode const &oldRootShadowNode) {
auto rootNode = oldRootShadowNode.cloneTree(
family, [&](ShadowNode const &oldShadowNode) {
auto &componentDescriptor =
componentDescriptorRegistry_->at(
shadowNode->getComponentHandle());
PropsParserContext propsParserContext{
family.getSurfaceId(), *contextContainer_.get()};
auto props = componentDescriptor.cloneProps(
propsParserContext,
getNewestCloneOfShadowNode(*shadowNode)->getProps(),
rawProps);
return oldShadowNode.clone({/* .props = */ props});
});
return oldShadowNode.clone({/* .props = */ props});
});
return std::static_pointer_cast<RootShadowNode>(rootNode);
});
return std::static_pointer_cast<RootShadowNode>(rootNode);
},
{/* default commit options */});
});
}
@ -439,10 +445,12 @@ ShadowNode::Shared UIManager::findShadowNodeByTag_DEPRECATED(Tag tag) const {
// We don't want to add a way to access a stored pointer to a root node
// because this `findShadowNodeByTag` is deprecated. It is only added
// to make migration to the new architecture easier.
shadowTree.tryCommit([&](RootShadowNode const &oldRootShadowNode) {
rootShadowNode = &oldRootShadowNode;
return nullptr;
});
shadowTree.tryCommit(
[&](RootShadowNode const &oldRootShadowNode) {
rootShadowNode = &oldRootShadowNode;
return nullptr;
},
{/* default commit options */});
if (rootShadowNode != nullptr) {
auto const &children = rootShadowNode->getChildren();