2018-04-10 16:37:01 -07:00
|
|
|
/**
|
2018-09-11 15:27:47 -07:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2018-04-10 16:37:01 -07:00
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2018-11-10 14:19:08 -08:00
|
|
|
#import <react/uimanager/ContextContainer.h>
|
|
|
|
#import <react/uimanager/Scheduler.h>
|
|
|
|
#import <react/uimanager/SchedulerDelegate.h>
|
2018-04-10 16:37:01 -07:00
|
|
|
|
2018-09-26 10:02:04 -07:00
|
|
|
#import <React/RCTFollyConvert.h>
|
|
|
|
|
2018-05-08 22:56:27 -07:00
|
|
|
#import "RCTConversions.h"
|
|
|
|
|
2018-04-10 16:37:01 -07:00
|
|
|
using namespace facebook::react;
|
|
|
|
|
|
|
|
class SchedulerDelegateProxy: public SchedulerDelegate {
|
|
|
|
public:
|
2018-09-24 12:54:26 -07:00
|
|
|
SchedulerDelegateProxy(void *scheduler):
|
|
|
|
scheduler_(scheduler) {}
|
2018-04-10 16:37:01 -07:00
|
|
|
|
2018-09-03 22:53:18 -07:00
|
|
|
void schedulerDidFinishTransaction(Tag rootTag, const ShadowViewMutationList &mutations) override {
|
2018-04-10 16:37:01 -07:00
|
|
|
RCTScheduler *scheduler = (__bridge RCTScheduler *)scheduler_;
|
2018-09-03 22:53:18 -07:00
|
|
|
[scheduler.delegate schedulerDidFinishTransaction:mutations rootTag:rootTag];
|
2018-04-10 16:37:01 -07:00
|
|
|
}
|
|
|
|
|
2018-11-11 15:18:09 -08:00
|
|
|
void schedulerDidRequestPreliminaryViewAllocation(SurfaceId surfaceId, ComponentName componentName, bool isLayoutable, ComponentHandle componentHandle) override {
|
2018-11-25 22:15:00 -08:00
|
|
|
if (!isLayoutable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-10 16:37:01 -07:00
|
|
|
RCTScheduler *scheduler = (__bridge RCTScheduler *)scheduler_;
|
2018-11-25 22:15:00 -08:00
|
|
|
[scheduler.delegate schedulerOptimisticallyCreateComponentViewWithComponentHandle:componentHandle];
|
2018-04-10 16:37:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void *scheduler_;
|
|
|
|
};
|
|
|
|
|
|
|
|
@implementation RCTScheduler {
|
|
|
|
std::shared_ptr<Scheduler> _scheduler;
|
|
|
|
std::shared_ptr<SchedulerDelegateProxy> _delegateProxy;
|
|
|
|
}
|
|
|
|
|
2018-09-24 12:54:26 -07:00
|
|
|
- (instancetype)initWithContextContainer:(std::shared_ptr<void>)contextContatiner
|
2018-04-10 16:37:01 -07:00
|
|
|
{
|
|
|
|
if (self = [super init]) {
|
|
|
|
_delegateProxy = std::make_shared<SchedulerDelegateProxy>((__bridge void *)self);
|
2018-09-24 12:54:26 -07:00
|
|
|
_scheduler = std::make_shared<Scheduler>(std::static_pointer_cast<ContextContainer>(contextContatiner));
|
2018-04-10 16:37:01 -07:00
|
|
|
_scheduler->setDelegate(_delegateProxy.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
_scheduler->setDelegate(nullptr);
|
|
|
|
}
|
|
|
|
|
2018-09-26 10:02:04 -07:00
|
|
|
- (void)startSurfaceWithSurfaceId:(SurfaceId)surfaceId
|
|
|
|
moduleName:(NSString *)moduleName
|
|
|
|
initailProps:(NSDictionary *)initialProps
|
2018-10-09 16:25:08 -07:00
|
|
|
layoutConstraints:(LayoutConstraints)layoutConstraints
|
|
|
|
layoutContext:(LayoutContext)layoutContext;
|
2018-04-10 16:37:01 -07:00
|
|
|
{
|
mostly working on Android + OTA
Summary:
It works great on iOS, and mostly works on Android, and is now OTA'able as part of the screen config! Haven't done template view yet. One remaining issue:
Layout is borked on Android. I'm guessing the issue has to do with the timing of setting the constraints in `updateRootLayoutSpecs` and calling `mBinding.startSurface` which actually builds the shadow tree. If I try to call `updateRootLayoutSpecs` earlier, it just crashes immediately. Here's the layout it spits out, which clearly has -440 for the x of 420006, which is the RCTText component, causing it to get cut off on the left of the screen:
```
updateLayoutMountItem for reactTag: 420006 x: -440, y: -13, width: 931, height: 78
updateLayoutMountItem for reactTag: 420010 x: 26, y: 79, width: 0, height: 1651
updateLayoutMountItem for reactTag: 420012 x: 0, y: 26, width: 0, height: 158
updateLayoutMountItem for reactTag: 420016 x: 0, y: 210, width: 454, height: 454
updateLayoutMountItem for reactTag: 420018 x: 454, y: 210, width: 455, height: 454
updateLayoutMountItem for reactTag: 420022 x: 0, y: 690, width: 454, height: 454
updateLayoutMountItem for reactTag: 420024 x: 454, y: 690, width: 455, height: 454
updateLayoutMountItem for reactTag: 420028 x: 0, y: 1171, width: 454, height: 454
updateLayoutMountItem for reactTag: 420030 x: 454, y: 1171, width: 455, height: 454
updateLayoutMountItem for reactTag: 420032 x: 0, y: 1651, width: 0, height: 0
```
Reviewed By: mdvacca
Differential Revision: D12813192
fbshipit-source-id: 450d646af4883ff25184141721351da67b091b7c
2018-11-05 15:32:47 -08:00
|
|
|
auto props = convertIdToFollyDynamic(initialProps);
|
2018-09-26 10:02:04 -07:00
|
|
|
_scheduler->startSurface(
|
mostly working on Android + OTA
Summary:
It works great on iOS, and mostly works on Android, and is now OTA'able as part of the screen config! Haven't done template view yet. One remaining issue:
Layout is borked on Android. I'm guessing the issue has to do with the timing of setting the constraints in `updateRootLayoutSpecs` and calling `mBinding.startSurface` which actually builds the shadow tree. If I try to call `updateRootLayoutSpecs` earlier, it just crashes immediately. Here's the layout it spits out, which clearly has -440 for the x of 420006, which is the RCTText component, causing it to get cut off on the left of the screen:
```
updateLayoutMountItem for reactTag: 420006 x: -440, y: -13, width: 931, height: 78
updateLayoutMountItem for reactTag: 420010 x: 26, y: 79, width: 0, height: 1651
updateLayoutMountItem for reactTag: 420012 x: 0, y: 26, width: 0, height: 158
updateLayoutMountItem for reactTag: 420016 x: 0, y: 210, width: 454, height: 454
updateLayoutMountItem for reactTag: 420018 x: 454, y: 210, width: 455, height: 454
updateLayoutMountItem for reactTag: 420022 x: 0, y: 690, width: 454, height: 454
updateLayoutMountItem for reactTag: 420024 x: 454, y: 690, width: 455, height: 454
updateLayoutMountItem for reactTag: 420028 x: 0, y: 1171, width: 454, height: 454
updateLayoutMountItem for reactTag: 420030 x: 454, y: 1171, width: 455, height: 454
updateLayoutMountItem for reactTag: 420032 x: 0, y: 1651, width: 0, height: 0
```
Reviewed By: mdvacca
Differential Revision: D12813192
fbshipit-source-id: 450d646af4883ff25184141721351da67b091b7c
2018-11-05 15:32:47 -08:00
|
|
|
surfaceId,
|
|
|
|
RCTStringFromNSString(moduleName),
|
|
|
|
props,
|
|
|
|
layoutConstraints,
|
|
|
|
layoutContext);
|
|
|
|
_scheduler->renderTemplateToSurface(
|
|
|
|
surfaceId,
|
|
|
|
props.getDefault("navigationConfig")
|
|
|
|
.getDefault("initialUITemplate", "")
|
|
|
|
.getString());
|
2018-04-10 16:37:01 -07:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:02:04 -07:00
|
|
|
- (void)stopSurfaceWithSurfaceId:(SurfaceId)surfaceId
|
2018-04-10 16:37:01 -07:00
|
|
|
{
|
2018-09-26 10:02:04 -07:00
|
|
|
_scheduler->stopSurface(surfaceId);
|
2018-04-10 16:37:01 -07:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:02:04 -07:00
|
|
|
- (CGSize)measureSurfaceWithLayoutConstraints:(LayoutConstraints)layoutConstraints
|
|
|
|
layoutContext:(LayoutContext)layoutContext
|
|
|
|
surfaceId:(SurfaceId)surfaceId
|
2018-05-08 22:56:27 -07:00
|
|
|
{
|
2018-09-26 10:02:04 -07:00
|
|
|
return RCTCGSizeFromSize(_scheduler->measureSurface(surfaceId, layoutConstraints, layoutContext));
|
2018-05-08 22:56:27 -07:00
|
|
|
}
|
|
|
|
|
2018-10-09 16:25:03 -07:00
|
|
|
- (void)constraintSurfaceLayoutWithLayoutConstraints:(LayoutConstraints)layoutConstraints
|
2018-09-26 10:02:04 -07:00
|
|
|
layoutContext:(LayoutContext)layoutContext
|
|
|
|
surfaceId:(SurfaceId)surfaceId
|
2018-05-08 22:56:27 -07:00
|
|
|
{
|
2018-10-09 16:25:03 -07:00
|
|
|
_scheduler->constraintSurfaceLayout(surfaceId, layoutConstraints, layoutContext);
|
2018-05-08 22:56:27 -07:00
|
|
|
}
|
|
|
|
|
2018-04-10 16:37:01 -07:00
|
|
|
@end
|