forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRCTScheduler.mm
More file actions
125 lines (102 loc) · 3.99 KB
/
RCTScheduler.mm
File metadata and controls
125 lines (102 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTScheduler.h"
#import <react/debug/SystraceSection.h>
#import <react/uimanager/ComponentDescriptorFactory.h>
#import <react/uimanager/Scheduler.h>
#import <react/uimanager/SchedulerDelegate.h>
#import <React/RCTFollyConvert.h>
#import "RCTConversions.h"
using namespace facebook::react;
class SchedulerDelegateProxy : public SchedulerDelegate {
public:
SchedulerDelegateProxy(void *scheduler) : scheduler_(scheduler) {}
void schedulerDidFinishTransaction(MountingCoordinator::Shared const &mountingCoordinator) override
{
RCTScheduler *scheduler = (__bridge RCTScheduler *)scheduler_;
[scheduler.delegate schedulerDidFinishTransaction:mountingCoordinator];
}
void schedulerDidRequestPreliminaryViewAllocation(SurfaceId surfaceId, const ShadowView &shadowView) override
{
// Does nothing.
// Preemptive allocation of native views on iOS does not require this call.
}
void schedulerDidDispatchCommand(
const ShadowView &shadowView,
const std::string &commandName,
const folly::dynamic args) override
{
RCTScheduler *scheduler = (__bridge RCTScheduler *)scheduler_;
[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_;
};
@implementation RCTScheduler {
std::shared_ptr<Scheduler> _scheduler;
std::shared_ptr<SchedulerDelegateProxy> _delegateProxy;
}
- (instancetype)initWithToolbox:(facebook::react::SchedulerToolbox)toolbox
{
if (self = [super init]) {
_delegateProxy = std::make_shared<SchedulerDelegateProxy>((__bridge void *)self);
_scheduler = std::make_shared<Scheduler>(toolbox, _delegateProxy.get());
}
return self;
}
- (void)dealloc
{
_scheduler->setDelegate(nullptr);
}
- (void)startSurfaceWithSurfaceId:(SurfaceId)surfaceId
moduleName:(NSString *)moduleName
initialProps:(NSDictionary *)initialProps
layoutConstraints:(LayoutConstraints)layoutConstraints
layoutContext:(LayoutContext)layoutContext;
{
SystraceSection s("-[RCTScheduler startSurfaceWithSurfaceId:...]");
auto props = convertIdToFollyDynamic(initialProps);
_scheduler->startSurface(surfaceId, RCTStringFromNSString(moduleName), props, layoutConstraints, layoutContext);
_scheduler->renderTemplateToSurface(
surfaceId, props.getDefault("navigationConfig").getDefault("initialUITemplate", "").getString());
}
- (void)stopSurfaceWithSurfaceId:(SurfaceId)surfaceId
{
SystraceSection s("-[RCTScheduler stopSurfaceWithSurfaceId:]");
_scheduler->stopSurface(surfaceId);
}
- (CGSize)measureSurfaceWithLayoutConstraints:(LayoutConstraints)layoutConstraints
layoutContext:(LayoutContext)layoutContext
surfaceId:(SurfaceId)surfaceId
{
SystraceSection s("-[RCTScheduler measureSurfaceWithLayoutConstraints:]");
return RCTCGSizeFromSize(_scheduler->measureSurface(surfaceId, layoutConstraints, layoutContext));
}
- (void)constraintSurfaceLayoutWithLayoutConstraints:(LayoutConstraints)layoutConstraints
layoutContext:(LayoutContext)layoutContext
surfaceId:(SurfaceId)surfaceId
{
SystraceSection s("-[RCTScheduler constraintSurfaceLayoutWithLayoutConstraints:]");
_scheduler->constraintSurfaceLayout(surfaceId, layoutConstraints, layoutContext);
}
- (const ComponentDescriptor &)getComponentDescriptor:(ComponentHandle)handle
{
return _scheduler->getComponentDescriptor(handle);
}
@end