synchronouslyUpdateViewOnUIThread on UIManager (#50379)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/50379

## Changelog:

[Android] [Added] - Allow invoking `synchronouslyUpdateViewOnUIThread` from c++ via `UIManager`
implementation is provided by SchedulerDelegate on the platform

Reviewed By: javache

Differential Revision: D71648772

fbshipit-source-id: bba0f7e9e2deafd074d28ff5cece6b7738c4d123
This commit is contained in:
Zeya Peng
2025-03-31 13:17:56 -07:00
committed by Facebook GitHub Bot
parent 97324abc0e
commit 4912958812
9 changed files with 46 additions and 0 deletions
@@ -68,6 +68,12 @@ class SchedulerDelegateProxy : public SchedulerDelegate {
[scheduler.delegate schedulerDidSendAccessibilityEvent:shadowView eventType:eventType];
}
void schedulerShouldSynchronouslyUpdateViewOnUIThread(facebook::react::Tag tag, const folly::dynamic &props) override
{
// Does nothing.
// This delegate method is not currently used on iOS.
}
private:
void *scheduler_;
};
@@ -620,6 +620,10 @@ void FabricUIManagerBinding::schedulerDidSetIsJSResponder(
shadowView, isJSResponder, blockNativeResponder);
}
void FabricUIManagerBinding::schedulerShouldSynchronouslyUpdateViewOnUIThread(
Tag tag,
const folly::dynamic& props) {}
void FabricUIManagerBinding::onAnimationStarted() {
auto mountingManager = getMountingManager("onAnimationStarted");
if (!mountingManager) {
@@ -120,6 +120,10 @@ class FabricUIManagerBinding : public jni::HybridClass<FabricUIManagerBinding>,
bool isJSResponder,
bool blockNativeResponder) override;
void schedulerShouldSynchronouslyUpdateViewOnUIThread(
Tag tag,
const folly::dynamic& props) override;
void setPixelDensity(float pointScaleFactor);
void driveCxxAnimations();
@@ -320,6 +320,14 @@ void Scheduler::uiManagerDidSetIsJSResponder(
}
}
void Scheduler::uiManagerShouldSynchronouslyUpdateViewOnUIThread(
Tag tag,
const folly::dynamic& props) {
if (delegate_ != nullptr) {
delegate_->schedulerShouldSynchronouslyUpdateViewOnUIThread(tag, props);
}
}
void Scheduler::reportMount(SurfaceId surfaceId) const {
uiManager_->reportMount(surfaceId);
}
@@ -95,6 +95,9 @@ class Scheduler final : public UIManagerDelegate {
const ShadowNode::Shared& shadowNode,
bool isJSResponder,
bool blockNativeResponder) override;
void uiManagerShouldSynchronouslyUpdateViewOnUIThread(
Tag tag,
const folly::dynamic& props) override;
#pragma mark - ContextContainer
ContextContainer::Shared getContextContainer() const;
@@ -64,6 +64,10 @@ class SchedulerDelegate {
bool isJSResponder,
bool blockNativeResponder) = 0;
virtual void schedulerShouldSynchronouslyUpdateViewOnUIThread(
Tag tag,
const folly::dynamic& props) = 0;
virtual ~SchedulerDelegate() noexcept = default;
};
@@ -690,4 +690,12 @@ void UIManager::animationTick() const {
}
}
void UIManager::synchronouslyUpdateViewOnUIThread(
Tag tag,
const folly::dynamic& props) {
if (delegate_ != nullptr) {
delegate_->uiManagerShouldSynchronouslyUpdateViewOnUIThread(tag, props);
}
}
} // namespace facebook::react
@@ -70,6 +70,8 @@ class UIManager final : public ShadowTreeDelegate {
void animationTick() const;
void synchronouslyUpdateViewOnUIThread(Tag tag, const folly::dynamic& props);
/*
* Provides access to a UIManagerBindging.
* The `callback` methods will not be called if the internal pointer to
@@ -58,6 +58,13 @@ class UIManagerDelegate {
bool isJSResponder,
bool blockNativeResponder) = 0;
/*
* Synchronous view update.
*/
virtual void uiManagerShouldSynchronouslyUpdateViewOnUIThread(
Tag tag,
const folly::dynamic& props) = 0;
virtual ~UIManagerDelegate() noexcept = default;
};