Skip to content
Merged
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 @@ -359,7 +359,7 @@ NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(
std::make_shared<AsyncEventEmitter<folly::dynamic>>();
eventEmitterMap_["onSubmit"] =
std::make_shared<AsyncEventEmitter<folly::dynamic>>();
configureEventEmitterCallback();
// configureEventEmitterCallback();
}

std::shared_ptr<TurboModule> SampleTurboModuleSpec_ModuleProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@

#include "ShadowTreeDelegate.h"

// Discord - Wrap with ScopeGuard for a function to run on the end of the scope:
#include <functional>
struct ScopeGuard {
std::function<void()> fn;
~ScopeGuard() { fn(); }
};
#define CONCAT_IMPL(x, y) x##y
#define CONCAT(x, y) CONCAT_IMPL(x, y)
#define defer(code) ScopeGuard CONCAT(defer, LINE)([&](){code;})

namespace facebook::react {

using CommitStatus = ShadowTree::CommitStatus;
Expand Down Expand Up @@ -297,6 +307,7 @@ CommitStatus ShadowTree::tryCommit(
*this, oldRootShadowNode, newRootShadowNode, commitOptions);

if (!newRootShadowNode) {
delegate_.shadowTreeCommitFinalized(commitOptions);
return CommitStatus::Cancelled;
}

Expand All @@ -313,6 +324,7 @@ CommitStatus ShadowTree::tryCommit(
{
// Updating `currentRevision_` in unique manner if it hasn't changed.
std::unique_lock lock(commitMutex_);
defer(delegate_.shadowTreeCommitFinalized(commitOptions));

if (ReactNativeFeatureFlags::
enableGranularShadowTreeStateReconciliation()) {
Expand All @@ -331,6 +343,8 @@ CommitStatus ShadowTree::tryCommit(

auto newRevisionNumber = currentRevision_.number + 1;

delegate_.shadowTreeCommitSucceeded(commitOptions);

{
std::scoped_lock dispatchLock(EventEmitter::DispatchMutex());
updateMountedFlag(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class ShadowTreeDelegate {
std::shared_ptr<const MountingCoordinator> mountingCoordinator,
bool mountSynchronously) const = 0;

// Called after a commit is known to succeed, however, still under the commit lock
virtual void shadowTreeCommitSucceeded(const ShadowTreeCommitOptions& commitOptions) const = 0;
// Will be called in each case once we are done with the current commit attempt
virtual void shadowTreeCommitFinalized(const ShadowTreeCommitOptions& commitOptions) const = 0;

virtual ~ShadowTreeDelegate() noexcept = default;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class DummyShadowTreeDelegate : public ShadowTreeDelegate {
void shadowTreeDidFinishTransaction(
std::shared_ptr<const MountingCoordinator> mountingCoordinator,
bool mountSynchronously) const override {};

void shadowTreeCommitSucceeded(const ShadowTreeCommitOptions& commitOptions) const override {};
void shadowTreeCommitFinalized(const ShadowTreeCommitOptions& commitOptions) const override {};
};

namespace {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,22 @@ RootShadowNode::Unshared UIManager::shadowTreeWillCommit(
return resultRootShadowNode;
}

void UIManager::shadowTreeCommitSucceeded(const ShadowTreeCommitOptions& commitOptions) const {
std::shared_lock lock(commitHookMutex_);

for (auto* commitHook : commitHooks_) {
commitHook->shadowTreeCommitSucceeded(commitOptions);
}
}

void UIManager::shadowTreeCommitFinalized(const ShadowTreeCommitOptions& commitOptions) const {
std::shared_lock lock(commitHookMutex_);

for (auto* commitHook : commitHooks_) {
commitHook->shadowTreeCommitFinalized(commitOptions);
}
}

void UIManager::shadowTreeDidFinishTransaction(
std::shared_ptr<const MountingCoordinator> mountingCoordinator,
bool mountSynchronously) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ class UIManager final : public ShadowTreeDelegate {
const RootShadowNode::Unshared& newRootShadowNode,
const ShadowTree::CommitOptions& commitOptions) const override;

void shadowTreeCommitSucceeded(const ShadowTreeCommitOptions& commitOptions) const override;
void shadowTreeCommitFinalized(const ShadowTreeCommitOptions& commitOptions) const override;

std::shared_ptr<ShadowNode> createNode(
Tag tag,
const std::string& componentName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class UIManagerCommitHook {
return newRootShadowNode;
}

// Discord - Called after a commit is known to succeed, however, still under the commit lock
virtual void shadowTreeCommitSucceeded(const ShadowTreeCommitOptions& commitOptions) = 0;
// Discord - Will be called in each case once we are done with the current commit attempt
virtual void shadowTreeCommitFinalized(const ShadowTreeCommitOptions& commitOptions) = 0;

virtual ~UIManagerCommitHook() noexcept = default;
};

Expand Down
Loading