react-native-macos/React/Fabric/RCTScheduler.mm

111 строки
3.6 KiB
Plaintext
Исходник Обычный вид История

/**
* 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/ContextContainer.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(Tag rootTag, const ShadowViewMutationList &mutations) override {
RCTScheduler *scheduler = (__bridge RCTScheduler *)scheduler_;
[scheduler.delegate schedulerDidFinishTransaction:mutations rootTag:rootTag];
}
void schedulerDidRequestPreliminaryViewAllocation(SurfaceId surfaceId, ComponentName componentName, bool isLayoutable, ComponentHandle componentHandle) override {
if (!isLayoutable) {
return;
}
RCTScheduler *scheduler = (__bridge RCTScheduler *)scheduler_;
[scheduler.delegate schedulerOptimisticallyCreateComponentViewWithComponentHandle:componentHandle];
}
private:
void *scheduler_;
};
@implementation RCTScheduler {
std::shared_ptr<Scheduler> _scheduler;
std::shared_ptr<SchedulerDelegateProxy> _delegateProxy;
}
- (instancetype)initWithContextContainer:(std::shared_ptr<void>)contextContatiner
{
if (self = [super init]) {
_delegateProxy = std::make_shared<SchedulerDelegateProxy>((__bridge void *)self);
_scheduler = std::make_shared<Scheduler>(std::static_pointer_cast<ContextContainer>(contextContatiner), getDefaultComponentRegistryFactory());
_scheduler->setDelegate(_delegateProxy.get());
}
return self;
}
- (void)dealloc
{
_scheduler->setDelegate(nullptr);
}
- (void)startSurfaceWithSurfaceId:(SurfaceId)surfaceId
moduleName:(NSString *)moduleName
initailProps:(NSDictionary *)initialProps
layoutConstraints:(LayoutConstraints)layoutConstraints
layoutContext:(LayoutContext)layoutContext;
{
SystraceSection s("-[RCTScheduler startSurfaceWithSurfaceId:...]");
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-06 02:32:47 +03:00
auto props = convertIdToFollyDynamic(initialProps);
_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-06 02:32:47 +03:00
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);
}
@end