2015-03-23 20:28:42 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-03-23 20:28:42 +00:00
|
|
|
*/
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
#import "RCTConvert.h"
|
|
|
|
|
|
|
|
#import <objc/message.h>
|
|
|
|
|
2016-11-23 15:47:52 +00:00
|
|
|
#import <CoreText/CoreText.h>
|
|
|
|
|
2015-04-21 16:48:29 +00:00
|
|
|
#import "RCTDefines.h"
|
2015-12-08 11:29:08 +00:00
|
|
|
#import "RCTImageSource.h"
|
2015-12-10 18:09:04 +00:00
|
|
|
#import "RCTParserUtils.h"
|
2015-10-12 11:14:21 +00:00
|
|
|
#import "RCTUtils.h"
|
2015-04-21 16:48:29 +00:00
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
@implementation RCTConvert
|
|
|
|
|
2015-06-05 15:46:17 +00:00
|
|
|
RCT_CONVERTER(id, id, self)
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
RCT_CONVERTER(BOOL, BOOL, boolValue)
|
2015-03-25 00:37:03 +00:00
|
|
|
RCT_NUMBER_CONVERTER(double, doubleValue)
|
|
|
|
RCT_NUMBER_CONVERTER(float, floatValue)
|
|
|
|
RCT_NUMBER_CONVERTER(int, intValue)
|
|
|
|
|
|
|
|
RCT_NUMBER_CONVERTER(int64_t, longLongValue);
|
|
|
|
RCT_NUMBER_CONVERTER(uint64_t, unsignedLongLongValue);
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-03-25 00:37:03 +00:00
|
|
|
RCT_NUMBER_CONVERTER(NSInteger, integerValue)
|
|
|
|
RCT_NUMBER_CONVERTER(NSUInteger, unsignedIntegerValue)
|
2015-03-11 02:03:59 +00:00
|
|
|
|
2015-08-13 11:01:06 +00:00
|
|
|
/**
|
|
|
|
* This macro is used for creating converter functions for directly
|
|
|
|
* representable json values that require no conversion.
|
|
|
|
*/
|
|
|
|
#if RCT_DEBUG
|
|
|
|
#define RCT_JSON_CONVERTER(type) \
|
|
|
|
+ (type *)type:(id)json \
|
|
|
|
{ \
|
|
|
|
if ([json isKindOfClass:[type class]]) { \
|
|
|
|
return json; \
|
|
|
|
} else if (json) { \
|
|
|
|
RCTLogConvertError(json, @#type); \
|
|
|
|
} \
|
|
|
|
return nil; \
|
2015-03-25 00:37:03 +00:00
|
|
|
}
|
2015-08-13 11:01:06 +00:00
|
|
|
#else
|
|
|
|
#define RCT_JSON_CONVERTER(type) \
|
|
|
|
+ (type *)type:(id)json { return json; }
|
|
|
|
#endif
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-08-13 11:01:06 +00:00
|
|
|
RCT_JSON_CONVERTER(NSArray)
|
|
|
|
RCT_JSON_CONVERTER(NSDictionary)
|
|
|
|
RCT_JSON_CONVERTER(NSString)
|
|
|
|
RCT_JSON_CONVERTER(NSNumber)
|
|
|
|
|
|
|
|
RCT_CUSTOM_CONVERTER(NSSet *, NSSet, [NSSet setWithArray:json])
|
|
|
|
RCT_CUSTOM_CONVERTER(NSData *, NSData, [json dataUsingEncoding:NSUTF8StringEncoding])
|
2015-04-10 03:18:31 +00:00
|
|
|
|
2015-05-06 17:46:45 +00:00
|
|
|
+ (NSIndexSet *)NSIndexSet:(id)json
|
|
|
|
{
|
|
|
|
json = [self NSNumberArray:json];
|
2015-08-17 14:35:34 +00:00
|
|
|
NSMutableIndexSet *indexSet = [NSMutableIndexSet new];
|
2015-05-06 17:46:45 +00:00
|
|
|
for (NSNumber *number in json) {
|
|
|
|
NSInteger index = number.integerValue;
|
|
|
|
if (RCT_DEBUG && index < 0) {
|
2017-09-25 17:23:02 +00:00
|
|
|
RCTLogError(@"Invalid index value %lld. Indices must be positive.", (long long)index);
|
2015-05-06 17:46:45 +00:00
|
|
|
}
|
|
|
|
[indexSet addIndex:index];
|
|
|
|
}
|
|
|
|
return indexSet;
|
|
|
|
}
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
+ (NSURL *)NSURL:(id)json
|
|
|
|
{
|
2015-04-25 21:52:18 +00:00
|
|
|
NSString *path = [self NSString:json];
|
2015-08-13 11:01:06 +00:00
|
|
|
if (!path) {
|
2015-04-18 17:43:20 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2015-04-25 21:52:18 +00:00
|
|
|
@try { // NSURL has a history of crashing with bad input, so let's be safe
|
2015-04-13 16:34:03 +00:00
|
|
|
|
2015-04-25 21:52:18 +00:00
|
|
|
NSURL *URL = [NSURL URLWithString:path];
|
|
|
|
if (URL.scheme) { // Was a well-formed absolute URL
|
|
|
|
return URL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if it has a scheme
|
2015-08-10 14:03:52 +00:00
|
|
|
if ([path rangeOfString:@":"].location != NSNotFound) {
|
2015-04-25 21:52:18 +00:00
|
|
|
path = [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
URL = [NSURL URLWithString:path];
|
|
|
|
if (URL) {
|
|
|
|
return URL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assume that it's a local path
|
2015-08-24 10:14:33 +00:00
|
|
|
path = path.stringByRemovingPercentEncoding;
|
2015-07-13 17:33:39 +00:00
|
|
|
if ([path hasPrefix:@"~"]) {
|
|
|
|
// Path is inside user directory
|
2015-08-24 10:14:33 +00:00
|
|
|
path = path.stringByExpandingTildeInPath;
|
|
|
|
} else if (!path.absolutePath) {
|
2015-07-13 17:33:39 +00:00
|
|
|
// Assume it's a resource path
|
2015-11-05 17:23:30 +00:00
|
|
|
path = [[NSBundle mainBundle].resourcePath stringByAppendingPathComponent:path];
|
2015-04-25 21:52:18 +00:00
|
|
|
}
|
2015-10-12 11:14:21 +00:00
|
|
|
if (!(URL = [NSURL fileURLWithPath:path])) {
|
|
|
|
RCTLogConvertError(json, @"a valid URL");
|
|
|
|
}
|
|
|
|
return URL;
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
2015-04-25 21:52:18 +00:00
|
|
|
@catch (__unused NSException *e) {
|
2015-08-10 14:03:52 +00:00
|
|
|
RCTLogConvertError(json, @"a valid URL");
|
2015-04-25 21:52:18 +00:00
|
|
|
return nil;
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-18 00:58:27 +00:00
|
|
|
RCT_ENUM_CONVERTER(NSURLRequestCachePolicy, (@{
|
|
|
|
@"default": @(NSURLRequestUseProtocolCachePolicy),
|
|
|
|
@"reload": @(NSURLRequestReloadIgnoringLocalCacheData),
|
|
|
|
@"force-cache": @(NSURLRequestReturnCacheDataElseLoad),
|
|
|
|
@"only-if-cached": @(NSURLRequestReturnCacheDataDontLoad),
|
|
|
|
}), NSURLRequestUseProtocolCachePolicy, integerValue)
|
|
|
|
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
+ (NSURLRequest *)NSURLRequest:(id)json
|
|
|
|
{
|
2016-02-02 02:00:18 +00:00
|
|
|
if ([json isKindOfClass:[NSString class]]) {
|
|
|
|
NSURL *URL = [self NSURL:json];
|
|
|
|
return URL ? [NSURLRequest requestWithURL:URL] : nil;
|
|
|
|
}
|
|
|
|
if ([json isKindOfClass:[NSDictionary class]]) {
|
2016-09-01 00:30:50 +00:00
|
|
|
NSString *URLString = json[@"uri"] ?: json[@"url"];
|
|
|
|
|
|
|
|
NSURL *URL;
|
|
|
|
NSString *bundleName = json[@"bundle"];
|
|
|
|
if (bundleName) {
|
|
|
|
URLString = [NSString stringWithFormat:@"%@.bundle/%@", bundleName, URLString];
|
|
|
|
}
|
|
|
|
|
|
|
|
URL = [self NSURL:URLString];
|
2016-02-02 02:00:18 +00:00
|
|
|
if (!URL) {
|
|
|
|
return nil;
|
|
|
|
}
|
2016-09-01 00:30:50 +00:00
|
|
|
|
2016-02-02 02:00:18 +00:00
|
|
|
NSData *body = [self NSData:json[@"body"]];
|
|
|
|
NSString *method = [self NSString:json[@"method"]].uppercaseString ?: @"GET";
|
2017-01-18 00:58:27 +00:00
|
|
|
NSURLRequestCachePolicy cachePolicy = [self NSURLRequestCachePolicy:json[@"cache"]];
|
2016-02-02 02:00:18 +00:00
|
|
|
NSDictionary *headers = [self NSDictionary:json[@"headers"]];
|
2017-01-18 00:58:27 +00:00
|
|
|
if ([method isEqualToString:@"GET"] && headers == nil && body == nil && cachePolicy == NSURLRequestUseProtocolCachePolicy) {
|
2016-02-02 02:00:18 +00:00
|
|
|
return [NSURLRequest requestWithURL:URL];
|
|
|
|
}
|
2016-06-01 17:32:20 +00:00
|
|
|
|
|
|
|
if (headers) {
|
|
|
|
__block BOOL allHeadersAreStrings = YES;
|
|
|
|
[headers enumerateKeysAndObjectsUsingBlock:^(NSString *key, id header, BOOL *stop) {
|
|
|
|
if (![header isKindOfClass:[NSString class]]) {
|
|
|
|
RCTLogError(@"Values of HTTP headers passed must be of type string. "
|
|
|
|
"Value of header '%@' is not a string.", key);
|
|
|
|
allHeadersAreStrings = NO;
|
|
|
|
*stop = YES;
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
if (!allHeadersAreStrings) {
|
|
|
|
// Set headers to nil here to avoid crashing later.
|
|
|
|
headers = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-02 02:00:18 +00:00
|
|
|
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
|
|
|
|
request.HTTPBody = body;
|
|
|
|
request.HTTPMethod = method;
|
2017-01-18 00:58:27 +00:00
|
|
|
request.cachePolicy = cachePolicy;
|
2016-02-02 02:00:18 +00:00
|
|
|
request.allHTTPHeaderFields = headers;
|
|
|
|
return [request copy];
|
|
|
|
}
|
|
|
|
if (json) {
|
|
|
|
RCTLogConvertError(json, @"a valid URLRequest");
|
|
|
|
}
|
|
|
|
return nil;
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
|
|
|
|
2015-06-23 12:17:36 +00:00
|
|
|
+ (RCTFileURL *)RCTFileURL:(id)json
|
|
|
|
{
|
|
|
|
NSURL *fileURL = [self NSURL:json];
|
2015-08-24 10:14:33 +00:00
|
|
|
if (!fileURL.fileURL) {
|
2015-06-23 12:17:36 +00:00
|
|
|
RCTLogError(@"URI must be a local file, '%@' isn't.", fileURL);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
if (![[NSFileManager defaultManager] fileExistsAtPath:fileURL.path]) {
|
|
|
|
RCTLogError(@"File '%@' could not be found.", fileURL);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
return fileURL;
|
|
|
|
}
|
|
|
|
|
2015-03-30 13:07:07 +00:00
|
|
|
+ (NSDate *)NSDate:(id)json
|
|
|
|
{
|
|
|
|
if ([json isKindOfClass:[NSNumber class]]) {
|
|
|
|
return [NSDate dateWithTimeIntervalSince1970:[self NSTimeInterval:json]];
|
|
|
|
} else if ([json isKindOfClass:[NSString class]]) {
|
|
|
|
static NSDateFormatter *formatter;
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
dispatch_once(&onceToken, ^{
|
2015-08-17 14:35:34 +00:00
|
|
|
formatter = [NSDateFormatter new];
|
2015-03-30 13:07:07 +00:00
|
|
|
formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ";
|
|
|
|
formatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
|
|
|
|
formatter.timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
|
|
|
|
});
|
|
|
|
NSDate *date = [formatter dateFromString:json];
|
|
|
|
if (!date) {
|
2015-04-25 21:52:18 +00:00
|
|
|
RCTLogError(@"JSON String '%@' could not be interpreted as a date. "
|
|
|
|
"Expected format: YYYY-MM-DD'T'HH:mm:ss.sssZ", json);
|
2015-03-30 13:07:07 +00:00
|
|
|
}
|
|
|
|
return date;
|
2015-08-13 11:01:06 +00:00
|
|
|
} else if (json) {
|
2015-08-10 14:03:52 +00:00
|
|
|
RCTLogConvertError(json, @"a date");
|
2015-03-30 13:07:07 +00:00
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2017-11-04 21:32:07 +00:00
|
|
|
+ (NSLocale *)NSLocale:(id)json
|
|
|
|
{
|
|
|
|
if ([json isKindOfClass:[NSString class]]) {
|
|
|
|
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:json];
|
|
|
|
if (!locale) {
|
|
|
|
RCTLogError(@"JSON String '%@' could not be interpreted as a valid locale. ", json);
|
|
|
|
}
|
|
|
|
return locale;
|
|
|
|
} else if (json) {
|
|
|
|
RCTLogConvertError(json, @"a locale");
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2015-03-04 01:27:33 +00:00
|
|
|
// JS Standard for time is milliseconds
|
2015-03-30 13:07:07 +00:00
|
|
|
RCT_CUSTOM_CONVERTER(NSTimeInterval, NSTimeInterval, [self double:json] / 1000.0)
|
2015-03-04 01:27:33 +00:00
|
|
|
|
|
|
|
// JS standard for time zones is minutes.
|
2015-03-30 13:07:07 +00:00
|
|
|
RCT_CUSTOM_CONVERTER(NSTimeZone *, NSTimeZone, [NSTimeZone timeZoneForSecondsFromGMT:[self double:json] * 60.0])
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-04-18 17:43:20 +00:00
|
|
|
NSNumber *RCTConvertEnumValue(const char *typeName, NSDictionary *mapping, NSNumber *defaultValue, id json)
|
2015-04-13 17:22:11 +00:00
|
|
|
{
|
2015-08-13 11:01:06 +00:00
|
|
|
if (!json) {
|
2015-04-13 17:22:11 +00:00
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
if ([json isKindOfClass:[NSNumber class]]) {
|
2015-08-24 10:14:33 +00:00
|
|
|
NSArray *allValues = mapping.allValues;
|
2015-12-03 11:26:08 +00:00
|
|
|
if ([allValues containsObject:json] || [json isEqual:defaultValue]) {
|
2015-04-13 17:22:11 +00:00
|
|
|
return json;
|
|
|
|
}
|
[Bridge] `RCT_REMAP_METHOD(js_name, selector)`
Summary:
cc @a2 @nicklockwood
This diff introduces a new macro called `RCT_EXPORT_NAMED_METHOD`, which is like `RCT_EXPORT_METHOD` but lets you choose the name of the method in JS. This diff is backwards compatible with the `RCT_EXPORT_METHOD` and legacy `RCT_EXPORT` macros.
The entries in the data segment now contain `__func__`, the Obj-C selector signature, and the JS name. If the JS name is `NULL`, we take the legacy `RCT_EXPORT` code path. If the JS name is an empty string, we use the Obj-C selector's name up to the first colon (that is, the behavior of `RCT_EXPORT_METHOD`).
Since there are three values in each data segment entry, the macros now specify 1-byte alignment. Without the byte alignment, the compiler defaults to 2-byte alignment meaning that each entry takes up 4 bytes instead of 3. The extra byte isn't a concern but being explicit about the alignment should reduce compiler surprises.
Closes https://github.com/facebook/react-native/pull/802
Github Author: James Ide <ide@jameside.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-14 20:03:16 +00:00
|
|
|
RCTLogError(@"Invalid %s '%@'. should be one of: %@", typeName, json, allValues);
|
2015-04-13 17:22:11 +00:00
|
|
|
return defaultValue;
|
|
|
|
}
|
2015-08-13 11:01:06 +00:00
|
|
|
if (RCT_DEBUG && ![json isKindOfClass:[NSString class]]) {
|
2015-04-13 17:22:11 +00:00
|
|
|
RCTLogError(@"Expected NSNumber or NSString for %s, received %@: %@",
|
|
|
|
typeName, [json classForCoder], json);
|
|
|
|
}
|
|
|
|
id value = mapping[json];
|
2015-08-13 11:01:06 +00:00
|
|
|
if (RCT_DEBUG && !value && [json description].length > 0) {
|
2015-06-24 16:47:48 +00:00
|
|
|
RCTLogError(@"Invalid %s '%@'. should be one of: %@", typeName, json, [[mapping allKeys] sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)]);
|
2015-04-13 17:22:11 +00:00
|
|
|
}
|
|
|
|
return value ?: defaultValue;
|
|
|
|
}
|
|
|
|
|
2015-05-18 14:32:21 +00:00
|
|
|
NSNumber *RCTConvertMultiEnumValue(const char *typeName, NSDictionary *mapping, NSNumber *defaultValue, id json)
|
|
|
|
{
|
|
|
|
if ([json isKindOfClass:[NSArray class]]) {
|
|
|
|
if ([json count] == 0) {
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
long long result = 0;
|
|
|
|
for (id arrayElement in json) {
|
|
|
|
NSNumber *value = RCTConvertEnumValue(typeName, mapping, defaultValue, arrayElement);
|
2015-08-24 10:14:33 +00:00
|
|
|
result |= value.longLongValue;
|
2015-05-18 14:32:21 +00:00
|
|
|
}
|
|
|
|
return @(result);
|
|
|
|
}
|
|
|
|
return RCTConvertEnumValue(typeName, mapping, defaultValue, json);
|
|
|
|
}
|
|
|
|
|
2015-10-27 10:39:10 +00:00
|
|
|
RCT_ENUM_CONVERTER(NSLineBreakMode, (@{
|
2016-06-10 11:26:45 +00:00
|
|
|
@"clip": @(NSLineBreakByClipping),
|
|
|
|
@"head": @(NSLineBreakByTruncatingHead),
|
|
|
|
@"tail": @(NSLineBreakByTruncatingTail),
|
|
|
|
@"middle": @(NSLineBreakByTruncatingMiddle),
|
2016-06-10 21:23:06 +00:00
|
|
|
@"wordWrapping": @(NSLineBreakByWordWrapping),
|
2016-06-10 11:26:45 +00:00
|
|
|
}), NSLineBreakByTruncatingTail, integerValue)
|
2015-10-27 10:39:10 +00:00
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
RCT_ENUM_CONVERTER(NSTextAlignment, (@{
|
|
|
|
@"auto": @(NSTextAlignmentNatural),
|
|
|
|
@"left": @(NSTextAlignmentLeft),
|
|
|
|
@"center": @(NSTextAlignmentCenter),
|
|
|
|
@"right": @(NSTextAlignmentRight),
|
2015-03-11 02:03:59 +00:00
|
|
|
@"justify": @(NSTextAlignmentJustified),
|
2015-02-20 04:10:52 +00:00
|
|
|
}), NSTextAlignmentNatural, integerValue)
|
|
|
|
|
2015-07-07 13:03:56 +00:00
|
|
|
RCT_ENUM_CONVERTER(NSUnderlineStyle, (@{
|
|
|
|
@"solid": @(NSUnderlineStyleSingle),
|
|
|
|
@"double": @(NSUnderlineStyleDouble),
|
|
|
|
@"dotted": @(NSUnderlinePatternDot | NSUnderlineStyleSingle),
|
|
|
|
@"dashed": @(NSUnderlinePatternDash | NSUnderlineStyleSingle),
|
|
|
|
}), NSUnderlineStyleSingle, integerValue)
|
|
|
|
|
2015-12-01 15:41:20 +00:00
|
|
|
RCT_ENUM_CONVERTER(RCTBorderStyle, (@{
|
|
|
|
@"solid": @(RCTBorderStyleSolid),
|
|
|
|
@"dotted": @(RCTBorderStyleDotted),
|
|
|
|
@"dashed": @(RCTBorderStyleDashed),
|
|
|
|
}), RCTBorderStyleSolid, integerValue)
|
|
|
|
|
2015-07-07 13:03:56 +00:00
|
|
|
RCT_ENUM_CONVERTER(RCTTextDecorationLineType, (@{
|
|
|
|
@"none": @(RCTTextDecorationLineTypeNone),
|
|
|
|
@"underline": @(RCTTextDecorationLineTypeUnderline),
|
|
|
|
@"line-through": @(RCTTextDecorationLineTypeStrikethrough),
|
|
|
|
@"underline line-through": @(RCTTextDecorationLineTypeUnderlineStrikethrough),
|
|
|
|
}), RCTTextDecorationLineTypeNone, integerValue)
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
RCT_ENUM_CONVERTER(NSWritingDirection, (@{
|
|
|
|
@"auto": @(NSWritingDirectionNatural),
|
|
|
|
@"ltr": @(NSWritingDirectionLeftToRight),
|
|
|
|
@"rtl": @(NSWritingDirectionRightToLeft),
|
|
|
|
}), NSWritingDirectionNatural, integerValue)
|
|
|
|
|
|
|
|
RCT_ENUM_CONVERTER(UITextAutocapitalizationType, (@{
|
|
|
|
@"none": @(UITextAutocapitalizationTypeNone),
|
|
|
|
@"words": @(UITextAutocapitalizationTypeWords),
|
|
|
|
@"sentences": @(UITextAutocapitalizationTypeSentences),
|
2015-03-04 22:04:52 +00:00
|
|
|
@"characters": @(UITextAutocapitalizationTypeAllCharacters)
|
2015-02-20 04:10:52 +00:00
|
|
|
}), UITextAutocapitalizationTypeSentences, integerValue)
|
|
|
|
|
2015-03-26 04:29:28 +00:00
|
|
|
RCT_ENUM_CONVERTER(UITextFieldViewMode, (@{
|
|
|
|
@"never": @(UITextFieldViewModeNever),
|
|
|
|
@"while-editing": @(UITextFieldViewModeWhileEditing),
|
|
|
|
@"unless-editing": @(UITextFieldViewModeUnlessEditing),
|
|
|
|
@"always": @(UITextFieldViewModeAlways),
|
|
|
|
}), UITextFieldViewModeNever, integerValue)
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
RCT_ENUM_CONVERTER(UIKeyboardType, (@{
|
|
|
|
@"default": @(UIKeyboardTypeDefault),
|
2015-03-31 01:25:30 +00:00
|
|
|
@"ascii-capable": @(UIKeyboardTypeASCIICapable),
|
|
|
|
@"numbers-and-punctuation": @(UIKeyboardTypeNumbersAndPunctuation),
|
|
|
|
@"url": @(UIKeyboardTypeURL),
|
|
|
|
@"number-pad": @(UIKeyboardTypeNumberPad),
|
|
|
|
@"phone-pad": @(UIKeyboardTypePhonePad),
|
|
|
|
@"name-phone-pad": @(UIKeyboardTypeNamePhonePad),
|
|
|
|
@"email-address": @(UIKeyboardTypeEmailAddress),
|
|
|
|
@"decimal-pad": @(UIKeyboardTypeDecimalPad),
|
|
|
|
@"twitter": @(UIKeyboardTypeTwitter),
|
|
|
|
@"web-search": @(UIKeyboardTypeWebSearch),
|
2015-06-05 15:46:17 +00:00
|
|
|
// Added for Android compatibility
|
|
|
|
@"numeric": @(UIKeyboardTypeDecimalPad),
|
2015-02-20 04:10:52 +00:00
|
|
|
}), UIKeyboardTypeDefault, integerValue)
|
2015-11-11 13:31:18 +00:00
|
|
|
|
2016-09-27 13:19:45 +00:00
|
|
|
#if !TARGET_OS_TV
|
2016-07-13 21:31:43 +00:00
|
|
|
RCT_MULTI_ENUM_CONVERTER(UIDataDetectorTypes, (@{
|
|
|
|
@"phoneNumber": @(UIDataDetectorTypePhoneNumber),
|
|
|
|
@"link": @(UIDataDetectorTypeLink),
|
|
|
|
@"address": @(UIDataDetectorTypeAddress),
|
|
|
|
@"calendarEvent": @(UIDataDetectorTypeCalendarEvent),
|
|
|
|
@"none": @(UIDataDetectorTypeNone),
|
|
|
|
@"all": @(UIDataDetectorTypeAll),
|
|
|
|
}), UIDataDetectorTypePhoneNumber, unsignedLongLongValue)
|
2016-09-27 13:19:45 +00:00
|
|
|
#endif
|
2016-07-13 21:31:43 +00:00
|
|
|
|
2015-11-11 13:31:18 +00:00
|
|
|
RCT_ENUM_CONVERTER(UIKeyboardAppearance, (@{
|
|
|
|
@"default": @(UIKeyboardAppearanceDefault),
|
|
|
|
@"light": @(UIKeyboardAppearanceLight),
|
|
|
|
@"dark": @(UIKeyboardAppearanceDark),
|
|
|
|
}), UIKeyboardAppearanceDefault, integerValue)
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-03-31 01:25:30 +00:00
|
|
|
RCT_ENUM_CONVERTER(UIReturnKeyType, (@{
|
|
|
|
@"default": @(UIReturnKeyDefault),
|
|
|
|
@"go": @(UIReturnKeyGo),
|
|
|
|
@"google": @(UIReturnKeyGoogle),
|
|
|
|
@"join": @(UIReturnKeyJoin),
|
|
|
|
@"next": @(UIReturnKeyNext),
|
|
|
|
@"route": @(UIReturnKeyRoute),
|
|
|
|
@"search": @(UIReturnKeySearch),
|
|
|
|
@"send": @(UIReturnKeySend),
|
|
|
|
@"yahoo": @(UIReturnKeyYahoo),
|
|
|
|
@"done": @(UIReturnKeyDone),
|
|
|
|
@"emergency-call": @(UIReturnKeyEmergencyCall),
|
|
|
|
}), UIReturnKeyDefault, integerValue)
|
|
|
|
|
2015-03-26 04:29:28 +00:00
|
|
|
RCT_ENUM_CONVERTER(UIViewContentMode, (@{
|
|
|
|
@"scale-to-fill": @(UIViewContentModeScaleToFill),
|
|
|
|
@"scale-aspect-fit": @(UIViewContentModeScaleAspectFit),
|
|
|
|
@"scale-aspect-fill": @(UIViewContentModeScaleAspectFill),
|
|
|
|
@"redraw": @(UIViewContentModeRedraw),
|
|
|
|
@"center": @(UIViewContentModeCenter),
|
|
|
|
@"top": @(UIViewContentModeTop),
|
|
|
|
@"bottom": @(UIViewContentModeBottom),
|
|
|
|
@"left": @(UIViewContentModeLeft),
|
|
|
|
@"right": @(UIViewContentModeRight),
|
|
|
|
@"top-left": @(UIViewContentModeTopLeft),
|
|
|
|
@"top-right": @(UIViewContentModeTopRight),
|
|
|
|
@"bottom-left": @(UIViewContentModeBottomLeft),
|
|
|
|
@"bottom-right": @(UIViewContentModeBottomRight),
|
2015-06-05 15:46:17 +00:00
|
|
|
// Cross-platform values
|
|
|
|
@"cover": @(UIViewContentModeScaleAspectFill),
|
|
|
|
@"contain": @(UIViewContentModeScaleAspectFit),
|
|
|
|
@"stretch": @(UIViewContentModeScaleToFill),
|
|
|
|
}), UIViewContentModeScaleAspectFill, integerValue)
|
2015-03-26 04:29:28 +00:00
|
|
|
|
2016-09-27 13:19:45 +00:00
|
|
|
#if !TARGET_OS_TV
|
2015-03-26 04:29:28 +00:00
|
|
|
RCT_ENUM_CONVERTER(UIBarStyle, (@{
|
|
|
|
@"default": @(UIBarStyleDefault),
|
|
|
|
@"black": @(UIBarStyleBlack),
|
|
|
|
}), UIBarStyleDefault, integerValue)
|
2016-09-27 13:19:45 +00:00
|
|
|
#endif
|
2015-03-26 04:29:28 +00:00
|
|
|
|
2017-08-09 10:16:34 +00:00
|
|
|
static void convertCGStruct(const char *type, NSArray *fields, CGFloat *result, id json)
|
2015-04-21 16:48:29 +00:00
|
|
|
{
|
|
|
|
NSUInteger count = fields.count;
|
|
|
|
if ([json isKindOfClass:[NSArray class]]) {
|
|
|
|
if (RCT_DEBUG && [json count] != count) {
|
2017-09-25 17:23:02 +00:00
|
|
|
RCTLogError(@"Expected array with count %llu, but count is %llu: %@", (unsigned long long)count, (unsigned long long)[json count], json);
|
2015-04-21 16:48:29 +00:00
|
|
|
} else {
|
|
|
|
for (NSUInteger i = 0; i < count; i++) {
|
2017-08-09 10:16:34 +00:00
|
|
|
result[i] = [RCTConvert CGFloat:RCTNilIfNull(json[i])];
|
2015-04-21 16:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ([json isKindOfClass:[NSDictionary class]]) {
|
|
|
|
for (NSUInteger i = 0; i < count; i++) {
|
2017-08-09 10:16:34 +00:00
|
|
|
result[i] = [RCTConvert CGFloat:RCTNilIfNull(json[fields[i]])];
|
2015-04-21 16:48:29 +00:00
|
|
|
}
|
2015-08-13 11:01:06 +00:00
|
|
|
} else if (json) {
|
2015-08-10 14:03:52 +00:00
|
|
|
RCTLogConvertError(json, @(type));
|
2015-04-21 16:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-30 13:07:07 +00:00
|
|
|
/**
|
|
|
|
* This macro is used for creating converter functions for structs that consist
|
|
|
|
* of a number of CGFloat properties, such as CGPoint, CGRect, etc.
|
|
|
|
*/
|
2017-08-09 10:16:34 +00:00
|
|
|
#define RCT_CGSTRUCT_CONVERTER(type, values) \
|
|
|
|
+ (type)type:(id)json \
|
|
|
|
{ \
|
|
|
|
static NSArray *fields; \
|
|
|
|
static dispatch_once_t onceToken; \
|
|
|
|
dispatch_once(&onceToken, ^{ \
|
|
|
|
fields = values; \
|
|
|
|
}); \
|
|
|
|
type result; \
|
|
|
|
convertCGStruct(#type, fields, (CGFloat *)&result, json); \
|
|
|
|
return result; \
|
2015-03-30 13:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RCT_CUSTOM_CONVERTER(CGFloat, CGFloat, [self double:json])
|
2017-08-09 10:16:34 +00:00
|
|
|
|
|
|
|
RCT_CGSTRUCT_CONVERTER(CGPoint, (@[@"x", @"y"]))
|
|
|
|
RCT_CGSTRUCT_CONVERTER(CGSize, (@[@"width", @"height"]))
|
|
|
|
RCT_CGSTRUCT_CONVERTER(CGRect, (@[@"x", @"y", @"width", @"height"]))
|
|
|
|
RCT_CGSTRUCT_CONVERTER(UIEdgeInsets, (@[@"top", @"left", @"bottom", @"right"]))
|
2015-03-15 23:08:42 +00:00
|
|
|
|
|
|
|
RCT_ENUM_CONVERTER(CGLineJoin, (@{
|
|
|
|
@"miter": @(kCGLineJoinMiter),
|
|
|
|
@"round": @(kCGLineJoinRound),
|
|
|
|
@"bevel": @(kCGLineJoinBevel),
|
|
|
|
}), kCGLineJoinMiter, intValue)
|
|
|
|
|
|
|
|
RCT_ENUM_CONVERTER(CGLineCap, (@{
|
|
|
|
@"butt": @(kCGLineCapButt),
|
|
|
|
@"round": @(kCGLineCapRound),
|
|
|
|
@"square": @(kCGLineCapSquare),
|
|
|
|
}), kCGLineCapButt, intValue)
|
|
|
|
|
2015-03-25 23:22:59 +00:00
|
|
|
RCT_CGSTRUCT_CONVERTER(CGAffineTransform, (@[
|
|
|
|
@"a", @"b", @"c", @"d", @"tx", @"ty"
|
2017-08-09 10:16:34 +00:00
|
|
|
]))
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
+ (UIColor *)UIColor:(id)json
|
|
|
|
{
|
2015-11-26 11:04:33 +00:00
|
|
|
if (!json) {
|
|
|
|
return nil;
|
|
|
|
}
|
2015-09-17 15:36:08 +00:00
|
|
|
if ([json isKindOfClass:[NSArray class]]) {
|
|
|
|
NSArray *components = [self NSNumberArray:json];
|
|
|
|
CGFloat alpha = components.count > 3 ? [self CGFloat:components[3]] : 1.0;
|
|
|
|
return [UIColor colorWithRed:[self CGFloat:components[0]]
|
|
|
|
green:[self CGFloat:components[1]]
|
|
|
|
blue:[self CGFloat:components[2]]
|
|
|
|
alpha:alpha];
|
2015-11-26 11:04:33 +00:00
|
|
|
} else if ([json isKindOfClass:[NSNumber class]]) {
|
2015-09-17 15:36:08 +00:00
|
|
|
NSUInteger argb = [self NSUInteger:json];
|
|
|
|
CGFloat a = ((argb >> 24) & 0xFF) / 255.0;
|
|
|
|
CGFloat r = ((argb >> 16) & 0xFF) / 255.0;
|
|
|
|
CGFloat g = ((argb >> 8) & 0xFF) / 255.0;
|
|
|
|
CGFloat b = (argb & 0xFF) / 255.0;
|
|
|
|
return [UIColor colorWithRed:r green:g blue:b alpha:a];
|
2015-11-26 11:04:33 +00:00
|
|
|
} else {
|
2015-12-08 11:29:08 +00:00
|
|
|
RCTLogConvertError(json, @"a UIColor. Did you forget to call processColor() on the JS side?");
|
2015-11-26 11:04:33 +00:00
|
|
|
return nil;
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (CGColorRef)CGColor:(id)json
|
|
|
|
{
|
|
|
|
return [self UIColor:json].CGColor;
|
|
|
|
}
|
|
|
|
|
2017-01-11 11:58:03 +00:00
|
|
|
+ (YGValue)YGValue:(id)json
|
|
|
|
{
|
|
|
|
if (!json) {
|
|
|
|
return YGValueUndefined;
|
|
|
|
} else if ([json isKindOfClass:[NSNumber class]]) {
|
2017-02-14 22:26:13 +00:00
|
|
|
return (YGValue) { [json floatValue], YGUnitPoint };
|
2017-01-11 11:58:03 +00:00
|
|
|
} else if ([json isKindOfClass:[NSString class]]) {
|
|
|
|
NSString *s = (NSString *) json;
|
2017-03-01 17:12:45 +00:00
|
|
|
if ([s isEqualToString:@"auto"]) {
|
|
|
|
return (YGValue) { YGUndefined, YGUnitAuto };
|
|
|
|
} else if ([s hasSuffix:@"%"]) {
|
2017-01-11 11:58:03 +00:00
|
|
|
return (YGValue) { [[s substringToIndex:s.length] floatValue], YGUnitPercent };
|
|
|
|
} else {
|
|
|
|
RCTLogConvertError(json, @"a YGValue. Did you forget the % or pt suffix?");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
RCTLogConvertError(json, @"a YGValue.");
|
|
|
|
}
|
|
|
|
return YGValueUndefined;
|
|
|
|
}
|
|
|
|
|
2015-04-21 16:48:29 +00:00
|
|
|
NSArray *RCTConvertArrayValue(SEL type, id json)
|
|
|
|
{
|
|
|
|
__block BOOL copy = NO;
|
|
|
|
__block NSArray *values = json = [RCTConvert NSArray:json];
|
2015-06-15 14:53:45 +00:00
|
|
|
[json enumerateObjectsUsingBlock:^(id jsonValue, NSUInteger idx, __unused BOOL *stop) {
|
2015-04-21 16:48:29 +00:00
|
|
|
id value = ((id(*)(Class, SEL, id))objc_msgSend)([RCTConvert class], type, jsonValue);
|
|
|
|
if (copy) {
|
|
|
|
if (value) {
|
|
|
|
[(NSMutableArray *)values addObject:value];
|
|
|
|
}
|
|
|
|
} else if (value != jsonValue) {
|
|
|
|
// Converted value is different, so we'll need to copy the array
|
|
|
|
values = [[NSMutableArray alloc] initWithCapacity:values.count];
|
2015-06-15 14:53:45 +00:00
|
|
|
for (NSUInteger i = 0; i < idx; i++) {
|
2015-04-21 16:48:29 +00:00
|
|
|
[(NSMutableArray *)values addObject:json[i]];
|
|
|
|
}
|
2015-05-05 14:16:53 +00:00
|
|
|
if (value) {
|
|
|
|
[(NSMutableArray *)values addObject:value];
|
|
|
|
}
|
2015-04-21 16:48:29 +00:00
|
|
|
copy = YES;
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
2015-03-25 00:37:03 +00:00
|
|
|
RCT_ARRAY_CONVERTER(NSURL)
|
2015-06-23 12:17:36 +00:00
|
|
|
RCT_ARRAY_CONVERTER(RCTFileURL)
|
2015-03-11 02:03:59 +00:00
|
|
|
RCT_ARRAY_CONVERTER(UIColor)
|
|
|
|
|
2015-08-13 11:01:06 +00:00
|
|
|
/**
|
|
|
|
* This macro is used for creating converter functions for directly
|
|
|
|
* representable json array values that require no conversion.
|
|
|
|
*/
|
|
|
|
#if RCT_DEBUG
|
2017-01-27 21:33:59 +00:00
|
|
|
#define RCT_JSON_ARRAY_CONVERTER_NAMED(type, name) RCT_ARRAY_CONVERTER_NAMED(type, name)
|
2015-08-13 11:01:06 +00:00
|
|
|
#else
|
2017-01-27 21:33:59 +00:00
|
|
|
#define RCT_JSON_ARRAY_CONVERTER_NAMED(type, name) + (NSArray *)name##Array:(id)json { return json; }
|
2015-08-13 11:01:06 +00:00
|
|
|
#endif
|
2017-01-27 21:33:59 +00:00
|
|
|
#define RCT_JSON_ARRAY_CONVERTER(type) RCT_JSON_ARRAY_CONVERTER_NAMED(type, type)
|
2015-08-13 11:01:06 +00:00
|
|
|
|
|
|
|
RCT_JSON_ARRAY_CONVERTER(NSArray)
|
|
|
|
RCT_JSON_ARRAY_CONVERTER(NSString)
|
2017-01-27 21:33:59 +00:00
|
|
|
RCT_JSON_ARRAY_CONVERTER_NAMED(NSArray<NSString *>, NSStringArray)
|
2015-08-13 11:01:06 +00:00
|
|
|
RCT_JSON_ARRAY_CONVERTER(NSDictionary)
|
|
|
|
RCT_JSON_ARRAY_CONVERTER(NSNumber)
|
|
|
|
|
2015-03-11 02:03:59 +00:00
|
|
|
// Can't use RCT_ARRAY_CONVERTER due to bridged cast
|
|
|
|
+ (NSArray *)CGColorArray:(id)json
|
|
|
|
{
|
2015-08-17 14:35:34 +00:00
|
|
|
NSMutableArray *colors = [NSMutableArray new];
|
2015-03-11 02:03:59 +00:00
|
|
|
for (id value in [self NSArray:json]) {
|
|
|
|
[colors addObject:(__bridge id)[self CGColor:value]];
|
|
|
|
}
|
|
|
|
return colors;
|
|
|
|
}
|
|
|
|
|
2015-05-05 12:34:38 +00:00
|
|
|
static id RCTConvertPropertyListValue(id json)
|
|
|
|
{
|
|
|
|
if (!json || json == (id)kCFNull) {
|
|
|
|
return nil;
|
2015-05-06 07:11:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ([json isKindOfClass:[NSDictionary class]]) {
|
2015-05-05 12:34:38 +00:00
|
|
|
__block BOOL copy = NO;
|
|
|
|
NSMutableDictionary *values = [[NSMutableDictionary alloc] initWithCapacity:[json count]];
|
2015-06-15 14:53:45 +00:00
|
|
|
[json enumerateKeysAndObjectsUsingBlock:^(NSString *key, id jsonValue, __unused BOOL *stop) {
|
2015-05-05 12:34:38 +00:00
|
|
|
id value = RCTConvertPropertyListValue(jsonValue);
|
|
|
|
if (value) {
|
|
|
|
values[key] = value;
|
|
|
|
}
|
|
|
|
copy |= value != jsonValue;
|
|
|
|
}];
|
|
|
|
return copy ? values : json;
|
2015-05-06 07:11:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ([json isKindOfClass:[NSArray class]]) {
|
2015-05-05 12:34:38 +00:00
|
|
|
__block BOOL copy = NO;
|
|
|
|
__block NSArray *values = json;
|
2015-06-15 14:53:45 +00:00
|
|
|
[json enumerateObjectsUsingBlock:^(id jsonValue, NSUInteger idx, __unused BOOL *stop) {
|
2015-05-05 12:34:38 +00:00
|
|
|
id value = RCTConvertPropertyListValue(jsonValue);
|
|
|
|
if (copy) {
|
|
|
|
if (value) {
|
|
|
|
[(NSMutableArray *)values addObject:value];
|
|
|
|
}
|
|
|
|
} else if (value != jsonValue) {
|
|
|
|
// Converted value is different, so we'll need to copy the array
|
|
|
|
values = [[NSMutableArray alloc] initWithCapacity:values.count];
|
2015-06-15 14:53:45 +00:00
|
|
|
for (NSUInteger i = 0; i < idx; i++) {
|
2015-05-05 12:34:38 +00:00
|
|
|
[(NSMutableArray *)values addObject:json[i]];
|
|
|
|
}
|
2015-05-06 07:11:31 +00:00
|
|
|
if (value) {
|
|
|
|
[(NSMutableArray *)values addObject:value];
|
|
|
|
}
|
2015-05-05 12:34:38 +00:00
|
|
|
copy = YES;
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
return values;
|
|
|
|
}
|
2015-05-06 07:11:31 +00:00
|
|
|
|
|
|
|
// All other JSON types are supported by property lists
|
|
|
|
return json;
|
2015-05-05 12:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSPropertyList)NSPropertyList:(id)json
|
|
|
|
{
|
|
|
|
return RCTConvertPropertyListValue(json);
|
|
|
|
}
|
|
|
|
|
2015-07-15 00:03:41 +00:00
|
|
|
RCT_ENUM_CONVERTER(css_backface_visibility_t, (@{
|
|
|
|
@"hidden": @NO,
|
|
|
|
@"visible": @YES
|
|
|
|
}), YES, boolValue)
|
|
|
|
|
2016-12-02 13:47:43 +00:00
|
|
|
RCT_ENUM_CONVERTER(YGOverflow, (@{
|
|
|
|
@"hidden": @(YGOverflowHidden),
|
|
|
|
@"visible": @(YGOverflowVisible),
|
|
|
|
@"scroll": @(YGOverflowScroll),
|
|
|
|
}), YGOverflowVisible, intValue)
|
|
|
|
|
2017-03-01 17:12:50 +00:00
|
|
|
RCT_ENUM_CONVERTER(YGDisplay, (@{
|
|
|
|
@"flex": @(YGDisplayFlex),
|
|
|
|
@"none": @(YGDisplayNone),
|
|
|
|
}), YGDisplayFlex, intValue)
|
|
|
|
|
2016-12-02 13:47:43 +00:00
|
|
|
RCT_ENUM_CONVERTER(YGFlexDirection, (@{
|
|
|
|
@"row": @(YGFlexDirectionRow),
|
|
|
|
@"row-reverse": @(YGFlexDirectionRowReverse),
|
|
|
|
@"column": @(YGFlexDirectionColumn),
|
|
|
|
@"column-reverse": @(YGFlexDirectionColumnReverse)
|
|
|
|
}), YGFlexDirectionColumn, intValue)
|
|
|
|
|
|
|
|
RCT_ENUM_CONVERTER(YGJustify, (@{
|
|
|
|
@"flex-start": @(YGJustifyFlexStart),
|
|
|
|
@"flex-end": @(YGJustifyFlexEnd),
|
|
|
|
@"center": @(YGJustifyCenter),
|
|
|
|
@"space-between": @(YGJustifySpaceBetween),
|
2018-01-31 18:03:26 +00:00
|
|
|
@"space-around": @(YGJustifySpaceAround),
|
|
|
|
@"space-evenly": @(YGJustifySpaceEvenly)
|
2016-12-02 13:47:43 +00:00
|
|
|
}), YGJustifyFlexStart, intValue)
|
|
|
|
|
|
|
|
RCT_ENUM_CONVERTER(YGAlign, (@{
|
|
|
|
@"flex-start": @(YGAlignFlexStart),
|
|
|
|
@"flex-end": @(YGAlignFlexEnd),
|
|
|
|
@"center": @(YGAlignCenter),
|
|
|
|
@"auto": @(YGAlignAuto),
|
2017-01-08 12:34:43 +00:00
|
|
|
@"stretch": @(YGAlignStretch),
|
Expose alignContent to react native
Summary:
This diff adds alignContent (https://developer.mozilla.org/en-US/docs/Web/CSS/align-content) support to React Native. This enables aligning the lines of multi-line content. See below playground for example usage.
```
class Playground extends React.Component {
render() {
return (
<View style={{width: '100%', height: '100%', flexDirection: 'row', backgroundColor: 'white', flexWrap: 'wrap', alignContent: 'space-between'}}>
<View style={{width: 100, height: 100, marginLeft: 10, marginTop: 10, backgroundColor: 'red'}}/>
<View style={{width: 100, height: 100, marginLeft: 10, marginTop: 10, backgroundColor: 'red'}}/>
<View style={{width: 100, height: 100, marginLeft: 10, marginTop: 10, backgroundColor: 'red'}}/>
<View style={{width: 100, height: 100, marginLeft: 10, marginTop: 10, backgroundColor: 'red'}}/>
<View style={{width: 100, height: 100, marginLeft: 10, marginTop: 10, backgroundColor: 'red'}}/>
<View style={{width: 100, height: 100, marginLeft: 10, marginTop: 10, backgroundColor: 'red'}}/>
<View style={{width: 100, height: 100, marginLeft: 10, marginTop: 10, backgroundColor: 'red'}}/>
</View>
);
}
}
```
Reviewed By: astreet
Differential Revision: D4611803
fbshipit-source-id: ae7f6b4b7e9f4bc78d2502da948214294aad4dd2
2017-03-01 17:12:48 +00:00
|
|
|
@"baseline": @(YGAlignBaseline),
|
|
|
|
@"space-between": @(YGAlignSpaceBetween),
|
|
|
|
@"space-around": @(YGAlignSpaceAround)
|
2016-12-02 13:47:43 +00:00
|
|
|
}), YGAlignFlexStart, intValue)
|
|
|
|
|
2017-02-07 04:58:23 +00:00
|
|
|
RCT_ENUM_CONVERTER(YGDirection, (@{
|
|
|
|
@"inherit": @(YGDirectionInherit),
|
|
|
|
@"ltr": @(YGDirectionLTR),
|
|
|
|
@"rtl": @(YGDirectionRTL),
|
|
|
|
}), YGDirectionInherit, intValue)
|
|
|
|
|
2016-12-02 13:47:43 +00:00
|
|
|
RCT_ENUM_CONVERTER(YGPositionType, (@{
|
|
|
|
@"absolute": @(YGPositionTypeAbsolute),
|
|
|
|
@"relative": @(YGPositionTypeRelative)
|
|
|
|
}), YGPositionTypeRelative, intValue)
|
|
|
|
|
|
|
|
RCT_ENUM_CONVERTER(YGWrap, (@{
|
|
|
|
@"wrap": @(YGWrapWrap),
|
|
|
|
@"nowrap": @(YGWrapNoWrap)
|
|
|
|
}), YGWrapNoWrap, intValue)
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
RCT_ENUM_CONVERTER(RCTPointerEvents, (@{
|
|
|
|
@"none": @(RCTPointerEventsNone),
|
2015-03-04 22:04:52 +00:00
|
|
|
@"box-only": @(RCTPointerEventsBoxOnly),
|
|
|
|
@"box-none": @(RCTPointerEventsBoxNone),
|
|
|
|
@"auto": @(RCTPointerEventsUnspecified)
|
2015-02-20 04:10:52 +00:00
|
|
|
}), RCTPointerEventsUnspecified, integerValue)
|
|
|
|
|
|
|
|
RCT_ENUM_CONVERTER(RCTAnimationType, (@{
|
|
|
|
@"spring": @(RCTAnimationTypeSpring),
|
|
|
|
@"linear": @(RCTAnimationTypeLinear),
|
|
|
|
@"easeIn": @(RCTAnimationTypeEaseIn),
|
|
|
|
@"easeOut": @(RCTAnimationTypeEaseOut),
|
|
|
|
@"easeInEaseOut": @(RCTAnimationTypeEaseInEaseOut),
|
2015-06-25 16:14:19 +00:00
|
|
|
@"keyboard": @(RCTAnimationTypeKeyboard),
|
2015-02-20 04:10:52 +00:00
|
|
|
}), RCTAnimationTypeEaseInEaseOut, integerValue)
|
|
|
|
|
|
|
|
@end
|
2015-12-08 11:29:08 +00:00
|
|
|
|
|
|
|
@interface RCTImageSource (Packager)
|
|
|
|
|
|
|
|
@property (nonatomic, assign) BOOL packagerAsset;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RCTConvert (Deprecated)
|
|
|
|
|
|
|
|
/* This method is only used when loading images synchronously, e.g. for tabbar icons */
|
|
|
|
+ (UIImage *)UIImage:(id)json
|
|
|
|
{
|
|
|
|
if (!json) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
RCTImageSource *imageSource = [self RCTImageSource:json];
|
|
|
|
if (!imageSource) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
__block UIImage *image;
|
2016-06-06 14:57:55 +00:00
|
|
|
if (!RCTIsMainQueue()) {
|
2015-12-08 11:29:08 +00:00
|
|
|
// It seems that none of the UIImage loading methods can be guaranteed
|
|
|
|
// thread safe, so we'll pick the lesser of two evils here and block rather
|
|
|
|
// than run the risk of crashing
|
|
|
|
RCTLogWarn(@"Calling [RCTConvert UIImage:] on a background thread is not recommended");
|
2017-06-30 13:54:43 +00:00
|
|
|
RCTUnsafeExecuteOnMainQueueSync(^{
|
2015-12-08 11:29:08 +00:00
|
|
|
image = [self UIImage:json];
|
|
|
|
});
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2016-06-01 17:32:20 +00:00
|
|
|
NSURL *URL = imageSource.request.URL;
|
2015-12-08 11:29:08 +00:00
|
|
|
NSString *scheme = URL.scheme.lowercaseString;
|
|
|
|
if ([scheme isEqualToString:@"file"]) {
|
2017-06-30 13:54:43 +00:00
|
|
|
image = RCTImageFromLocalAssetURL(URL);
|
2015-12-08 11:29:08 +00:00
|
|
|
if (!image) {
|
2017-06-30 13:54:43 +00:00
|
|
|
RCTLogConvertError(json, @"an image. File not found.");
|
2015-12-08 11:29:08 +00:00
|
|
|
}
|
|
|
|
} else if ([scheme isEqualToString:@"data"]) {
|
|
|
|
image = [UIImage imageWithData:[NSData dataWithContentsOfURL:URL]];
|
|
|
|
} else if ([scheme isEqualToString:@"http"] && imageSource.packagerAsset) {
|
|
|
|
image = [UIImage imageWithData:[NSData dataWithContentsOfURL:URL]];
|
|
|
|
} else {
|
2016-08-17 11:36:52 +00:00
|
|
|
RCTLogConvertError(json, @"an image. Only local files or data URIs are supported.");
|
|
|
|
return nil;
|
2015-12-08 11:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CGFloat scale = imageSource.scale;
|
|
|
|
if (!scale && imageSource.size.width) {
|
|
|
|
// If no scale provided, set scale to image width / source width
|
|
|
|
scale = CGImageGetWidth(image.CGImage) / imageSource.size.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scale) {
|
|
|
|
image = [UIImage imageWithCGImage:image.CGImage
|
|
|
|
scale:scale
|
|
|
|
orientation:image.imageOrientation];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CGSizeEqualToSize(imageSource.size, CGSizeZero) &&
|
|
|
|
!CGSizeEqualToSize(imageSource.size, image.size)) {
|
2016-05-31 12:18:17 +00:00
|
|
|
RCTLogError(@"Image source %@ size %@ does not match loaded image size %@.",
|
2016-06-01 17:32:20 +00:00
|
|
|
URL.path.lastPathComponent,
|
2016-05-31 12:18:17 +00:00
|
|
|
NSStringFromCGSize(imageSource.size),
|
|
|
|
NSStringFromCGSize(image.size));
|
2015-12-08 11:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (CGImageRef)CGImage:(id)json
|
|
|
|
{
|
|
|
|
return [self UIImage:json].CGImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|