Skip to content

Commit 744a0f8

Browse files
zeyapfacebook-github-bot
authored andcommitted
Move rncxx scheduler to oss (#50535)
Summary: Pull Request resolved: #50535 ## Changelog: [General] [Added] - Move rncxx scheduler to oss Reviewed By: rshest Differential Revision: D72588228 fbshipit-source-id: 428c60e20351b9fed49fcbdbd617b5b5940b8a2c
1 parent 7938919 commit 744a0f8

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
2+
3+
#include "SchedulerDelegateImpl.h"
4+
5+
namespace facebook::react {
6+
7+
SchedulerDelegateImpl::SchedulerDelegateImpl(
8+
std::shared_ptr<IMountingManager> mountingManager) noexcept
9+
: mountingManager_(std::move(mountingManager)) {}
10+
11+
void SchedulerDelegateImpl::schedulerDidFinishTransaction(
12+
const std::shared_ptr<const MountingCoordinator>& /*mountingCoordinator*/) {
13+
// no-op, we will flush the transaction from schedulerShouldRenderTransactions
14+
}
15+
16+
void SchedulerDelegateImpl::schedulerShouldRenderTransactions(
17+
const std::shared_ptr<const MountingCoordinator>& mountingCoordinator) {
18+
auto surfaceId = mountingCoordinator->getSurfaceId();
19+
if (auto transaction = mountingCoordinator->pullTransaction();
20+
transaction.has_value()) {
21+
if (auto& transactionValue = transaction.value();
22+
!transactionValue.getMutations().empty()) {
23+
mountingManager_->executeMount(surfaceId, std::move(transactionValue));
24+
}
25+
}
26+
}
27+
28+
void SchedulerDelegateImpl::schedulerDidRequestPreliminaryViewAllocation(
29+
const ShadowNode& shadowNode) {}
30+
31+
void SchedulerDelegateImpl::schedulerDidDispatchCommand(
32+
const ShadowView& shadowView,
33+
const std::string& commandName,
34+
const folly::dynamic& args) {
35+
mountingManager_->dispatchCommand(shadowView, commandName, args);
36+
}
37+
38+
void SchedulerDelegateImpl::schedulerDidSetIsJSResponder(
39+
const ShadowView& shadowView,
40+
bool isJSResponder,
41+
bool blockNativeResponder) {
42+
mountingManager_->setIsJSResponder(
43+
shadowView, isJSResponder, blockNativeResponder);
44+
}
45+
46+
void SchedulerDelegateImpl::schedulerDidSendAccessibilityEvent(
47+
const ShadowView& shadowView,
48+
const std::string& eventType) {}
49+
50+
void SchedulerDelegateImpl::schedulerShouldSynchronouslyUpdateViewOnUIThread(
51+
Tag tag,
52+
const folly::dynamic& props) {
53+
mountingManager_->synchronouslyUpdateViewOnUIThread(tag, props);
54+
}
55+
56+
} // namespace facebook::react
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
2+
3+
#pragma once
4+
5+
#include <react/renderer/scheduler/SchedulerDelegate.h>
6+
#include <react/renderer/uimanager/IMountingManager.h>
7+
8+
namespace facebook::react {
9+
10+
class IMountingManager;
11+
12+
class SchedulerDelegateImpl : public SchedulerDelegate {
13+
public:
14+
SchedulerDelegateImpl(
15+
std::shared_ptr<IMountingManager> mountingManager) noexcept;
16+
17+
~SchedulerDelegateImpl() noexcept override = default;
18+
19+
SchedulerDelegateImpl(SchedulerDelegateImpl&&) noexcept = default;
20+
SchedulerDelegateImpl& operator=(SchedulerDelegateImpl&&) noexcept = default;
21+
SchedulerDelegateImpl(const SchedulerDelegateImpl&) = delete;
22+
SchedulerDelegateImpl& operator=(const SchedulerDelegateImpl&) = delete;
23+
24+
private:
25+
void schedulerDidFinishTransaction(
26+
const std::shared_ptr<const MountingCoordinator>& mountingCoordinator)
27+
override;
28+
29+
void schedulerShouldRenderTransactions(
30+
const std::shared_ptr<const MountingCoordinator>& mountingCoordinator)
31+
override;
32+
33+
void schedulerDidRequestPreliminaryViewAllocation(
34+
const ShadowNode& shadowNode) override;
35+
36+
void schedulerDidDispatchCommand(
37+
const ShadowView& shadowView,
38+
const std::string& commandName,
39+
const folly::dynamic& args) override;
40+
41+
void schedulerDidSetIsJSResponder(
42+
const ShadowView& shadowView,
43+
bool isJSResponder,
44+
bool blockNativeResponder) override;
45+
46+
void schedulerDidSendAccessibilityEvent(
47+
const ShadowView& shadowView,
48+
const std::string& eventType) override;
49+
50+
void schedulerShouldSynchronouslyUpdateViewOnUIThread(
51+
Tag tag,
52+
const folly::dynamic& props) override;
53+
54+
std::shared_ptr<IMountingManager> mountingManager_;
55+
};
56+
57+
}; // namespace facebook::react
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
2+
3+
#pragma once
4+
5+
#include <string>
6+
7+
namespace facebook::react {
8+
/**
9+
* Interface for handling a surface in React Native. Each platform can have
10+
* custom logic to show/hide.
11+
* Inspired by
12+
* xplat/js/react-native-github/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/SurfaceDelegate.java
13+
*/
14+
class SurfaceDelegate {
15+
public:
16+
virtual ~SurfaceDelegate() = default;
17+
18+
/**
19+
* Create the React content view that uses the appKey as the React application
20+
* name
21+
*/
22+
virtual void createContentView(std::string appKey) = 0;
23+
24+
/**
25+
* Check if the content view is created and ready to be shown
26+
*/
27+
virtual bool isContentViewReady() = 0;
28+
29+
/** Destroy the React content view to avoid memory leak */
30+
virtual void destroyContentView() = 0;
31+
32+
/** Show the surface containing the React content view */
33+
virtual void show() = 0;
34+
35+
/** Hide the surface containing the React content view */
36+
virtual void hide() = 0;
37+
38+
/** Check if the surface is currently showing */
39+
virtual bool isShowing() = 0;
40+
};
41+
} // namespace facebook::react

0 commit comments

Comments
 (0)