iOS: create C++ <-> ObjC++ connector for FabricUIManager to do UI operations

Reviewed By: shergin

Differential Revision: D7162911

fbshipit-source-id: 3e303020dafdccc51f52c3359a7054dc8a787978
This commit is contained in:
Kevin Gozali 2018-03-07 16:40:38 -08:00 committed by Facebook Github Bot
parent 23e0f868c9
commit 7bf3b20837
9 changed files with 163 additions and 14 deletions

View File

@ -0,0 +1,46 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <memory>
#include <fabric/IFabricPlatformUIOperationManager.h>
@class RCTFabricPlatformUIOperationManager;
namespace facebook {
namespace react {
/**
* Connector class (from C++ to ObjC++) to allow FabricUIManager to invoke native UI operations/updates.
* UIKit-related impl doesn't live here, but this class gets passed to the FabricUIManager C++ impl directly.
*/
class RCTFabricPlatformUIOperationManagerConnector : public IFabricPlatformUIOperationManager {
public:
RCTFabricPlatformUIOperationManagerConnector();
~RCTFabricPlatformUIOperationManagerConnector();
void performUIOperation();
private:
void *self_;
RCTFabricPlatformUIOperationManager *manager_;
};
} // namespace react
} // namespace facebook
/**
* Actual ObjC++ implementation of the UI operations.
*/
@interface RCTFabricPlatformUIOperationManager : NSObject
- (void)performUIOperation;
@end

View File

@ -0,0 +1,48 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTFabricPlatformUIOperationManager.h"
namespace facebook {
namespace react {
RCTFabricPlatformUIOperationManagerConnector::RCTFabricPlatformUIOperationManagerConnector() {
self_ = (__bridge_retained void *)[RCTFabricPlatformUIOperationManager new];
manager_ = (__bridge RCTFabricPlatformUIOperationManager *)self_;
}
RCTFabricPlatformUIOperationManagerConnector::~RCTFabricPlatformUIOperationManagerConnector() {
CFRelease(self_);
self_ = NULL;
manager_ = NULL;
}
void RCTFabricPlatformUIOperationManagerConnector::performUIOperation() {
[manager_ performUIOperation];
}
} // namespace react
} // namespace facebook
// -----------------------------------------------------------------------------
// Start of ObjC++ impl
// Access UIKit here.
// -----------------------------------------------------------------------------
@implementation RCTFabricPlatformUIOperationManager
- (void)dealloc
{
NSLog(@"RCTFabricPlatformUIOperationManager: dealloc()");
}
- (void)performUIOperation
{
// TODO
NSLog(@"RCTFabricPlatformUIOperationManager: performUIOperation()");
}
@end

View File

@ -18,8 +18,8 @@ namespace react {
class FabricUIManager; class FabricUIManager;
} } // namespace react
} } // namespace facebook
using namespace facebook::react; using namespace facebook::react;
@ -28,7 +28,6 @@ using namespace facebook::react;
*/ */
@interface RCTFabricUIManagerWrapper : NSObject <RCTInvalidating> @interface RCTFabricUIManagerWrapper : NSObject <RCTInvalidating>
- (instancetype)initWithManager:(std::shared_ptr<FabricUIManager>)manager;
- (std::shared_ptr<FabricUIManager>)manager; - (std::shared_ptr<FabricUIManager>)manager;
@end @end

View File

@ -9,17 +9,21 @@
#include <fabric/FabricUIManager.h> #include <fabric/FabricUIManager.h>
#import "RCTFabricPlatformUIOperationManager.h"
// This file contains experimental placeholders, nothing is finalized. // This file contains experimental placeholders, nothing is finalized.
@implementation RCTFabricUIManagerWrapper @implementation RCTFabricUIManagerWrapper
{ {
std::shared_ptr<FabricUIManager> _manager; std::shared_ptr<FabricUIManager> _manager;
std::shared_ptr<IFabricPlatformUIOperationManager> _platformUIOperationManager;
} }
- (instancetype)initWithManager:(std::shared_ptr<FabricUIManager>)manager - (instancetype)init
{ {
self = [super init]; self = [super init];
if (self) { if (self) {
_manager = manager; _platformUIOperationManager = std::make_shared<RCTFabricPlatformUIOperationManagerConnector>();
_manager = std::make_shared<FabricUIManager>(_platformUIOperationManager);
} }
return self; return self;
} }

View File

@ -1,14 +1,23 @@
// Copyright 2004-present Facebook. All Rights Reserved. /**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "FabricUIManager.h" #include "FabricUIManager.h"
#include "IFabricPlatformUIOperationManager.h"
#include "ShadowNode.h" #include "ShadowNode.h"
namespace facebook { namespace facebook {
namespace react { namespace react {
FabricUIManager::FabricUIManager() {} FabricUIManager::FabricUIManager(const std::shared_ptr<IFabricPlatformUIOperationManager> &platformUIOperationManager) :
platformUIOperationManager_(platformUIOperationManager) {};
ShadowNodeRef FabricUIManager::createNode(int reactTag, std::string viewName, int rootTag, folly::dynamic props, void *instanceHandle) { ShadowNodeRef FabricUIManager::createNode(int reactTag, std::string viewName, int rootTag, folly::dynamic props, void *instanceHandle) {
platformUIOperationManager_->performUIOperation();
return std::make_shared<ShadowNode>(reactTag, viewName, rootTag, props, instanceHandle); return std::make_shared<ShadowNode>(reactTag, viewName, rootTag, props, instanceHandle);
} }
@ -41,4 +50,5 @@ void FabricUIManager::appendChildToSet(const ShadowNodeSetRef &childSet, const S
void FabricUIManager::completeRoot(int rootTag, const ShadowNodeSetRef &childSet) { void FabricUIManager::completeRoot(int rootTag, const ShadowNodeSetRef &childSet) {
} }
}} } // namespace react
} // namespace facebook

View File

@ -1,4 +1,9 @@
// Copyright 2004-present Facebook. All Rights Reserved. /**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once #pragma once
@ -10,6 +15,7 @@ namespace facebook {
namespace react { namespace react {
class ShadowNode; class ShadowNode;
class IFabricPlatformUIOperationManager;
typedef std::shared_ptr<const ShadowNode> ShadowNodeRef; typedef std::shared_ptr<const ShadowNode> ShadowNodeRef;
typedef folly::fbvector<const ShadowNodeRef> ShadowNodeSet; typedef folly::fbvector<const ShadowNodeRef> ShadowNodeSet;
@ -17,7 +23,7 @@ typedef std::shared_ptr<const ShadowNodeSet> ShadowNodeSetRef;
class FabricUIManager { class FabricUIManager {
public: public:
FabricUIManager(); FabricUIManager(const std::shared_ptr<IFabricPlatformUIOperationManager> &platformUIOperationManager);
ShadowNodeRef createNode(int reactTag, std::string viewName, int rootTag, folly::dynamic props, void *instanceHandle); ShadowNodeRef createNode(int reactTag, std::string viewName, int rootTag, folly::dynamic props, void *instanceHandle);
ShadowNodeRef cloneNode(const ShadowNodeRef &node); ShadowNodeRef cloneNode(const ShadowNodeRef &node);
@ -28,7 +34,10 @@ public:
ShadowNodeSetRef createChildSet(int rootTag); ShadowNodeSetRef createChildSet(int rootTag);
void appendChildToSet(const ShadowNodeSetRef &childSet, const ShadowNodeRef &childNode); void appendChildToSet(const ShadowNodeSetRef &childSet, const ShadowNodeRef &childNode);
void completeRoot(int rootTag, const ShadowNodeSetRef &childSet); void completeRoot(int rootTag, const ShadowNodeSetRef &childSet);
private:
std::shared_ptr<IFabricPlatformUIOperationManager> platformUIOperationManager_;
}; };
}} } // namespace react
} // namespace facebook

View File

@ -0,0 +1,23 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
namespace facebook {
namespace react {
/**
* An interface for FabricUIManager to perform platform-specific UI operations, like updating native UIView's in iOS.
*/
class IFabricPlatformUIOperationManager {
public:
// TODO: add meaningful methods
virtual void performUIOperation() = 0;
};
} // namespace react
} // namespace facebook

View File

@ -1,4 +1,9 @@
// Copyright 2004-present Facebook. All Rights Reserved. /**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "ShadowNode.h" #include "ShadowNode.h"

View File

@ -1,4 +1,9 @@
// Copyright 2004-present Facebook. All Rights Reserved. /**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once #pragma once