2015-03-23 20:28:42 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2015-03-23 20:28:42 +00:00
|
|
|
*
|
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
|
|
|
|
2015-03-01 23:33:55 +00:00
|
|
|
#import <tgmath.h>
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
#import <CoreGraphics/CoreGraphics.h>
|
|
|
|
#import <Foundation/Foundation.h>
|
2015-09-22 17:43:56 +00:00
|
|
|
#import <UIKit/UIKit.h>
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2016-11-23 15:47:52 +00:00
|
|
|
#import <React/RCTAssert.h>
|
|
|
|
#import <React/RCTDefines.h>
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2016-01-21 15:49:45 +00:00
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
2015-07-16 16:34:28 +00:00
|
|
|
// JSON serialization/deserialization
|
2016-01-21 15:49:45 +00:00
|
|
|
RCT_EXTERN NSString *__nullable RCTJSONStringify(id __nullable jsonObject, NSError **error);
|
|
|
|
RCT_EXTERN id __nullable RCTJSONParse(NSString *__nullable jsonString, NSError **error);
|
|
|
|
RCT_EXTERN id __nullable RCTJSONParseMutable(NSString *__nullable jsonString, NSError **error);
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2016-02-09 13:45:23 +00:00
|
|
|
// Sanitize a JSON object by stripping invalid types and/or NaN values
|
2015-05-06 07:11:31 +00:00
|
|
|
RCT_EXTERN id RCTJSONClean(id object);
|
|
|
|
|
2015-07-16 16:34:28 +00:00
|
|
|
// Get MD5 hash of a string
|
2015-04-21 12:26:51 +00:00
|
|
|
RCT_EXTERN NSString *RCTMD5Hash(NSString *string);
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2017-01-11 07:01:07 +00:00
|
|
|
// Check if we are currently on the main queue (not to be confused with
|
2018-01-13 06:03:51 +00:00
|
|
|
// the main thread, which is not necessarily the same thing)
|
2016-06-06 14:57:55 +00:00
|
|
|
// https://twitter.com/olebegemann/status/738656134731599872
|
|
|
|
RCT_EXTERN BOOL RCTIsMainQueue(void);
|
|
|
|
|
|
|
|
// Execute the specified block on the main queue. Unlike dispatch_async()
|
|
|
|
// this will execute immediately if we're already on the main queue.
|
|
|
|
RCT_EXTERN void RCTExecuteOnMainQueue(dispatch_block_t block);
|
|
|
|
|
2017-01-11 07:01:07 +00:00
|
|
|
// Legacy function to execute the specified block on the main queue synchronously.
|
|
|
|
// Please do not use this unless you know what you're doing.
|
|
|
|
RCT_EXTERN void RCTUnsafeExecuteOnMainQueueSync(dispatch_block_t block);
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
// Get screen metrics in a thread-safe way
|
2015-04-21 12:26:51 +00:00
|
|
|
RCT_EXTERN CGFloat RCTScreenScale(void);
|
|
|
|
RCT_EXTERN CGSize RCTScreenSize(void);
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
// Round float coordinates to nearest whole screen pixel (not point)
|
2015-04-21 12:26:51 +00:00
|
|
|
RCT_EXTERN CGFloat RCTRoundPixelValue(CGFloat value);
|
|
|
|
RCT_EXTERN CGFloat RCTCeilPixelValue(CGFloat value);
|
|
|
|
RCT_EXTERN CGFloat RCTFloorPixelValue(CGFloat value);
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2016-01-20 19:03:22 +00:00
|
|
|
// Convert a size in points to pixels, rounded up to the nearest integral size
|
|
|
|
RCT_EXTERN CGSize RCTSizeInPixels(CGSize pointSize, CGFloat scale);
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
// Method swizzling
|
2015-04-21 12:26:51 +00:00
|
|
|
RCT_EXTERN void RCTSwapClassMethods(Class cls, SEL original, SEL replacement);
|
|
|
|
RCT_EXTERN void RCTSwapInstanceMethods(Class cls, SEL original, SEL replacement);
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
// Module subclass support
|
2015-04-21 12:26:51 +00:00
|
|
|
RCT_EXTERN BOOL RCTClassOverridesClassMethod(Class cls, SEL selector);
|
|
|
|
RCT_EXTERN BOOL RCTClassOverridesInstanceMethod(Class cls, SEL selector);
|
2015-03-01 23:33:55 +00:00
|
|
|
|
2016-01-21 15:49:45 +00:00
|
|
|
// Creates a standardized error object to return in callbacks
|
|
|
|
RCT_EXTERN NSDictionary<NSString *, id> *RCTMakeError(NSString *message, id __nullable toStringify, NSDictionary<NSString *, id> *__nullable extraData);
|
|
|
|
RCT_EXTERN NSDictionary<NSString *, id> *RCTMakeAndLogError(NSString *message, id __nullable toStringify, NSDictionary<NSString *, id> *__nullable extraData);
|
2015-11-14 18:25:00 +00:00
|
|
|
RCT_EXTERN NSDictionary<NSString *, id> *RCTJSErrorFromNSError(NSError *error);
|
2016-01-21 15:49:45 +00:00
|
|
|
RCT_EXTERN NSDictionary<NSString *, id> *RCTJSErrorFromCodeMessageAndNSError(NSString *code, NSString *message, NSError *__nullable error);
|
2016-01-19 20:19:47 +00:00
|
|
|
|
2016-01-21 15:49:45 +00:00
|
|
|
// The default error code to use as the `code` property for callback error objects
|
2016-01-19 20:19:47 +00:00
|
|
|
RCT_EXTERN NSString *const RCTErrorUnspecified;
|
2015-04-27 10:50:07 +00:00
|
|
|
|
|
|
|
// Returns YES if React is running in a test environment
|
|
|
|
RCT_EXTERN BOOL RCTRunningInTestEnvironment(void);
|
2015-05-22 14:17:08 +00:00
|
|
|
|
2015-09-22 17:43:56 +00:00
|
|
|
// Returns YES if React is running in an iOS App Extension
|
|
|
|
RCT_EXTERN BOOL RCTRunningInAppExtension(void);
|
|
|
|
|
|
|
|
// Returns the shared UIApplication instance, or nil if running in an App Extension
|
2016-01-21 15:49:45 +00:00
|
|
|
RCT_EXTERN UIApplication *__nullable RCTSharedApplication(void);
|
2015-09-22 17:43:56 +00:00
|
|
|
|
2015-11-05 11:49:41 +00:00
|
|
|
// Returns the current main window, useful if you need to access the root view
|
2016-05-21 00:03:34 +00:00
|
|
|
// or view controller
|
2016-01-21 15:49:45 +00:00
|
|
|
RCT_EXTERN UIWindow *__nullable RCTKeyWindow(void);
|
2015-11-05 11:49:41 +00:00
|
|
|
|
2016-05-21 00:03:34 +00:00
|
|
|
// Returns the presented view controller, useful if you need
|
|
|
|
// e.g. to present a modal view controller or alert over it
|
|
|
|
RCT_EXTERN UIViewController *__nullable RCTPresentedViewController(void);
|
|
|
|
|
2016-01-27 17:04:14 +00:00
|
|
|
// Does this device support force touch (aka 3D Touch)?
|
|
|
|
RCT_EXTERN BOOL RCTForceTouchAvailable(void);
|
|
|
|
|
2015-07-07 15:47:23 +00:00
|
|
|
// Create an NSError in the RCTErrorDomain
|
2015-06-09 19:25:24 +00:00
|
|
|
RCT_EXTERN NSError *RCTErrorWithMessage(NSString *message);
|
|
|
|
|
|
|
|
// Convert nil values to NSNull, and vice-versa
|
2016-09-05 14:32:20 +00:00
|
|
|
#define RCTNullIfNil(value) (value ?: (id)kCFNull)
|
2017-08-09 10:16:31 +00:00
|
|
|
#define RCTNilIfNull(value) \
|
|
|
|
({ __typeof__(value) t = (value); (id)t == (id)kCFNull ? (__typeof(value))nil : t; })
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-11-26 11:04:33 +00:00
|
|
|
// Convert NaN or infinite values to zero, as these aren't JSON-safe
|
|
|
|
RCT_EXTERN double RCTZeroIfNaN(double value);
|
|
|
|
|
2017-04-21 18:25:31 +00:00
|
|
|
// Returns `0` and log special warning if value is NaN or INF.
|
|
|
|
RCT_EXTERN double RCTSanitizeNaNValue(double value, NSString *property);
|
|
|
|
|
2015-07-13 17:33:39 +00:00
|
|
|
// Convert data to a Base64-encoded data URL
|
|
|
|
RCT_EXTERN NSURL *RCTDataURL(NSString *mimeType, NSData *data);
|
2015-07-16 16:34:28 +00:00
|
|
|
|
|
|
|
// Gzip functionality - compression level in range 0 - 1 (-1 for default)
|
2016-01-22 16:39:44 +00:00
|
|
|
RCT_EXTERN NSData *__nullable RCTGzipData(NSData *__nullable data, float level);
|
2015-10-12 11:14:21 +00:00
|
|
|
|
|
|
|
// Returns the relative path within the main bundle for an absolute URL
|
|
|
|
// (or nil, if the URL does not specify a path within the main bundle)
|
2016-01-21 15:49:45 +00:00
|
|
|
RCT_EXTERN NSString *__nullable RCTBundlePathForURL(NSURL *__nullable URL);
|
2015-10-12 11:14:21 +00:00
|
|
|
|
2017-12-14 22:23:35 +00:00
|
|
|
// Returns the Path of Library directory
|
|
|
|
RCT_EXTERN NSString *__nullable RCTLibraryPath(void);
|
|
|
|
|
|
|
|
// Returns the relative path within the library for an absolute URL
|
|
|
|
// (or nil, if the URL does not specify a path within the Library directory)
|
|
|
|
RCT_EXTERN NSString *__nullable RCTLibraryPathForURL(NSURL *__nullable URL);
|
|
|
|
|
|
|
|
// Determines if a given image URL refers to a image in bundle
|
|
|
|
RCT_EXTERN BOOL RCTIsBundleAssetURL(NSURL *__nullable imageURL);
|
|
|
|
|
|
|
|
// Determines if a given image URL refers to a image in library
|
|
|
|
RCT_EXTERN BOOL RCTIsLibraryAssetURL(NSURL *__nullable imageURL);
|
|
|
|
|
2016-07-21 14:45:54 +00:00
|
|
|
// Determines if a given image URL refers to a local image
|
|
|
|
RCT_EXTERN BOOL RCTIsLocalAssetURL(NSURL *__nullable imageURL);
|
2015-11-26 11:04:33 +00:00
|
|
|
|
2017-03-17 23:47:58 +00:00
|
|
|
// Returns an UIImage for a local image asset. Returns nil if the URL
|
|
|
|
// does not correspond to a local asset.
|
2017-03-23 18:25:28 +00:00
|
|
|
RCT_EXTERN UIImage *__nullable RCTImageFromLocalAssetURL(NSURL *imageURL);
|
2017-03-17 23:47:58 +00:00
|
|
|
|
2016-02-23 10:26:11 +00:00
|
|
|
// Creates a new, unique temporary file path with the specified extension
|
|
|
|
RCT_EXTERN NSString *__nullable RCTTempFilePath(NSString *__nullable extension, NSError **error);
|
|
|
|
|
2015-11-26 11:04:33 +00:00
|
|
|
// Converts a CGColor to a hex string
|
|
|
|
RCT_EXTERN NSString *RCTColorToHexString(CGColorRef color);
|
2015-12-01 02:44:06 +00:00
|
|
|
|
|
|
|
// Get standard localized string (if it exists)
|
|
|
|
RCT_EXTERN NSString *RCTUIKitLocalizedString(NSString *string);
|
2016-01-04 18:39:07 +00:00
|
|
|
|
|
|
|
// URL manipulation
|
2016-01-21 15:49:45 +00:00
|
|
|
RCT_EXTERN NSString *__nullable RCTGetURLQueryParam(NSURL *__nullable URL, NSString *param);
|
|
|
|
RCT_EXTERN NSURL *__nullable RCTURLByReplacingQueryParam(NSURL *__nullable URL, NSString *param, NSString *__nullable value);
|
|
|
|
|
2018-10-26 18:46:45 +00:00
|
|
|
// Given a string, drop common RN prefixes (RCT, RK, etc.)
|
|
|
|
RCT_EXTERN NSString *RCTDropReactPrefixes(NSString *s);
|
|
|
|
|
2016-01-21 15:49:45 +00:00
|
|
|
NS_ASSUME_NONNULL_END
|