Skip to content

Commit 08e4537

Browse files
mdvaccafacebook-github-bot
authored andcommitted
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
1 parent 470ace0 commit 08e4537

File tree

8 files changed

+98
-2
lines changed

8 files changed

+98
-2
lines changed

React/Fabric/RNScheduler.mm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ void schedulerDidDispatchCommand(
4343
[scheduler.delegate schedulerDidDispatchCommand:shadowView commandName:commandName args:args];
4444
}
4545

46+
void schedulerDidSetJSResponder(
47+
SurfaceId surfaceId,
48+
const ShadowView &shadowView,
49+
const ShadowView &initialShadowView,
50+
bool blockNativeResponder) override
51+
{
52+
// Does nothing for now.
53+
}
54+
55+
void schedulerDidClearJSResponder() override
56+
{
57+
// Does nothing for now.
58+
}
59+
4660
private:
4761
void *scheduler_;
4862
};

ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,14 @@ void Binding::schedulerDidDispatchCommand(
724724
dispatchCommand(localJavaUIManager, shadowView.tag, command.get(), argsArray.get());
725725
}
726726

727+
void Binding::schedulerDidSetJSResponder(
728+
SurfaceId surfaceId,
729+
const ShadowView &shadowView,
730+
const ShadowView &initialShadowView,
731+
bool blockNativeResponder) { }
732+
733+
void Binding::schedulerDidClearJSResponder() { }
734+
727735
void Binding::registerNatives() {
728736
registerHybrid(
729737
{makeNativeMethod("initHybrid", Binding::initHybrid),

ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ class Binding : public jni::HybridClass<Binding>, public SchedulerDelegate {
8989

9090
void setPixelDensity(float pointScaleFactor);
9191

92+
void schedulerDidSetJSResponder(
93+
SurfaceId surfaceId,
94+
const ShadowView &shadowView,
95+
const ShadowView &initialShadowView,
96+
bool blockNativeResponder);
97+
98+
void schedulerDidClearJSResponder();
99+
92100
void uninstallFabricUIManager();
93101
};
94102

ReactCommon/fabric/uimanager/Scheduler.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,5 +274,30 @@ void Scheduler::uiManagerDidDispatchCommand(
274274
}
275275
}
276276

277+
/*
278+
* Set JS responder for a view
279+
*/
280+
void Scheduler::uiManagerDidSetJSResponder(
281+
SurfaceId surfaceId,
282+
const SharedShadowNode &shadowNode,
283+
bool blockNativeResponder) {
284+
if (delegate_) {
285+
// TODO: the first shadowView paramenter, should be the first parent that
286+
// is non virtual.
287+
auto shadowView = ShadowView(*shadowNode);
288+
delegate_->schedulerDidSetJSResponder(
289+
surfaceId, shadowView, shadowView, blockNativeResponder);
290+
}
291+
}
292+
293+
/*
294+
* Clear the JSResponder for a view
295+
*/
296+
void Scheduler::uiManagerDidClearJSResponder() {
297+
if (delegate_) {
298+
delegate_->schedulerDidClearJSResponder();
299+
}
300+
}
301+
277302
} // namespace react
278303
} // namespace facebook

ReactCommon/fabric/uimanager/Scheduler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ class Scheduler final : public UIManagerDelegate, public ShadowTreeDelegate {
9090
const SharedShadowNode &shadowNode,
9191
std::string const &commandName,
9292
folly::dynamic const args) override;
93+
void uiManagerDidSetJSResponder(
94+
SurfaceId surfaceId,
95+
const SharedShadowNode &shadowView,
96+
bool blockNativeResponder) override;
97+
void uiManagerDidClearJSResponder() override;
9398

9499
#pragma mark - ShadowTreeDelegate
95100

ReactCommon/fabric/uimanager/SchedulerDelegate.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ class SchedulerDelegate {
4040
std::string const &commandName,
4141
folly::dynamic const args) = 0;
4242

43+
/*
44+
* Set JS responder for a view
45+
*/
46+
virtual void schedulerDidSetJSResponder(
47+
SurfaceId surfaceId,
48+
const ShadowView &shadowView,
49+
const ShadowView &initialShadowView,
50+
bool blockNativeResponder) = 0;
51+
52+
/*
53+
* Clear the JSResponder for a view
54+
*/
55+
virtual void schedulerDidClearJSResponder() = 0;
56+
4357
virtual ~SchedulerDelegate() noexcept = default;
4458
};
4559

ReactCommon/fabric/uimanager/UIManager.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,18 @@ void UIManager::completeSurface(
9393

9494
void UIManager::setJSResponder(
9595
const SharedShadowNode &shadowNode,
96-
const bool blockNativeResponder) const {}
96+
const bool blockNativeResponder) const {
97+
if (delegate_) {
98+
delegate_->uiManagerDidSetJSResponder(
99+
shadowNode->getSurfaceId(), shadowNode, blockNativeResponder);
100+
}
101+
}
97102

98-
void UIManager::clearJSResponder() const {}
103+
void UIManager::clearJSResponder() const {
104+
if (delegate_) {
105+
delegate_->uiManagerDidClearJSResponder();
106+
}
107+
}
99108

100109
void UIManager::setNativeProps(
101110
const SharedShadowNode &shadowNode,

ReactCommon/fabric/uimanager/UIManagerDelegate.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ class UIManagerDelegate {
4242
std::string const &commandName,
4343
folly::dynamic const args) = 0;
4444

45+
/*
46+
* Set JS responder for a view
47+
*/
48+
virtual void uiManagerDidSetJSResponder(
49+
SurfaceId surfaceId,
50+
SharedShadowNode const &shadowView,
51+
bool blockNativeResponder) = 0;
52+
53+
/*
54+
* Clear the JSResponder for a view
55+
*/
56+
virtual void uiManagerDidClearJSResponder() = 0;
57+
4558
virtual ~UIManagerDelegate() noexcept = default;
4659
};
4760

0 commit comments

Comments
 (0)