-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Cxx objects as arguments to native modules
Reviewed By: fkgozali Differential Revision: D5589269 fbshipit-source-id: 1bd7004adc397241cabfb1dc59ba1aebad943bf8
- Loading branch information
1 parent
2a6965d
commit 6783694
Showing
10 changed files
with
221 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
/** | ||
* This class provides a collection of conversion functions for mapping | ||
* JSON objects to cxx types. Extensible via categories. | ||
* Convert methods are expected to return cxx objects wraped in RCTManagedPointer. | ||
*/ | ||
|
||
@interface RCTCxxConvert : NSObject | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
#import "RCTCxxConvert.h" | ||
|
||
@implementation RCTCxxConvert | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
#include <memory> | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
/** | ||
* Type erased wrapper over any cxx value that can be passed as an argument | ||
* to native method. | ||
*/ | ||
|
||
@interface RCTManagedPointer: NSObject | ||
|
||
@property (nonatomic, readonly) void *voidPointer; | ||
|
||
- (instancetype)initWithPointer:(std::shared_ptr<void>)pointer; | ||
|
||
@end | ||
|
||
namespace RCT { | ||
template <typename T, typename P> | ||
RCTManagedPointer *managedPointer(P initializer) | ||
{ | ||
auto ptr = std::shared_ptr<void>(new T((NSDictionary *)initializer)); | ||
return [[RCTManagedPointer alloc] initWithPointer:std::move(ptr)]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
#import "RCTManagedPointer.h" | ||
|
||
@implementation RCTManagedPointer { | ||
std::shared_ptr<void> _pointer; | ||
} | ||
|
||
- (instancetype)initWithPointer:(std::shared_ptr<void>)pointer { | ||
if (self = [super init]) { | ||
_pointer = std::move(pointer); | ||
} | ||
return self; | ||
} | ||
|
||
- (void *)voidPointer { | ||
return _pointer.get(); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.