From 08e4537680df2671f3ae561a54d0424132b96376 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Fri, 2 Aug 2019 16:34:58 -0700 Subject: [PATCH] Expose JS Responder handler in Scheduler API Summary: This diff implements the JSResponderHandler methods in the core of RN (scheduler API and friends) Reviewed By: ejanzer Differential Revision: D16543437 fbshipit-source-id: dac03e30c4330d182ecf134f3174ba942dbf7289 --- React/Fabric/RNScheduler.mm | 14 +++++++++++ .../com/facebook/react/fabric/jni/Binding.cpp | 8 ++++++ .../com/facebook/react/fabric/jni/Binding.h | 8 ++++++ ReactCommon/fabric/uimanager/Scheduler.cpp | 25 +++++++++++++++++++ ReactCommon/fabric/uimanager/Scheduler.h | 5 ++++ .../fabric/uimanager/SchedulerDelegate.h | 14 +++++++++++ ReactCommon/fabric/uimanager/UIManager.cpp | 13 ++++++++-- .../fabric/uimanager/UIManagerDelegate.h | 13 ++++++++++ 8 files changed, 98 insertions(+), 2 deletions(-) diff --git a/React/Fabric/RNScheduler.mm b/React/Fabric/RNScheduler.mm index 2e4a647b231..7ef7fda25de 100644 --- a/React/Fabric/RNScheduler.mm +++ b/React/Fabric/RNScheduler.mm @@ -43,6 +43,20 @@ class SchedulerDelegateProxy : public SchedulerDelegate { [scheduler.delegate schedulerDidDispatchCommand:shadowView commandName:commandName args:args]; } + void schedulerDidSetJSResponder( + SurfaceId surfaceId, + const ShadowView &shadowView, + const ShadowView &initialShadowView, + bool blockNativeResponder) override + { + // Does nothing for now. + } + + void schedulerDidClearJSResponder() override + { + // Does nothing for now. + } + private: void *scheduler_; }; diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp index 42ffb8af28d..0b6407a9330 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp @@ -724,6 +724,14 @@ void Binding::schedulerDidDispatchCommand( dispatchCommand(localJavaUIManager, shadowView.tag, command.get(), argsArray.get()); } +void Binding::schedulerDidSetJSResponder( + SurfaceId surfaceId, + const ShadowView &shadowView, + const ShadowView &initialShadowView, + bool blockNativeResponder) { } + +void Binding::schedulerDidClearJSResponder() { } + void Binding::registerNatives() { registerHybrid( {makeNativeMethod("initHybrid", Binding::initHybrid), diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.h b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.h index 0589e6985cb..c4c65e5f602 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.h +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.h @@ -89,6 +89,14 @@ class Binding : public jni::HybridClass, public SchedulerDelegate { void setPixelDensity(float pointScaleFactor); + void schedulerDidSetJSResponder( + SurfaceId surfaceId, + const ShadowView &shadowView, + const ShadowView &initialShadowView, + bool blockNativeResponder); + + void schedulerDidClearJSResponder(); + void uninstallFabricUIManager(); }; diff --git a/ReactCommon/fabric/uimanager/Scheduler.cpp b/ReactCommon/fabric/uimanager/Scheduler.cpp index 0247a4bccd0..cb4b38c61c0 100644 --- a/ReactCommon/fabric/uimanager/Scheduler.cpp +++ b/ReactCommon/fabric/uimanager/Scheduler.cpp @@ -274,5 +274,30 @@ void Scheduler::uiManagerDidDispatchCommand( } } +/* + * Set JS responder for a view + */ +void Scheduler::uiManagerDidSetJSResponder( + SurfaceId surfaceId, + const SharedShadowNode &shadowNode, + bool blockNativeResponder) { + if (delegate_) { + // TODO: the first shadowView paramenter, should be the first parent that + // is non virtual. + auto shadowView = ShadowView(*shadowNode); + delegate_->schedulerDidSetJSResponder( + surfaceId, shadowView, shadowView, blockNativeResponder); + } +} + +/* + * Clear the JSResponder for a view + */ +void Scheduler::uiManagerDidClearJSResponder() { + if (delegate_) { + delegate_->schedulerDidClearJSResponder(); + } +} + } // namespace react } // namespace facebook diff --git a/ReactCommon/fabric/uimanager/Scheduler.h b/ReactCommon/fabric/uimanager/Scheduler.h index 286561299a8..4f87ab77803 100644 --- a/ReactCommon/fabric/uimanager/Scheduler.h +++ b/ReactCommon/fabric/uimanager/Scheduler.h @@ -90,6 +90,11 @@ class Scheduler final : public UIManagerDelegate, public ShadowTreeDelegate { const SharedShadowNode &shadowNode, std::string const &commandName, folly::dynamic const args) override; + void uiManagerDidSetJSResponder( + SurfaceId surfaceId, + const SharedShadowNode &shadowView, + bool blockNativeResponder) override; + void uiManagerDidClearJSResponder() override; #pragma mark - ShadowTreeDelegate diff --git a/ReactCommon/fabric/uimanager/SchedulerDelegate.h b/ReactCommon/fabric/uimanager/SchedulerDelegate.h index d6cafde2ac3..acc0ddc279b 100644 --- a/ReactCommon/fabric/uimanager/SchedulerDelegate.h +++ b/ReactCommon/fabric/uimanager/SchedulerDelegate.h @@ -40,6 +40,20 @@ class SchedulerDelegate { std::string const &commandName, folly::dynamic const args) = 0; + /* + * Set JS responder for a view + */ + virtual void schedulerDidSetJSResponder( + SurfaceId surfaceId, + const ShadowView &shadowView, + const ShadowView &initialShadowView, + bool blockNativeResponder) = 0; + + /* + * Clear the JSResponder for a view + */ + virtual void schedulerDidClearJSResponder() = 0; + virtual ~SchedulerDelegate() noexcept = default; }; diff --git a/ReactCommon/fabric/uimanager/UIManager.cpp b/ReactCommon/fabric/uimanager/UIManager.cpp index 088994583b6..10903085afc 100644 --- a/ReactCommon/fabric/uimanager/UIManager.cpp +++ b/ReactCommon/fabric/uimanager/UIManager.cpp @@ -93,9 +93,18 @@ void UIManager::completeSurface( void UIManager::setJSResponder( const SharedShadowNode &shadowNode, - const bool blockNativeResponder) const {} + const bool blockNativeResponder) const { + if (delegate_) { + delegate_->uiManagerDidSetJSResponder( + shadowNode->getSurfaceId(), shadowNode, blockNativeResponder); + } +} -void UIManager::clearJSResponder() const {} +void UIManager::clearJSResponder() const { + if (delegate_) { + delegate_->uiManagerDidClearJSResponder(); + } +} void UIManager::setNativeProps( const SharedShadowNode &shadowNode, diff --git a/ReactCommon/fabric/uimanager/UIManagerDelegate.h b/ReactCommon/fabric/uimanager/UIManagerDelegate.h index 73cd581d19c..e2e7e939269 100644 --- a/ReactCommon/fabric/uimanager/UIManagerDelegate.h +++ b/ReactCommon/fabric/uimanager/UIManagerDelegate.h @@ -42,6 +42,19 @@ class UIManagerDelegate { std::string const &commandName, folly::dynamic const args) = 0; + /* + * Set JS responder for a view + */ + virtual void uiManagerDidSetJSResponder( + SurfaceId surfaceId, + SharedShadowNode const &shadowView, + bool blockNativeResponder) = 0; + + /* + * Clear the JSResponder for a view + */ + virtual void uiManagerDidClearJSResponder() = 0; + virtual ~UIManagerDelegate() noexcept = default; };