2015-03-23 20:28:42 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
#import <QuartzCore/QuartzCore.h>
|
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
|
2016-11-23 15:47:52 +00:00
|
|
|
#import <React/RCTAnimationType.h>
|
|
|
|
#import <React/RCTBorderStyle.h>
|
|
|
|
#import <React/RCTDefines.h>
|
|
|
|
#import <React/RCTLog.h>
|
|
|
|
#import <React/RCTPointerEvents.h>
|
|
|
|
#import <React/RCTTextDecorationLineType.h>
|
2017-01-11 11:58:03 +00:00
|
|
|
#import <yoga/Yoga.h>
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides a collection of conversion functions for mapping
|
|
|
|
* JSON objects to native types and classes. These are useful when writing
|
|
|
|
* custom RCTViewManager setter methods.
|
|
|
|
*/
|
|
|
|
@interface RCTConvert : NSObject
|
|
|
|
|
2015-06-05 15:46:17 +00:00
|
|
|
+ (id)id:(id)json;
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
+ (BOOL)BOOL:(id)json;
|
|
|
|
+ (double)double:(id)json;
|
|
|
|
+ (float)float:(id)json;
|
|
|
|
+ (int)int:(id)json;
|
|
|
|
|
2015-03-25 00:37:03 +00:00
|
|
|
+ (int64_t)int64_t:(id)json;
|
|
|
|
+ (uint64_t)uint64_t:(id)json;
|
|
|
|
|
2015-03-11 02:03:59 +00:00
|
|
|
+ (NSInteger)NSInteger:(id)json;
|
|
|
|
+ (NSUInteger)NSUInteger:(id)json;
|
|
|
|
|
2015-03-09 10:04:44 +00:00
|
|
|
+ (NSArray *)NSArray:(id)json;
|
|
|
|
+ (NSDictionary *)NSDictionary:(id)json;
|
2015-02-20 04:10:52 +00:00
|
|
|
+ (NSString *)NSString:(id)json;
|
|
|
|
+ (NSNumber *)NSNumber:(id)json;
|
2015-08-13 11:01:06 +00:00
|
|
|
|
|
|
|
+ (NSSet *)NSSet:(id)json;
|
2015-04-10 03:18:31 +00:00
|
|
|
+ (NSData *)NSData:(id)json;
|
2015-05-06 17:46:45 +00:00
|
|
|
+ (NSIndexSet *)NSIndexSet:(id)json;
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2017-01-18 00:58:27 +00:00
|
|
|
+ (NSURLRequestCachePolicy)NSURLRequestCachePolicy:(id)json;
|
2015-02-20 04:10:52 +00:00
|
|
|
+ (NSURL *)NSURL:(id)json;
|
|
|
|
+ (NSURLRequest *)NSURLRequest:(id)json;
|
|
|
|
|
2015-06-23 12:17:36 +00:00
|
|
|
typedef NSURL RCTFileURL;
|
|
|
|
+ (RCTFileURL *)RCTFileURL:(id)json;
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
+ (NSDate *)NSDate:(id)json;
|
|
|
|
+ (NSTimeZone *)NSTimeZone:(id)json;
|
|
|
|
+ (NSTimeInterval)NSTimeInterval:(id)json;
|
|
|
|
|
2015-10-27 10:39:10 +00:00
|
|
|
+ (NSLineBreakMode)NSLineBreakMode:(id)json;
|
2015-02-20 04:10:52 +00:00
|
|
|
+ (NSTextAlignment)NSTextAlignment:(id)json;
|
2015-07-07 13:03:56 +00:00
|
|
|
+ (NSUnderlineStyle)NSUnderlineStyle:(id)json;
|
2015-02-20 04:10:52 +00:00
|
|
|
+ (NSWritingDirection)NSWritingDirection:(id)json;
|
2015-03-17 14:04:39 +00:00
|
|
|
+ (UITextAutocapitalizationType)UITextAutocapitalizationType:(id)json;
|
2015-03-26 04:29:28 +00:00
|
|
|
+ (UITextFieldViewMode)UITextFieldViewMode:(id)json;
|
2015-02-20 04:10:52 +00:00
|
|
|
+ (UIKeyboardType)UIKeyboardType:(id)json;
|
2015-11-11 13:31:18 +00:00
|
|
|
+ (UIKeyboardAppearance)UIKeyboardAppearance:(id)json;
|
2015-03-31 01:25:30 +00:00
|
|
|
+ (UIReturnKeyType)UIReturnKeyType:(id)json;
|
2016-09-27 13:19:45 +00:00
|
|
|
#if !TARGET_OS_TV
|
2016-07-13 21:31:43 +00:00
|
|
|
+ (UIDataDetectorTypes)UIDataDetectorTypes:(id)json;
|
2016-09-27 13:19:45 +00:00
|
|
|
#endif
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-03-26 04:29:28 +00:00
|
|
|
+ (UIViewContentMode)UIViewContentMode:(id)json;
|
2016-09-27 13:19:45 +00:00
|
|
|
#if !TARGET_OS_TV
|
2015-03-26 04:29:28 +00:00
|
|
|
+ (UIBarStyle)UIBarStyle:(id)json;
|
2016-09-27 13:19:45 +00:00
|
|
|
#endif
|
2015-03-26 04:29:28 +00:00
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
+ (CGFloat)CGFloat:(id)json;
|
|
|
|
+ (CGPoint)CGPoint:(id)json;
|
|
|
|
+ (CGSize)CGSize:(id)json;
|
|
|
|
+ (CGRect)CGRect:(id)json;
|
|
|
|
+ (UIEdgeInsets)UIEdgeInsets:(id)json;
|
|
|
|
|
2015-03-15 23:08:42 +00:00
|
|
|
+ (CGLineCap)CGLineCap:(id)json;
|
|
|
|
+ (CGLineJoin)CGLineJoin:(id)json;
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
+ (CGAffineTransform)CGAffineTransform:(id)json;
|
|
|
|
|
|
|
|
+ (UIColor *)UIColor:(id)json;
|
2015-08-24 10:14:33 +00:00
|
|
|
+ (CGColorRef)CGColor:(id)json CF_RETURNS_NOT_RETAINED;
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2017-01-11 11:58:03 +00:00
|
|
|
+ (YGValue)YGValue:(id)json;
|
|
|
|
|
2015-11-03 22:45:46 +00:00
|
|
|
+ (NSArray<NSArray *> *)NSArrayArray:(id)json;
|
|
|
|
+ (NSArray<NSString *> *)NSStringArray:(id)json;
|
|
|
|
+ (NSArray<NSArray<NSString *> *> *)NSStringArrayArray:(id)json;
|
|
|
|
+ (NSArray<NSDictionary *> *)NSDictionaryArray:(id)json;
|
|
|
|
+ (NSArray<NSURL *> *)NSURLArray:(id)json;
|
2015-12-10 18:09:04 +00:00
|
|
|
+ (NSArray<RCTFileURL *> *)RCTFileURLArray:(id)json;
|
2015-11-03 22:45:46 +00:00
|
|
|
+ (NSArray<NSNumber *> *)NSNumberArray:(id)json;
|
|
|
|
+ (NSArray<UIColor *> *)UIColorArray:(id)json;
|
2015-04-08 15:52:48 +00:00
|
|
|
|
|
|
|
typedef NSArray CGColorArray;
|
|
|
|
+ (CGColorArray *)CGColorArray:(id)json;
|
|
|
|
|
2015-05-05 12:34:38 +00:00
|
|
|
/**
|
|
|
|
* Convert a JSON object to a Plist-safe equivalent by stripping null values.
|
|
|
|
*/
|
|
|
|
typedef id NSPropertyList;
|
|
|
|
+ (NSPropertyList)NSPropertyList:(id)json;
|
|
|
|
|
2016-08-30 07:58:15 +00:00
|
|
|
typedef BOOL css_backface_visibility_t;
|
2016-12-02 13:47:43 +00:00
|
|
|
+ (YGOverflow)YGOverflow:(id)json;
|
2017-03-01 17:12:50 +00:00
|
|
|
+ (YGDisplay)YGDisplay:(id)json;
|
2015-07-15 00:03:41 +00:00
|
|
|
+ (css_backface_visibility_t)css_backface_visibility_t:(id)json;
|
2016-12-02 13:47:43 +00:00
|
|
|
+ (YGFlexDirection)YGFlexDirection:(id)json;
|
|
|
|
+ (YGJustify)YGJustify:(id)json;
|
|
|
|
+ (YGAlign)YGAlign:(id)json;
|
|
|
|
+ (YGPositionType)YGPositionType:(id)json;
|
|
|
|
+ (YGWrap)YGWrap:(id)json;
|
2017-02-07 04:58:23 +00:00
|
|
|
+ (YGDirection)YGDirection:(id)json;
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
+ (RCTPointerEvents)RCTPointerEvents:(id)json;
|
|
|
|
+ (RCTAnimationType)RCTAnimationType:(id)json;
|
2015-12-01 15:41:20 +00:00
|
|
|
+ (RCTBorderStyle)RCTBorderStyle:(id)json;
|
2015-07-07 13:03:56 +00:00
|
|
|
+ (RCTTextDecorationLineType)RCTTextDecorationLineType:(id)json;
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2015-12-08 11:29:08 +00:00
|
|
|
@interface RCTConvert (Deprecated)
|
|
|
|
|
2015-12-10 18:09:04 +00:00
|
|
|
/**
|
|
|
|
* Use lightweight generics syntax instead, e.g. NSArray<NSString *>
|
|
|
|
*/
|
|
|
|
typedef NSArray NSArrayArray __deprecated_msg("Use NSArray<NSArray *>");
|
|
|
|
typedef NSArray NSStringArray __deprecated_msg("Use NSArray<NSString *>");
|
|
|
|
typedef NSArray NSStringArrayArray __deprecated_msg("Use NSArray<NSArray<NSString *> *>");
|
|
|
|
typedef NSArray NSDictionaryArray __deprecated_msg("Use NSArray<NSDictionary *>");
|
|
|
|
typedef NSArray NSURLArray __deprecated_msg("Use NSArray<NSURL *>");
|
|
|
|
typedef NSArray RCTFileURLArray __deprecated_msg("Use NSArray<RCTFileURL *>");
|
|
|
|
typedef NSArray NSNumberArray __deprecated_msg("Use NSArray<NSNumber *>");
|
|
|
|
typedef NSArray UIColorArray __deprecated_msg("Use NSArray<UIColor *>");
|
|
|
|
|
2015-12-08 11:29:08 +00:00
|
|
|
/**
|
|
|
|
* Synchronous image loading is generally a bad idea for performance reasons.
|
|
|
|
* If you need to pass image references, try to use `RCTImageSource` and then
|
|
|
|
* `RCTImageLoader` instead of converting directly to a UIImage.
|
|
|
|
*/
|
|
|
|
+ (UIImage *)UIImage:(id)json;
|
|
|
|
+ (CGImageRef)CGImage:(id)json CF_RETURNS_NOT_RETAINED;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
[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
|
|
|
/**
|
2015-04-21 16:48:29 +00:00
|
|
|
* Underlying implementations of RCT_XXX_CONVERTER macros. Ignore these.
|
[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
|
|
|
*/
|
2015-04-21 12:26:51 +00:00
|
|
|
RCT_EXTERN NSNumber *RCTConvertEnumValue(const char *, NSDictionary *, NSNumber *, id);
|
2015-05-18 14:32:21 +00:00
|
|
|
RCT_EXTERN NSNumber *RCTConvertMultiEnumValue(const char *, NSDictionary *, NSNumber *, id);
|
2015-04-21 16:48:29 +00:00
|
|
|
RCT_EXTERN NSArray *RCTConvertArrayValue(SEL, id);
|
2015-08-10 14:03:52 +00:00
|
|
|
|
2015-12-10 18:09:04 +00:00
|
|
|
/**
|
|
|
|
* Get the converter function for the specified type
|
|
|
|
*/
|
|
|
|
RCT_EXTERN SEL RCTConvertSelectorForType(NSString *type);
|
|
|
|
|
2015-08-10 14:03:52 +00:00
|
|
|
/**
|
|
|
|
* This macro is used for logging conversion errors. This is just used to
|
|
|
|
* avoid repeating the same boilerplate for every error message.
|
|
|
|
*/
|
|
|
|
#define RCTLogConvertError(json, typeName) \
|
|
|
|
RCTLogError(@"JSON value '%@' of type %@ cannot be converted to %@", \
|
|
|
|
json, [json classForCoder], typeName)
|
2015-03-15 23:08:42 +00:00
|
|
|
|
2015-03-30 13:07:07 +00:00
|
|
|
/**
|
|
|
|
* This macro is used for creating simple converter functions that just call
|
|
|
|
* the specified getter method on the json value.
|
|
|
|
*/
|
|
|
|
#define RCT_CONVERTER(type, name, getter) \
|
|
|
|
RCT_CUSTOM_CONVERTER(type, name, [json getter])
|
|
|
|
|
2015-03-15 23:08:42 +00:00
|
|
|
/**
|
|
|
|
* This macro is used for creating converter functions with arbitrary logic.
|
|
|
|
*/
|
2015-03-30 13:07:07 +00:00
|
|
|
#define RCT_CUSTOM_CONVERTER(type, name, code) \
|
2015-03-15 23:08:42 +00:00
|
|
|
+ (type)name:(id)json \
|
|
|
|
{ \
|
2015-04-21 16:48:29 +00:00
|
|
|
if (!RCT_DEBUG) { \
|
2015-03-15 23:08:42 +00:00
|
|
|
return code; \
|
2015-04-21 16:48:29 +00:00
|
|
|
} else { \
|
|
|
|
@try { \
|
|
|
|
return code; \
|
|
|
|
} \
|
|
|
|
@catch (__unused NSException *e) { \
|
2015-08-10 14:03:52 +00:00
|
|
|
RCTLogConvertError(json, @#type); \
|
2015-04-21 16:48:29 +00:00
|
|
|
json = nil; \
|
|
|
|
return code; \
|
|
|
|
} \
|
2015-03-15 23:08:42 +00:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2015-03-25 00:37:03 +00:00
|
|
|
/**
|
|
|
|
* This macro is similar to RCT_CONVERTER, but specifically geared towards
|
|
|
|
* numeric types. It will handle string input correctly, and provides more
|
[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
|
|
|
* detailed error reporting if an invalid value is passed in.
|
2015-03-25 00:37:03 +00:00
|
|
|
*/
|
|
|
|
#define RCT_NUMBER_CONVERTER(type, getter) \
|
2015-08-13 11:01:06 +00:00
|
|
|
RCT_CUSTOM_CONVERTER(type, type, [RCT_DEBUG ? [self NSNumber:json] : json getter])
|
2015-03-25 00:37:03 +00:00
|
|
|
|
2015-03-15 23:08:42 +00:00
|
|
|
/**
|
|
|
|
* This macro is used for creating converters for enum types.
|
|
|
|
*/
|
|
|
|
#define RCT_ENUM_CONVERTER(type, values, default, getter) \
|
|
|
|
+ (type)type:(id)json \
|
|
|
|
{ \
|
|
|
|
static NSDictionary *mapping; \
|
|
|
|
static dispatch_once_t onceToken; \
|
|
|
|
dispatch_once(&onceToken, ^{ \
|
|
|
|
mapping = values; \
|
|
|
|
}); \
|
2015-04-21 22:08:20 +00:00
|
|
|
return [RCTConvertEnumValue(#type, mapping, @(default), json) getter]; \
|
2015-03-15 23:08:42 +00:00
|
|
|
}
|
|
|
|
|
2015-05-18 14:32:21 +00:00
|
|
|
/**
|
|
|
|
* This macro is used for creating converters for enum types for
|
|
|
|
* multiple enum values combined with | operator
|
|
|
|
*/
|
|
|
|
#define RCT_MULTI_ENUM_CONVERTER(type, values, default, getter) \
|
|
|
|
+ (type)type:(id)json \
|
|
|
|
{ \
|
|
|
|
static NSDictionary *mapping; \
|
|
|
|
static dispatch_once_t onceToken; \
|
|
|
|
dispatch_once(&onceToken, ^{ \
|
|
|
|
mapping = values; \
|
|
|
|
}); \
|
|
|
|
return [RCTConvertMultiEnumValue(#type, mapping, @(default), json) getter]; \
|
|
|
|
}
|
|
|
|
|
2015-03-15 23:08:42 +00:00
|
|
|
/**
|
2017-01-27 21:33:59 +00:00
|
|
|
* This macro is used for creating explicitly-named converter functions
|
|
|
|
* for typed arrays.
|
2015-03-15 23:08:42 +00:00
|
|
|
*/
|
2017-01-27 21:33:59 +00:00
|
|
|
#define RCT_ARRAY_CONVERTER_NAMED(type, name) \
|
|
|
|
+ (NSArray<type *> *)name##Array:(id)json \
|
2015-04-21 16:48:29 +00:00
|
|
|
{ \
|
2017-01-27 21:33:59 +00:00
|
|
|
return RCTConvertArrayValue(@selector(name:), json); \
|
2015-03-15 23:08:42 +00:00
|
|
|
}
|
2017-01-27 21:33:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This macro is used for creating converter functions for typed arrays.
|
|
|
|
* RCT_ARRAY_CONVERTER_NAMED may be used when type contains characters
|
|
|
|
* which are disallowed in selector names.
|
|
|
|
*/
|
|
|
|
#define RCT_ARRAY_CONVERTER(type) RCT_ARRAY_CONVERTER_NAMED(type, type)
|