2019-10-16 20:03:47 +03:00
|
|
|
/*
|
2018-09-12 01:27:47 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2018-04-11 02:37:06 +03:00
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*/
|
|
|
|
|
2019-08-08 17:13:22 +03:00
|
|
|
#import "RCTSurfacePresenter.h"
|
2018-04-11 02:37:06 +03:00
|
|
|
|
2018-09-26 20:02:06 +03:00
|
|
|
#import <mutex>
|
|
|
|
|
2018-04-11 02:37:06 +03:00
|
|
|
#import <React/RCTAssert.h>
|
2019-08-08 17:13:22 +03:00
|
|
|
#import <React/RCTComponentViewFactory.h>
|
|
|
|
#import <React/RCTComponentViewRegistry.h>
|
|
|
|
#import <React/RCTFabricSurface.h>
|
2019-02-25 23:22:24 +03:00
|
|
|
#import <React/RCTFollyConvert.h>
|
2019-08-08 17:13:22 +03:00
|
|
|
#import <React/RCTMountingManager.h>
|
|
|
|
#import <React/RCTMountingManagerDelegate.h>
|
|
|
|
#import <React/RCTScheduler.h>
|
|
|
|
#import <React/RCTSurfaceRegistry.h>
|
2018-04-11 02:37:06 +03:00
|
|
|
#import <React/RCTSurfaceView+Internal.h>
|
2019-02-25 23:22:24 +03:00
|
|
|
#import <React/RCTSurfaceView.h>
|
2018-06-22 17:28:29 +03:00
|
|
|
#import <React/RCTUtils.h>
|
2019-04-30 07:17:40 +03:00
|
|
|
|
2018-11-26 09:15:00 +03:00
|
|
|
#import <react/components/root/RootShadowNode.h>
|
2019-02-25 23:22:24 +03:00
|
|
|
#import <react/core/LayoutConstraints.h>
|
|
|
|
#import <react/core/LayoutContext.h>
|
2019-04-18 08:39:41 +03:00
|
|
|
#import <react/uimanager/ComponentDescriptorFactory.h>
|
2019-06-07 22:00:01 +03:00
|
|
|
#import <react/uimanager/SchedulerToolbox.h>
|
2019-04-13 01:10:40 +03:00
|
|
|
#import <react/utils/ContextContainer.h>
|
2019-04-30 07:17:40 +03:00
|
|
|
#import <react/utils/ManagedObjectWrapper.h>
|
2018-05-09 08:56:27 +03:00
|
|
|
|
2018-09-24 22:54:26 +03:00
|
|
|
#import "MainRunLoopEventBeat.h"
|
2019-08-08 17:13:22 +03:00
|
|
|
#import "RCTConversions.h"
|
2019-06-07 22:00:01 +03:00
|
|
|
#import "RuntimeEventBeat.h"
|
2018-05-09 08:56:27 +03:00
|
|
|
|
2018-04-11 02:37:06 +03:00
|
|
|
using namespace facebook::react;
|
|
|
|
|
2019-08-08 17:13:22 +03:00
|
|
|
@interface RCTSurfacePresenter () <RCTSchedulerDelegate, RCTMountingManagerDelegate>
|
2018-04-11 02:37:06 +03:00
|
|
|
@end
|
|
|
|
|
2019-08-08 17:13:22 +03:00
|
|
|
@implementation RCTSurfacePresenter {
|
|
|
|
RCTMountingManager *_mountingManager; // Thread-safe.
|
|
|
|
RCTSurfaceRegistry *_surfaceRegistry; // Thread-safe.
|
2019-12-30 22:13:07 +03:00
|
|
|
|
|
|
|
better::shared_mutex _schedulerMutex;
|
|
|
|
RCTScheduler *_Nullable _scheduler; // Thread-safe. Pointer is protected by `_schedulerMutex`.
|
|
|
|
ContextContainer::Shared _contextContainer; // Protected by `_schedulerMutex`.
|
|
|
|
RuntimeExecutor _runtimeExecutor; // Protected by `_schedulerMutex`.
|
|
|
|
|
2019-03-26 19:52:27 +03:00
|
|
|
better::shared_mutex _observerListMutex;
|
2019-08-08 17:13:22 +03:00
|
|
|
NSMutableArray<id<RCTSurfacePresenterObserver>> *_observers;
|
2018-04-11 02:37:06 +03:00
|
|
|
}
|
|
|
|
|
2019-10-25 03:43:08 +03:00
|
|
|
- (instancetype)initWithContextContainer:(ContextContainer::Shared)contextContainer
|
|
|
|
runtimeExecutor:(RuntimeExecutor)runtimeExecutor
|
2018-04-11 02:37:06 +03:00
|
|
|
{
|
|
|
|
if (self = [super init]) {
|
2019-10-25 03:43:08 +03:00
|
|
|
assert(contextContainer && "RuntimeExecutor must be not null.");
|
|
|
|
|
2019-08-15 21:27:29 +03:00
|
|
|
_runtimeExecutor = runtimeExecutor;
|
2019-10-25 03:43:08 +03:00
|
|
|
_contextContainer = contextContainer;
|
2018-04-11 02:37:06 +03:00
|
|
|
|
2019-08-08 17:13:22 +03:00
|
|
|
_surfaceRegistry = [[RCTSurfaceRegistry alloc] init];
|
|
|
|
_mountingManager = [[RCTMountingManager alloc] init];
|
2018-04-11 02:37:06 +03:00
|
|
|
_mountingManager.delegate = self;
|
2018-06-15 20:56:40 +03:00
|
|
|
|
2019-03-20 08:11:32 +03:00
|
|
|
_observers = [NSMutableArray array];
|
2018-12-06 02:00:34 +03:00
|
|
|
|
2019-10-25 03:43:08 +03:00
|
|
|
_scheduler = [self _createScheduler];
|
2018-04-11 02:37:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2019-10-25 03:43:08 +03:00
|
|
|
- (ContextContainer::Shared)contextContainer
|
2018-11-26 09:15:00 +03:00
|
|
|
{
|
2019-12-30 22:13:07 +03:00
|
|
|
std::shared_lock<better::shared_mutex> lock(_schedulerMutex);
|
2019-10-25 03:43:08 +03:00
|
|
|
return _contextContainer;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setContextContainer:(ContextContainer::Shared)contextContainer
|
|
|
|
{
|
2019-12-30 22:13:07 +03:00
|
|
|
std::unique_lock<better::shared_mutex> lock(_schedulerMutex);
|
2019-10-25 03:43:08 +03:00
|
|
|
_contextContainer = contextContainer;
|
|
|
|
}
|
|
|
|
|
2019-12-30 22:13:07 +03:00
|
|
|
- (RuntimeExecutor)runtimeExecutor
|
2019-10-25 03:43:08 +03:00
|
|
|
{
|
2019-12-30 22:13:07 +03:00
|
|
|
std::shared_lock<better::shared_mutex> lock(_schedulerMutex);
|
|
|
|
return _runtimeExecutor;
|
2019-10-25 03:43:08 +03:00
|
|
|
}
|
|
|
|
|
2019-12-30 22:13:07 +03:00
|
|
|
- (void)setRuntimeExecutor:(RuntimeExecutor)runtimeExecutor
|
2019-10-25 03:43:08 +03:00
|
|
|
{
|
2019-12-30 22:13:07 +03:00
|
|
|
std::unique_lock<better::shared_mutex> lock(_schedulerMutex);
|
|
|
|
_runtimeExecutor = runtimeExecutor;
|
2018-11-26 09:15:00 +03:00
|
|
|
}
|
|
|
|
|
2018-04-11 02:37:06 +03:00
|
|
|
#pragma mark - Internal Surface-dedicated Interface
|
|
|
|
|
2019-08-08 17:13:22 +03:00
|
|
|
- (void)registerSurface:(RCTFabricSurface *)surface
|
2018-04-11 02:37:06 +03:00
|
|
|
{
|
2019-12-30 22:13:07 +03:00
|
|
|
std::shared_lock<better::shared_mutex> lock(_schedulerMutex);
|
2018-04-11 02:37:06 +03:00
|
|
|
[_surfaceRegistry registerSurface:surface];
|
2019-10-25 03:43:08 +03:00
|
|
|
if (_scheduler) {
|
|
|
|
[self _startSurface:surface];
|
|
|
|
}
|
2018-04-11 02:37:06 +03:00
|
|
|
}
|
|
|
|
|
2019-08-08 17:13:22 +03:00
|
|
|
- (void)unregisterSurface:(RCTFabricSurface *)surface
|
2018-04-11 02:37:06 +03:00
|
|
|
{
|
2019-12-30 22:13:07 +03:00
|
|
|
std::shared_lock<better::shared_mutex> lock(_schedulerMutex);
|
2019-10-25 03:43:08 +03:00
|
|
|
if (_scheduler) {
|
|
|
|
[self _stopSurface:surface];
|
|
|
|
}
|
2018-04-11 02:37:06 +03:00
|
|
|
[_surfaceRegistry unregisterSurface:surface];
|
|
|
|
}
|
|
|
|
|
2019-08-08 17:13:22 +03:00
|
|
|
- (void)setProps:(NSDictionary *)props surface:(RCTFabricSurface *)surface
|
2018-09-26 20:01:42 +03:00
|
|
|
{
|
2019-12-30 22:13:07 +03:00
|
|
|
std::shared_lock<better::shared_mutex> lock(_schedulerMutex);
|
2018-09-26 20:01:42 +03:00
|
|
|
// This implementation is suboptimal indeed but still better than nothing for now.
|
2018-09-26 20:02:06 +03:00
|
|
|
[self _stopSurface:surface];
|
|
|
|
[self _startSurface:surface];
|
2018-09-26 20:01:42 +03:00
|
|
|
}
|
|
|
|
|
2019-08-08 17:13:22 +03:00
|
|
|
- (RCTFabricSurface *)surfaceForRootTag:(ReactTag)rootTag
|
2018-06-15 06:39:44 +03:00
|
|
|
{
|
|
|
|
return [_surfaceRegistry surfaceForRootTag:rootTag];
|
|
|
|
}
|
|
|
|
|
2019-08-08 17:13:22 +03:00
|
|
|
- (CGSize)sizeThatFitsMinimumSize:(CGSize)minimumSize
|
|
|
|
maximumSize:(CGSize)maximumSize
|
|
|
|
surface:(RCTFabricSurface *)surface
|
2018-05-09 08:56:27 +03:00
|
|
|
{
|
2019-12-30 22:13:07 +03:00
|
|
|
std::shared_lock<better::shared_mutex> lock(_schedulerMutex);
|
2019-06-07 22:00:01 +03:00
|
|
|
LayoutContext layoutContext = {.pointScaleFactor = RCTScreenScale()};
|
|
|
|
LayoutConstraints layoutConstraints = {.minimumSize = RCTSizeFromCGSize(minimumSize),
|
|
|
|
.maximumSize = RCTSizeFromCGSize(maximumSize)};
|
2019-10-25 03:43:08 +03:00
|
|
|
return [_scheduler measureSurfaceWithLayoutConstraints:layoutConstraints
|
|
|
|
layoutContext:layoutContext
|
|
|
|
surfaceId:surface.rootTag];
|
2018-05-09 08:56:27 +03:00
|
|
|
}
|
|
|
|
|
2019-08-08 17:13:22 +03:00
|
|
|
- (void)setMinimumSize:(CGSize)minimumSize maximumSize:(CGSize)maximumSize surface:(RCTFabricSurface *)surface
|
2018-05-09 08:56:27 +03:00
|
|
|
{
|
2019-12-30 22:13:07 +03:00
|
|
|
std::shared_lock<better::shared_mutex> lock(_schedulerMutex);
|
2019-06-07 22:00:01 +03:00
|
|
|
LayoutContext layoutContext = {.pointScaleFactor = RCTScreenScale()};
|
|
|
|
LayoutConstraints layoutConstraints = {.minimumSize = RCTSizeFromCGSize(minimumSize),
|
|
|
|
.maximumSize = RCTSizeFromCGSize(maximumSize)};
|
2019-10-25 03:43:08 +03:00
|
|
|
[_scheduler constraintSurfaceLayoutWithLayoutConstraints:layoutConstraints
|
|
|
|
layoutContext:layoutContext
|
|
|
|
surfaceId:surface.rootTag];
|
2018-09-26 20:02:06 +03:00
|
|
|
}
|
|
|
|
|
2019-02-25 23:22:24 +03:00
|
|
|
- (BOOL)synchronouslyUpdateViewOnUIThread:(NSNumber *)reactTag props:(NSDictionary *)props
|
|
|
|
{
|
2019-12-30 22:13:07 +03:00
|
|
|
std::shared_lock<better::shared_mutex> lock(_schedulerMutex);
|
2019-02-25 23:22:24 +03:00
|
|
|
ReactTag tag = [reactTag integerValue];
|
2019-11-01 19:35:40 +03:00
|
|
|
UIView<RCTComponentViewProtocol> *componentView =
|
|
|
|
[_mountingManager.componentViewRegistry findComponentViewWithTag:tag];
|
2019-02-25 23:22:24 +03:00
|
|
|
if (componentView == nil) {
|
|
|
|
return NO; // This view probably isn't managed by Fabric
|
|
|
|
}
|
2019-04-18 08:39:40 +03:00
|
|
|
ComponentHandle handle = [[componentView class] componentDescriptorProvider].handle;
|
2019-12-07 04:56:37 +03:00
|
|
|
auto *componentDescriptor = [_scheduler findComponentDescriptorByHandle_DO_NOT_USE_THIS_IS_BROKEN:handle];
|
|
|
|
|
|
|
|
if (!componentDescriptor) {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
[_mountingManager synchronouslyUpdateViewOnUIThread:tag changedProps:props componentDescriptor:*componentDescriptor];
|
2019-02-25 23:22:24 +03:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2019-10-25 03:43:08 +03:00
|
|
|
- (BOOL)suspend
|
|
|
|
{
|
2019-12-30 22:13:07 +03:00
|
|
|
std::unique_lock<better::shared_mutex> lock(_schedulerMutex);
|
2019-10-25 03:43:08 +03:00
|
|
|
|
|
|
|
if (!_scheduler) {
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
[self _stopAllSurfaces];
|
|
|
|
_scheduler = nil;
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)resume
|
|
|
|
{
|
2019-12-30 22:13:07 +03:00
|
|
|
std::unique_lock<better::shared_mutex> lock(_schedulerMutex);
|
2019-10-25 03:43:08 +03:00
|
|
|
|
|
|
|
if (_scheduler) {
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
_scheduler = [self _createScheduler];
|
|
|
|
[self _startAllSurfaces];
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2018-09-26 20:02:06 +03:00
|
|
|
#pragma mark - Private
|
|
|
|
|
2019-10-25 03:43:08 +03:00
|
|
|
- (RCTScheduler *)_createScheduler
|
2019-09-11 07:30:53 +03:00
|
|
|
{
|
2019-12-19 18:33:36 +03:00
|
|
|
auto componentRegistryFactory =
|
|
|
|
[factory = wrapManagedObject(_mountingManager.componentViewRegistry.componentViewFactory)](
|
|
|
|
EventDispatcher::Weak const &eventDispatcher, ContextContainer::Shared const &contextContainer) {
|
|
|
|
return [(RCTComponentViewFactory *)unwrapManagedObject(factory)
|
|
|
|
createComponentDescriptorRegistryWithParameters:{eventDispatcher, contextContainer}];
|
|
|
|
};
|
2019-04-18 08:39:41 +03:00
|
|
|
|
2019-10-25 03:43:08 +03:00
|
|
|
auto runtimeExecutor = _runtimeExecutor;
|
2019-09-11 07:30:53 +03:00
|
|
|
|
2019-06-07 22:00:01 +03:00
|
|
|
auto toolbox = SchedulerToolbox{};
|
2019-10-25 03:43:08 +03:00
|
|
|
toolbox.contextContainer = _contextContainer;
|
2019-06-07 22:00:01 +03:00
|
|
|
toolbox.componentRegistryFactory = componentRegistryFactory;
|
|
|
|
toolbox.runtimeExecutor = runtimeExecutor;
|
|
|
|
|
2019-08-31 04:21:59 +03:00
|
|
|
toolbox.synchronousEventBeatFactory = [runtimeExecutor](EventBeat::SharedOwnerBox const &ownerBox) {
|
|
|
|
return std::make_unique<MainRunLoopEventBeat>(ownerBox, runtimeExecutor);
|
2019-06-07 22:00:01 +03:00
|
|
|
};
|
|
|
|
|
2019-08-31 04:21:59 +03:00
|
|
|
toolbox.asynchronousEventBeatFactory = [runtimeExecutor](EventBeat::SharedOwnerBox const &ownerBox) {
|
|
|
|
return std::make_unique<RuntimeEventBeat>(ownerBox, runtimeExecutor);
|
2019-06-07 22:00:01 +03:00
|
|
|
};
|
|
|
|
|
2019-10-25 03:43:08 +03:00
|
|
|
RCTScheduler *scheduler = [[RCTScheduler alloc] initWithToolbox:toolbox];
|
|
|
|
scheduler.delegate = self;
|
2018-12-22 04:57:32 +03:00
|
|
|
|
2019-10-25 03:43:08 +03:00
|
|
|
return scheduler;
|
2019-09-11 07:30:53 +03:00
|
|
|
}
|
2018-12-22 04:57:32 +03:00
|
|
|
|
2019-08-08 17:13:22 +03:00
|
|
|
- (void)_startSurface:(RCTFabricSurface *)surface
|
2018-04-11 02:37:06 +03:00
|
|
|
{
|
2019-08-08 17:13:22 +03:00
|
|
|
RCTMountingManager *mountingManager = _mountingManager;
|
2019-05-11 01:31:00 +03:00
|
|
|
RCTExecuteOnMainQueue(^{
|
|
|
|
[mountingManager.componentViewRegistry dequeueComponentViewWithComponentHandle:RootShadowNode::Handle()
|
|
|
|
tag:surface.rootTag];
|
|
|
|
});
|
2018-09-26 20:01:42 +03:00
|
|
|
|
2019-06-07 22:00:01 +03:00
|
|
|
LayoutContext layoutContext = {.pointScaleFactor = RCTScreenScale()};
|
2018-10-10 02:25:08 +03:00
|
|
|
|
2019-06-07 22:00:01 +03:00
|
|
|
LayoutConstraints layoutConstraints = {.minimumSize = RCTSizeFromCGSize(surface.minimumSize),
|
|
|
|
.maximumSize = RCTSizeFromCGSize(surface.maximumSize)};
|
2018-10-10 02:25:08 +03:00
|
|
|
|
2019-10-25 03:43:08 +03:00
|
|
|
[_scheduler startSurfaceWithSurfaceId:surface.rootTag
|
|
|
|
moduleName:surface.moduleName
|
|
|
|
initialProps:surface.properties
|
|
|
|
layoutConstraints:layoutConstraints
|
|
|
|
layoutContext:layoutContext];
|
2018-04-11 02:37:06 +03:00
|
|
|
}
|
|
|
|
|
2019-08-08 17:13:22 +03:00
|
|
|
- (void)_stopSurface:(RCTFabricSurface *)surface
|
2018-04-11 02:37:06 +03:00
|
|
|
{
|
2019-10-25 03:43:08 +03:00
|
|
|
[_scheduler stopSurfaceWithSurfaceId:surface.rootTag];
|
2018-09-26 20:01:42 +03:00
|
|
|
|
2019-08-08 17:13:22 +03:00
|
|
|
RCTMountingManager *mountingManager = _mountingManager;
|
2019-05-11 01:31:00 +03:00
|
|
|
RCTExecuteOnMainQueue(^{
|
2019-11-01 19:35:40 +03:00
|
|
|
RCTComponentViewDescriptor rootViewDescriptor =
|
|
|
|
[mountingManager.componentViewRegistry componentViewDescriptorWithTag:surface.rootTag];
|
2019-05-11 01:31:00 +03:00
|
|
|
[mountingManager.componentViewRegistry enqueueComponentViewWithComponentHandle:RootShadowNode::Handle()
|
|
|
|
tag:surface.rootTag
|
2019-11-01 19:35:40 +03:00
|
|
|
componentViewDescriptor:rootViewDescriptor];
|
2019-05-11 01:31:00 +03:00
|
|
|
});
|
2018-09-26 20:01:42 +03:00
|
|
|
|
|
|
|
[surface _unsetStage:(RCTSurfaceStagePrepared | RCTSurfaceStageMounted)];
|
2018-04-11 02:37:06 +03:00
|
|
|
}
|
|
|
|
|
2018-09-26 20:02:06 +03:00
|
|
|
- (void)_startAllSurfaces
|
2018-09-26 20:01:42 +03:00
|
|
|
{
|
2019-08-08 17:13:22 +03:00
|
|
|
[_surfaceRegistry enumerateWithBlock:^(NSEnumerator<RCTFabricSurface *> *enumerator) {
|
|
|
|
for (RCTFabricSurface *surface in enumerator) {
|
2019-03-22 09:34:14 +03:00
|
|
|
[self _startSurface:surface];
|
|
|
|
}
|
|
|
|
}];
|
2018-09-26 20:01:42 +03:00
|
|
|
}
|
2018-04-11 02:37:06 +03:00
|
|
|
|
2018-09-26 20:02:06 +03:00
|
|
|
- (void)_stopAllSurfaces
|
2018-04-11 02:37:06 +03:00
|
|
|
{
|
2019-08-08 17:13:22 +03:00
|
|
|
[_surfaceRegistry enumerateWithBlock:^(NSEnumerator<RCTFabricSurface *> *enumerator) {
|
|
|
|
for (RCTFabricSurface *surface in enumerator) {
|
2019-03-22 09:34:14 +03:00
|
|
|
[self _stopSurface:surface];
|
|
|
|
}
|
|
|
|
}];
|
2018-04-11 02:37:06 +03:00
|
|
|
}
|
|
|
|
|
2019-08-08 17:13:22 +03:00
|
|
|
#pragma mark - RCTSchedulerDelegate
|
2018-09-26 20:01:42 +03:00
|
|
|
|
2019-10-25 03:43:08 +03:00
|
|
|
- (void)schedulerDidFinishTransaction:(MountingCoordinator::Shared const &)mountingCoordinator
|
2018-04-11 02:37:06 +03:00
|
|
|
{
|
2019-08-08 17:13:22 +03:00
|
|
|
RCTFabricSurface *surface = [_surfaceRegistry surfaceForRootTag:mountingCoordinator->getSurfaceId()];
|
2018-04-11 02:37:06 +03:00
|
|
|
|
2018-09-26 20:01:42 +03:00
|
|
|
[surface _setStage:RCTSurfaceStagePrepared];
|
|
|
|
|
2019-05-04 01:05:26 +03:00
|
|
|
[_mountingManager scheduleTransaction:mountingCoordinator];
|
2018-09-26 20:01:42 +03:00
|
|
|
}
|
|
|
|
|
2019-10-25 03:43:08 +03:00
|
|
|
- (void)schedulerDidDispatchCommand:(ShadowView const &)shadowView
|
2019-07-19 21:45:40 +03:00
|
|
|
commandName:(std::string const &)commandName
|
|
|
|
args:(folly::dynamic const)args
|
|
|
|
{
|
|
|
|
ReactTag tag = shadowView.tag;
|
|
|
|
NSString *commandStr = [[NSString alloc] initWithUTF8String:commandName.c_str()];
|
|
|
|
NSArray *argsArray = convertFollyDynamicToId(args);
|
|
|
|
|
|
|
|
[self->_mountingManager dispatchCommand:tag commandName:commandStr args:argsArray];
|
|
|
|
}
|
|
|
|
|
2019-08-08 17:13:22 +03:00
|
|
|
- (void)addObserver:(id<RCTSurfacePresenterObserver>)observer
|
2019-03-08 04:34:41 +03:00
|
|
|
{
|
2019-03-26 19:52:27 +03:00
|
|
|
std::unique_lock<better::shared_mutex> lock(_observerListMutex);
|
2019-03-08 04:34:41 +03:00
|
|
|
[self->_observers addObject:observer];
|
|
|
|
}
|
|
|
|
|
2019-08-08 17:13:22 +03:00
|
|
|
- (void)removeObserver:(id<RCTSurfacePresenterObserver>)observer
|
2019-03-08 04:34:41 +03:00
|
|
|
{
|
2019-03-26 19:52:27 +03:00
|
|
|
std::unique_lock<better::shared_mutex> lock(_observerListMutex);
|
2019-03-08 04:34:41 +03:00
|
|
|
[self->_observers removeObject:observer];
|
|
|
|
}
|
|
|
|
|
2019-08-08 17:13:22 +03:00
|
|
|
#pragma mark - RCTMountingManagerDelegate
|
2018-09-26 20:01:42 +03:00
|
|
|
|
2019-08-08 17:13:22 +03:00
|
|
|
- (void)mountingManager:(RCTMountingManager *)mountingManager willMountComponentsWithRootTag:(ReactTag)rootTag
|
2018-09-26 20:01:42 +03:00
|
|
|
{
|
|
|
|
RCTAssertMainQueue();
|
|
|
|
|
2019-03-26 19:52:27 +03:00
|
|
|
std::shared_lock<better::shared_mutex> lock(_observerListMutex);
|
2019-08-08 17:13:22 +03:00
|
|
|
for (id<RCTSurfacePresenterObserver> observer in _observers) {
|
2019-03-08 04:34:41 +03:00
|
|
|
if ([observer respondsToSelector:@selector(willMountComponentsWithRootTag:)]) {
|
|
|
|
[observer willMountComponentsWithRootTag:rootTag];
|
|
|
|
}
|
|
|
|
}
|
2018-09-26 20:01:42 +03:00
|
|
|
}
|
2018-04-11 02:37:06 +03:00
|
|
|
|
2019-08-08 17:13:22 +03:00
|
|
|
- (void)mountingManager:(RCTMountingManager *)mountingManager didMountComponentsWithRootTag:(ReactTag)rootTag
|
2018-09-26 20:01:42 +03:00
|
|
|
{
|
|
|
|
RCTAssertMainQueue();
|
2018-04-11 02:37:06 +03:00
|
|
|
|
2019-08-08 17:13:22 +03:00
|
|
|
RCTFabricSurface *surface = [_surfaceRegistry surfaceForRootTag:rootTag];
|
2018-09-26 20:01:42 +03:00
|
|
|
RCTSurfaceStage stage = surface.stage;
|
|
|
|
if (stage & RCTSurfaceStagePrepared) {
|
|
|
|
// We have to progress the stage only if the preparing phase is done.
|
|
|
|
if ([surface _setStage:RCTSurfaceStageMounted]) {
|
2019-11-01 19:35:40 +03:00
|
|
|
auto rootComponentViewDescriptor =
|
|
|
|
[_mountingManager.componentViewRegistry componentViewDescriptorWithTag:rootTag];
|
|
|
|
surface.view.rootView = (RCTSurfaceRootView *)rootComponentViewDescriptor.view;
|
2018-09-26 20:01:42 +03:00
|
|
|
}
|
|
|
|
}
|
2019-03-26 19:52:27 +03:00
|
|
|
|
|
|
|
std::shared_lock<better::shared_mutex> lock(_observerListMutex);
|
2019-08-08 17:13:22 +03:00
|
|
|
for (id<RCTSurfacePresenterObserver> observer in _observers) {
|
2019-03-08 04:34:41 +03:00
|
|
|
if ([observer respondsToSelector:@selector(didMountComponentsWithRootTag:)]) {
|
|
|
|
[observer didMountComponentsWithRootTag:rootTag];
|
|
|
|
}
|
|
|
|
}
|
2018-04-11 02:37:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|