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:54:16 -08:00
committed by Facebook Github Bot
parent 23e0f868c9
commit 7bf3b20837
9 changed files with 163 additions and 14 deletions
@@ -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
@@ -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
+2 -3
View File
@@ -18,8 +18,8 @@ namespace react {
class FabricUIManager;
}
}
} // namespace react
} // namespace facebook
using namespace facebook::react;
@@ -28,7 +28,6 @@ using namespace facebook::react;
*/
@interface RCTFabricUIManagerWrapper : NSObject <RCTInvalidating>
- (instancetype)initWithManager:(std::shared_ptr<FabricUIManager>)manager;
- (std::shared_ptr<FabricUIManager>)manager;
@end
+6 -2
View File
@@ -9,17 +9,21 @@
#include <fabric/FabricUIManager.h>
#import "RCTFabricPlatformUIOperationManager.h"
// This file contains experimental placeholders, nothing is finalized.
@implementation RCTFabricUIManagerWrapper
{
std::shared_ptr<FabricUIManager> _manager;
std::shared_ptr<IFabricPlatformUIOperationManager> _platformUIOperationManager;
}
- (instancetype)initWithManager:(std::shared_ptr<FabricUIManager>)manager
- (instancetype)init
{
self = [super init];
if (self) {
_manager = manager;
_platformUIOperationManager = std::make_shared<RCTFabricPlatformUIOperationManagerConnector>();
_manager = std::make_shared<FabricUIManager>(_platformUIOperationManager);
}
return self;
}