Fabric: Conversion functions between NSString and std::string

Summary:
@public
Trivial. It's also nice this we have a default encoding now.

Reviewed By: fkgozali

Differential Revision: D8528919

fbshipit-source-id: 0853eca828f22ead1a337fea3d7a2fc9a48e84c8
This commit is contained in:
Valentin Shergin 2018-06-22 11:53:44 -07:00 committed by Facebook Github Bot
parent 93b568cc51
commit 3ea4a3309f
4 changed files with 15 additions and 8 deletions

View File

@ -129,8 +129,8 @@ using namespace facebook::react;
// `nativeId`
if (oldViewProps.nativeId != newViewProps.nativeId) {
self.nativeId = [NSString stringWithCString:newViewProps.nativeId.c_str()
encoding:NSASCIIStringEncoding];
self.nativeId = RCTNSStringFromString(newViewProps.nativeId);
}
}
}
@ -165,7 +165,7 @@ using namespace facebook::react;
- (BOOL)didActivateAccessibilityCustomAction:(UIAccessibilityCustomAction *)action
{
_eventEmitter->onAccessibilityAction([action.name cStringUsingEncoding:NSASCIIStringEncoding]);
_eventEmitter->onAccessibilityAction(RCTStringFromNSString(action.name));
return YES;
}

View File

@ -16,6 +16,7 @@
#import "RCTMountItemProtocol.h"
#import "RCTCreateMountItem.h"
#import "RCTConversions.h"
#import "RCTDeleteMountItem.h"
#import "RCTInsertMountItem.h"
#import "RCTRemoveMountItem.h"
@ -46,8 +47,7 @@ using namespace facebook::react;
for (auto instruction : instructions) {
switch (instruction.getType()) {
case TreeMutationInstruction::Creation: {
NSString *componentName = [NSString stringWithCString:instruction.getNewChildNode()->getComponentName().c_str()
encoding:NSASCIIStringEncoding];
NSString *componentName = RCTNSStringFromString(instruction.getNewChildNode()->getComponentName(), NSASCIIStringEncoding);
RCTCreateMountItem *mountItem =
[[RCTCreateMountItem alloc] initWithComponentName:componentName
tag:instruction.getNewChildNode()->getTag()];
@ -56,8 +56,7 @@ using namespace facebook::react;
}
case TreeMutationInstruction::Deletion: {
NSString *componentName = [NSString stringWithCString:instruction.getOldChildNode()->getComponentName().c_str()
encoding:NSASCIIStringEncoding];
NSString *componentName = RCTNSStringFromString(instruction.getOldChildNode()->getComponentName(), NSASCIIStringEncoding);
RCTDeleteMountItem *mountItem =
[[RCTDeleteMountItem alloc] initWithComponentName:componentName
tag:instruction.getOldChildNode()->getTag()];

View File

@ -11,6 +11,14 @@
#import <fabric/graphics/Geometry.h>
#import <fabric/view/primitives.h>
inline NSString *_Nullable RCTNSStringFromString(const std::string &string, const NSStringEncoding &encoding = NSUTF8StringEncoding) {
return [NSString stringWithCString:string.c_str() encoding:encoding];
}
inline std::string RCTStringFromNSString(NSString *string, const NSStringEncoding &encoding = NSUTF8StringEncoding) {
return [string cStringUsingEncoding:encoding];
}
inline UIColor *_Nullable RCTUIColorFromSharedColor(const facebook::react::SharedColor &sharedColor) {
return sharedColor ? [UIColor colorWithCGColor:sharedColor.get()] : nil;
}

View File

@ -29,7 +29,7 @@ public:
void schedulerDidRequestPreliminaryViewAllocation(ComponentName componentName) override {
RCTScheduler *scheduler = (__bridge RCTScheduler *)scheduler_;
[scheduler.delegate schedulerDidRequestPreliminaryViewAllocationWithComponentName:[NSString stringWithCString:componentName.c_str() encoding:NSASCIIStringEncoding]];
[scheduler.delegate schedulerDidRequestPreliminaryViewAllocationWithComponentName:RCTNSStringFromString(componentName, NSASCIIStringEncoding)];
}
private: